Skip to content
Audit finding Intermediate

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.

0xGoodess Follow with 0xJuda, Juntao and 10 others

Originally disclosed on Sherlock

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

https://github.com/sherlock-audit/2023-04-unitasprotocol/blob/d5328421bea80e3b0fd4595e4eb6b732a40e421e/Unitas-Protocol/src/XOracle.sol#L34-L46

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:

Solidity
 if (threshold < type(uint32).max) {
            uint64 priceTimestamp = prices[asset].timestamp;
            _require(
                priceTimestamp > block.timestamp || block.timestamp - priceTimestamp <= threshold,
                Errors.PRICE_STALE
            );

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

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.

More by 0xGoodess

View all

13 more disclosed reports, best first.

More from Unitas Protocol

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.