Skip to content

Commit 1078983

Browse files
committed
WIP
1 parent c408854 commit 1078983

File tree

8 files changed

+64
-17
lines changed

8 files changed

+64
-17
lines changed

l1-contracts/test/fee_portal/depositToAztecPublic.t.sol

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ contract DepositToAztecPublic is Test {
8181
uint256 amount = 100 ether;
8282
uint256 expectedIndex = 2 ** Constants.L1_TO_L2_MSG_SUBTREE_HEIGHT;
8383

84+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
85+
// it has nothing to do with calling the function.
8486
DataStructures.L1ToL2Msg memory message = DataStructures.L1ToL2Msg({
8587
sender: DataStructures.L1Actor(address(feeJuicePortal), block.chainid),
8688
recipient: DataStructures.L2Actor(feeJuicePortal.L2_TOKEN_ADDRESS(), 1 + numberOfRollups),

l1-contracts/test/portals/TokenPortal.sol

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ contract TokenPortal {
5353
DataStructures.L2Actor memory actor = DataStructures.L2Actor(l2Bridge, 1);
5454

5555
// Hash the message content to be reconstructed in the receiving contract
56+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
57+
// it has nothing to do with calling the function.
5658
bytes32 contentHash =
5759
Hash.sha256ToField(abi.encodeWithSignature("mint_to_public(bytes32,uint256)", _to, _amount));
5860

@@ -123,6 +125,8 @@ contract TokenPortal {
123125
uint256 _leafIndex,
124126
bytes32[] calldata _path
125127
) external {
128+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
129+
// it has nothing to do with calling the function.
126130
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
127131
sender: DataStructures.L2Actor(l2Bridge, 1),
128132
recipient: DataStructures.L1Actor(address(this), block.chainid),

l1-contracts/test/portals/TokenPortal.t.sol

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ contract TokenPortalTest is Test {
8888
view
8989
returns (DataStructures.L1ToL2Msg memory)
9090
{
91+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
92+
// it has nothing to do with calling the function.
9193
return DataStructures.L1ToL2Msg({
9294
sender: DataStructures.L1Actor(address(tokenPortal), block.chainid),
9395
recipient: DataStructures.L2Actor(l2TokenAddress, 1),
@@ -102,6 +104,8 @@ contract TokenPortalTest is Test {
102104
view
103105
returns (DataStructures.L1ToL2Msg memory)
104106
{
107+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
108+
// it has nothing to do with calling the function.
105109
return DataStructures.L1ToL2Msg({
106110
sender: DataStructures.L1Actor(address(tokenPortal), block.chainid),
107111
recipient: DataStructures.L2Actor(l2TokenAddress, 1),
@@ -171,6 +175,8 @@ contract TokenPortalTest is Test {
171175
internal
172176
returns (bytes32, bytes32)
173177
{
178+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
179+
// it has nothing to do with calling the function.
174180
bytes32 l2ToL1Message = Hash.sha256ToField(
175181
DataStructures.L2ToL1Msg({
176182
sender: DataStructures.L2Actor({actor: l2TokenAddress, version: 1}),

l1-contracts/test/portals/UniswapPortal.sol

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ contract UniswapPortal {
8787

8888
{
8989
// prevent stack too deep errors
90+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
91+
// it has nothing to do with calling the function.
9092
vars.contentHash = Hash.sha256ToField(
9193
abi.encodeWithSignature(
9294
"swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)",
@@ -191,6 +193,8 @@ contract UniswapPortal {
191193

192194
{
193195
// prevent stack too deep errors
196+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
197+
// it has nothing to do with calling the function.
194198
vars.contentHash = Hash.sha256ToField(
195199
abi.encodeWithSignature(
196200
"swap_private(address,uint256,uint24,address,uint256,bytes32,address)",

l1-contracts/test/portals/UniswapPortal.t.sol

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ contract UniswapPortalTest is Test {
9494
view
9595
returns (bytes32 l2ToL1MessageHash)
9696
{
97+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
98+
// it has nothing to do with calling the function.
9799
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
98100
sender: DataStructures.L2Actor(l2TokenAddress, 1),
99101
recipient: DataStructures.L1Actor(address(daiTokenPortal), block.chainid),
@@ -116,6 +118,8 @@ contract UniswapPortalTest is Test {
116118
view
117119
returns (bytes32 l2ToL1MessageHash)
118120
{
121+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
122+
// it has nothing to do with calling the function.
119123
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
120124
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
121125
recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid),
@@ -143,6 +147,8 @@ contract UniswapPortalTest is Test {
143147
* Set to address(0) if anyone can call.
144148
*/
145149
function _createUniswapSwapMessagePrivate(address _caller) internal view returns (bytes32) {
150+
// The purpose of including the function selector is to make the message unique to that specific call. Note that
151+
// it has nothing to do with calling the function.
146152
DataStructures.L2ToL1Msg memory message = DataStructures.L2ToL1Msg({
147153
sender: DataStructures.L2Actor(l2UniswapAddress, 1),
148154
recipient: DataStructures.L1Actor(address(uniswapPortal), block.chainid),

noir-projects/noir-contracts/contracts/fee_juice_contract/src/lib.nr

+8-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ pub fn get_bridge_gas_msg_hash(owner: AztecAddress, amount: Field) -> Field {
1616
hash_bytes[i + 36] = amount_bytes[i];
1717
}
1818

19-
// Function selector: 0x63f44968 keccak256('claim(bytes32,uint256)')
20-
hash_bytes[0] = 0x63;
21-
hash_bytes[1] = 0xf4;
22-
hash_bytes[2] = 0x49;
23-
hash_bytes[3] = 0x68;
19+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
20+
// it has nothing to do with calling the function.
21+
let selector = comptime { std::hash::keccak256("claim(bytes32,uint256)".as_bytes(), 22) };
22+
23+
hash_bytes[0] = selector[0];
24+
hash_bytes[1] = selector[1];
25+
hash_bytes[2] = selector[2];
26+
hash_bytes[3] = selector[3];
2427

2528
let content_hash = sha256_to_field(hash_bytes);
2629
content_hash

noir-projects/noir-contracts/contracts/token_portal_content_hash_lib/src/lib.nr

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub fn get_mint_to_public_content_hash(owner: AztecAddress, amount: Field) -> Fi
1414
hash_bytes[i + 36] = amount_bytes[i];
1515
}
1616

17-
let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 24) };
17+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
18+
// it has nothing to do with calling the function.
19+
let selector = comptime { std::hash::keccak256("mint_to_public(bytes32,uint256)".as_bytes(), 31) };
1820

1921
hash_bytes[0] = selector[0];
2022
hash_bytes[1] = selector[1];
@@ -39,6 +41,8 @@ pub fn get_mint_to_private_content_hash(
3941
hash_bytes[i + 4] = amount_bytes[i];
4042
}
4143

44+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
45+
// it has nothing to do with calling the function.
4246
let selector = comptime { std::hash::keccak256("mint_to_private(uint256)".as_bytes(), 24) };
4347

4448
hash_bytes[0] = selector[0];
@@ -63,7 +67,9 @@ pub fn get_withdraw_content_hash(recipient: EthAddress, amount: Field, caller_on
6367
let amount_bytes: [u8; 32] = amount.to_be_bytes();
6468
let caller_on_l1_bytes: [u8; 32] = caller_on_l1.to_field().to_be_bytes();
6569

66-
let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 24) };
70+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
71+
// it has nothing to do with calling the function.
72+
let selector = comptime { std::hash::keccak256("withdraw(address,uint256,address)".as_bytes(), 33) };
6773

6874
hash_bytes[0] = selector[0];
6975
hash_bytes[1] = selector[1];

noir-projects/noir-contracts/contracts/uniswap_contract/src/util.nr

+26-10
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ pub fn compute_swap_public_content_hash(
2727
secret_hash_for_L1_to_l2_message.to_be_bytes();
2828
let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes();
2929

30-
// function selector: 0xf18186d8 keccak256("swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)")
31-
hash_bytes[0] = 0xf1;
32-
hash_bytes[1] = 0x81;
33-
hash_bytes[2] = 0x86;
34-
hash_bytes[3] = 0xd8;
30+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
31+
// it has nothing to do with calling the function.
32+
let selector = comptime {
33+
std::hash::keccak256(
34+
"swap_public(address,uint256,uint24,address,uint256,bytes32,bytes32,address)".as_bytes(),
35+
75,
36+
)
37+
};
38+
39+
hash_bytes[0] = selector[0];
40+
hash_bytes[1] = selector[1];
41+
hash_bytes[2] = selector[2];
42+
hash_bytes[3] = selector[3];
3543

3644
for i in 0..32 {
3745
hash_bytes[i + 4] = input_token_portal_bytes[i];
@@ -73,11 +81,19 @@ pub fn compute_swap_private_content_hash(
7381
secret_hash_for_L1_to_l2_message.to_be_bytes();
7482
let caller_on_L1_bytes: [u8; 32] = caller_on_L1.to_field().to_be_bytes();
7583

76-
// function selector: 0x84e55078 keccak256("swap_private(address,uint256,uint24,address,uint256,bytes32,address)")
77-
hash_bytes[0] = 0x84;
78-
hash_bytes[1] = 0xe5;
79-
hash_bytes[2] = 0x50;
80-
hash_bytes[3] = 0x78;
84+
// The purpose of including the following selector is to make the message unique to that specific call. Note that
85+
// it has nothing to do with calling the function.
86+
let selector = comptime {
87+
std::hash::keccak256(
88+
"swap_private(address,uint256,uint24,address,uint256,bytes32,address)".as_bytes(),
89+
68,
90+
)
91+
};
92+
93+
hash_bytes[0] = selector[0];
94+
hash_bytes[1] = selector[1];
95+
hash_bytes[2] = selector[2];
96+
hash_bytes[3] = selector[3];
8197

8298
for i in 0..32 {
8399
hash_bytes[i + 4] = input_token_portal_bytes[i];

0 commit comments

Comments
 (0)