Skip to content
Business logic Audit finding Intermediate

Vulnerabilities in Deposit Limit Enforcement and the Impact on Failed Deposits

The deposit limit check in the L1ERC20Bridge contract only tracks a user's deposited amount when a limit is active, so failed deposits made before a limit is set are not counted. This allows a malicious user to claim those failed deposits after the limit is enforced, reducing their tracked total and bypassing the deposit cap.

anon Follow with rvierdiiev, Koolex and 14 others

Originally disclosed on Code4rena

Submitted by anon, also found by rvierdiiev, hals (1, 2), Koolex, cccz, AkshaySrivastav, bin2chen, 0xsomeone, Aymen0909, brgltd, shealtielanz, zzzitron, peanuts, Mohandes, tsvetanovv, J4de, ladboy233, and max10afternoon

  1. Users Failed Deposits: If a token has no deposit limitation initially and a user’s deposit transaction fails, they may not be able to claim their failed deposits later if a deposit limit is imposed on that token.
  2. Deposit Limit Bypass: Malicious users can exploit the deposit limit system by making failed deposits before the deposit limit is introduced. By claiming these failed deposits, they can reset their total deposited amount, allowing them to exceed the deposit cap once it is enforced.

Proof of Concept

When depositing an ERC20 token into the L1ERC20Bridge, the _verifyDepositLimit function plays a pivotal role. This function’s primary purpose is to ascertain whether there is a predefined deposit limit in place for the given token and, if such a cap exists, to determine if the user’s cumulative deposit amount surpasses this imposed restriction. The user’s total deposited amount is meticulously tracked and maintained using the totalDepositedAmountPerUser mapping.

https://github.com/code-423n4/2023-10-zksync/blob/main/code/contracts/ethereum/contracts/bridge/L1ERC20Bridge.sol#L188 https://github.com/code-423n4/2023-10-zksync/blob/main/code/contracts/ethereum/contracts/bridge/L1ERC20Bridge.sol#L348

This same mechanism is applied when a user seeks to reclaim their failed deposit. In this scenario, the claimFailedDeposit function is invoked, which once again triggers the _verifyDepositLimit function. However, in this context, the objective is to adjust the totalDepositedAmountPerUser mapping by decreasing the total deposited amount due to the claiming failed transaction.

https://github.com/code-423n4/2023-10-zksync/blob/main/code/contracts/ethereum/contracts/bridge/L1ERC20Bridge.sol#L278 https://github.com/code-423n4/2023-10-zksync/blob/main/code/contracts/ethereum/contracts/bridge/L1ERC20Bridge.sol#L345

This implementation can give rise to significant issues, which can be illustrated through the following scenarios:

Scenario 1: Suppose there’s no deposit limitation imposed on tokenX, indicated by limitData.depositLimitation = false. Alice (an honest user) initiates a deposit of 100 tokenX. However, these deposits unfortunately fail. At a later point, the owner decides to enforce a deposit limit on this token by employing the setDepositLimit function within the AllowList contract. Now, Alice seeks to claim her previously failed deposits. However, when the _verifyDepositLimit function is invoked during this process, the if-condition is met. Yet, the issue arises when the amount 100 is going to be deducted from totalDepositedAmountPerUser[tokenX][Alice] (which equals 0). This results in an underflow, causing the transaction to revert. So, Alice can not claim her failed deposit in this scenario.

In summary, if there was no deposit limit set for a token initially, and users experienced failed deposit transactions for that token, they encounter difficulties in claiming those failed deposits when a deposit limit is subsequently enforced.

Scenario 2: Consider a scenario in which there’s no deposit limitation for tokenY initially. However, Bob (a malicious user) monitors the owner’s transaction that is going to set a deposit limit for tokenY, specifying tokenDeposit[tokenY].depositCap = 100. Immediately, Bob deposits 100 tokenY three times, a total of 300 tokenY, deliberately ensuring that these transactions fail on L2 due to a low _l2TxGasLimit. Subsequently, the owner’s transaction to establish a deposit limit of 100 for tokenY is executed. Now, Bob decides to deposit another 100 tokenY, resulting in totalDepositedAmountPerUser[tokenY][Bob] being set to 100.

