Skip to content
Audit finding Intermediate

The `Vault._to_usd_oracle_price()` function uses the same `ORACLE_FRESHNESS_THRESHOLD` for all token prices feeds which is incorrect

The Vault contract used a single 24-hour freshness threshold for all Chainlink price feeds, but some feeds update hourly, so the staleness check was ineffective for those pairs. An attacker could potentially exploit stale prices for tokens with shorter heartbeats.

0xbepresent Follow with 0xpinky, TheNaubit and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-unstoppable-judging/issues/104

Found by

0xbepresent, 0xpinky, TheNaubit, n33k, pengun, stopthecap, twicek

Summary

The same ORACLE_FRESHNESS_THRESHOLD is used for all the token prices feeds which can be dangerous because different pairs of tokens have different freshness intervals.

Vulnerability Detail

The ORACLE_FRESHNESS_THRESHOLD is 24 hours constant. It is used to check if the Oracle price is fresh in the 580 code line.

Python
File: Vault.vy
562: def _to_usd_oracle_price(_token: address) -> uint256:
...
...
576:     round_id, answer, started_at, updated_at, answered_in_round = ChainlinkOracle(
577:         self.to_usd_oracle[_token]
578:     ).latestRoundData()
579: 
580:     assert (block.timestamp - updated_at) < ORACLE_FRESHNESS_THRESHOLD, "oracle not fresh"
...
...

The problem is that different pairs have diferrent heartbeats. For example the LINK/USD has a heartbeat of 3600 seconds so since the ORACLE_FRESHNESS_THRESHOLD is set to 24 hours, the check for LINK/USD is useless since the its hearbeat is 3600 seconds. The same behaivour in CRV/USD which has a heartbeat of 3600 seconds.

Impact

Using the same ORACLE_FRESHNESS_THRESHOLD (heartbeat) for all the price feeds is not correct becuase the freshness validation would be useless for some pairs which can return stale data.

Code Snippet

The Vault._to_usd_oracle_price() function:

Python
File: Vault.vy
562: def _to_usd_oracle_price(_token: address) -> uint256:
563:     """
564:     @notice
565:         Retrieves the latest Chainlink oracle price for _token.
566:         Ensures that the Arbitrum sequencer is up and running and
567:         that the Chainlink feed is fresh.
568:     """
569:     assert self._sequencer_up(), "sequencer down"
570: 
571:     round_id: uint80 = 0
572:     answer: int256 = 0
573:     started_at: uint256 = 0
574:     updated_at: uint256 = 0
575:     answered_in_round: uint80 = 0
576:     round_id, answer, started_at, updated_at, answered_in_round = ChainlinkOracle(
577:         self.to_usd_oracle[_token]
578:     ).latestRoundData()
579: 
580:     assert (block.timestamp - updated_at) < ORACLE_FRESHNESS_THRESHOLD, "oracle not fresh"
581: 
582:     usd_price: uint256 = convert(answer, uint256)  # 8 dec
583:     return usd_price

Tool used

Manual review

Recommendation

Use the corresponding heartbeat ORACLE_FRESHNESS_THRESHOLD for each token in the Vault._to_usd_oracle_price() function.

Discussion

Unstoppable-DeFi

https://github.com/Unstoppable-DeFi/unstoppable-dex-audit/pull/11

maarcweiss

Fixed by introducing a mapping that has an individual ORACLE_FRESHNESS_THRESHOLD for each token, instead of using the same one for all of them.

The original report as published on Sherlock, by 0xbepresent. 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

Root cause

The contract hard-codes a single freshness threshold instead of using each Chainlink feed's own heartbeat interval.

Impact

The freshness check is useless for feeds with short heartbeats, so the contract could accept stale prices and allow trades at incorrect values.

What the attacker needed

None

The fix

The issue was fixed by introducing a mapping that stores an individual freshness threshold for each token.

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 smart contract checks how old a price is before using it, but it uses the same age limit for every token. Some tokens' prices update every hour, so a 24-hour limit means the contract might accept a price that is many hours out of date. This could let someone trade at an incorrect price.

More by 0xbepresent

View all

13 more disclosed reports, best first.

More from Unstoppable

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.