No clear threshold on when the oracle is updated will cause stale prices to be accepted
The oracle contract had no defined maximum age for price data, so when gas fees were high and updates were skipped, outdated prices were still treated as current. An attacker could exploit this by trading against stale prices during expensive network periods.
Source: https://github.com/sherlock-audit/2023-04-unitasprotocol-judging/issues/150
Found by
0xGoodess, 0xJuda, Juntao, Norah, PRAISE, PawelK, carrotsmuggler, ctf_sec, kutugu, mau, stopthecap, thekmj, toshii
Summary
No clear threshold on when the oracle is updated will cause stale prices to be accepted
Vulnerability Detail
According to the team, the oracle is updated depending on the gas fees.
"" the oracle price update is limited by cost of gas fee during updating. we want to have a balance between reaching the true price vs saving the cost. Once we move to cheaper chains like arbitrum or matic, we will update the oracle a lot more frequently just fyi ""
Not having a clear point in time when the oracle will be updated, will cause that in times when the network is very expensive to include transactions, stale prices of assets/stables will be accepted as the current price, causing wrong/stale prices be fetched as if they were the latest.
Impact
Wrong/stale prices will be used in times when gas fees are very expensive
Code Snippet8
Tool used
Manual Review
Recommendation
Add a clear threshold when the prices should be updated (ex. each 2 minutes), potentially not using the gas fees as an indicator to when updating the oracle.
Discussion
SunXrex
Fixed: https://github.com/xrex-inc/Unitas-Protocol/pull/9
0xffff11
Fix looks good.
The new implementation includes a default threshold of 1 day and a threshold according to each token that unitas uses, which can be changed with a specific setter function. If a threshold is not added for whatever reason or token, it will return the default 1 day threshold.
If the threshold is less than type(uint32).max , basically always, the stale price will be checked and validated:
if (threshold < type(uint32).max) {
uint64 priceTimestamp = prices[asset].timestamp;
_require(
priceTimestamp > block.timestamp || block.timestamp - priceTimestamp <= threshold,
Errors.PRICE_STALE
);
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
Wrong or stale prices could be used when gas fees are very expensive, potentially allowing trades at incorrect prices.
What the attacker needed
High gas fees on the network; oracle not updated recently
The fix
The issue was fixed by adding a configurable staleness threshold (defaulting to one day) that rejects prices older than the threshold.
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 feeds outside price data into a smart contract. This report says the contract never checked how old that price data was, so if the oracle had not been updated recently, the contract still used the old price as if it were fresh. That could let someone trade at an outdated price and profit unfairly.