Skip to content
Business logic Audit finding Intermediate

Vault.sol Tokens with fee on transfer are not supported

The vault's addValue function credits the caller with the full requested amount even when the token actually delivers less because it charges a transfer fee. An attacker could therefore receive more attributions and balance than the tokens they actually contributed.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by pmerkleplant, cmichel, Ruhum, and Dravee

There are ERC20 tokens that charge fee for every transfer() / transferFrom().

Vault.sol#addValue() assumes that the received amount is the same as the transfer amount, and uses it to calculate attributions, balance amounts, etc. While the actual transferred amount can be lower for those tokens.

https://github.com/code-423n4/2022-01-insure/blob/19d1a7819fe7ce795e6d4814e7ddf8b8e1323df3/contracts/Vault.sol#L124-L140

function addValue(
    uint256 _amount,
    address _from,
    address _beneficiary
) external override onlyMarket returns (uint256 _attributions) {

    if (totalAttributions == 0) {
        _attributions = _amount;
    } else {
        uint256 _pool = valueAll();
        _attributions = (_amount * totalAttributions) / _pool;
    }
    IERC20(token).safeTransferFrom(_from, address(this), _amount);
    balance += _amount;
    totalAttributions += _attributions;
    attributions[_beneficiary] += _attributions;
}

Recommendation

Consider comparing before and after balance to get the actual transferred amount.

oishun1112 (Insure) acknowledged:

only USDC can be underwriting asset. We are trying to make it multi currency. We won’t implement this now due to the gas consumption, but we will when we develop new type of Vault

The original report as published on Code4rena, by WatchPug. 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 the code trusts the requested transfer amount instead of measuring the actual change in token balance after the transfer.

Impact

Where a fee-on-transfer token is used, a depositor could be credited with more attributions and balance than the tokens actually received, diluting other holders; the project noted only USDC was supported at the time, limiting real exposure.

What the attacker needed

A fee-on-transfer token used as the asset; ability to call addValue via the market

The fix

The code should compare the token balance before and after the transfer and use the actual received amount for attributions and balance; the project said it would address this when building a new vault type.

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.

Some tokens take a small cut every time they are moved, so the receiver gets less than the sender sent. This vault recorded the amount it asked for rather than the amount that actually arrived, so a user could be credited with more than they paid in. That mismatch lets someone gain a larger share of the pool than they should.

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 WatchPug

View all

197 more disclosed reports, best first.

More from InsureDAO 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.