Skip to content
Audit finding Intermediate

CurveTricryptoOracle#getPrice contains math error that causes LP to be priced completely wrong

The Curve tricrypto LP oracle divided an already USD-denominated LP price by the ETH price, so it returned the LP value in ETH rather than USD. This made LP tokens appear far cheaper than they were, so positions that were actually well collateralised could be liquidated.

0x52 Follow with Kow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-07-blueberry-judging/issues/100

Found by

0x52, Kow

CurveTricryptoOracle#getPrice incorrectly divides the LP price by the price of ETH which causes it to return the price of LP in terms of ETH instead of USD

Vulnerability Detail

CurveTricryptoOracle.sol#L57-L62

            (lpPrice(
                virtualPrice,
                base.getPrice(tokens[1]),
                ethPrice,
                base.getPrice(tokens[0])
            ) * 1e18) / ethPrice;

After the LP price has been calculated in USD it is mistakenly divided by the price of ETH causing the contract to return the LP price in terms of ETH rather than USD. This leads to LP that is massively undervalued causing positions which are actually heavily over collateralized to be liquidated.

Impact

Healthy positions are liquidated due to incorrect LP pricing

Code Snippet

CurveTricryptoOracle.sol#L48-L65

Tool used

Manual Review

Recommendation

Don't divide the price by the price of ETH

Discussion

sherlock-admin2

2 comment(s) were left on this issue during the judging contest.

0xyPhilic commented:

invalid because lpPrice is considered in ETH so dividing by ETH/USD price returns the final result in USD

Kral01 commented:

there is a precision value

Gornutz

Judges accurately state why the division by ETH/USD is required to return the proper USD value.

Shogoki

Closing in regards to other judges and sponsors comments.

IAm0x52

This is valid. The code being used here was borrowed from the Sentiment CurveTriCryptoOracle, which is specifically meant to return the price in terms of ETH. This oracle is meant to return the valuation in USD which means the division by the price of ETH needs to be dropped.

Shogoki

This is valid. The code being used here was borrowed from the Sentiment CurveTriCryptoOracle, which is specifically meant to return the price in terms of ETH. This oracle is meant to return the valuation in USD which means the division by the price of ETH needs to be dropped.

Maybe was a bit quick in closing. Will reopen it and we will take a deeper look at it.

The original report as published on Sherlock, by 0x52. 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 reused code written to return a price in ETH, so it kept a division by the ETH price even though the value had already been converted to USD.

Impact

LP tokens were massively undervalued, so positions that were heavily over collateralised could be liquidated.

What the attacker needed

LP tokens used as collateral; oracle used for liquidation checks

The fix

The division by the ETH price should be removed so the oracle returns the LP price in USD.

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 contract that tells other contracts what an asset is worth. Here the oracle worked out the value of a liquidity pool token in dollars, then divided that number by the price of ether, so the answer came out in ether instead of dollars. Because the number was much smaller than the real dollar value, the system thought borrowers had far less collateral than they did and could liquidate them unfairly.

More by 0x52

View all

211 more disclosed reports, best first.

More from Blueberry Update #3

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.