Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): hash deposit IDs #13853

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
davidtaikocha marked this conversation as resolved.
Show resolved Hide resolved
});

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