feat(token portal standard): Create a token portal standard#2351
feat(token portal standard): Create a token portal standard#2351rahul-kothari merged 6 commits intomasterfrom
Conversation
b3ca162 to
978ce04
Compare
|
|
||
| // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly | ||
| #[aztec(public)] | ||
| fn deposit_public( |
There was a problem hiding this comment.
The naming with deposit and withdraw can make it quite hard to figure out the direction. Like, am I depositing into L1 from this contract, or am I depositing into L2 using a prior deposit.
Think it would make sense to make it a bit more clear that this is the second part of a deposit as well.
Withdraw might become withdrawToL1 or exitToL1 or the like, and deposits becoming a claim of funds?
| ) -> Field { | ||
| let storage = Storage::init(Context::public(&mut context)); | ||
|
|
||
| let content_hash = get_mint_content_hash(amount, context.msg_sender(), canceller.address); |
There was a problem hiding this comment.
There should be two different content_hashes, one for public and one for private. Say you do:
bytes32 content = sha256ToField(
abi.encodeWithSelector(
"mint_public(bytes32,uint256,address)",
to,
amount,
canceller
);And then a separate
bytes32 content = sha256ToField(
abi.encodeWithSelector(
"mint_private(uint256,bytes32,address)",
amount,
secretHash,
canceller
);With these two, you will be unambigious on what you are calling. Also, it is easier for you to let someone else perform the deposit action on L2 on your behalf without, in private use the to that was part of the content, and for public use the secretHash for the secretHash that is used when minting the asset.
There was a problem hiding this comment.
Note that this require two flows on the L1 contract as well.
For withdrawals, you can get away with just having one content hash function, as you cannot consume it in private or public when on L1, so no need for both options.
|
|
||
| // This way, user hashes their secret in private and only sends the hash in public | ||
| // meaning only user can `redeem_shield` at a later time with their secret. | ||
| #[aztec(public)] |
There was a problem hiding this comment.
Could be fine to add a comment in here that you are doing this as a public call because you need to read from public storage.
| fn withdraw_private( | ||
| token: AztecAddress, | ||
| amount: Field, | ||
| recipient: EthereumAddress, // ethereum address to withdraw to |
There was a problem hiding this comment.
Good use of the types, makes it easier to spot if things make sense instead of Fields all over the place.
| nonce: Field, | ||
| ) -> Field { | ||
| // Burn tokens | ||
| Token::at(token.address).burn(&mut context, context.msg_sender(), amount, nonce); |
There was a problem hiding this comment.
This could potentially be used to perform a re-entry before you are altering any of your local state. Should be moved to the bottom of the function to not allow it to influence much.
Note that, yes this is doing a public call, but it is not super clear from here, so better just follow checks-effects-interactions
| hash_bytes[i + 68] = canceller_bytes[i]; | ||
| } | ||
|
|
||
| // Function selector: 0xeeb73071 keccak256('mint(uint256,bytes32,address)') |
There was a problem hiding this comment.
Remember to alter these with the changes higher up.
| types::type_serialisation::field_serialisation::{ | ||
| FieldSerialisationMethods, FIELD_SERIALISED_LEN, | ||
| }, | ||
| types::address::{AztecAddress}, |
| } | ||
|
|
||
| impl EthereumAddress { | ||
| fn new(address: Field) -> Self { |
There was a problem hiding this comment.
To be pedantic, we should probably constrain this to throw an error when using >160 bits. Can be constrained similarly to the SafeU120 just with more bits
8ff0425 to
8bab903
Compare
LHerskind
left a comment
There was a problem hiding this comment.
Some nits but looks pretty nice 👍
yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr
Outdated
Show resolved
Hide resolved
yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr
Outdated
Show resolved
Hide resolved
yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr
Show resolved
Hide resolved
8bab903 to
16a3b94
Compare
16a3b94 to
e9e07ac
Compare
| #[aztec(private)] | ||
| fn exit_to_l1_private( | ||
| recipient: EthereumAddress, // ethereum address to withdraw to | ||
| token: AztecAddress, |
There was a problem hiding this comment.
The token here is only really used for validation in here while the rest are passed into the hash. So I would prefer that we had that closer to the end, such that the tree values put into the hash are in a row, but practically don't matter. Should probably get a style-guide going for this kind of thing.
LHerskind
left a comment
There was a problem hiding this comment.
I'm ok with this as is. Had a minor comment on style, but probably better for us to do a style guide for that as well 🤷
🤖 I have created a release *beep* *boop* --- <details><summary>aztec-packages: 0.7.10</summary> ## [0.7.10](aztec-packages-v0.7.9...aztec-packages-v0.7.10) (2023-09-20) ### Features * Aztec-cli unbox "really empty box" ([#2388](#2388)) ([b57182d](b57182d)) * **docs:** Document noir macros ([#2016](#2016)) ([1f1a17f](1f1a17f)) * **docs:** Include aztec rpc interface typedoc output in docs ([#2255](#2255)) ([62c9e9b](62c9e9b)) * **token portal standard:** Create a token portal standard ([#2351](#2351)) ([426a3ea](426a3ea)) ### Bug Fixes * **build:** Fix build system post deployment tests ([#2420](#2420)) ([d509dc3](d509dc3)) * CLI encoding for arrays and structs ([#2407](#2407)) ([85283bd](85283bd)) * Correct sandbox addresses in up-quick-start test ([#2412](#2412)) ([974d859](974d859)) * **docs:** Revert include aztec rpc interface typedoc output in docs ([#2255](#2255)) ([f852432](f852432)) * Handle falsy bigints in json-rpc ([#2403](#2403)) ([d100650](d100650)), closes [#2402](#2402) * **nargo_check.sh:** UNIX standard grep ([#2396](#2396)) ([02e788a](02e788a)) ### Miscellaneous * **docs:** Note getter options ([#2411](#2411)) ([8a95d8c](8a95d8c)) * Update docs url in config ([#2386](#2386)) ([e44066d](e44066d)) </details> <details><summary>barretenberg.js: 0.7.10</summary> ## [0.7.10](barretenberg.js-v0.7.9...barretenberg.js-v0.7.10) (2023-09-20) ### Miscellaneous * **barretenberg.js:** Synchronize aztec-packages versions </details> <details><summary>barretenberg: 0.7.10</summary> ## [0.7.10](barretenberg-v0.7.9...barretenberg-v0.7.10) (2023-09-20) ### Miscellaneous * **barretenberg:** Synchronize aztec-packages versions </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Part of #2167 - creates the tokenPortal Standard + updates cross chain tests (and cross chain harness file)
Doc is TBD
NonNativeTokencrosschainHarnesswhich is integral to the other cross-chain e2e tests