Skip to content
Business logic Audit finding Intermediate

There is no slippage check for the eth deposits processing in the LibDepositing.processDeposits

The deposit processing function charges a fee based on the current L1 block basefee without any slippage check, so if the basefee rises significantly before the deposit is processed, the recipient can lose a large portion of the deposited amount. An attacker cannot directly trigger this, but users are exposed to unpredictable fee deductions.

Shield Follow with ladboy233

Originally disclosed on Code4rena

Submitted by Shield, also found by ladboy233

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L138-L142

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/TaikoL1.sol#L209-L211

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L83

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L93

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L101

The LibDepositing.depositEtherToL2 function is called by the TaikoL1.depositEtherToL2 to deposit ether to the L2 chain. The maximum number of unprocessed eth deposits are capped at _config.ethDepositRingBufferSize - 1 as shown here:

        unchecked {
            return _amount >= _config.ethDepositMinAmount && _amount <= _config.ethDepositMaxAmount
                && _state.slotA.numEthDeposits - _state.slotA.nextEthDepositToProcess
                    < _config.ethDepositRingBufferSize - 1;
        }

The Taiko configuration states that ethDepositRingBufferSize == 1024. Hence the maximum unprocessed eth deposits allowed by the taiko L1 contract is capped at 1023.

When the L2 block is proposed by calling the LibProposing.proposeBlock function by the TaikoL1 contract, it processes the unprocessed eth deposits by calling the LibDepositing.processDeposits. But it is allowed to process at most 32 eth deposits per block as per the following conditional check in the processDeposits function.

deposits_ = new TaikoData.EthDeposit[(numPending.min(_config.ethDepositMaxCountPerBlock));

Here the ethDepositMaxCountPerBlock == 32 as configured in the TaikoL1.getConfig function.

And the fee amount for each of the eth deposits are calculated as follows:

uint96 fee = uint96(_config.ethDepositMaxFee.min(block.basefee * _config.ethDepositGas));

uint96 _fee = deposits_[i].amount > fee ? fee : deposits_[i].amount;

deposits_[i].amount -= _fee;

Hence the deposited eth amount is deducted by the calculated _fee amount for the eth deposit transaction. If the basefee of the L1 block increases significantly then the maximum fee of ethDepositMaxFee: 1 ether / 10 will be applied. Thus deducting that amount from the transferred eth deposit to the recipient in L2.

Now let’s consider the following scenario:

  1. nextEthDepositToProcess is currently 100.
  2. numEthDeposits is 1060 currently.
  3. The number of proposed L2 blocks required to process 1060th eth deposit is = 1060 - 100 / 32 = 30 L2 blocks.
  4. As a result all the above 30 L2 blocks will not be proposed in a single L1 block and will require multiple L1 blocks for it.
  5. If there is huge congestion in the mainnet during this time the block.basefee of the subsequent L1 blocks would increase. And this could prompt the maximum fee of _config.ethDepositMaxFee to be charged on the deposited amount (in the LibDepositing.processDeposits function, since subsequent L1 block would have a higher block.basefee) thus prompting loss of funds on the recipient.
  6. For example let’s assume the depositor deposit 1.1 ether and current gas fee is 0.01 ether. Hence the recipient expects to receive approximately 1.09 ether at the time of the deposit on L1. But when the deposit is processed in a subsequent L1 block, if the fee amount increases to the maximum amount of 0.1 ether then the recipient will only get approximately 1 ether only. This will cost the recipient a loss of 0.9 ether. If there was a slippage check a depositor can set for his eth deposits then the he can prevent excessive gas costs during processing.

Proof of Concept

        unchecked {
            return _amount >= _config.ethDepositMinAmount && _amount <= _config.ethDepositMaxAmount
                && _state.slotA.numEthDeposits - _state.slotA.nextEthDepositToProcess
                    < _config.ethDepositRingBufferSize - 1;
        }

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L138-L142

            ethDepositRingBufferSize: 1024,
            ethDepositMinCountPerBlock: 8,
            ethDepositMaxCountPerBlock: 32,

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/TaikoL1.sol#L209-L211

            uint96 fee = uint96(_config.ethDepositMaxFee.min(block.basefee * _config.ethDepositGas));

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L83

                uint96 _fee = deposits_[i].amount > fee ? fee : deposits_[i].amount;

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L93

                    deposits_[i].amount -= _fee;

https://github.com/code-423n4/2024-03-taiko/blob/main/packages/protocol/contracts/L1/libs/LibDepositing.sol#L101

Tools Used

VSCode

Recommended Mitigation Steps

Hence it is recommended to add a slippage check for the fee amount of the deposited eth amount in the LibDepositing.processDeposits function, since depositEtherToL2 and processDepositare two different transactions with a delay during which the L1 block basefee can increase significantly causing loss of funds to the recipient in the form of fee increase.

dantaik (Taiko) acknowledged, but disagreed with severity and commented:

Thank you for the feedback. The current issue is valid but minor as we believe users can choose not to deposit Ether using the depositEtherToL2 function if there are already many deposits pending in the queue. Going forward, the processing of such deposits will likely be moved to the node software directly.

0xean (Judge) commented:

Agree this is valid, the impact is most likely small, but I think the likelihood of it occurring at some point is relatively high. The user is exposed to non-deterministic behavior that they cannot fully understand ahead of signing a transaction.


The original report as published on Code4rena, by Shield. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the deposit processing calculates the fee using the current block's basefee at processing time, without allowing the depositor to set a maximum acceptable fee.

Impact

The recipient could lose a significant portion of the deposited amount if the L1 basefee rises before processing, though the likelihood depends on network congestion and the team considers it minor.

What the attacker needed

User deposits ether via depositEtherToL2; L1 basefee rises before processing

The fix

A slippage check should be added so the depositor can specify a maximum acceptable fee for the deposit processing.

How it was found

  1. A user deposits ether via depositEtherToL2, expecting a certain fee based on the current basefee.
  2. The deposit is queued and processed later in a subsequent L1 block.
  3. If the basefee has risen significantly by then, the fee is recalculated and may hit the maximum.
  4. The recipient receives less ether than expected due to the higher fee.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you send ether to another chain through this contract, the fee is calculated later, when the deposit is actually processed. If the network is busy at that later time, the fee can jump to a maximum, and you receive less than you expected. There is no way to say 'don't process if the fee is too high'.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Shield

View all

3 more disclosed reports, best first.

More from Taiko

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.