Skip to content
Audit finding Intermediate

`ERC4626Oracle` Price will be wrong when the ERC4626's `decimals` is different from the underlying token’s decimals

The ERC4626Oracle contract incorrectly used the vault's decimals instead of the underlying token's decimals when calculating the price of an ERC4626 vault token. This caused the price to be significantly underestimated or overestimated when the vault's decimals differed from the underlying token's decimals.

Lambda Follow with JohnSmith, WATCHPUG and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/025-H

Found by

Lambda, JohnSmith, WATCHPUG, 0x52, berndartmueller, Bahurum

Summary

EIP-4626 does not require the decimals must be the same as the underlying tokens' decimals, and when it's not, ERC4626Oracle will malfunction.

Vulnerability Detail

In the current implementation, IERC4626(token).decimals() is used as the IERC4626(token).asset()'s decimals to calculate the ERC4626's price.

However, while most ERC4626s are using the underlying token’s decimals as decimals, there are some ERC4626s use a different decimals from underlying token’s decimals since EIP-4626 does not require the decimals must be the same as the underlying token’s decimals:

Although the convertTo functions should eliminate the need for any use of an EIP-4626 Vault’s decimals variable, it is still strongly recommended to mirror the underlying token’s decimals if at all possible, to eliminate possible sources of confusion and simplify integration across front-ends and for other off-chain users.

Ref: https://eips.ethereum.org/EIPS/eip-4626

Impact

The price of ERC4626 will be significantly underestimated when the underlying token's decimals > ERC4626's decimals, and be significantly overestimated when the underlying token's decimals < ERC4626's decimals.

Code Snippet

https://github.com/sentimentxyz/oracle/blob/59b26a3d8c295208437aad36c470386c9729a4bc/src/erc4626/ERC4626Oracle.sol#L35-L43

Solidity
    function getPrice(address token) external view returns (uint) {
        uint decimals = IERC4626(token).decimals();
        return IERC4626(token).previewRedeem(
            10 ** decimals
        ).mulDivDown(
            oracleFacade.getPrice(IERC4626(token).asset()),
            10 ** decimals
        );
    }

Tool used

Manual Review

Recommendation

getPrice() can be changed to:

Solidity
    function getPrice(address token) external view returns (uint) {
        uint decimals = IERC4626(token).decimals();
        address underlyingToken = IERC4626(token).asset();
        return IERC4626(token).previewRedeem(
            10 ** decimals
        ).mulDivDown(
            oracleFacade.getPrice(underlyingToken),
            10 ** IERC20Metadata(underlyingToken).decimals()
        );
    }

Sentiment Team

Fixed as recommended. PR here.

Lead Senior Watson

Confirmed fix.

The original report as published on Sherlock, by Lambda. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 oracle used the ERC4626 vault's decimals instead of the underlying asset's decimals when scaling the price calculation.

What the attacker needed

ERC4626 vault with decimals different from underlying token

The fix

The fix was to use the underlying token's decimals instead of the vault's decimals in the price calculation, and this was implemented and confirmed.

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.

An oracle is a service that provides price data to a smart contract. This oracle calculated the price of a vault token (ERC4626) using the vault's own decimal places, but it should have used the decimal places of the token held inside the vault. If those two numbers differ, the calculated price is wrong, which could lead to financial losses.

More by Lambda

View all

64 more disclosed reports, best first.

More from Sentiment Update #3

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.