Skip to content
Smart contracts Audit finding Intermediate

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.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by 0xliumin, CertoraInc, Picodes, and Ruhum

The docs/video say ERC4626.sol is in scope as its part of TurboSafe

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 pay 1000 asset amount but receive 1000 shares => vault.totalSupply() = 2000, totalAssets = 2500.
  • call redeem(shares=1000). Receive (1000 / 2000) * 2500 = 1250 amounts. Make a profit of 250 asset tokens.
  • repeat until shares <> assets are 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.


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

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

  1. Assume vault has totalSupply=1000 and totalAssets=1500.
  2. Call mint with shares=1000, paying only 1000 asset tokens but receiving 1000 shares.
  3. Call redeem with shares=1000, receiving 1250 asset tokens, making a profit of 250.
  4. 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.

More by cmichel

View all

196 more disclosed reports, best first.

More from Tribe Turbo contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.