Skip to content

Commit

Permalink
fix(protocol): fix issue for fee-collecting eth-deposit (#13864)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jun 2, 2023
1 parent e48f17c commit c53b135
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
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
);
}
}

0 comments on commit c53b135

Please sign in to comment.