Depositor can bypass the max deposit limit
The vault's maximum deposit limit is checked against the depositor's own share balance rather than the recipient's, so a depositor can bypass the limit by sending deposits to a different recipient address. An attacker could deposit unlimited assets by repeatedly using fresh recipient addresses.
0xlemon Follow with MrPotatoMagic and shaflow2
Originally disclosed on Code4rena
Submitted by 0xlemon, also found by MrPotatoMagic and shaflow2
https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultBase.sol#L251
Summary
Depositors can easily bypass the maximum deposit limit by specifying another recipient address than the one they are depositing from
Vulnerability Details
VaultBase::_depositInternal() limits the amount of assets a single depositor (wallet) can deposit into the vault if _maxDeposit > 0. We can see the following checks being performed:
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();
}
//...
}
The problem here is that we take the shares of msg.sender which can be different from the recipient specified when depositing. This means that a single depositor can deposit as much as he wants, he just has to specify a different recipient address.
Attack path
- Bob has never deposited in the vault so his shares are 0 -
balanceOf(Bob) = 0 - He creates a second wallet to recieve the shares that will be minted to him on deposit
- Bob calls
Vault::deposit()specifying his second wallet as a recipient - At the end of the deposit transaction
balanceOf(Bob)is still 0 because we mint the shares to the recipient (Bob’s second wallet) - Bob repeats this process as much as he wants and his
depositInAssetswill always be 0 so he can never reach the deposit limit.
Impact
Bypassing the deposit limit
Recommended mitigation steps
Introduce a mapping that keeps track of the deposits of msg.sender
chefkenji (BakerFi) confirmed
Status: Unmitigated. Full details in report from shaflow2, and also included in the Mitigation Review section below.
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 deposit limit check uses the share balance of msg.sender instead of the receiver, so deposits to a different address do not count towards the limit.
Impact
An attacker could bypass the per-wallet deposit limit and deposit unlimited assets into the vault.
What the attacker needed
A vault with a maximum deposit limit; ability to create multiple addresses
The fix
The fix should track deposits per sender using a mapping, rather than relying on the sender's current share balance.
How it was found
- Bob has never deposited, so his share balance is zero.
- Bob creates a second wallet to receive the shares.
- Bob calls deposit, specifying the second wallet as recipient.
- Bob's own share balance remains zero because shares are minted to the recipient.
- Bob repeats the process to keep depositing without ever reaching 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 has a rule that one wallet can only deposit up to a certain amount. The code checks how much the sender already has, but the new shares go to a different address. So the sender's balance stays zero and the limit never applies, letting someone deposit as much as they want.
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.