diff --git a/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol b/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol index db038cfe772a..fc68df1a4441 100644 --- a/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol +++ b/l1-contracts/test/fee_portal/depositToAztecPublic.t.sol @@ -81,6 +81,8 @@ contract DepositToAztecPublic is Test { uint256 amount = 100 ether; uint256 expectedIndex = 2 ** Constants.L1_TO_L2_MSG_SUBTREE_HEIGHT; + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(feeJuicePortal), block.chainid), recipient: DataStructures.L2Actor(feeJuicePortal.L2_TOKEN_ADDRESS(), 1 + numberOfRollups), diff --git a/l1-contracts/test/portals/TokenPortal.sol b/l1-contracts/test/portals/TokenPortal.sol index a2f67e047486..115132e52346 100644 --- a/l1-contracts/test/portals/TokenPortal.sol +++ b/l1-contracts/test/portals/TokenPortal.sol @@ -53,6 +53,8 @@ contract TokenPortal { DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1); // Hash the message content to be reconstructed in the receiving contract + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. bytes32 contentHash = Hash.sha256ToField(abi.encodeWithSignature("mint_to_public(bytes32,uint256)", _to, _amount)); @@ -123,6 +125,8 @@ contract TokenPortal { uint256 _leafIndex, bytes32[] calldata _path ) external { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2Bridge, 1), recipient: DataStructures.L1Actor(address(this), block.chainid), diff --git a/l1-contracts/test/portals/TokenPortal.t.sol b/l1-contracts/test/portals/TokenPortal.t.sol index 31e8a85045d8..da7af0eb534b 100644 --- a/l1-contracts/test/portals/TokenPortal.t.sol +++ b/l1-contracts/test/portals/TokenPortal.t.sol @@ -88,6 +88,8 @@ contract TokenPortalTest is Test { view returns (DataStructures.L1ToL2Msg memory) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. return DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(tokenPortal), block.chainid), recipient: DataStructures.L2Actor(l2TokenAddress, 1), @@ -102,6 +104,8 @@ contract TokenPortalTest is Test { view returns (DataStructures.L1ToL2Msg memory) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. return DataStructures.L1ToL2Msg({ sender: DataStructures.L1Actor(address(tokenPortal), block.chainid), recipient: DataStructures.L2Actor(l2TokenAddress, 1), @@ -171,6 +175,8 @@ contract TokenPortalTest is Test { internal returns (bytes32, bytes32) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. bytes32 l2ToL1Message = Hash.sha256ToField( DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor({actor: l2TokenAddress, version: 1}), diff --git a/l1-contracts/test/portals/UniswapPortal.sol b/l1-contracts/test/portals/UniswapPortal.sol index a4eb66d8b806..37e02ee69bb6 100644 --- a/l1-contracts/test/portals/UniswapPortal.sol +++ b/l1-contracts/test/portals/UniswapPortal.sol @@ -87,6 +87,8 @@ contract UniswapPortal { { // prevent stack too deep errors + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. vars.contentHash = Hash.sha256ToField( abi.encodeWithSignature( "swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)", @@ -191,6 +193,8 @@ contract UniswapPortal { { // prevent stack too deep errors + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. vars.contentHash = Hash.sha256ToField( abi.encodeWithSignature( "swap_private(address,uint256,uint24,address,uint256,bytes32,address)", diff --git a/l1-contracts/test/portals/UniswapPortal.t.sol b/l1-contracts/test/portals/UniswapPortal.t.sol index bf37ae19e64f..ac646e17bac7 100644 --- a/l1-contracts/test/portals/UniswapPortal.t.sol +++ b/l1-contracts/test/portals/UniswapPortal.t.sol @@ -94,6 +94,8 @@ contract UniswapPortalTest is Test { view returns (bytes32 l2ToL1MessageHash) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2TokenAddress, 1), recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid), @@ -116,6 +118,8 @@ contract UniswapPortalTest is Test { view returns (bytes32 l2ToL1MessageHash) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2UniswapAddress, 1), recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid), @@ -143,6 +147,8 @@ contract UniswapPortalTest is Test { * Set to address(0) if anyone can call. */ function _createUniswapSwapMessagePrivate(address _caller) internal view returns (bytes32) { + // The purpose of including the function selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({ sender: DataStructures.L2Actor(l2UniswapAddress, 1), recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid), diff --git a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr index 6f77d74b16e9..98167e293a8d 100644 --- a/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr @@ -16,11 +16,14 @@ pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field { hash_bytes[i + 36] = amount_bytes[i]; } - // Function selector: 0x63f44968 keccak256('claim(bytes32,uint256)') - hash_bytes[0] = 0x63; - hash_bytes[1] = 0xf4; - hash_bytes[2] = 0x49; - hash_bytes[3] = 0x68; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("claim(bytes32,uint256)".as_bytes(), 22) }; + + hash_bytes[0] = selector[0]; + hash_bytes[1] = selector[1]; + hash_bytes[2] = selector[2]; + hash_bytes[3] = selector[3]; let content_hash = sha256_to_field(hash_bytes); content_hash diff --git a/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr b/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr index a25b24cd650a..022c4876ad25 100644 --- a/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr +++ b/noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr @@ -14,7 +14,9 @@ pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: Field) -> Fi hash_bytes[i + 36] = amount_bytes[i]; } - let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 24) }; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) }; hash_bytes[0] = selector[0]; hash_bytes[1] = selector[1]; @@ -39,6 +41,8 @@ pub fn get_mint_to_private_content_hash( hash_bytes[i + 4] = amount_bytes[i]; } + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. let selector = comptime { std::hash::keccak256("mint_to_private(uint256)".as_bytes(), 24) }; hash_bytes[0] = selector[0]; @@ -63,7 +67,9 @@ pub fn get_withdraw_content_hash(recipient: EthAddress, amount: Field, caller_on let amount_bytes: [u8; 32] = amount.to_be_bytes(); let caller_on_l1_bytes: [u8; 32] = caller_on_l1.to_field().to_be_bytes(); - let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 24) }; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) }; hash_bytes[0] = selector[0]; hash_bytes[1] = selector[1]; diff --git a/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr b/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr index a0e2ca12774b..dc5605d7fd09 100644 --- a/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr +++ b/noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr @@ -27,11 +27,19 @@ pub fn compute_swap_public_content_hash( secret_hash_for_L1_to_l2_message.to_be_bytes(); let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes(); - // function selector: 0xf18186d8 keccak256("swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)") - hash_bytes[0] = 0xf1; - hash_bytes[1] = 0x81; - hash_bytes[2] = 0x86; - hash_bytes[3] = 0xd8; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { + std::hash::keccak256( + "swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)".as_bytes(), + 75, + ) + }; + + hash_bytes[0] = selector[0]; + hash_bytes[1] = selector[1]; + hash_bytes[2] = selector[2]; + hash_bytes[3] = selector[3]; for i in 0..32 { hash_bytes[i + 4] = input_token_portal_bytes[i]; @@ -73,11 +81,19 @@ pub fn compute_swap_private_content_hash( secret_hash_for_L1_to_l2_message.to_be_bytes(); let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes(); - // function selector: 0x84e55078 keccak256("swap_private(address,uint256,uint24,address,uint256,bytes32,address)") - hash_bytes[0] = 0x84; - hash_bytes[1] = 0xe5; - hash_bytes[2] = 0x50; - hash_bytes[3] = 0x78; + // The purpose of including the following selector is to make the message unique to that specific call. Note that + // it has nothing to do with calling the function. + let selector = comptime { + std::hash::keccak256( + "swap_private(address,uint256,uint24,address,uint256,bytes32,address)".as_bytes(), + 68, + ) + }; + + hash_bytes[0] = selector[0]; + hash_bytes[1] = selector[1]; + hash_bytes[2] = selector[2]; + hash_bytes[3] = selector[3]; for i in 0..32 { hash_bytes[i + 4] = input_token_portal_bytes[i];