Skip to content
Business logic Audit finding Intermediate

ERC4626 does not work with fee-on-transfer tokens

The ERC4626 deposit and mint functions use the pre-fee amount when calculating shares, so with fee-on-transfer tokens a user can receive more shares than intended. An attacker could exploit this to mint excess shares, diluting other depositors.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

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

The ERC4626.deposit/mint functions do not work well with fee-on-transfer tokens as the amount variable is the pre-fee amount, including the fee, whereas the totalAssets do not include the fee anymore.

This can be abused to mint more shares than desired.

function deposit(uint256 amount, address to) public virtual returns (uint256 shares) {
    // Check for rounding error since we round down in previewDeposit.
    require((shares = previewDeposit(amount)) != 0, "ZERO_SHARES");

    // Need to transfer before minting or ERC777s could reenter.
    asset.safeTransferFrom(msg.sender, address(this), amount);

    _mint(to, shares);

    emit Deposit(msg.sender, to, amount, shares);

    afterDeposit(amount, shares);
}

Proof of Concept

A deposit(1000) should result in the same shares as two deposits of deposit(500) but it does not because amount is the pre-fee amount. Assume a fee-on-transfer of 20%. Assume current totalAmount = 1000, totalShares = 1000 for simplicity.

  • deposit(1000) = 1000 / totalAmount * totalShares = 1000 shares
  • deposit(500) = 500 / totalAmount * totalShares = 500 shares. Now the totalShares increased by 500 but the totalAssets only increased by (100% - 20%) * 500 = 400. Therefore, the second deposit(500) = 500 / (totalAmount + 400) * (newTotalShares) = 500 / (1400) * 1500 = 535.714285714 shares.

In total, the two deposits lead to 35 more shares than a single deposit of the sum of the deposits.

Recommended Mitigation Steps

amount should be the amount excluding the fee, i.e., the amount the contract actually received. This can be done by subtracting the pre-contract balance from the post-contract balance. However, this would create another issue with ERC777 tokens.

Maybe previewDeposit should be overwritten by vaults supporting fee-on-transfer tokens to predict the post-fee amount. And do the shares computation on that, but then the afterDeposit is still called with the original amount and implementers need to be aware of this.

Joeysantoro (Tribe Turbo) disputed and commented:

This is intended. Fee-on-transfer functions can be implemented in another base contract. This contract is only one implementation of the standard.

Alex the Entreprenerd (judge) commented:

Given no context, I would side with the sponsor as the ERC4626 standard is meant to work with ERC20 Standard tokens.

However, in bringing the ERC4626 mixin into scope, the sponsor’s code has an explicit mention of ERC777 which does open up to the possibility of having fees on transfer.

Because ultimately the warden didn’t stretch the scope (as that happened because of the mixin), and the warden showed a way to provide leakage of value or denial of service exclusively if the mixin code is used in conjunction with a feeOnTransfer token.

Given that the mixin code comments explicitly mention attempting to support non-standard tokens.

I believe medium severity to be valid as any type of misbehavior is contingent on deploying an ERC4626 mixin with a feeOnTransfer Token.

Given the circumstances, the best recommendation for developers is to use the mixin with ERC20 Standard Tokens.


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

The deposit function calculates shares using the amount before the transfer fee is deducted, rather than the amount actually received by the contract.

Impact

An attacker could mint more shares than intended, potentially causing value leakage or denial of service, but only if the ERC4626 mixin is used with a fee-on-transfer token.

What the attacker needed

ERC4626 mixin used with a fee-on-transfer token

The fix

The amount used for share calculation should be the amount actually received by the contract (post-fee), or vaults supporting fee-on-transfer tokens should override previewDeposit to account for the fee.

How it was found

  1. Assume a fee-on-transfer token with a 20% fee and initial totalAssets = 1000, totalShares = 1000.
  2. Call deposit(1000): shares = 1000 / 1000 * 1000 = 1000 shares.
  3. Call deposit(500): shares = 500 / 1000 * 1000 = 500 shares, but totalAssets only increases by 400 (after 20% fee).
  4. Call deposit(500) again: shares = 500 / 1400 * 1500 = 535.714285714 shares.
  5. Total shares from two deposits of 500 is 1035.714, which is 35 more than a single deposit of 1000.

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 fee-on-transfer token takes a small cut each time it is sent. The vault contract assumed the full amount arrived, so it gave out shares based on the larger number. This means someone could get more shares than they paid for, taking value from others.

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.

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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.