Users lose their entire investment when making a deposit and resulting shares are zero
A deposit could mint zero shares due to rounding down in share calculation, causing the user to lose their entire deposited amount. An attacker could exploit this by depositing a small amount when the share price is high, resulting in zero shares and loss of funds.
Submitted by DadeKuma, also found by chaduke
Impact
Users could receive 0 shares and thus lose their entire investment when making a deposit.
Proof of Concept
Alice calls deposit with 999 assets, with herself as the receiver
function deposit(uint256 assets, address receiver)
public
virtual
override
returns (uint256)
{
if (assets > maxDeposit(receiver)) revert MaxError(assets);
uint256 shares = _previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
return shares;
}
Shares are calculated through _previewDeposit, which uses _convertToShares rounding down
function _convertToShares(uint256 assets, Math.Rounding rounding)
internal
view
virtual
override
returns (uint256 shares)
{
uint256 _totalSupply = totalSupply();
uint256 _totalAssets = totalAssets();
return
(assets == 0 || _totalSupply == 0 || _totalAssets == 0)
? assets
: assets.mulDiv(_totalSupply, _totalAssets, rounding);
}
With specific conditions, the share calculation will round to zero. Let’s suppose that _totalSupply = 100_000 and _totalAssets = 100_000_000, then:
assets * _totalSupply / _totalAssets => 999 * 100_000 / 100_000_000
which rounds to zero, so total shares are 0.
Finally, the deposit is completed, and the adapter mints 0 shares.
function _deposit(
address caller,
address receiver,
uint256 assets,
uint256 shares
) internal nonReentrant virtual override {
IERC20(asset()).safeTransferFrom(caller, address(this), assets);
uint256 underlyingBalance_ = _underlyingBalance();
_protocolDeposit(assets, shares);
// Update the underlying balance to prevent inflation attacks
underlyingBalance += _underlyingBalance() - underlyingBalance_;
_mint(receiver, shares);
harvest();
emit Deposit(caller, receiver, assets, shares);
}
Alice has lost 999 assets and she has received nothing in return.
Recommended Mitigation Steps
Revert the transaction when a deposit would result in 0 shares minted.
RedVeil (Popcorn) confirmed, but disagreed with severity
LSDan (judge) decreased severity to Medium
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 share calculation rounds down without checking for zero shares, so small deposits relative to the total assets can mint zero shares.
What the attacker needed
Vault total assets much larger than total supply; user deposits a small amount
The fix
The transaction should revert when a deposit would result in 0 shares minted.
How it was found
- Alice calls deposit with 999 assets and herself as receiver.
- The contract calculates shares using _previewDeposit, which rounds down.
- With totalSupply=100,000 and totalAssets=100,000,000, the calculation yields 0 shares.
- The deposit completes and mints 0 shares to Alice.
- Alice loses her 999 assets and receives nothing.
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 deposit money into a vault, you get shares representing your portion. If the maths rounds your shares down to zero, you lose your deposit because you get nothing back. This report shows that can happen when the vault's total value is much larger than its total shares.