Skip to content
Business logic Audit finding Intermediate

Vault.withdraw mixes normalized and standard amounts

The Vault contract mixes normalized (18-decimal) and standard token amounts when calculating withdrawals, so a user withdrawing a small amount of shares could receive an inflated amount of a token with fewer than 18 decimals, such as USDC. This could let an attacker steal tokens by exploiting the decimal mismatch.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by hickuphh3 and jonah1005

The Vault.balance function uses the balanceOfThis function which scales (“normalizes”) all balances to 18 decimals.

for (uint8 i; i < _tokens.length; i++) {
    address _token = _tokens[i];
    // everything is padded to 18 decimals
    _balance = _balance.add(_normalizeDecimals(_token, IERC20(_token).balanceOf(address(this))));
}

Note that balance()’s second term IController(manager.controllers(address(this))).balanceOf() is not normalized, but it must be.

This leads to many issues through the contracts that use balance but don’t treat these values as normalized values. For example, in Vault.withdraw, the computed _amount value is normalized (in 18 decimals). But the uint256 _balance = IERC20(_output).balanceOf(address(this)); value is not normalized but compared to the normalized _amount and even subtracted:

// @audit compares unnormalzied output to normalized output
if (_balance < _amount) {
    IController _controller = IController(manager.controllers(address(this)));
    // @audit cannot directly subtract unnormalized
    uint256 _toWithdraw = _amount.sub(_balance);
    if (_controller.strategies() > 0) {
        _controller.withdraw(_output, _toWithdraw);
    }
    uint256 _after = IERC20(_output).balanceOf(address(this));
    uint256 _diff = _after.sub(_balance);
    if (_diff < _toWithdraw) {
        _amount = _balance.add(_diff);
    }
}

Impact

Imagine in withdraw, the output is USDC with 6 decimals, then the normalized _toWithdraw with 18 decimals (due to using _amount) will be a huge number and attempt to withdraw an inflated amount. An attacker can steal tokens this way by withdrawing a tiny amount of shares and receive an inflated USDC or USDT amount (or any _output token with less than 18 decimals).

Recommended Mitigation Steps

Whenever using anything involving vault.balanceOfThis() or vault.balance() one needs to be sure that any derived token amount needs to be denormalized again before using them.

GalloDaSballo (judge) commented:

An inconsistent usage of _normalizeDecimals will cause accounting issues and potentially paths for an exploit

BobbyYaxis (yAxis) noted:

Mitigated in PR 114: https://github.com/yaxis-project/metavault/pull/114/commits/b3c0405640719aa7d43560f4b4b910b7ba88170b

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 the code compares and subtracts a normalized 18-decimal amount against a raw token balance that may have fewer decimals, without converting between the two representations.

Impact

An attacker could withdraw a tiny amount of shares and receive an inflated amount of a token with fewer than 18 decimals, potentially stealing funds.

What the attacker needed

A vault holding tokens with <18 decimals; attacker has a small share balance

The fix

The code should denormalize any derived token amount before using it in comparisons or subtractions with raw token balances.

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 like USDC have 6 decimal places, while others have 18. The vault tries to treat all balances as if they had 18 decimals, but in one place it forgets to convert back. This means a small withdrawal could be multiplied by a huge factor, letting someone take more tokens 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 cmichel

View all

196 more disclosed reports, best first.

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