Skip to content

Commit

Permalink
fix(protocol): hash deposit IDs (#13853)
Browse files Browse the repository at this point in the history
Co-authored-by: dantaik <[email protected]>
  • Loading branch information
dantaik and dantaik authored Jun 2, 2023
1 parent 0f06392 commit d3aea36
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/TaikoData.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ library TaikoData {
uint24 size;
}

// 1 slot
// 2 slot
struct EthDeposit {
address recipient;
uint96 amount;
uint64 id;
}

struct State {
Expand Down
18 changes: 3 additions & 15 deletions packages/protocol/contracts/L1/libs/LibEthDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}
}
4 changes: 2 additions & 2 deletions packages/protocol/test/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ struct TxListInfo {
struct EthDeposit {
address recipient;
uint96 amount;
uint64 id;
}
```

Expand Down

0 comments on commit d3aea36

Please sign in to comment.