Oracle price does not compound
The oracle price does not compound monthly APRs because the start time is reset when a CPI request is made, causing the price to reset to 1.0 after each fulfilment. An attacker could potentially profit from the sudden drop in oracle price.
Submitted by cmichel
ScalingPriceOracle.sol#L136 ScalingPriceOracle.sol#L113
The oracle does not correctly compound the monthly APRs - it resets on fulfill.
Note that the oraclePrice storage variable is only set in _updateCPIData as part of the oracle fulfill callback.
It’s set to the old price (price from 1 month ago) plus the interpolation from startTime to now.
However, startTime is reset in requestCPIData due to the afterTimeInit modifier, and therefore when Chainlink calls fulfill in response to the CPI request, the timeDelta = block.timestamp - startTime is close to zero again and oraclePrice is updated to itself again.
This breaks the core functionality of the protocol as the oracle does not track the CPI, it always resets to 1.0 after every fulfill instead of compounding it.
In addition, there should also be a way for an attacker to profit from the sudden drop of the oracle price to 1.0 again.
Proof of Concept
As an example, assume oraclePrice = 1.0 (1e18), monthlyAPR = 10%. The time elapsed is 14 days. Calling getCurrentOraclePrice() now would return 1.0 + 14/28 * 10% = 1.05.
- It’s now the 15th of the month and one can trigger
requestCPIData. This resetsstartTime = now. - Calling
getCurrentOraclePrice()now would return1.0again astimeDelta(andpriceDelta) is zero:oraclePriceInt + priceDelta = oraclePriceInt = 1.0. - When
fulfillis called it setsoraclePrice = getCurrentOraclePrice()which will be close to1.0as thetimeDeltais tiny.
Recommended Mitigation Steps
The oraclePrice should be updated in requestCPIData() not in fulfill.
Cover this scenario of multi-month accumulation in tests.
ElliotFriedman (Volt) commented:
Oracle price does compound per this line of code: https://github.com/code-423n4/2022-03-volt/blob/f1210bf3151095e4d371c9e9d7682d9031860bbd/contracts/oracle/ScalingPriceOracle.sol#L197-L198
ElliotFriedman (Volt) confirmed and commented:
This is the only valid critical finding we have seen so far! Great work cmichel!
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 start time is reset in requestCPIData, so when the oracle fulfilment callback runs, the time delta is near zero and the price is updated to itself instead of compounding.
Impact
The oracle does not track the CPI and always resets to 1.0 after every fulfil instead of compounding, breaking core protocol functionality; an attacker could potentially profit from the sudden drop.
What the attacker needed
Ability to trigger requestCPIData
The fix
The oraclePrice should be updated in requestCPIData() instead of in fulfill, and tests should cover multi-month accumulation.
How it was found
- Assume oraclePrice is 1.0 and monthlyAPR is 10%, with 14 days elapsed; getCurrentOraclePrice() returns 1.05.
- Trigger requestCPIData, which resets startTime to now.
- Call getCurrentOraclePrice() again; it returns 1.0 because timeDelta is zero.
- When fulfill is called, it sets oraclePrice to getCurrentOraclePrice(), which is close to 1.0 due to tiny timeDelta.
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 service that provides external data to a smart contract. Here, the oracle is supposed to increase a price gradually each month based on inflation data, but a mistake causes it to reset to its starting value instead of building on previous months. This means the price is wrong, and someone might exploit the sudden drop.