From d2823ece45f3bda8cda8aec0657748196ac2a31a Mon Sep 17 00:00:00 2001 From: David Date: Fri, 2 Jun 2023 21:49:23 +0800 Subject: [PATCH] feat(protocol): cherry-pick changes in #13853 into alpha-3 branch (#13859) Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> Co-authored-by: dantaik --- packages/protocol/contracts/L1/TaikoData.sol | 3 ++- .../contracts/L1/libs/LibEthDepositing.sol | 22 +++++-------------- packages/protocol/test/TaikoL1.t.sol | 6 +++-- .../contract-documentation/L1/TaikoData.md | 1 + 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoData.sol b/packages/protocol/contracts/L1/TaikoData.sol index 956690766b9..223a7936932 100644 --- a/packages/protocol/contracts/L1/TaikoData.sol +++ b/packages/protocol/contracts/L1/TaikoData.sol @@ -112,10 +112,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 501d960dff4..ea8436615d2 100644 --- a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol @@ -31,8 +31,11 @@ library LibEthDepositing { revert L1_INVALID_ETH_DEPOSIT(); } - TaikoData.EthDeposit memory deposit = - TaikoData.EthDeposit({recipient: msg.sender, amount: uint96(msg.value)}); + TaikoData.EthDeposit memory deposit = TaikoData.EthDeposit({ + recipient: msg.sender, + amount: uint96(msg.value), + id: uint64(state.ethDeposits.length) + }); address to = resolver.resolve("ether_vault", true); if (to == address(0)) { @@ -111,19 +114,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 64206e90df4..ca2d02406bb 100644 --- a/packages/protocol/test/TaikoL1.t.sol +++ b/packages/protocol/test/TaikoL1.t.sol @@ -286,11 +286,13 @@ contract TaikoL1Test is TaikoL1TestBase { // We shall invoke proposeBlock() because this is what will call the processDeposits() TaikoData.BlockMetadata memory meta = proposeBlock(Alice, 1000000, 1024); - // Expected: 0x8117066d69ff650d78f0d7383a10cc802c2b8c0eedd932d70994252e2438c636 (pre calculated with these values) + // Expected: + // 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 37abc79bd72..b64ad08060e 100644 --- a/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md +++ b/packages/website/pages/docs/reference/contract-documentation/L1/TaikoData.md @@ -138,6 +138,7 @@ struct TxListInfo { struct EthDeposit { address recipient; uint96 amount; + uint64 id; } ```