From 54bf4a528d90c37b8082587a73276353dab6c0d3 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Wed, 11 Oct 2023 15:09:50 +0000 Subject: [PATCH] reorder hashes + sol functions + nr fns --- l1-contracts/test/portals/TokenPortal.sol | 36 ++++++------- l1-contracts/test/portals/TokenPortal.t.sol | 34 ++++++------ l1-contracts/test/portals/UniswapPortal.sol | 8 +-- l1-contracts/test/portals/UniswapPortal.t.sol | 4 +- yarn-project/acir-simulator/package.json | 6 +-- .../src/client/private_execution.test.ts | 6 +-- .../acir-simulator/src/public/index.test.ts | 6 +-- .../src/e2e_cross_chain_messaging.test.ts | 8 +-- .../e2e_public_cross_chain_messaging.test.ts | 8 +-- .../src/fixtures/cross_chain_test_harness.ts | 21 ++++---- .../src/integration_archiver_l1_to_l2.test.ts | 4 +- .../contracts/test_contract/src/interface.nr | 18 +++---- .../src/contracts/test_contract/src/main.nr | 8 +-- .../token_bridge_contract/src/main.nr | 16 +++--- .../src/contracts/token_contract/src/main.nr | 1 + .../token_portal_content_hash_lib/src/lib.nr | 54 +++++++++---------- .../uniswap_contract/src/interfaces.nr | 6 +-- .../contracts/uniswap_contract/src/main.nr | 2 +- 18 files changed, 124 insertions(+), 122 deletions(-) diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index d03f2cc74bf8..19ef29bb3a58 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -27,16 +27,16 @@ contract TokenPortal { // docs:start:deposit_public /** * @notice Deposit funds into the portal and adds an L2 message which can only be consumed publicly on Aztec - * @param _amount - The amount to deposit * @param _to - The aztec address of the recipient + * @param _amount - The amount to deposit * @param _canceller - The address that can cancel the L1 to L2 message * @param _deadline - The timestamp after which the entry can be cancelled * @param _secretHash - The hash of the secret consumable message. The hash should be 254 bits (so it can fit in a Field element) * @return The key of the entry in the Inbox */ function depositToAztecPublic( - uint256 _amount, bytes32 _to, + uint256 _amount, address _canceller, uint32 _deadline, bytes32 _secretHash @@ -47,7 +47,7 @@ contract TokenPortal { // Hash the message content to be reconstructed in the receiving contract bytes32 contentHash = Hash.sha256ToField( - abi.encodeWithSignature("mint_public(uint256,bytes32,address)", _amount, _to, _canceller) + abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, _canceller) ); // Hold the tokens in the portal @@ -60,16 +60,16 @@ contract TokenPortal { /** * @notice Deposit funds into the portal and adds an L2 message which can only be consumed privately on Aztec - * @param _amount - The amount to deposit * @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec. The hash should be 254 bits (so it can fit in a Field element) + * @param _amount - The amount to deposit * @param _canceller - The address that can cancel the L1 to L2 message * @param _deadline - The timestamp after which the entry can be cancelled * @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message. The hash should be 254 bits (so it can fit in a Field element) * @return The key of the entry in the Inbox */ function depositToAztecPrivate( - uint256 _amount, bytes32 _secretHashForRedeemingMintedNotes, + uint256 _amount, address _canceller, uint32 _deadline, bytes32 _secretHashForL2MessageConsumption @@ -81,9 +81,9 @@ contract TokenPortal { // Hash the message content to be reconstructed in the receiving contract bytes32 contentHash = Hash.sha256ToField( abi.encodeWithSignature( - "mint_private(uint256,bytes32,address)", - _amount, + "mint_private(bytes32,uint256,address)", _secretHashForRedeemingMintedNotes, + _amount, _canceller ) ); @@ -101,16 +101,16 @@ contract TokenPortal { /** * @notice Cancel a public depositToAztec L1 to L2 message * @dev only callable by the `canceller` of the message - * @param _amount - The amount to deposit per the original message * @param _to - The aztec address of the recipient in the original message + * @param _amount - The amount to deposit per the original message * @param _deadline - The timestamp after which the entry can be cancelled * @param _secretHash - The hash of the secret consumable message in the original message * @param _fee - The fee paid to the sequencer * @return The key of the entry in the Inbox */ function cancelL1ToAztecMessagePublic( - uint256 _amount, bytes32 _to, + uint256 _amount, uint32 _deadline, bytes32 _secretHash, uint64 _fee @@ -122,7 +122,7 @@ contract TokenPortal { sender: l1Actor, recipient: l2Actor, content: Hash.sha256ToField( - abi.encodeWithSignature("mint_public(uint256,bytes32,address)", _amount, _to, msg.sender) + abi.encodeWithSignature("mint_public(bytes32,uint256,address)", _to, _amount, msg.sender) ), secretHash: _secretHash, deadline: _deadline, @@ -138,16 +138,16 @@ contract TokenPortal { /** * @notice Cancel a private depositToAztec L1 to L2 message * @dev only callable by the `canceller` of the message - * @param _amount - The amount to deposit per the original message * @param _secretHashForRedeemingMintedNotes - The hash of the secret to redeem minted notes privately on Aztec + * @param _amount - The amount to deposit per the original message * @param _deadline - The timestamp after which the entry can be cancelled * @param _secretHashForL2MessageConsumption - The hash of the secret consumable L1 to L2 message * @param _fee - The fee paid to the sequencer * @return The key of the entry in the Inbox */ function cancelL1ToAztecMessagePrivate( - uint256 _amount, bytes32 _secretHashForRedeemingMintedNotes, + uint256 _amount, uint32 _deadline, bytes32 _secretHashForL2MessageConsumption, uint64 _fee @@ -160,9 +160,9 @@ contract TokenPortal { recipient: l2Actor, content: Hash.sha256ToField( abi.encodeWithSignature( - "mint_private(uint256,bytes32,address)", - _amount, + "mint_private(bytes32,uint256,address)", _secretHashForRedeemingMintedNotes, + _amount, msg.sender ) ), @@ -183,13 +183,13 @@ contract TokenPortal { /** * @notice Withdraw funds from the portal * @dev Second part of withdraw, must be initiated from L2 first as it will consume a message from outbox - * @param _amount - The amount to withdraw * @param _recipient - The address to send the funds to + * @param _amount - The amount to withdraw * @param _withCaller - Flag to use `msg.sender` as caller, otherwise address(0) * Must match the caller of the message (specified from L2) to consume it. * @return The key of the entry in the Outbox */ - function withdraw(uint256 _amount, address _recipient, bool _withCaller) + function withdraw(address _recipient, uint256 _amount, bool _withCaller) external returns (bytes32) { @@ -198,9 +198,9 @@ contract TokenPortal { recipient: DataStructures.L1Actor(address(this), block.chainid), content: Hash.sha256ToField( abi.encodeWithSignature( - "withdraw(uint256,address,address)", - _amount, + "withdraw(address,uint256,address)", _recipient, + _amount, _withCaller ? msg.sender : address(0) ) ) diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index 53340684b874..aeb110fb8305 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -86,9 +86,9 @@ contract TokenPortalTest is Test { recipient: DataStructures.L2Actor(l2TokenAddress, 1), content: Hash.sha256ToField( abi.encodeWithSignature( - "mint_private(uint256,bytes32,address)", - amount, + "mint_private(bytes32,uint256,address)", secretHashForRedeemingMintedNotes, + amount, _canceller ) ), @@ -107,7 +107,7 @@ contract TokenPortalTest is Test { sender: DataStructures.L1Actor(address(tokenPortal), block.chainid), recipient: DataStructures.L2Actor(l2TokenAddress, 1), content: Hash.sha256ToField( - abi.encodeWithSignature("mint_public(uint256,bytes32,address)", amount, to, _canceller) + abi.encodeWithSignature("mint_public(bytes32,uint256,address)", to, amount, _canceller) ), secretHash: secretHashForL2MessageConsumption, deadline: deadline, @@ -142,8 +142,8 @@ contract TokenPortalTest is Test { // Perform op bytes32 entryKey = tokenPortal.depositToAztecPrivate{value: bid}( - amount, secretHashForRedeemingMintedNotes, + amount, address(this), deadline, secretHashForL2MessageConsumption @@ -185,7 +185,7 @@ contract TokenPortalTest is Test { // Perform op bytes32 entryKey = tokenPortal.depositToAztecPublic{value: bid}( - amount, to, address(this), deadline, secretHashForL2MessageConsumption + to, amount, address(this), deadline, secretHashForL2MessageConsumption ); assertEq(entryKey, expectedEntryKey, "returned entry key and calculated entryKey should match"); @@ -210,7 +210,7 @@ contract TokenPortalTest is Test { abi.encodeWithSelector(Errors.Inbox__NothingToConsume.selector, expectedWrongEntryKey) ); tokenPortal.cancelL1ToAztecMessagePublic( - amount, to, deadline, secretHashForL2MessageConsumption, bid + to, amount, deadline, secretHashForL2MessageConsumption, bid ); vm.stopPrank(); @@ -221,7 +221,7 @@ contract TokenPortalTest is Test { abi.encodeWithSelector(Errors.Inbox__NothingToConsume.selector, expectedWrongEntryKey) ); tokenPortal.cancelL1ToAztecMessagePrivate( - amount, secretHashForRedeemingMintedNotes, deadline, secretHashForL2MessageConsumption, bid + secretHashForRedeemingMintedNotes, amount, deadline, secretHashForL2MessageConsumption, bid ); // actually cancel the message @@ -231,7 +231,7 @@ contract TokenPortalTest is Test { emit L1ToL2MessageCancelled(expectedEntryKey); // perform op bytes32 entryKey = tokenPortal.cancelL1ToAztecMessagePublic( - amount, to, deadline, secretHashForL2MessageConsumption, bid + to, amount, deadline, secretHashForL2MessageConsumption, bid ); assertEq(entryKey, expectedEntryKey, "returned entry key and calculated entryKey should match"); @@ -257,7 +257,7 @@ contract TokenPortalTest is Test { abi.encodeWithSelector(Errors.Inbox__NothingToConsume.selector, expectedWrongEntryKey) ); tokenPortal.cancelL1ToAztecMessagePrivate( - amount, secretHashForRedeemingMintedNotes, deadline, secretHashForL2MessageConsumption, bid + secretHashForRedeemingMintedNotes, amount, deadline, secretHashForL2MessageConsumption, bid ); vm.stopPrank(); @@ -268,7 +268,7 @@ contract TokenPortalTest is Test { abi.encodeWithSelector(Errors.Inbox__NothingToConsume.selector, expectedWrongEntryKey) ); tokenPortal.cancelL1ToAztecMessagePublic( - amount, to, deadline, secretHashForL2MessageConsumption, bid + to, amount, deadline, secretHashForL2MessageConsumption, bid ); // actually cancel the message @@ -278,7 +278,7 @@ contract TokenPortalTest is Test { emit L1ToL2MessageCancelled(expectedEntryKey); // perform op bytes32 entryKey = tokenPortal.cancelL1ToAztecMessagePrivate( - amount, secretHashForRedeemingMintedNotes, deadline, secretHashForL2MessageConsumption, bid + secretHashForRedeemingMintedNotes, amount, deadline, secretHashForL2MessageConsumption, bid ); assertEq(entryKey, expectedEntryKey, "returned entry key and calculated entryKey should match"); @@ -302,7 +302,7 @@ contract TokenPortalTest is Test { recipient: DataStructures.L1Actor({actor: address(tokenPortal), chainId: block.chainid}), content: Hash.sha256ToField( abi.encodeWithSignature( - "withdraw(uint256,address,address)", withdrawAmount, recipient, _designatedCaller + "withdraw(address,uint256,address)", recipient, withdrawAmount, _designatedCaller ) ) }) @@ -331,7 +331,7 @@ contract TokenPortalTest is Test { vm.startPrank(_caller); vm.expectEmit(true, true, true, true); emit MessageConsumed(expectedEntryKey, address(tokenPortal)); - bytes32 actualEntryKey = tokenPortal.withdraw(withdrawAmount, recipient, false); + bytes32 actualEntryKey = tokenPortal.withdraw(recipient, withdrawAmount, false); assertEq(expectedEntryKey, actualEntryKey); // Should have received 654 RNA tokens assertEq(portalERC20.balanceOf(recipient), withdrawAmount); @@ -340,7 +340,7 @@ contract TokenPortalTest is Test { vm.expectRevert( abi.encodeWithSelector(Errors.Outbox__NothingToConsume.selector, actualEntryKey) ); - tokenPortal.withdraw(withdrawAmount, recipient, false); + tokenPortal.withdraw(recipient, withdrawAmount, false); vm.stopPrank(); } @@ -354,13 +354,13 @@ contract TokenPortalTest is Test { vm.expectRevert( abi.encodeWithSelector(Errors.Outbox__NothingToConsume.selector, entryKeyPortalChecksAgainst) ); - tokenPortal.withdraw(withdrawAmount, recipient, true); + tokenPortal.withdraw(recipient, withdrawAmount, true); entryKeyPortalChecksAgainst = _createWithdrawMessageForOutbox(address(0)); vm.expectRevert( abi.encodeWithSelector(Errors.Outbox__NothingToConsume.selector, entryKeyPortalChecksAgainst) ); - tokenPortal.withdraw(withdrawAmount, recipient, false); + tokenPortal.withdraw(recipient, withdrawAmount, false); vm.stopPrank(); } @@ -370,7 +370,7 @@ contract TokenPortalTest is Test { vm.expectEmit(true, true, true, true); emit MessageConsumed(expectedEntryKey, address(tokenPortal)); - bytes32 actualEntryKey = tokenPortal.withdraw(withdrawAmount, recipient, true); + bytes32 actualEntryKey = tokenPortal.withdraw(recipient, withdrawAmount, true); assertEq(expectedEntryKey, actualEntryKey); // Should have received 654 RNA tokens assertEq(portalERC20.balanceOf(recipient), withdrawAmount); diff --git a/l1-contracts/test/portals/UniswapPortal.sol b/l1-contracts/test/portals/UniswapPortal.sol index cca4ad7eea93..41a29c394692 100644 --- a/l1-contracts/test/portals/UniswapPortal.sol +++ b/l1-contracts/test/portals/UniswapPortal.sol @@ -70,7 +70,7 @@ contract UniswapPortal { vars.outputAsset = TokenPortal(_outputTokenPortal).underlying(); // Withdraw the input asset from the portal - TokenPortal(_inputTokenPortal).withdraw(_inAmount, address(this), true); + TokenPortal(_inputTokenPortal).withdraw(address(this), _inAmount, true); { // prevent stack too deep errors vars.contentHash = Hash.sha256ToField( @@ -123,7 +123,7 @@ contract UniswapPortal { // Deposit the output asset to the L2 via its portal return TokenPortal(_outputTokenPortal).depositToAztecPublic{value: msg.value}( - amountOut, _aztecRecipient, _canceller, _deadlineForL1ToL2Message, _secretHashForL1ToL2Message + _aztecRecipient, amountOut, _canceller, _deadlineForL1ToL2Message, _secretHashForL1ToL2Message ); } // docs:end:solidity_uniswap_swap @@ -163,7 +163,7 @@ contract UniswapPortal { vars.outputAsset = TokenPortal(_outputTokenPortal).underlying(); // Withdraw the input asset from the portal - TokenPortal(_inputTokenPortal).withdraw(_inAmount, address(this), true); + TokenPortal(_inputTokenPortal).withdraw(address(this), _inAmount, true); { // prevent stack too deep errors vars.contentHash = Hash.sha256ToField( @@ -216,8 +216,8 @@ contract UniswapPortal { // Deposit the output asset to the L2 via its portal return TokenPortal(_outputTokenPortal).depositToAztecPrivate{value: msg.value}( - amountOut, _secretHashForRedeemingMintedNotes, + amountOut, _canceller, _deadlineForL1ToL2Message, _secretHashForL1ToL2Message diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index 9e42a3c0b8d6..0e769074408f 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -82,7 +82,7 @@ contract UniswapPortalTest is Test { sender: DataStructures.L2Actor(l2TokenAddress, 1), recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid), content: Hash.sha256ToField( - abi.encodeWithSignature("withdraw(uint256,address,address)", amount, _recipient, _caller) + abi.encodeWithSignature("withdraw(address,uint256,address)", _recipient, amount, _caller) ) }); entryKey = outbox.computeEntryKey(message); @@ -379,7 +379,7 @@ contract UniswapPortalTest is Test { // perform op // TODO(2167) - Update UniswapPortal properly with new portal standard. bytes32 entryKey = wethTokenPortal.cancelL1ToAztecMessagePublic( - wethAmountOut, aztecRecipient, deadlineForL1ToL2Message, secretHash, 1 ether + aztecRecipient, wethAmountOut, deadlineForL1ToL2Message, secretHash, 1 ether ); assertEq(entryKey, l1ToL2MessageKey, "returned entry key and calculated entryKey should match"); assertFalse(inbox.contains(entryKey), "entry still in inbox"); diff --git a/yarn-project/acir-simulator/package.json b/yarn-project/acir-simulator/package.json index 070ee6ba9521..fffee9b0428b 100644 --- a/yarn-project/acir-simulator/package.json +++ b/yarn-project/acir-simulator/package.json @@ -36,8 +36,7 @@ "@noir-lang/acvm_js": "0.26.1", "levelup": "^5.1.1", "memdown": "^6.1.1", - "tslib": "^2.4.0", - "viem": "^1.2.5" + "tslib": "^2.4.0" }, "devDependencies": { "@aztec/merkle-tree": "workspace:^", @@ -53,7 +52,8 @@ "toml": "^3.0.0", "ts-jest": "^29.1.0", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "typescript": "^5.0.4", + "viem": "^1.2.5" }, "files": [ "dest", diff --git a/yarn-project/acir-simulator/src/client/private_execution.test.ts b/yarn-project/acir-simulator/src/client/private_execution.test.ts index 43aae8e5d71a..58b7c5d49ae6 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.test.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.test.ts @@ -656,8 +656,8 @@ describe('Private Execution test suite', () => { const secretHashForRedeemingNotes = new Fr(2n); const canceller = EthAddress.random(); const preimage = await buildL1ToL2Message( - getFunctionSelector('mint_private(uint256,bytes32,address)').substring(2), - [new Fr(bridgedAmount), secretHashForRedeemingNotes, canceller.toField()], + getFunctionSelector('mint_private(bytes32,uint256,address)').substring(2), + [secretHashForRedeemingNotes, new Fr(bridgedAmount), canceller.toField()], contractAddress, secretForL1ToL2MessageConsumption, ); @@ -675,8 +675,8 @@ describe('Private Execution test suite', () => { }); const args = [ - bridgedAmount, secretHashForRedeemingNotes, + bridgedAmount, canceller.toField(), messageKey, secretForL1ToL2MessageConsumption, diff --git a/yarn-project/acir-simulator/src/public/index.test.ts b/yarn-project/acir-simulator/src/public/index.test.ts index 539b10c20f1d..bda1757eccc8 100644 --- a/yarn-project/acir-simulator/src/public/index.test.ts +++ b/yarn-project/acir-simulator/src/public/index.test.ts @@ -360,8 +360,8 @@ describe('ACIR public execution simulator', () => { const recipient = AztecAddress.random(); const preimage = await buildL1ToL2Message( - getFunctionSelector('mint_public(uint256,bytes32,address)').substring(2), - [new Fr(bridgedAmount), recipient.toField(), canceller.toField()], + getFunctionSelector('mint_public(bytes32,uint256,address)').substring(2), + [recipient.toField(), new Fr(bridgedAmount), canceller.toField()], contractAddress, secret, ); @@ -369,8 +369,8 @@ describe('ACIR public execution simulator', () => { // Stub message key const messageKey = Fr.random(); const args = encodeArguments(mintPublicArtifact, [ - bridgedAmount, recipient.toField(), + bridgedAmount, canceller.toField(), messageKey, secret, diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index ceef3b806422..78584656bd35 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -146,8 +146,8 @@ describe('e2e_cross_chain_messaging', () => { l2Bridge .withWallet(user2Wallet) .methods.claim_private( - bridgeAmount, secretHashForL2MessageConsumption, + bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption, @@ -159,8 +159,8 @@ describe('e2e_cross_chain_messaging', () => { const consumptionTx = l2Bridge .withWallet(user2Wallet) .methods.claim_private( - bridgeAmount, secretHashForRedeemingMintedNotes, + bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption, @@ -193,7 +193,7 @@ describe('e2e_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user1Wallet) - .methods.exit_to_l1_private(l2Token.address, withdrawAmount, ethAccount, EthAddress.ZERO, nonce) + .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .simulate(), ).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedBurnMessageHash.toString('hex')}`); }); @@ -224,7 +224,7 @@ describe('e2e_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_public(bridgeAmount, ownerAddress, ethAccount, messageKey, secretForL2MessageConsumption) + .methods.claim_public(ownerAddress, bridgeAmount, ethAccount, messageKey, secretForL2MessageConsumption) .simulate(), ).rejects.toThrowError( "Failed to solve brillig function, reason: explicit trap hit in brillig 'l1_to_l2_message_data.message.content == content'", diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index e43a318d8253..1135d44ba7c5 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -128,7 +128,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_public(bridgeAmount, user2Wallet.getAddress(), ownerEthAddress, messageKey, secret) + .methods.claim_public(user2Wallet.getAddress(), bridgeAmount, ownerEthAddress, messageKey, secret) .simulate(), ).rejects.toThrow(); @@ -136,7 +136,7 @@ describe('e2e_public_cross_chain_messaging', () => { logger("user2 consumes owner's message on L2 Publicly"); const tx = l2Bridge .withWallet(user2Wallet) - .methods.claim_public(bridgeAmount, ownerAddress, ownerEthAddress, messageKey, secret) + .methods.claim_public(ownerAddress, bridgeAmount, ownerEthAddress, messageKey, secret) .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); @@ -155,7 +155,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(ownerWallet) - .methods.exit_to_l1_public(withdrawAmount, ownerEthAddress, EthAddress.ZERO, nonce) + .methods.exit_to_l1_public(ownerEthAddress, withdrawAmount, EthAddress.ZERO, nonce) .simulate(), ).rejects.toThrowError('Assertion failed: Message not authorized by account'); }); @@ -177,7 +177,7 @@ describe('e2e_public_cross_chain_messaging', () => { await expect( l2Bridge .withWallet(user2Wallet) - .methods.claim_private(bridgeAmount, secretHash, ownerEthAddress, messageKey, secret) + .methods.claim_private(secretHash, bridgeAmount, ownerEthAddress, messageKey, secret) .simulate(), ).rejects.toThrowError("Cannot satisfy constraint 'l1_to_l2_message_data.message.content == content"); }); diff --git a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts index 01080e108a40..6df89d853d3e 100644 --- a/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/fixtures/cross_chain_test_harness.ts @@ -119,8 +119,8 @@ export class CrossChainTestHarness { this.logger('Sending messages to L1 portal to be consumed publicly'); const args = [ - bridgeAmount, this.ownerAddress.toString(), + bridgeAmount, this.ethAccount.toString(), deadline, secretHash.toString(true), @@ -145,8 +145,8 @@ export class CrossChainTestHarness { this.logger('Sending messages to L1 portal to be consumed privately'); const args = [ - bridgeAmount, secretHashForRedeemingMintedNotes.toString(true), + bridgeAmount, this.ethAccount.toString(), deadline, secretHashForL2MessageConsumption.toString(true), @@ -192,8 +192,8 @@ export class CrossChainTestHarness { // Call the mint tokens function on the Aztec.nr contract const consumptionTx = this.l2Bridge.methods .claim_private( - bridgeAmount, secretHashForRedeemingMintedNotes, + bridgeAmount, this.ethAccount, messageKey, secretForL2MessageConsumption, @@ -209,7 +209,7 @@ export class CrossChainTestHarness { this.logger('Consuming messages on L2 Publicly'); // Call the mint tokens function on the Aztec.nr contract const tx = this.l2Bridge.methods - .claim_public(bridgeAmount, this.ownerAddress, this.ethAccount, messageKey, secret) + .claim_public(this.ownerAddress, bridgeAmount, this.ethAccount, messageKey, secret) .send(); const receipt = await tx.wait(); expect(receipt.status).toBe(TxStatus.MINED); @@ -217,7 +217,7 @@ export class CrossChainTestHarness { async withdrawPrivateFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO) { const withdrawTx = this.l2Bridge.methods - .exit_to_l1_private(this.l2Token.address, withdrawAmount, this.ethAccount, EthAddress.ZERO, nonce) + .exit_to_l1_private(this.l2Token.address, this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .send(); const withdrawReceipt = await withdrawTx.wait(); expect(withdrawReceipt.status).toBe(TxStatus.MINED); @@ -225,7 +225,7 @@ export class CrossChainTestHarness { async withdrawPublicFromAztecToL1(withdrawAmount: bigint, nonce: Fr = Fr.ZERO) { const withdrawTx = this.l2Bridge.methods - .exit_to_l1_public(withdrawAmount, this.ethAccount, EthAddress.ZERO, nonce) + .exit_to_l1_public(this.ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .send(); const withdrawReceipt = await withdrawTx.wait(); expect(withdrawReceipt.status).toBe(TxStatus.MINED); @@ -252,12 +252,13 @@ export class CrossChainTestHarness { async checkEntryIsNotInOutbox(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Promise { this.logger('Ensure that the entry is not in outbox yet'); - // 0xb460af94, selector for "withdraw(uint256,address,address)" + // 0x69328dec, selector for "withdraw(address,uint256,address)" + // todo - USE viem!!! const content = sha256ToField( Buffer.concat([ - Buffer.from([0xb4, 0x60, 0xaf, 0x94]), - new Fr(withdrawAmount).toBuffer(), + Buffer.from([0x69, 0x32, 0x8d, 0xec]), this.ethAccount.toBuffer32(), + new Fr(withdrawAmount).toBuffer(), callerOnL1.toBuffer32(), ]), ); @@ -279,8 +280,8 @@ export class CrossChainTestHarness { this.logger('Send L1 tx to consume entry and withdraw funds'); // Call function on L1 contract to consume the message const { request: withdrawRequest, result: withdrawEntryKey } = await this.tokenPortal.simulate.withdraw([ - withdrawAmount, this.ethAccount.toString(), + withdrawAmount, false, ]); diff --git a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts index 80854ff4264b..85b722452690 100644 --- a/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts +++ b/yarn-project/end-to-end/src/integration_archiver_l1_to_l2.test.ts @@ -85,7 +85,7 @@ describe('archiver integration with l1 to l2 messages', () => { const deadline = Number((await publicClient.getBlock()).timestamp + 1000n); logger('Sending messages to L1 portal'); - const args = [mintAmount, owner.toString(), ethAccount.toString(), deadline, secretString] as const; + const args = [owner.toString(), mintAmount, ethAccount.toString(), deadline, secretString] as const; await tokenPortal.write.depositToAztecPublic(args, {} as any); expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(initialL1MintAmount - mintAmount); @@ -97,7 +97,7 @@ describe('archiver integration with l1 to l2 messages', () => { // cancel the message logger('cancelling the l1 to l2 message'); - const argsCancel = [mintAmount, owner.toString(), deadline, secretString, 0n] as const; + const argsCancel = [owner.toString(), mintAmount, deadline, secretString, 0n] as const; await tokenPortal.write.cancelL1ToAztecMessagePublic(argsCancel, { gas: 1_000_000n } as any); expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(initialL1MintAmount); // let archiver sync up diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr index 6b2d7f9845a0..2a8addc00e9a 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/interface.nr @@ -42,15 +42,15 @@ impl TestPrivateContextInterface { pub fn consume_mint_private_message( self, context: &mut PrivateContext, - amount: Field, secret_hash_for_redeeming_minted_notes: Field, + amount: Field, canceller: Field, msg_key: Field, secret_for_L1_to_L2_message_consumption: Field ) -> [Field; RETURN_VALUES_LENGTH] { let mut serialized_args = [0; 5]; - serialized_args[0] = amount; - serialized_args[1] = secret_hash_for_redeeming_minted_notes; + serialized_args[0] = secret_hash_for_redeeming_minted_notes; + serialized_args[1] = amount; serialized_args[2] = canceller; serialized_args[3] = msg_key; serialized_args[4] = secret_for_L1_to_L2_message_consumption; @@ -62,15 +62,15 @@ impl TestPrivateContextInterface { pub fn consume_mint_public_message( self, context: &mut PrivateContext, - amount: Field, to: Field, + amount: Field, canceller: Field, msg_key: Field, secret: Field ) { let mut serialized_args = [0; 5]; - serialized_args[0] = amount; - serialized_args[1] = to; + serialized_args[0] = to; + serialized_args[1] = amount; serialized_args[2] = canceller; serialized_args[3] = msg_key; serialized_args[4] = secret; @@ -239,15 +239,15 @@ impl TestPublicContextInterface { pub fn consume_mint_public_message( self, context: PublicContext, - amount: Field, to: Field, + amount: Field, canceller: Field, msg_key: Field, secret: Field ) -> [Field; RETURN_VALUES_LENGTH] { let mut serialized_args = [0; 5]; - serialized_args[0] = amount; - serialized_args[1] = to; + serialized_args[0] = to; + serialized_args[1] = amount; serialized_args[2] = canceller; serialized_args[3] = msg_key; serialized_args[4] = secret; diff --git a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr index 76f4fd922b04..7b5277774160 100644 --- a/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/test_contract/src/main.nr @@ -140,27 +140,27 @@ contract Test { #[aztec(public)] fn consume_mint_public_message( - amount: Field, to: Field, + amount: Field, canceller: Field, msg_key: Field, secret: Field, ) { - let content_hash = get_mint_public_content_hash(amount, to, canceller); + let content_hash = get_mint_public_content_hash(to, amount, canceller); // Consume message and emit nullifier context.consume_l1_to_l2_message(msg_key, content_hash, secret); } #[aztec(private)] fn consume_mint_private_message( - amount: Field, secret_hash_for_redeeming_minted_notes: Field, + amount: Field, canceller: Field, msg_key: Field, secret_for_L1_to_L2_message_consumption: Field, ) { // Consume L1 to L2 message and emit nullifier - let content_hash = get_mint_private_content_hash(amount, secret_hash_for_redeeming_minted_notes, canceller); + let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller); context.consume_l1_to_l2_message(msg_key, content_hash, secret_for_L1_to_L2_message_consumption); } diff --git a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr index dad2866cdc93..a27049a7e4e7 100644 --- a/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_bridge_contract/src/main.nr @@ -48,13 +48,13 @@ contract TokenBridge { // Consumes a L1->L2 message and calls the token contract to mint the appropriate amount publicly #[aztec(public)] fn claim_public( - amount: Field, to: AztecAddress, + amount: Field, canceller: EthereumAddress, msg_key: Field, secret: Field, ) -> Field { - let content_hash = get_mint_public_content_hash(amount, to.address, canceller.address); + let content_hash = get_mint_public_content_hash(to.address, amount, canceller.address); // Consume message and emit nullifier context.consume_l1_to_l2_message(msg_key, content_hash, secret); @@ -70,13 +70,13 @@ contract TokenBridge { // Requires `msg.sender` to give approval to the bridge to burn tokens on their behalf using witness signatures #[aztec(public)] fn exit_to_l1_public( - amount: Field, recipient: EthereumAddress, // ethereum address to withdraw to + amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) nonce: Field, // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 ) -> Field { // Send an L2 to L1 message - let content = get_withdraw_content_hash(amount, recipient.address, callerOnL1.address); + let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); context.message_portal(content); // Burn tokens @@ -90,14 +90,14 @@ contract TokenBridge { // User needs to call token.redeem_shield() to get the private assets #[aztec(private)] fn claim_private( - amount: Field, secret_hash_for_redeeming_minted_notes: Field, // secret hash used to redeem minted notes at a later time. This enables anyone to call this function and mint tokens to a user on their behalf + amount: Field, canceller: EthereumAddress, msg_key: Field, // L1 to L2 message key as derived from the inbox contract secret_for_L1_to_L2_message_consumption: Field, // secret used to consume the L1 to L2 message ) -> Field { // Consume L1 to L2 message and emit nullifier - let content_hash = get_mint_private_content_hash(amount, secret_hash_for_redeeming_minted_notes, canceller.address); + let content_hash = get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes, amount, canceller.address); context.consume_l1_to_l2_message(msg_key, content_hash, secret_for_L1_to_L2_message_consumption); // Mint tokens on L2 @@ -119,13 +119,13 @@ contract TokenBridge { #[aztec(private)] fn exit_to_l1_private( token: AztecAddress, - amount: Field, recipient: EthereumAddress, // ethereum address to withdraw to + amount: Field, callerOnL1: EthereumAddress, // ethereum address that can call this function on the L1 portal (0x0 if anyone can call) nonce: Field, // nonce used in the approval message by `msg.sender` to let bridge burn their tokens on L2 ) -> Field { // Send an L2 to L1 message - let content = get_withdraw_content_hash(amount, recipient.address, callerOnL1.address); + let content = get_withdraw_content_hash(recipient.address, amount, callerOnL1.address); context.message_portal(content); // Assert that user provided token address is same as seen in storage. diff --git a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr index 73e0c9f33607..26eb5a8e6239 100644 --- a/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/token_contract/src/main.nr @@ -174,6 +174,7 @@ contract Token { // docs:start:mint_private #[aztec(public)] + // TODO!!!!!!! fn mint_private( amount: Field, secret_hash: Field, diff --git a/yarn-project/noir-contracts/src/contracts/token_portal_content_hash_lib/src/lib.nr b/yarn-project/noir-contracts/src/contracts/token_portal_content_hash_lib/src/lib.nr index fbef79c10d1e..f2a634b9f8ca 100644 --- a/yarn-project/noir-contracts/src/contracts/token_portal_content_hash_lib/src/lib.nr +++ b/yarn-project/noir-contracts/src/contracts/token_portal_content_hash_lib/src/lib.nr @@ -4,24 +4,24 @@ use dep::aztec::hash::{sha256_to_field}; // Computes a content hash of a deposit/mint_public message. // Refer TokenPortal.sol for reference on L1. -pub fn get_mint_public_content_hash(amount: Field, owner_address: Field, canceller: Field) -> Field { +pub fn get_mint_public_content_hash(owner_address: Field, amount: Field, canceller: Field) -> 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 amount_bytes = amount.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 + 4] = recipient_bytes[i]; + hash_bytes[i + 36] = amount_bytes[i]; hash_bytes[i + 68] = canceller_bytes[i]; } - // Function selector: 0x63c9440d keccak256('mint_public(uint256,bytes32,address)') - hash_bytes[0] = 0x63; - hash_bytes[1] = 0xc9; - hash_bytes[2] = 0x44; - hash_bytes[3] = 0x0d; + // Function selector: 0xefc2aae6 keccak256('mint_public(bytes32,uint256,address)') + hash_bytes[0] = 0xef; + hash_bytes[1] = 0xc2; + hash_bytes[2] = 0xaa; + hash_bytes[3] = 0xe6; let content_hash = sha256_to_field(hash_bytes); content_hash @@ -30,48 +30,48 @@ pub fn get_mint_public_content_hash(amount: Field, owner_address: Field, cancell // Computes a content hash of a deposit/mint_private message. // Refer TokenPortal.sol for reference on L1. -pub fn get_mint_private_content_hash(amount: Field, secret_hash_for_redeeming_minted_notes: Field, canceller: Field) -> Field { +pub fn get_mint_private_content_hash(secret_hash_for_redeeming_minted_notes: Field, amount: Field, canceller: Field) -> Field { let mut hash_bytes: [u8; 100] = [0; 100]; - let amount_bytes = amount.to_be_bytes(32); let secret_hash_bytes = secret_hash_for_redeeming_minted_notes.to_be_bytes(32); + let amount_bytes = amount.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] = secret_hash_bytes[i]; + hash_bytes[i + 4] = secret_hash_bytes[i]; + hash_bytes[i + 36] = amount_bytes[i]; hash_bytes[i + 68] = canceller_bytes[i]; } - // Function selector: 0x25d46b0f keccak256('mint_private(uint256,bytes32,address)') - hash_bytes[0] = 0x25; - hash_bytes[1] = 0xd4; - hash_bytes[2] = 0x6b; - hash_bytes[3] = 0x0f; + // Function selector: 0xf512262e keccak256('mint_private(bytes32,uint256,address)') + hash_bytes[0] = 0xf5; + hash_bytes[1] = 0x12; + hash_bytes[2] = 0x26; + hash_bytes[3] = 0x2e; let content_hash = sha256_to_field(hash_bytes); content_hash } // Computes a content hash of a withdraw message. -pub fn get_withdraw_content_hash(amount: Field, recipient: Field, callerOnL1: Field) -> Field { +pub fn get_withdraw_content_hash(recipient: Field, amount: Field, callerOnL1: Field) -> 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 amount_bytes = amount.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; + // 0x69328dec, selector for "withdraw(address,uint256,address)" + hash_bytes[0] = 0x69; + hash_bytes[1] = 0x32; + hash_bytes[2] = 0x8d; + hash_bytes[3] = 0xec; for i in 0..32 { - hash_bytes[i + 4] = amount_bytes[i]; - hash_bytes[i + 36] = recipient_bytes[i]; + hash_bytes[i + 4] = recipient_bytes[i]; + hash_bytes[i + 36] = amount_bytes[i]; hash_bytes[i + 68] = callerOnL1_bytes[i]; } let content_hash = sha256_to_field(hash_bytes); diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr index d0497b8c52dd..82c3a9961143 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/interfaces.nr @@ -44,11 +44,11 @@ impl TokenBridge { AztecAddress::new(return_values[0]) } - pub fn exit_to_l1_public(self: Self, context: PublicContext, amount: Field, recipient: Field, callerOnL1: Field, nonce: Field) { + pub fn exit_to_l1_public(self: Self, context: PublicContext, recipient: Field, amount: Field, callerOnL1: Field, nonce: Field) { let _return_values = context.call_public_function( self.address, - compute_selector("exit_to_l1_public(Field,(Field),(Field),Field)"), - [amount, recipient, callerOnL1, nonce] + compute_selector("exit_to_l1_public((Field),Field,(Field),Field)"), + [recipient, amount, callerOnL1, nonce] ); } } diff --git a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr index 7aff80e36908..2d372eca1cde 100644 --- a/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr +++ b/yarn-project/noir-contracts/src/contracts/uniswap_contract/src/main.nr @@ -221,8 +221,8 @@ contract Uniswap { // Exit to L1 Uniswap Portal ! TokenBridge::at(token_bridge.address).exit_to_l1_public( context, - amount, context.this_portal_address(), + amount, context.this_portal_address(), nonce_for_burn_approval, );