From d3aea36ce715d45ba444dbc261a3efff4912e9b1 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Fri, 2 Jun 2023 21:12:21 +0800 Subject: [PATCH] fix(protocol): hash deposit IDs (#13853) Co-authored-by: dantaik --- packages/protocol/contracts/L1/TaikoData.sol | 3 ++- .../contracts/L1/libs/LibEthDepositing.sol | 18 +++--------------- packages/protocol/test/TaikoL1.t.sol | 4 ++-- .../contract-documentation/L1/TaikoData.md | 1 + 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index f7be7519898..6ff39b4fb78 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -108,10 +108,11 @@ library TaikoData { uint24 size; } - // 1 slot + // 2 slot struct EthDeposit { 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 ef09e7e54a7..d90d4f554ab 100644 --- a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol @@ -38,7 +38,8 @@ library LibEthDepositing { TaikoData.EthDeposit memory deposit = TaikoData.EthDeposit({ recipient: msg.sender, - amount: uint96(msg.value) + amount: uint96(msg.value), + id: uint64(state.ethDeposits.length) }); address to = resolver.resolve("ether_vault", true); @@ -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..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: - // 0x8117066d69ff650d78f0d7383a10cc802c2b8c0eedd932d70994252e2438c636 (pre + // 0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30 (pre // calculated with these values) //console2.logBytes32(meta.depositsRoot); assertEq( LibEthDepositing.hashEthDeposits(meta.depositsProcessed), - 0x8117066d69ff650d78f0d7383a10cc802c2b8c0eedd932d70994252e2438c636 + 0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30 ); } } 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; } ```