-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove public_private contract. * Add send_note util. * Add claim note.
- Loading branch information
Showing
21 changed files
with
427 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
yarn-project/noir-contracts/src/contracts/non_native_token_contract/src/hash.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use dep::std::hash::sha256; | ||
|
||
// Computes a content hash of a deposit/mint message. | ||
fn get_mint_content_hash(amount: Field, owner_address: Field, canceller: Field) -> pub Field { | ||
let mut hash_bytes: [u8; 100] = [0; 100]; | ||
let amount_bytes = amount.to_be_bytes(32); | ||
let recipient_bytes = owner_address.to_be_bytes(32); | ||
let canceller_bytes = canceller.to_be_bytes(32); | ||
|
||
for i in 0..32 { | ||
hash_bytes[i + 4] = amount_bytes[i]; | ||
hash_bytes[i + 36] = recipient_bytes[i]; | ||
hash_bytes[i + 68] = canceller_bytes[i]; | ||
} | ||
|
||
// Function selector: 0xeeb73071 keccak256('mint(uint256,bytes32,address)') | ||
hash_bytes[0] = 0xee; | ||
hash_bytes[1] = 0xb7; | ||
hash_bytes[2] = 0x30; | ||
hash_bytes[3] = 0x71; | ||
|
||
let content_sha256 = sha256(hash_bytes); | ||
|
||
// // Convert the content_sha256 to a field element | ||
let mut v = 1; | ||
let mut high = 0 as Field; | ||
let mut low = 0 as Field; | ||
|
||
for i in 0..16 { | ||
high = high + (content_sha256[15 - i] as Field) * v; | ||
low = low + (content_sha256[16 + 15 - i] as Field) * v; | ||
v = v * 256; | ||
} | ||
|
||
// Abuse that a % p + b % p = (a + b) % p and that low < p | ||
let content_hash = low + high * v; | ||
content_hash | ||
} | ||
|
||
// Computes a content hash of a withdraw message. | ||
fn get_withdraw_content_hash(amount: Field, recipient: Field, callerOnL1: Field) -> pub Field { | ||
// Compute the content hash | ||
// Compute sha256(selector || amount || recipient) | ||
// then convert to a single field element | ||
// add that to the l2 to l1 messages | ||
let mut hash_bytes: [u8; 100] = [0; 100]; | ||
let amount_bytes = amount.to_be_bytes(32); | ||
let recipient_bytes = recipient.to_be_bytes(32); | ||
let callerOnL1_bytes = callerOnL1.to_be_bytes(32); | ||
|
||
// 0xb460af94, selector for "withdraw(uint256,address,address)" | ||
hash_bytes[0] = 0xb4; | ||
hash_bytes[1] = 0x60; | ||
hash_bytes[2] = 0xaf; | ||
hash_bytes[3] = 0x94; | ||
|
||
for i in 0..32 { | ||
hash_bytes[i + 4] = amount_bytes[i]; | ||
hash_bytes[i + 36] = recipient_bytes[i]; | ||
hash_bytes[i + 68] = callerOnL1_bytes[i]; | ||
} | ||
let content_sha256 = sha256(hash_bytes); | ||
|
||
// Convert the content_sha256 to a field element | ||
let mut v = 1; | ||
let mut high = 0 as Field; | ||
let mut low = 0 as Field; | ||
|
||
for i in 0..16 { | ||
high = high + (content_sha256[15 - i] as Field) * v; | ||
low = low + (content_sha256[16 + 15 - i] as Field) * v; | ||
v = v * 256; | ||
} | ||
|
||
// Abuse that a % p + b % p = (a + b) % p and that low < p | ||
let content = low + high * v; | ||
content | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
yarn-project/noir-contracts/src/contracts/public_private_contract/Nargo.toml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.