ERC4626 mint uses wrong amount
The ERC4626 mint function mints the asset amount instead of the requested share amount, so when shares and assets are not 1-to-1, users receive more shares than they should. An attacker could repeatedly mint and redeem to drain the vault's assets.
Submitted by cmichel, also found by 0xliumin, CertoraInc, Picodes, and Ruhum
The docs/video say
ERC4626.solis in scope as its part ofTurboSafe
The ERC4626.mint function mints amount instead of shares. This will lead to issues when the asset <> shares are not 1-to-1 as will be the case for most vaults over time. Usually, the asset amount is larger than the share amount as vaults receive asset yield. Therefore, when minting, shares should be less than amount. Users receive a larger share amount here which can be exploited to drain the vault assets.
function mint(uint256 shares, address to) public virtual returns (uint256 amount) {
amount = previewMint(shares); // No need to check for rounding error, previewMint rounds up.
// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), amount);
_mint(to, amount);
emit Deposit(msg.sender, to, amount, shares);
afterDeposit(amount, shares);
}
Proof of Concept
Assume vault.totalSupply() = 1000, totalAssets = 1500
- call
mint(shares=1000). Only need to pay1000asset amount but receive1000shares =>vault.totalSupply() = 2000,totalAssets = 2500. - call
redeem(shares=1000). Receive(1000 / 2000) * 2500 = 1250amounts. Make a profit of250asset tokens. - repeat until
shares <> assetsare 1-to-1
Recommended Mitigation Steps
In deposit:
function mint(uint256 shares, address to) public virtual returns (uint256 amount) {
- _mint(to, amount);
+ _mint(to, shares);
}
Alex the Entreprenerd (judge):
The warden has identified what is most likely a small oversight, which would have drastic consequences in the internal accounting of the Vault. Because of impact, I agree with high severity.
The sponsor has mitigated.
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 a copy-paste or oversight error where the mint function uses the asset amount instead of the share amount when calling _mint.
Impact
An attacker could drain the vault's assets by repeatedly minting and redeeming when the share-to-asset ratio is not 1:1.
What the attacker needed
Vault shares and assets not 1-to-1; attacker has asset tokens to mint
The fix
The mint function should mint the requested shares amount, not the asset amount.
How it was found
- Assume vault has totalSupply=1000 and totalAssets=1500.
- Call mint with shares=1000, paying only 1000 asset tokens but receiving 1000 shares.
- Call redeem with shares=1000, receiving 1250 asset tokens, making a profit of 250.
- Repeat until shares and assets are 1-to-1.
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 lets people deposit assets and get shares in return. The mint function is supposed to give you exactly the number of shares you ask for, but it mistakenly gives you a number based on the asset amount, which can be larger. This means you can get more shares than you paid for and then redeem them for a profit, taking money from the vault.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.