Skip to content
Business logic Audit finding Intermediate

Mailbox.requestL2Transaction() checks the deposit limit of msg.sender ( L1WethBridge ) instead of the real depositor of weth from L1, as a result, after certain time, nobody will be able to deposit weth anymore from L1

The deposit limit check in Mailbox.requestL2Transaction() uses msg.sender (the L1WethBridge contract) instead of the actual depositor, so the bridge's cumulative deposits count against a single limit. Once that limit is reached, no further WETH deposits from L1 are possible even if individual users are under their own limits.

chaduke Follow with chaduke, Udsen and 11 others

Originally disclosed on Code4rena

Submitted by chaduke, also found by chaduke, Udsen, zero-idea, J4de, bin2chen, Aymen0909, Nyx, bart1e, anon, ladboy233, tapir, rvierdiiev, and mahdirostami

Proof of Concept

The flow bridgeProxy.deposit() -> L1WethBridge.deposit() -> Mailbox.requestL2Transaction() allows one to deposit WETH from L1 to L2. However, when checking the deposit limit for a particular depositor, Mailbox.requestL2Transaction() checks the limit of msg.sender, which is the address of L1WethBridge.

https://github.com/code-423n4/2023-10-zksync/blob/1fb4649b612fac7b4ee613df6f6b7d921ddd6b0d/code/contracts/ethereum/contracts/zksync/facets/Mailbox.sol#L236-L273

As a result, when the limit of the bridge is reached, nobody can deposit anymore, even though their limit is not reached yet. As a result, sooner or later, nobody will be able to use Zksync to deposit weth to L2 from L1.

POC:

  1. We set the deposit limit to 10 ether.
  2. User1 deposits 3 ether of weth and sends 0.1 ether of eth, this is successful, we have s.totalDepositedAmountPerUser\[L1WethBridge] = 3.1 ether.
  3. User2 deposits 4 ether of weth and 0.1 ether of eth. This is successful and we have s.totalDepositedAmountPerUser\[L1WethBridge] = 7.2 ether.
  4. User3 deposits 2.7 ether of weth and 0.1 weth. This is successful and we have s.totalDepositedAmountPerUser\[L1WethBridge] = 10 ether. It has not exceeded the limit; however, if User3 deposits 2.7 ether + 1 of weth and 0.1 weth, then it will revert since now s.totalDepositedAmountPerUser\[L1WethBridge] = 10 ether + 1. Note that User3 has not exceeded its limit. However, the limit check is on L1WethBridge, not on User3, and that is the problem.

The following test file is a modification of the test file: zksync/code/contracts/ethereum/test/foundry/unit/concrete/Bridge/L1WethBridge/Deposit.t.sol. The test function is test_DepositExceedLimit().

Please run the following command under zksync/code/contracts/ethereum:

forge test --match-test test_DepositExceedLimit -vv

The following line has been commented out to skip the check of merkle root:

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

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.17;

import "lib/forge-std/src/Test.sol";

import {L1WethBridgeTest} from "./_L1WethBridge_Shared.t.sol";
import {IAllowList} from "../../../../../../cache/solpp-generated-contracts/common/interfaces/IAllowList.sol";
import {REQUIRED_L2_GAS_PRICE_PER_PUBDATA} from "../../../../../../cache/solpp-generated-contracts/zksync/Config.sol";

contract DepositTest is L1WethBridgeTest {
    function deposit(address user, uint256 amount) private returns (bool) {
        hoax(user);
        l1Weth.deposit{value: amount}();

        hoax(user);
        l1Weth.approve(address(bridgeProxy), amount);

        bytes memory depositCallData = abi.encodeWithSelector(
            bridgeProxy.deposit.selector,
            user,
            bridgeProxy.l1WethAddress(),
            amount,
            1000000,                        // gas limit
            REQUIRED_L2_GAS_PRICE_PER_PUBDATA,
            user
        );

        hoax(user);
        (bool success, ) = address(bridgeProxy).call{value: 0.1 ether}(depositCallData);
        return success;
    }

    function test_DepositExceedLimit() public {
        console.log("\n \n test_DepositExceeLimit is started....$$$$$$$$$$$$$$4");

        address user1 = address(111);
        address user2 = address(222);
        address user3 = address(333);

        vm.prank(owner);
        allowList.setDepositLimit(address(0), true, 10 ether); // deposit at most 10 ether
        IAllowList.Deposit memory limitData = IAllowList(allowList).getTokenDepositLimitData(address(0));
        assertEq(limitData.depositCap, 10 ether);

        bool success = deposit(user1, 3 ether); // send 3 ether weth and 0.1 ether eth
        assertTrue(success);

        success = deposit(user2, 4 ether); // send 4 ether weth and 0.1 ether eth
        assertTrue(success);

        success =  deposit(user3, 2.7 ether + 1); // send 2.7 ether + 1 weth  and 0.1 ether eth, now a total of 10ether + 1, will it exceed?
        assertFalse(success);   // s.totalDepositedAmountPerUser[L1WethBridge] = 10 ether + 1, it exceeds the limit of 10 ether
    }
}

Tools Used

Foundry, VScode

Recommended Mitigation Steps

Check the limit of the real depositor instead of the limit for the L1WethBridge.

Assessed type

Math

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

Deposit limitation is a temporary feature implemented to protect users from depositing large amount of fund into the protocol while it is in alpha mode. So, issues like this does not cause damage to the protocol. Medium can be a fair severity.

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

The Warden has shown how the implementation of limits, which are indexed by address, will cause the bridge to be subject to the caps that should apply to a single wallet. Since the finding would deny functionality but can technically be removed, I think Medium Severity to be most appropriate.


The original report as published on Code4rena, by chaduke. 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 is keyed on msg.sender rather than on the actual depositor address passed through the bridge call.

Impact

After the bridge's cumulative deposits reach the limit, no user can deposit WETH from L1 to L2, even if their own limit is not reached; the project noted the limit is a temporary alpha protection, so the issue denies functionality rather than causing direct loss.

What the attacker needed

Deposit limit feature enabled; users deposit WETH via the L1 bridge

The fix

The limit should be checked against the real depositor rather than the L1WethBridge address.

How it was found

  1. Set the deposit limit to 10 ether.
  2. User1 deposits 3 ether of WETH and 0.1 ether of ETH; the bridge's recorded total becomes 3.1 ether.
  3. User2 deposits 4 ether of WETH and 0.1 ether of ETH; the bridge's recorded total becomes 7.2 ether.
  4. User3 deposits 2.7 ether of WETH and 0.1 ether of ETH; the bridge's recorded total reaches 10 ether.
  5. User3 attempts to deposit 2.7 ether plus 1 wei of WETH and 0.1 ether of ETH; the transaction reverts because the bridge's total would exceed 10 ether.

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 meant to cap how much each user can send. Here the code checks the limit for the bridge contract itself, not for the person depositing. So all users' deposits add up against one shared cap, and when that cap is hit, everyone is blocked from depositing more.

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 chaduke

View all

21 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.