Algo Ssstablecoinsss

AI First Flight #2
Beginner FriendlyDeFi
EXP
View results
Submission Details
Severity: medium
Valid

M-1: Oracle staleness timeout of 72 hours allows exploitation of severely outdated prices

Description

Severity: Medium

The oracle staleness timeout in oracle_lib.vy:15 is set to 72 hours (3 days):

TIMEOUT: constant(uint256) = 72 * 3600 # 259,200 seconds

Chainlink's ETH/USD heartbeat on Ethereum mainnet is 3,600 seconds (1 hour) and BTC/USD is also 3,600 seconds. A 72-hour timeout accepts price data that is up to 72x older than the feed's actual heartbeat.

During the March 2023 banking crisis, BTC dropped ~15% in a single hour. In May 2021, ETH dropped ~40% in 24 hours. A 72-hour stale window allows an attacker to exploit severely outdated prices.

Proof of Concept

def test_stale_price_exploitation():
# Setup: ETH/USD oracle last updated 70 hours ago at $3000
# Real current price: $1500 (50% crash over 70 hours)
# Oracle still passes staleness check (70h < 72h timeout)
price_feed.updateAnswer(3000e8) # $3000
boa.env.time_travel(70 * 3600) # 70 hours pass
# Attacker deposits 100 ETH, oracle values it at $300,000 (stale)
weth.approve(dsc_engine, 100e18, sender=attacker)
dsc_engine.deposit_collateral(weth, 100e18, sender=attacker)
# Attacker mints 150,000 DSC (200% collateralization at stale price)
dsc_engine.mint_dsc(150_000e18, sender=attacker)
# Attacker sells 150,000 DSC on secondary market for ~$150,000
# Oracle updates to real price: $1500
price_feed.updateAnswer(1500e8)
# 100 ETH now worth $150,000 — exactly 100% ratio
# Position is insolvent, protocol absorbs the bad debt
# Attacker profit: ~$150,000 in DSC - $150,000 in ETH = net zero collateral
# but the DSC holders suffer: backing dropped from 200% to 100%

Risk

  • Impact: Medium — stale prices allow minting DSC against inflated collateral values. During market crashes, this creates undercollateralized positions that erode the DSC peg.

  • Likelihood: Medium — crypto price crashes of 20-50% within 72 hours are well-documented events that occur multiple times per year.

Recommended Mitigation

Reduce the timeout to match Chainlink's actual heartbeat, with a safety margin:

TIMEOUT: constant(uint256) = 3 * 3600 # 3 hours (3x the 1-hour heartbeat)

For a more robust design, consider per-feed timeouts since the README states users can swap collateral assets (different feeds have different heartbeats).

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 4 days ago
Submission Judgement Published
Validated
Assigned finding tags:

[M-01] The TIMEOUT is set as a fixed constant of 72 hours, which makes it inflexible in adapting to the market price.

## Description In this contract, the TIMEOUT is set as a fixed constant (72 hours, or 259200 seconds). This means that if the oracle price data is not updated within 72 hours, the data will be considered outdated, and the contract will trigger a revert. ## Vulnerability Details At this location in the code, <https://github.com/Cyfrin/2024-12-algo-ssstablecoinsss/blob/4cc3197b13f1db728fd6509cc1dcbfd7a2360179/src/oracle_lib.vy#L15> ```Solidity TIMEOUT: constant(uint256) = 72 * 3600 ``` the timeout is directly set to 72 hours. For an oracle, which cannot dynamically adjust the price updates, this is a suboptimal approach. ## Impact - Fixed Timeout: The TIMEOUT is hardcoded to 72 hours. In markets with frequent fluctuations or assets that require more frequent price updates, 72 hours might be too long. Conversely, if the timeout is too short, it could cause frequent errors due to the inability to update data in time, disrupting normal contract operations. - Non-adjustable Timeout: If the contract's requirements change (e.g., market conditions evolve or the protocol requires more flexibility), the fixed TIMEOUT cannot be dynamically adjusted, leading to potential mismatches with current needs. - Lack of Flexibility: The current timeout mechanism is static and cannot be adjusted based on market volatility or the frequency of oracle updates. In volatile markets, a shorter TIMEOUT might be necessary, while in stable markets, a longer timeout would be more appropriate. \##Tools Used Manual review ## Recommendations Introduce a dynamic price expiration mechanism that adjusts based on market conditions. Use volatility data (such as standard deviation or market price fluctuation) to dynamically adjust the timeout period. This can be achieved by monitoring market volatility and adjusting the TIMEOUT accordingly: ```Solidity # Monitor market volatility and dynamically adjust TIMEOUT @external def adjustTimeoutBasedOnVolatility(volatility: uint256): if volatility > HIGH_VOLATILITY_THRESHOLD: self.TIMEOUT = SHORTER_TIMEOUT # In high volatility, decrease TIMEOUT else: self.TIMEOUT = LONGER_TIMEOUT # In stable market, increase TIMEOUT log TimeoutAdjusted(self.TIMEOUT) ```

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!