System is Vulnerable to Downtime and has no Checks for it
The TWAP oracle functions do not check how much time has passed since the last observation, so after a period of network downtime the returned price can be stale and too high. An attacker could then borrow stablecoins against $CANTO at an inflated rate.
Submitted by Respx
Description
There is insufficient resilience in the design for the case where there has been no call to _update() for a long time. Consider these possible scenarios:
- A denial of service attack on the blockchain has prevented transactions occurring for a significant period of time.
- An extreme spike in gas prices has prevented transactions occurring for a significant period of time.
- Some unforeseen technical error takes the blockchain down, perhaps during an upgrade or fork.
In any of these scenarios, it is possible that the price of any non-stablecoin token might be prone to serious volatility, $CANTO in particular.
The system has no provision for this issue.
Impact
Consider the following attack scenario:
- Assume a period of network downtime, perhaps a DOS attack.
- Assume a large drop in the price of
$CANTOduring this time. - Assume attacker is able to queue a transaction to be executed as soon as network service resumes (perhaps through producing a block themselves or high gas pricing). This transaction uses a lending system that relies on this oracle, and that lending system calls
reserves()to calculate the TWAP price of$CANTO. The values returned are out of date and far too high. The attacker is then able to borrow stablecoins against their$CANTOat too high a rate.
Proof of Concept
reserves(), sampleReserves() and sampleSupply() make no use of block.timestamp. They all measure only the time duration of the observations. There is no awareness of how much time has passed since the most recent observation was made.
quote() and sample() have the same logic, and these functions are called in getPriceCanto() and getPriceNote(). getPriceLP() relies on sampleReserves(). They therefore have the same issue.
Recommended Mitigation Steps
The system could track the average duration time of observations and, if any of the observations in a sample are significantly greater than this average, the system could either refuse to return a sample, or could return a warning flag to indicate that the sample data could be unreliable.
There is precedent in the system for refusing to return a sample (see line 242 of BaseV1-core.sol).
nivasan1 (Canto) disputed and commented:
The oracle has been designed specifically for the purpose of use in the lending market, for pairs that have seen a long period of down-time (which is highly unexpected for supported pairs) the collateral factors can be adjusted to scale the price of the asset’s collateral value downwards to reflect the volatility after the long period of downtime.
0xean (judge) decreased severity to Medium and commented:
This has a high level of external factors that are required to be realized but knowing that the CANTO network has already suffered downtime, I don’t think these are too far out of the realm of possibility. Downgrading to Medium.
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 oracle's sampling functions measure only the duration between observations and never compare the time since the most recent observation to the current block timestamp, so stale data is treated as current.
Impact
An attacker could borrow stablecoins against $CANTO at an inflated rate after downtime, though the report notes this requires several external factors and the judge downgraded it to Medium.
What the attacker needed
A period of network downtime; a large price drop during downtime; ability to queue a transaction for resume
The fix
The system should track the average duration between observations and refuse to return a sample, or return a warning flag, when any observation is significantly longer than that average.
How it was found
- Assume a period of network downtime, perhaps a DOS attack.
- Assume a large drop in the price of $CANTO during this time.
- Assume attacker is able to queue a transaction to be executed as soon as network service resumes.
- The transaction uses a lending system that relies on this oracle and calls reserves() to calculate the TWAP price.
- The values returned are out of date and far too high, so the attacker borrows stablecoins at too high a rate.
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. This oracle averages past prices but never checks how old the latest price is, so if the blockchain stops for a while the average can be badly out of date. An attacker could then use that wrong price to borrow more money than they should.