Skip to content
Audit finding Intermediate

PriceOracle will use the wrong price if the Chainlink registry returns price outside min/max range

The price oracle contract only checks that the price returned by Chainlink is positive, not that it falls within a reasonable range. If an asset's price crashes below Chainlink's minimum, the oracle would keep returning the minimum price, letting users borrow against an inflated value and creating bad debt.

0x52 Follow with 0x8chars, Angry_Mustache_Man and 12 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-05-ironbank-judging/issues/25

Found by

0x52, 0x8chars, Angry_Mustache_Man, Bauchibred, BenRai, BugBusters, Jaraxxus, Madalad, R-Nemes, bitsurfer, branch_indigo, deadrxsezzz, shaka, thekmj, tsvetanovv

Summary

Chainlink aggregators have a built in circuit breaker if the price of an asset goes outside of a predetermined price band. The result is that if an asset experiences a huge drop in value (i.e. LUNA crash) the price of the oracle will continue to return the minPrice instead of the actual price of the asset. This would allow user to continue borrowing with the asset but at the wrong price. This is exactly what happened to Venus on BSC when LUNA imploded.

Vulnerability Detail

Note there is only a check for price to be non-negative, and not within an acceptable range.

Solidity
function getPriceFromChainlink(address base, address quote) internal view returns (uint256) {
    (, int256 price,,,) = registry.latestRoundData(base, quote);
    require(price > 0, "invalid price");

    // Extend the decimals to 1e18.
    return uint256(price) * 10 ** (18 - uint256(registry.decimals(base, quote)));
}

https://github.com/sherlock-audit/2023-05-ironbank/blob/main/ib-v2/src/protocol/oracle/PriceOracle.sol#L66-L72

A similar issue is seen here.

Impact

The wrong price may be returned in the event of a market crash. An adversary will then be able to borrow against the wrong price and incur bad debt to the protocol.

Code Snippet

https://github.com/sherlock-audit/2023-05-ironbank/blob/main/ib-v2/src/protocol/oracle/PriceOracle.sol#L66-L72

Tool used

Manual Review

Recommendation

Implement the proper check for each asset. It must revert in the case of bad price.

Solidity
function getPriceFromChainlink(address base, address quote) internal view returns (uint256) {
    (, int256 price,,,) = registry.latestRoundData(base, quote);
    require(price >= minPrice && price <= maxPrice, "invalid price"); // @audit use the proper minPrice and maxPrice for each asset

    // Extend the decimals to 1e18.
    return uint256(price) * 10 ** (18 - uint256(registry.decimals(base, quote)));
}

Discussion

ibsunhub

It's not practical to setup the min price and max price for individual asset. It's hard to define a reasonable range for each asset and it will make oracle configuration more complex. It's much easier to make human error.

Also, we had an off-chain backend system to monitor the price from ChainLink. If the price is off, we would intervene to pause the oracle.

0xffff11

@ibsunhub If the oracle is paused, wouldn't functions that require of that oracle response also be paused during that time?

ibsunhub

Yes, functions that need to retrieve the price will revert. They are borrow, redeem, transferIBToken, and liquidate.

0xffff11

So, I see what the watson points out. I see that you have an off-chain safeguard for this. Therefore, I would mark the issue as invalid. Though I don't think the solution should be to revert. Liquidations can be key while oracle is paused. I think the fix should be the one from https://github.com/sherlock-audit/2023-05-ironbank-judging/issues/433 (secondary oracle and a try catch)

0xffff11

Invalid, Iron has an off-chain safeguard for price deviation that would prevent this

iamjakethehuman

Escalate for 10 USDC The off-chain safeguard is never mentioned. Watsons are not supposed to know it exists. Also, the supposed solution imposes an even larger risk as any user would be able to enter tbe market of which the oracle reverts and avoid liquidations. Issue should be marked as valid and another solution should be proposed.

sherlock-admin

Escalate for 10 USDC The off-chain safeguard is never mentioned. Watsons are not supposed to know it exists. Also, the supposed solution imposes an even larger risk as any user would be able to enter tbe market of which the oracle reverts and avoid liquidations. Issue should be marked as valid and another solution should be proposed.

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

ADK0010

Also the contest page doesn't talk about any off-chain safeguards.

hrishibhat

Result: Medium Has duplicates This is a valid medium

sherlock-admin

Escalations have been resolved successfully!

Escalation status:

ib-tycho

How do you establish a reasonable minimum and maximum price range for each asset? The incident related to Venus that you mentioned was caused by the inherent risk of the LUNA token itself. Evaluating the risk associated with an asset should always be taken into account when listing it. I disagree with relying solely on manual human input for setting the price range, as it does not address the underlying issue faced by Venus. Therefore, we will not make changes to address this matter.

jacksanford1

Issue was labeled "Won't Fix" by protocol team. Categorizing as an acknowledged issue.

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

Impact

The wrong price may be returned in the event of a market crash, allowing an adversary to borrow against the wrong price and incur bad debt to the protocol; the protocol team said an off-chain monitoring system would pause the oracle if the price is off, but the judge still rated the issue as a valid medium.

What the attacker needed

A market crash pushes price below Chainlink minimum; off-chain monitoring fails to pause oracle

The fix

The report recommends adding a check that the price is within a per-asset minimum and maximum and reverting if not, but the protocol team said they will not make changes.

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 tells a smart contract the current price of an asset. This contract trusted the oracle's number as long as it was above zero, even if the real price had crashed far below. That meant someone could borrow money using the overpriced asset as collateral, and the protocol would lose money when the price stayed low.

More by 0x52

View all

211 more disclosed reports, best first.

More from Iron Bank

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.