Skip to content

Commit

Permalink
feat(protocol): cherry-pick changes in #13853 into alpha-3 branch (#1…
Browse files Browse the repository at this point in the history
…3859)

Co-authored-by: Daniel Wang <[email protected]>
Co-authored-by: dantaik <[email protected]>
  • Loading branch information
3 people authored Jun 2, 2023
1 parent f6bdc1d commit d2823ec
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 19 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 @@ -112,10 +112,11 @@ library TaikoData {
uint24 size;
}

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

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

Expand Down

0 comments on commit d2823ec

Please sign in to comment.