From 14464a257987b2d0b0c6908bafb9d85625cc0e69 Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Fri, 2 Jun 2023 15:07:25 +0800 Subject: [PATCH 1/3] bring id to eth deposit --- packages/protocol/contracts/L1/TaikoData.sol | 3 ++- .../contracts/L1/libs/LibEthDepositing.sol | 16 ++-------------- packages/protocol/test/TaikoL1.t.sol | 4 ++-- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index f7be7519898..9cf5a1986a5 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -108,8 +108,9 @@ library TaikoData { uint24 size; } - // 1 slot + // 2 slot struct EthDeposit { + uint64 id; address recipient; uint96 amount; } diff --git a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol index ef09e7e54a7..33f7f87e63c 100644 --- a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol @@ -37,6 +37,7 @@ library LibEthDepositing { } TaikoData.EthDeposit memory deposit = TaikoData.EthDeposit({ + id: uint64(state.ethDeposits.length), recipient: msg.sender, amount: uint96(msg.value) }); @@ -126,19 +127,6 @@ library LibEthDepositing { pure returns (bytes32) { - bytes memory buffer = new bytes(32 * deposits.length); - - for (uint256 i; i < deposits.length;) { - uint256 encoded = uint256(uint160(deposits[i].recipient)) << 96 - | uint256(deposits[i].amount); - assembly { - mstore(add(buffer, mul(32, add(1, i))), encoded) - } - unchecked { - ++i; - } - } - - return keccak256(buffer); + return keccak256(abi.encode(deposits)); } } diff --git a/packages/protocol/test/TaikoL1.t.sol b/packages/protocol/test/TaikoL1.t.sol index bbe93892944..1155a9db138 100644 --- a/packages/protocol/test/TaikoL1.t.sol +++ b/packages/protocol/test/TaikoL1.t.sol @@ -334,12 +334,12 @@ contract TaikoL1Test is TaikoL1TestBase { proposeBlock(Alice, 1_000_000, 1024); // Expected: - // 0x8117066d69ff650d78f0d7383a10cc802c2b8c0eedd932d70994252e2438c636 (pre + // 0x25fdce9f620e3ee4c33ae0841c3cce2030516a75c8e045847364d1c280bfb714 (pre // calculated with these values) //console2.logBytes32(meta.depositsRoot); assertEq( LibEthDepositing.hashEthDeposits(meta.depositsProcessed), - 0x8117066d69ff650d78f0d7383a10cc802c2b8c0eedd932d70994252e2438c636 + 0x25fdce9f620e3ee4c33ae0841c3cce2030516a75c8e045847364d1c280bfb714 ); } } From 8024db0177bece96e2647165755678bd5ad816af Mon Sep 17 00:00:00 2001 From: Daniel Wang Date: Fri, 2 Jun 2023 15:10:51 +0800 Subject: [PATCH 2/3] bring id to eth deposit --- packages/protocol/contracts/L1/TaikoData.sol | 2 +- packages/protocol/contracts/L1/libs/LibEthDepositing.sol | 4 ++-- packages/protocol/test/TaikoL1.t.sol | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index 9cf5a1986a5..6ff39b4fb78 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -110,9 +110,9 @@ library TaikoData { // 2 slot struct EthDeposit { - uint64 id; address recipient; uint96 amount; + uint64 id; } struct State { diff --git a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol index 33f7f87e63c..d90d4f554ab 100644 --- a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol @@ -37,9 +37,9 @@ library LibEthDepositing { } TaikoData.EthDeposit memory deposit = TaikoData.EthDeposit({ - id: uint64(state.ethDeposits.length), recipient: msg.sender, - amount: uint96(msg.value) + amount: uint96(msg.value), + id: uint64(state.ethDeposits.length) }); address to = resolver.resolve("ether_vault", true); diff --git a/packages/protocol/test/TaikoL1.t.sol b/packages/protocol/test/TaikoL1.t.sol index 1155a9db138..5a7038da7a4 100644 --- a/packages/protocol/test/TaikoL1.t.sol +++ b/packages/protocol/test/TaikoL1.t.sol @@ -334,12 +334,12 @@ contract TaikoL1Test is TaikoL1TestBase { proposeBlock(Alice, 1_000_000, 1024); // Expected: - // 0x25fdce9f620e3ee4c33ae0841c3cce2030516a75c8e045847364d1c280bfb714 (pre + // 0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30 (pre // calculated with these values) //console2.logBytes32(meta.depositsRoot); assertEq( LibEthDepositing.hashEthDeposits(meta.depositsProcessed), - 0x25fdce9f620e3ee4c33ae0841c3cce2030516a75c8e045847364d1c280bfb714 + 0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30 ); } } From 3cd6febb63626bed2dcd35acfb2bce6c23aede4a Mon Sep 17 00:00:00 2001 From: dantaik Date: Fri, 2 Jun 2023 07:16:14 +0000 Subject: [PATCH 3/3] Add auto-generated contract documentation --- .../pages/docs/reference/contract-documentation/L1/TaikoData.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md b/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md index 16bb9c07c22..7c515bdd37d 100644 --- a/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md +++ b/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md @@ -134,6 +134,7 @@ struct TxListInfo { struct EthDeposit { address recipient; uint96 amount; + uint64 id; } ```