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

chore(protocol): optimize _hashEthDeposits #13782

Merged
merged 8 commits into from
May 19, 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
24 changes: 18 additions & 6 deletions packages/protocol/contracts/L1/libs/LibEthDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,26 @@ library LibEthDepositing {
assembly {
mstore(depositsProcessed, j)
}
depositsRoot = hashDeposits(depositsProcessed);
}

function hashDeposits(TaikoData.EthDeposit[] memory deposits) internal pure returns (bytes32) {
bytes memory buffer;
depositsRoot = _hashEthDeposits(depositsProcessed);
}

for (uint256 i = 0; i < deposits.length; i++) {
buffer = abi.encodePacked(buffer, deposits[i].recipient, deposits[i].amount);
function _hashEthDeposits(TaikoData.EthDeposit[] memory deposits)
private
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);
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ contract TaikoL1Test is TaikoL1TestBase {
}

function test_deposit_hash_creation() external {
uint96 minAmount = conf.minEthDepositAmount;
// uint96 minAmount = conf.minEthDepositAmount;
uint96 maxAmount = conf.maxEthDepositAmount;

// We need 8 depostis otherwise we are not processing them !
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function getBlockFee() public view returns (uint64)
### getProofReward

```solidity
function getProofReward(uint64 provenAt, uint64 proposedAt) public view returns (uint64)
function getProofReward(uint64 proofTime) public view returns (uint64)
```

### getBlock
Expand Down