However, Bob intends to deposit another 100 tokenY. As the condition require(totalDepositedAmountPerUser[_l1Token][_depositor] + _amount <= limitData.depositCap, "d1"); is examined, this requirement stipulates that totalDepositedAmountPerUser[tokenY][Bob] + 100 must not exceed the deposit cap of 100. Bob’s attempt to deposit an additional 100 tokenY is therefore denied.

Nonetheless, Bob realizes he can exploit a potential vulnerability. He decides to claim one of his three failed transactions that occurred prior to the deposit cap set up. As a result, totalDepositedAmountPerUser[tokenY][Bob] decreases by 100, effectively resetting it to 0. Now Bob can once again deposit 100 tokenY, despite having previously reached the imposed deposit limit. Bob continues this process, claiming his failed deposits after each attempt, thus resetting totalDepositedAmountPerUser[tokenY][Bob] and allowing him to deposit 400 tokenY, exceeding the deposit limit of 100.

In summary, this implementation opens the door for malicious users to circumvent deposit limits by arranging failed deposits prior to the imposition of such limits. Subsequently, by claiming these failed deposits, they can effectively increase their deposit limit by resetting totalDepositedAmountPerUser.

Recommended Mitigation Steps

The function _verifyDepositLimit should be revised such that it tracks the deposited amount of users even if there is no deposit limitation in place.

function _verifyDepositLimit(address _l1Token, address _depositor, uint256 _amount, bool _claiming) internal {
        IAllowList.Deposit memory limitData = IAllowList(allowList).getTokenDepositLimitData(_l1Token);

        if (_claiming) {
            totalDepositedAmountPerUser[_l1Token][_depositor] -= _amount;
        } else {
            totalDepositedAmountPerUser[_l1Token][_depositor] += _amount;
	    if(limitData.depositLimitation){
               require(totalDepositedAmountPerUser[_l1Token][_depositor] <= limitData.depositCap, "d1");
            }
        }
    }

https://github.com/code-423n4/2023-10-zksync/blob/main/code/contracts/ethereum/contracts/zksync/facets/Mailbox.sol#L275

Assessed type

Context

miladpiri (zkSync) confirmed, but disagreed with severity and commented:

This is an issue if we switch the deposit limitation feature on/off. But, this is not going to happen as the deposit limitation is only active temporarily during alpha version, later it will be deactivated (removed fully). So, medium severity is fair.

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

Primary because, while other findings have a Coded POC, this one captures an additional risk.


The original report as published on Code4rena, by anon. 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 limit check only updates the user's total deposited amount when a deposit limitation is active, so failed deposits made before the limit was set are not recorded and can later be claimed to reduce the total.

Impact

A malicious user could bypass the deposit limit, and honest users may be unable to claim failed deposits if a limit is later imposed; the project stated the limit is only temporary during alpha.

What the attacker needed

Deposit limit not yet set for token; attacker can make failed deposits; owner later sets deposit limit

How it was found

  1. Before a deposit limit is set for a token, the attacker makes multiple deposits that are designed to fail on L2.
  2. The owner sets a deposit limit for that token.
  3. The attacker deposits up to the limit, then claims one of the earlier failed deposits, which reduces their tracked total.
  4. The attacker repeats depositing and claiming failed deposits to exceed the limit.

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.

A deposit limit is a rule that says how much of a token a user can deposit in total. The bridge contract only keeps a running total of deposits when a limit is turned on, so deposits made before the limit are not counted. A user can make deposits that fail on purpose, then later claim them back after the limit is set, which lowers their recorded total and lets them deposit more than the limit allows.

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 anon

View all

10 more disclosed reports, best first.

More from zkSync Era

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.