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): fix issue for fee-collecting eth-deposit #13864

Merged
merged 4 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
29 changes: 15 additions & 14 deletions packages/protocol/contracts/L1/libs/LibEthDepositing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ library LibEthDepositing {
{
// Allocate one extra slot for collecting fees on L2
depositsProcessed = new TaikoData.EthDeposit[](
config.maxEthDepositsPerBlock + 1
config.maxEthDepositsPerBlock
);

uint256 j; // number of deposits to process on L2
Expand All @@ -89,28 +89,29 @@ library LibEthDepositing {
&& state.nextEthDepositToProcess
+ config.maxEthDepositsPerBlock > i
) {
TaikoData.EthDeposit storage deposit = state.ethDeposits[i];
if (deposit.amount > feePerDeposit) {
depositsProcessed[j] = state.ethDeposits[i];

if (depositsProcessed[j].amount > feePerDeposit) {
totalFee += feePerDeposit;
depositsProcessed[j].recipient = deposit.recipient;
depositsProcessed[j].amount =
deposit.amount - feePerDeposit;
++j;
depositsProcessed[j].amount -= feePerDeposit;
} else {
totalFee += deposit.amount;
totalFee += depositsProcessed[j].amount;
depositsProcessed[j].amount = 0;
}

// delete the deposit
deposit.recipient = address(0);
deposit.amount = 0;
++i;
++j;
}

// Fee collecting deposit
if (totalFee > 0) {
depositsProcessed[j].recipient = beneficiary;
depositsProcessed[j].amount = totalFee;
++j;
TaikoData.EthDeposit memory deposit = TaikoData.EthDeposit({
recipient: beneficiary,
amount: totalFee,
id: uint64(state.ethDeposits.length)
});

state.ethDeposits.push(deposit);
}
// Advance cursor
state.nextEthDepositToProcess = i;
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/test/TaikoL1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ contract TaikoL1Test is TaikoL1TestBase {
LibEthDepositing.hashEthDeposits(meta.depositsProcessed)
!= emptyDepositsRoot
);
assertEq(meta.depositsProcessed.length, count + 1);
assertEq(meta.depositsProcessed.length, count);

gas = gasleft();
meta = proposeBlock(Alice, 1_000_000, 1024);
Expand Down Expand Up @@ -334,12 +334,12 @@ contract TaikoL1Test is TaikoL1TestBase {
proposeBlock(Alice, 1_000_000, 1024);

// Expected:
// 0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30 (pre
// 0x60386add6a400d9b23968e1239bd600d22d2eea4709246895c0e5d8f5ae49dc3 (pre
// calculated with these values)
//console2.logBytes32(meta.depositsRoot);
assertEq(
LibEthDepositing.hashEthDeposits(meta.depositsProcessed),
0x9098dca53e2412a11d456add7b3652df403e043b2a20f456d4651b9a73b70a30
0x60386add6a400d9b23968e1239bd600d22d2eea4709246895c0e5d8f5ae49dc3
);
}
}