Skip to content
Business logic Audit finding Intermediate

MagicLpAggregator can be incompatible with potential integrators due to incorrect latestRoundData function

The MagicLpAggregator's latestRoundData function returns zero for roundId, startedAt, updatedAt, and answeredInRound, which can cause integrations that check updatedAt for staleness to revert. An attacker could not directly exploit this, but it breaks compatibility with potential integrators.

DarkTower Follow

Originally disclosed on Code4rena

Submitted by DarkTower

MagicLpAggregator does not update the roundId, startAt, updatedAt and answeredInRound to correct values.

MagicLpAggregator.sol#L48-L50

    function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
        return (0, latestAnswer(), 0, 0, 0);
    }

A common code is to check updatedAt for staleness issue (although it isn’t required to do so anymore.

(, int256 price, , uint256 updatedAt, ) = priceFeed.latestRoundData();

if (updatedAt < block.timestamp - 60 * 60 /* 1 hour */) {
   revert("stale price feed");
}

Therefore any integrator that uses the above code will not be able to integrate MagicLpAggregator oracles as it will always revert due to the incorrect updatedAt being provided.

Recommended Mitigation Steps

Use the values roundId, startAt, updatedAt and answeredInRound from whichever oracle, baseOracle or quoteOracle was used.

rexjoseph (Warden) commented:

I think we should reiterate the issue here as the submission has tried its best to point out:

  1. The MagicLpAggregator gets the price from Chainlink’s Feed
  2. Integrators (for example protocol A) query the MagicLPAggregator Oracle for price specifically the latestRoundData() function it exposes in their implementation
  3. They make sure the prices returned are fresh and so do well to check the time specifically updatedAt so they can be sure the feed is fresh to proceed with utilizing the returned data
  4. Since the updatedAt as well as other returned data are hardcoded to 0 in MagicLpAggregator oracle implementation, the call reverts. 0 will always be less than block.timestamp - 60 * 60

The step by step description of the issue above I believe is sufficient but here’s a provided POC to elaborate on this in code:

Test file in the abracadabra codebase is: MagicLPAggregator.t.sol

function testProtocolAIntegrationOfMagicLPAggReverts() public {

        // return values of `MagicLpAggregator` latestRoundData()
        (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = aggregator.latestRoundData();

        // protocol A tries to make sure the prices returned is fresh by checking the time

        // keep in mind the time aka updatedAt is hardcoded to 0. So 0 will always be less than `block.timestamp - 60 * 60` hence a revert

        if (updatedAt < block.timestamp - 60 * 60 /* 1 hour */) {
         revert("stale price feed");
        }
    }
Ran 1 test for test/MagicLpAggregator.t.sol:MagicLpAggregatorTest
[FAIL. Reason: revert: stale price feed] testProtocolAIntegrationOfMagicLPAggReverts() (gas: 57187)
Suite result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 2.56s (2.88ms CPU time)

cccz (Judge) commented:

latestRoundData() is different from the standard and may cause integration issues. Will consider it a valid M.


The original report as published on Code4rena, by DarkTower. 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

The latestRoundData function hardcodes the roundId, startedAt, updatedAt, and answeredInRound values to zero instead of returning the actual values from the underlying oracles.

Impact

Integrators that check updatedAt for staleness will always revert, making the oracle unusable for them.

What the attacker needed

Integrator checks updatedAt for staleness

The fix

The latestRoundData function should return the roundId, startedAt, updatedAt, and answeredInRound values from the baseOracle or quoteOracle that was used.

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 price data to smart contracts. The MagicLpAggregator is such an oracle, but its latestRoundData function returns zeros for the timestamp fields instead of real times. If another contract checks that the price is recent by comparing the timestamp to the current time, it will always see zero and think the price is stale, so it will refuse to use it.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by DarkTower

View all

4 more disclosed reports, best first.

More from Abracadabra Mimswap

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.