Skip to content
Smart contracts Audit finding Intermediate

The price from `StableOracleDAI` is returned with the incorrect number of decimals

The StableOracleDAI contract incorrectly assumes the Chainlink DAI/ETH price feed returns 8 decimals, but it actually returns 18 decimals, causing the returned price to have 28 decimals instead of 18. This drastically overvalues DAI, allowing users to mint 1e10 times more USSD than intended.

0xStalin Follow with 0xeix, 0xlmanini and 24 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-05-USSD-judging/issues/236

Found by

0xStalin, 0xeix, 0xlmanini, Bahurum, Brenzee, Dug, G-Security, PNS, Proxy, SanketKogekar, T1MOH, Vagner, WATCHPUG, ast3ros, ctf_sec, immeas, juancito, kutugu, n33k, peanuts, pengun, qbs, qpzm, saidam017, sam_gmk, sashik_eth, twicek

Summary

The price returned from the getPriceUSD function of the StableOracleDAI is scaled up by 1e10, which results in 28 decimals instead of the intended 18.

Vulnerability Detail

In StableOracleDAI the getPriceUSD function is defined as follows...

Solidity
    function getPriceUSD() external view override returns (uint256) {
        address[] memory pools = new address[](1);
        pools[0] = 0x60594a405d53811d3BC4766596EFD80fd545A270;
        uint256 DAIWethPrice = DAIEthOracle.quoteSpecificPoolsWithTimePeriod(
            1000000000000000000, // 1 Eth
            0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, // WETH (base token)
            0x6B175474E89094C44Da98b954EedeAC495271d0F, // DAI (quote token)
            pools, // DAI/WETH pool uni v3
            600 // period
        );

        uint256 wethPriceUSD = ethOracle.getPriceUSD();

        // chainlink price data is 8 decimals for WETH/USD, so multiply by 10 decimals to get 18 decimal fractional
        //(uint80 roundID, int256 price, uint256 startedAt, uint256 timeStamp, uint80 answeredInRound) = priceFeedDAIETH.latestRoundData();
        (, int256 price,,,) = priceFeedDAIETH.latestRoundData();

        return (wethPriceUSD * 1e18) / ((DAIWethPrice + uint256(price) * 1e10) / 2);
    }

The assumption is made that the DAIWethPrice is 8 decimals, and is therefore multiplied by 1e10 in the return statement to scale it up to 18 decimals.

The other price feeds used in the protocol are indeed received with decimals, however, the Chainlink DAI/ETH price feed returns a value with 18 decimals as can be seen on their site.

https://docs.chain.link/data-feeds/price-feeds/addresses

Impact

This means that the price returned from the getPriceUSD function is scaled up by 1e10, which results in 28 decimals instead of the intended 18, drastically overvaluing the DAI/USD price.

This will result in the USSD token price being a tiny fraction of what it is intended to be. Instead of being pegged to $1, it will be pegged to $0.0000000001, completely defeating the purpose of the protocol.

For example, if a user calls USSD.mintForToken, supplying DAI, they'll be able to mint 1e10 times more USSD than intended.

Code Snippet

https://github.com/sherlock-audit/2023-05-USSD/blob/main/ussd-contracts/contracts/oracles/StableOracleDAI.sol#L33-L53

Tool used

Manual Review

Recommendation

Remove the * 1e10 from the return statement.

Diff
-   return (wethPriceUSD * 1e18) / ((DAIWethPrice + uint256(price) * 1e10) / 2);
+   return (wethPriceUSD * 1e18) / (DAIWethPrice + uint256(price) / 2);

The original report as published on Sherlock, by 0xStalin. 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 code incorrectly assumed the Chainlink DAI/ETH price feed returns 8 decimals, but it actually returns 18 decimals, leading to an extra scaling factor of 1e10.

Impact

The price returned is scaled up by 1e10, resulting in 28 decimals instead of 18, drastically overvaluing DAI and allowing users to mint 1e10 times more USSD than intended.

What the attacker needed

None

The fix

Remove the `* 1e10` from the return statement.

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 price oracle is a service that provides the current price of an asset. This contract used a price feed that returns numbers with 18 decimal places, but the code treated it as if it had only 8 decimal places, multiplying it by 10^10. That made the price 10 billion times too large, so users could mint far more of the protocol's stablecoin than they should.

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 0xStalin

View all

20 more disclosed reports, best first.

More from USSD - Autonomous Secure Dollar

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.