From c53b135aa2e78dc2f829a79c20f12bf2d48a247a Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Sat, 3 Jun 2023 02:57:18 +0800 Subject: [PATCH] fix(protocol): fix issue for fee-collecting eth-deposit (#13864) --- .../contracts/L1/libs/LibEthDepositing.sol | 29 ++++++++++--------- packages/protocol/test/TaikoL1.t.sol | 6 ++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol index d90d4f554ab..75650487207 100644 --- a/packages/protocol/contracts/L1/libs/LibEthDepositing.sol +++ b/packages/protocol/contracts/L1/libs/LibEthDepositing.sol @@ -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 @@ -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; diff --git a/packages/protocol/test/TaikoL1.t.sol b/packages/protocol/test/TaikoL1.t.sol index a0833a9263f..3a01922ac65 100644 --- a/packages/protocol/test/TaikoL1.t.sol +++ b/packages/protocol/test/TaikoL1.t.sol @@ -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); @@ -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 ); } }