Skip to content
Audit finding Intermediate

Min and maxAnswer never checked for oracle price feed

The oracle contract reads the latest price from a Chainlink aggregator but does not check that the returned answer falls within the aggregator's configured minimum and maximum price band. If an asset crashes below the minimum, the oracle would keep returning the minimum price, letting users borrow against an inflated value.

t0x1c Follow

Originally disclosed on Code4rena

Submitted by t0x1c

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. However, the protocol misses to implement such a check.

Link to code:

    function getLatestPrice() public view override returns (IOracle.Price memory price) {
@-->    (, int256 answer, uint256 startedAt, uint256 updatedAt,) = _ethPriceFeed.latestRoundData();
        if ( answer<= 0 ) revert InvalidPriceFromOracle();
        if ( startedAt ==0 || updatedAt == 0 ) revert InvalidPriceUpdatedAt();

        price.price = uint256(answer);
        price.lastUpdate = updatedAt;
    }

Similar past issues

Recommended Mitigation Steps

Add logic along the lines of:

    require(answer >= minPrice && answer <= maxPrice, "invalid price");

Min and max prices can be gathered using one of these ways.

hvasconcelos (BakerFi) confirmed

ickas (BakerFi) commented:

Fixed → https://github.com/baker-fi/bakerfi-contracts/pull/46


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

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

Likely the contract does not validate that the oracle answer lies within the aggregator's minPrice and maxPrice bounds before using it as the asset price.

Impact

If an asset's price falls below the aggregator's minimum, the oracle would return the minimum price, allowing users to borrow against an inflated value and potentially leaving the protocol with bad debt.

What the attacker needed

Asset price falls below aggregator minPrice

The fix

The issue was fixed by adding a check that the oracle answer is within the aggregator's minimum and maximum price bounds.

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 what an asset is worth. Chainlink oracles have a safety feature that stops reporting prices outside a set range, so during a crash they may keep returning the lowest allowed price instead of the real, much lower price. This contract trusts that number without checking the range, so borrowers could keep borrowing as if the asset were still worth more than it is.

More by t0x1c

View all

19 more disclosed reports, best first.

More from BakerFi Invitational

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.