Inverse Finance contest - Franfran's results

Rethink the way you borrow.

General Information

Platform: Code4rena

Start Date: 25/10/2022

Pot Size: $50,000 USDC

Total HM: 18

Participants: 127

Period: 5 days

Judge: 0xean

Total Solo HM: 9

Id: 175

League: ETH

Inverse Finance

Findings Distribution

Researcher Performance

Rank: 91/127

Findings: 2

Award: $24.60

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Awards

24.2165 USDC - $24.22

Labels

bug
2 (Med Risk)
downgraded by judge
unsatisfactory
duplicate-533

External Links

Lines of code

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L119-L121

Vulnerability details

Impact

The line 122 in the Oracle.sol contract purpose is to normalize the price of the feed to 18 decimals in order to return the price of the underlying token in DOLA. The issue is that the decimals calculation is done wrong, leading to incorrect calculations and for most of the time (when the underlying decimals are less than 18) an hyper-inflated price of the token in DOLA.

Proof of Concept

Let's take the BTC/USD price feed contract. We can see that the feed decimals is 8, and the BTC decimals is 8 as well. By doing a quick calculation, the decimals will be

uint8 decimals = 36 - feedDecimals (8) - feedDecimals (8); └── (decimals = 20)

So at a today price of BTC at about 21k$, the normalized price would be

uint normalizedPrice = price * (10 ** decimals); | | â”” (20) | â”” (21,000 * 1e8) â”” (21,000 * 1e28)

While the "fair" price should be 21,000 * 1e18 (DOLA). This would of course lead to disastrous consequence because every lender loan in BTC would be scaled by 1e10.

Tools Used

CLion

// Oracle.sol L.121 - | uint8 decimals = 36 - feedDecimals - tokenDecimals; + | uint8 decimals = 18 - feedDecimals;

Thanks to this, tokenDecimals is now useless and there is no need for a FeedData struct.

#0 - c4-judge

2022-11-05T00:13:56Z

0xean marked the issue as duplicate

#2 - c4-judge

2022-11-28T15:52:34Z

0xean marked the issue as unsatisfactory: Invalid

#3 - c4-judge

2022-12-06T00:03:42Z

0xean changed the severity to 2 (Med Risk)

#4 - c4-judge

2022-12-07T08:18:20Z

Simon-Busch marked the issue as duplicate of #533

Awards

0.385 USDC - $0.38

Labels

bug
2 (Med Risk)
downgraded by judge
satisfactory
sponsor confirmed
edited-by-warden
duplicate-584

External Links

Lines of code

https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L6 https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L82 https://github.com/code-423n4/2022-10-inverse/blob/main/src/Oracle.sol#L82

Vulnerability details

Impact

Chainlink latestAnswer() should never be used as it is not a reliable source of data. From one of the deployed oracles at: 0x72AFAECF99C9d9C8215fF44C77B94B99C28741e8 on etherscan

overridden function to add the checkAccess() modifier "deprecated". Use latestRoundData instead. This does not error if no answer has been reached, it will simply return 0. Either wait to point to an already answered Aggregator or use the recommended latestRoundData instead which includes better verification information.

It is also explained in the Chainlink docs that the latestAnswer() function is deprecated.

Even if it is checked that the price is not null, an invalid price could be returned by the aggregators during an unfinished round. As explained, we should use latestRoundData and take care of the return parameters.

Proof of Concept

Chainlink docs

Tools Used

CLion

- uint price = feeds[token].feed.latestAnswer(); + (uint80 roundId, int256 price, uint256 timestamp, uint80 ansRoundId) = feeds[token].feed.latestRoundData(); + require(price > 0, "Invalid feed price"); + require(ansRoundId >= roundID, "Stale feed price"); + require(timestamp != 0, "Incomplete feed round");

#0 - neumoxx

2022-10-31T08:48:38Z

Probably over-inflated severity Duplicate of #601

#1 - iFrostizz

2022-10-31T09:24:07Z

Probably over-inflated severity Duplicate of #601

There is a similar finding that was a high severity one: https://code4rena.com/reports/2022-07-juicebox/#h-01-oracle-data-feed-can-be-outdated-yet-used-anyways-which-will-impact-payment-logic

#2 - neumoxx

2022-10-31T10:08:51Z

It has also been flagged as Med before: https://github.com/code-423n4/2021-06-tracer-findings/issues/145 Let's see what the Judge and the Sponsor think about it, but there are 45 duplicates of your issue and only one marked as High.

#3 - 0xean

2022-11-05T17:45:44Z

Certainly doesn't qualify as H severity. Will leave open as M for sponsor review.

#4 - c4-judge

2022-11-05T17:45:51Z

0xean marked the issue as change severity

#5 - c4-judge

2022-11-05T17:45:55Z

0xean marked the issue as primary issue

#6 - 08xmt

2022-11-15T14:25:56Z

#7 - c4-sponsor

2022-11-15T14:26:21Z

08xmt marked the issue as sponsor confirmed

#8 - c4-judge

2022-11-28T19:35:28Z

0xean marked the issue as satisfactory

#9 - c4-judge

2022-12-07T08:14:13Z

Simon-Busch marked the issue as duplicate of #584

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter