# oracleCircuitBreaker: Not checking if price information of asset is stale

Chainlink oracle circuit breaker in DittoETH never checks price staleness, so trades execute against outdated asset prices, mispricing trades.

- Payout: Audit contest
- Severity: medium
- Program: DittoETH
- Found by: klau5
- Disclosed: 2024-06-25
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-03-dittoeth-findings/issues/164
- Library page: https://bugbountylibrary.com/r/c4%3A2024-03-dittoeth%3AM-05
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:oracle-manipulation

**Target:** LibOracle.getOraclePrice / oracleCircuitBreaker (Chainlink price feed consumer)
**Root cause:** oracleCircuitBreaker validates roundId, timestamp==0, future timestamp, and price>0, but never compares block.timestamp against timeStamp plus a per-asset staleness limit, so stale Chainlink answers are accepted as valid.
**Steps:**
1. Read LibOracle.sol getOraclePrice: fetches oracle.latestRoundData() for asset and base oracle.
2. Observe oracleCircuitBreaker only rejects roundId==0, timeStamp==0, timeStamp>block.timestamp, price<=0 (and same for base).
3. Note no check like `block.timestamp > chainlinkStaleLimit[asset] + timeStamp`.
4. When Chainlink feed stops updating (heartbeat missed), latestRoundData returns old price with old timeStamp; circuit breaker passes.
5. Trades in DittoETH settle at the stale price, mispricing shorts/longs.
**How found:** Code review of the oracle circuit breaker: noticed timeStamp is fetched and passed but only checked for zero/future, not for age relative to block.timestamp, unlike standard Chainlink staleness checks.
**Exploitation:** No direct attacker action described; precondition is a stale Chainlink feed (missed heartbeat or feed outage). During that window users trade at outdated prices, causing mispriced fills and potential value transfer between traders.
**Insight:** When auditing Chainlink integrations, verify the full staleness triple: timeStamp!=0, timeStamp<=block.timestamp, AND block.timestamp - timeStamp <= heartbeat/staleLimit per feed; a circuit breaker that only checks zero/future timestamps silently accepts stale answers.

## Proof of concept (copied exactly from the original report)

**oracleCircuitBreaker missing stale timestamp check**

```
function oracleCircuitBreaker(
    uint80 roundId,
    uint80 baseRoundId,
    int256 chainlinkPrice,
    int256 baseChainlinkPrice,
    uint256 timeStamp,
    uint256 baseTimeStamp
) private view {
@>  bool invalidFetchData = roundId == 0 || timeStamp == 0 || timeStamp > block.timestamp || chainlinkPrice <= 0
        || baseRoundId == 0 || baseTimeStamp == 0 || baseTimeStamp > block.timestamp || baseChainlinkPrice <= 0;

    if (invalidFetchData) revert Errors.InvalidPrice();
}
```

**getOraclePrice catch block stale check**

```
if (roundID == 0 || price == 0 || timeStamp > block.timestamp) revert Errors.InvalidPrice();

            uint256 twapInv = twapCircuitBreaker();
            uint256 priceInEth = uint256(price * C.BASE_ORACLE_DECIMALS).mul(twapInv);
```

