Skip to content
DoS Audit finding Intermediate

VaultRouter cannot be used for deposits when it reaches the maximum deposit limit

The VaultRouter contract, when depositing to a vault, is treated as the depositor and thus subject to the vault's maximum deposit limit. An attacker can deposit through the router with the router as recipient and then withdraw in the same transaction, causing the router to reach its limit and preventing all future deposits via the router.

0xlemon Follow

Originally disclosed on Code4rena

Submitted by 0xlemon

https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultBase.sol#L251

https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultRouter.sol#L116

Summary

VaultRouter cannot be used for deposits when it reaches the maximum deposit limit because this contract is the msg.sender to the vault and it is treated as a depositor who has a limit.

Vulnerability Details

When doing deposits to a vault from the VaultRouter the router does an external call to the vault meaning that in Vault’s case msg.sender will be the router itself. The protocol, however, enforces a max deposit limit for depositors. This means that after the VaultRouter reaches the vault’s getMaxDeposit() no one will be able to deposit to the vault using the router.

Since the vault looks at balanceOf(msg.sender) for the deposit limit, an attacker can use the router to deposit to the vault specifying the recipient to be the router itself and then immediately withdrawing in the same transaction so that his tokens won’t be stolen. He can do that to reach VaultRouter deposit limit and now no one will be able to deposit through the router.

    function _depositInternal(uint256 assets, address receiver) private returns (uint256 shares) {
        //...

        // Check if deposit exceeds the maximum allowed per wallet
        uint256 maxDepositLocal = getMaxDeposit();
        if (maxDepositLocal > 0) {
@->            uint256 depositInAssets = (balanceOf(msg.sender) * _ONE) / tokenPerAsset();
            uint256 newBalance = assets + depositInAssets;
            if (newBalance > maxDepositLocal) revert MaxDepositReached();
        }
        //...
    }

Impact

DoS of the router’s deposit functionality

Recommended mitigation steps

You can try to enforce the same deposit limit on the router level and give the router unlimited deposit limit

klau5 (warden) commented:

Same root cause different impact. S-2 mitigation would work.

Dravee (judge) commented:

While the finding here is interesting, according to the Supreme Court decisions, this should be a duplicate.

0xlemon (warden) commented:

@Dravee - the recommended mitigation in S-2 is absolutely wrong. As I said previously it is a deposit limit so taking the balanceOf (receiver) does absolutely nothing but limit the amount a single user can “hold”.

The correct way to fix S-2 would be to implement some kind of a mapping to account for any deposit and limit the amount msg.sender can deposit. This, however, doesn’t solve this finding. The root cause is not the same because here it is shown the interactions between VaultRouter and the Vault and it blocks the VaultRouter from depositing.

Dravee (judge) commented:

0xlemon, I agree. Additionally, making S-15 as primary instead of S-2 due to the wrong mitigation.

shaflow2 (warden) commented:

  1. The current implementation of the deposit limit in the system is incorrect. This report is based on the issue that the sponsor implemented an erroneous mitigation measure. Therefore, this issue should be categorized under implementation problems related to the deposit limit. Relevant historical judgments:https://github.com/code-423n4/2024-08-chakra-findings/issues/33

  2. In report s-2, it was mentioned:

    “Additionally, considering the whitelist mechanism, if you want to limit the deposit amount for whitelisted addresses, it is recommended to create a mapping to store the deposit amount for each address, rather than checking the balanceOf.”

    This point was not elaborated further because managing the deposit limit mapping is challenging. For example, if an address has a deposit limit of 1000, and it deposits 1000, increasing depositLimit[addr1] by 1000. If this address then transfers shares to another address addr2, and addr2 withdraws, with depositLimit[addr2] = 0, how should the deposit limit be deducted? If the deposit limit is not reduced, under the condition that the whitelist is not increased, the total assets in the system will only decrease over time.

0xlemon (warden) commented:

shaflow2 - the problem in this issue is that the VaultRouter is the msg.sender and since we are limiting msg.sender it will get blocked after it reaches the limit. The problem in S-15 is that balanceOf was used to account for the deposit limit. Do you see the difference? In my problem it doesn’t matter how this deposit limit is implemented when it limits msg.sender as it can be seen.

For the mapping part first of all it would be highly unlikely for a user to just give (transfer) his tokens away to someone but even if they do why do we need to deduct the limit when transfering? As I said it doesn’t matter how much a single user holds, we only need to make sure he doesn’t deposit more than maxDepositLocal

MrPotatoMagic (warden) commented:

@Dravee, I agree with klau5 and shaflow2. This issue should not be considered as separate.

According to the SC ruling here, if fixing the root cause (in a reasonable manner) resolves the issue, they’re dups. It is important to focus on the point of fixing the issue in reasonable manner here.

How can the issue actually be mitigated?

  • If msg.sender is the router, take in another parameter routerMsgSender to the deposit()/_depositInternal() function that stores the msg.sender of the router contract.
  • Implement an if check in deposit()/_depositInternal() that when msg.sender == router is true, we utilize the parameter routerMsgSender to check the limit as per the method suggested by S-2. I.e., “it is recommended to create a mapping to store the deposit amount for each address”.

Both the issues are two sides of the same coin. A universal mitigation as mentioned above resolves both of them.

Dravee (judge) commented:

I’m agreeing with 0xlemon on this one, as reasonably fixing the other issue (by strictly fixing the other issue) would leave this current issue unfixed (unless already aware of this finding, which would be unreasonable).

chefkenji (BakerFi) disputed and commented:

Duplicate issue

BakerFi mitigated:

PR-4

Status: Mitigation confirmed. Full details in the report from 0xlemon.


The original report as published on Code4rena, by 0xlemon. 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

The vault enforces its deposit limit based on the caller (msg.sender), and when deposits go through VaultRouter, the router itself becomes the caller, so its balance counts toward the limit.

Impact

The router's deposit functionality is blocked, causing a denial of service for all users who rely on the router to deposit.

What the attacker needed

Access to the VaultRouter deposit function; ability to withdraw in the same transaction

The fix

The deposit limit should be enforced at the router level, giving the router an unlimited deposit limit, or the vault should track deposits per actual user rather than per caller.

How it was found

  1. Call the router to deposit into the vault, setting the recipient as the router itself.
  2. Immediately withdraw the deposited tokens in the same transaction to avoid loss.
  3. Repeat until the router's balance reaches the vault's maximum deposit limit.
  4. Now no one can deposit through the router because it has reached 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 vault contract limits how much each depositor can put in. When people deposit through a helper contract called VaultRouter, the vault sees the router as the depositor. An attacker can fill up the router's limit and then take their money back, leaving the router unable to deposit for anyone else.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xlemon

View all

4 more disclosed reports, best first.

More from BakerFi Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.