Malicious Users Can Drain The Assets Of Vault. (Due to not being ERC4626 Complaint)
The vault's withdraw function converts assets to shares using rounding down, so small withdrawals can burn zero shares. An attacker could repeatedly withdraw assets without reducing their share balance, draining the vault.
Submitted by fs0c, also found by 0xmuxyz, bin2chen, ladboy233, Kumpa, nadin, DadeKuma, koxuan, rvierdiiev, and rvi0x
Malicious users can drain the assets of the vault.
Proof of Concept
The withdraw function users convertToShares to convert the assets to the amount of shares. These shares are burned from the users account and the assets are returned to the user.
The function withdraw is shown below:
function withdraw(
uint256 assets,
address receiver,
address owner
) public nonReentrant syncFeeCheckpoint returns (uint256 shares) {
if (receiver == address(0)) revert InvalidReceiver();
shares = convertToShares(assets);
/// .... [skipped the code]
The function convertToShares is shown below:
function convertToShares(uint256 assets) public view returns (uint256) {
uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.
return
supply == 0
? assets
: assets.mulDiv(supply, totalAssets(), Math.Rounding.Down);
}
It uses Math.Rounding.Down , but it should use Math.Rounding.Up
Assume that the vault with the following state:
- Total Asset = 1000 WETH
- Total Supply = 10 shares
Assume that Alice wants to withdraw 99 WETH from the vault. Thus, she calls the Vault.withdraw(99 WETH) function.
The calculation would go like this:
assets = 99
return value = assets * supply / totalAssets()
return value = 99 * 10 / 1000
return value = 0
The value would be rounded round to zero. This will be the amount of shares burned from users account, which is zero.
Hence user can drain the assets from the vault without burning their shares.
Note : A similar issue also exists in
mintfunctionality whereMath.Rounding.Downis used andMath.Rounding.Upshould be used.
Recommended Mitigation Steps
Use Math.Rounding.Up instead of Math.Rounding.Down.
As per OZ implementation here is the rounding method that should be used:
deposit : convertToShares → Math.Rounding.Down
mint : converttoAssets → Math.Rounding.Up
withdraw : convertToShares → Math.Rounding.Up
redeem : convertToAssets → Math.Rounding.Down
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
The withdraw function uses Math.Rounding.Down when converting assets to shares, but it should round up so that at least one share is burned.
Impact
A malicious user could drain the assets from the vault without burning their shares.
What the attacker needed
A vault with a small total supply relative to assets; ability to call withdraw
The fix
The withdraw function should use Math.Rounding.Up instead of Math.Rounding.Down when converting assets to shares.
How it was found
- The vault has 1000 WETH in assets and 10 shares in total supply.
- Alice calls withdraw for 99 WETH.
- The conversion calculates 99 * 10 / 1000, which rounds down to 0 shares.
- Zero shares are burned, so Alice receives 99 WETH while keeping her shares.
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 holds money for many people and tracks each person's share. When you take money out, the vault should burn a matching number of shares. Here the maths rounded the share amount down to zero, so someone could take money out while keeping all their shares, and repeat until the vault is empty.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.