QuantAMM

QuantAMM
49,600 OP
View results
Submission Details
Severity: low
Invalid

Multi-Source Oracle Data Timestamp Inconsistency Leading to Price Feed Manipulation in MultiHopOracle

Summary

A vulnerability has been identified in the MultiHopOracle contract's _getData() function where the implementation lacks proper timestamp validation mechanisms. The contract's core logic is centered around a simplistic timestamp tracking approach that only records the oldest timestamp among all oracle readings:

https://github.com/Cyfrin/2024-12-quantamm/blob/main/pkg/pool-quantamm/contracts/MultiHopOracle.sol#L40

if (oracleTimestamp < timestamp) {
timestamp = oracleTimestamp; // Only tracks oldest timestamp
}

The fundamental flaw in this design stems from the absence of temporal consistency checks between oracle data points. When aggregating prices across multiple oracles, the contract fails to ensure chronological coherence of the pricing data. This architectural weakness manifests in several dimensions:

The contract operates without temporal bounds verification, allowing the combination of price feeds from disparate time periods. Moreover, there's no synchronization enforcement between sequential oracle readings, which can result in price derivations from inconsistent market states. This issue is exacerbated by the lack of staleness validation against the current block timestamp.

The severity of this vulnerability is particularly pronounced within QuantAMM's TFMM (Temporal Function Market Making) framework, where oracle price accuracy directly influences pool weight dynamics. The attack surface extends beyond simple price reporting, as it can cascade into pool weight calculations, strategy execution parameters, and ultimately affect LP positions.

Malicious actors can exploit this vulnerability by selectively targeting price disparities during high volatility periods. By constructing transactions that leverage the timestamp inconsistency, attackers can manipulate the effective exchange rates used for trades. The impact is magnified in multi-hop oracle paths where price differences can be compounded across multiple token conversions.

Furthermore, the vulnerability creates systemic risk within the QuantAMM ecosystem as the compromised price feeds affect:

  • Dynamic pool weight adjustments, potentially leading to suboptimal portfolio allocations

  • Strategy execution timing and effectiveness

  • LP position valuations and withdrawal calculations

  • Arbitrage boundaries and market efficiency mechanisms

Proof of Concept

Consider this scenario:

  1. Bob is monitoring market conditions where:

    • ETH trades at $2000

    • BTC trades at $50,000

    • ETH/BTC ratio is 0.04

  2. A market flash crash occurs:

    • ETH price rapidly drops to $1800

    • BTC price drops to $48,000

    • Actual ETH/BTC ratio should be ~0.0375

  3. The MultiHopOracle's price feed consists of:

    • Oracle A: Fresh ETH/BTC data from 1 minute ago

    • Oracle B: Stale BTC/USD data from 30 minutes ago

  4. Alice, a sophisticated trader:

    • Notices the stale data in the oracle path

    • Sees that the oracle is returning inflated prices

    • Executes trades using this price disparity

    • Profits from the difference between actual market price and stale oracle price

  5. The pool processes Alice's trade at the incorrect price due to mixed timestamps

  6. LPs suffer losses as trades execute at non-market prices

  7. This exploitation can continue until the stale oracle updates

In this scenario:

  1. An attacker could wait for significant price movements

  2. Use the stale price combination for profitable trades

  3. The reported timestamp would only indicate the oldest data point

Time t=0 (30 minutes ago):
ETH/USD = $2000
BTC/USD = $50000
ETH/BTC = 0.04
Time t=1 (current):
ETH/USD = $1800 (-10%)
BTC/USD = $48000 (-4%)
ETH/BTC = 0.0375 (-6.25%)
Oracle Readings:
Oracle A (ETH/BTC): 0.0375 (fresh, from t=1)
Oracle B (BTC/USD): $50000 (stale, from t=0)
Calculation with mixed timestamps:
ETH/USD = ETH/BTC * BTC/USD
= 0.0375 * $50000
= $1875
Actual current price should be:
ETH/USD = 0.0375 * $48000 = $1800
Price Discrepancy: $75 per ETH (4.17% higher than actual)

Recommended mitigation steps

  1. Add maximum age validation:

function _getData() internal view override returns (int216 data, uint40 timestamp) {
uint40 constant MAX_ORACLE_DELAY = 1 hours;
uint40 constant MAX_TIME_DEVIATION = 5 minutes;
uint40 currentTime = uint40(block.timestamp);
HopConfig memory firstOracle = oracles[0];
(data, timestamp) = firstOracle.oracle.getData();
// Check freshness of first oracle
require(currentTime - timestamp <= MAX_ORACLE_DELAY, "Stale oracle data");
for (uint i = 1; i < oracles.length; ) {
HopConfig memory oracleConfig = oracles[i];
(int216 oracleRes, uint40 oracleTimestamp) = oracleConfig.oracle.getData();
// Ensure data freshness
require(currentTime - oracleTimestamp <= MAX_ORACLE_DELAY, "Stale oracle data");
// Ensure consistency between oracle timestamps
require(abs(int256(uint256(timestamp)) - int256(uint256(oracleTimestamp))) <= MAX_TIME_DEVIATION,
"Inconsistent timestamps");
// Rest of the logic...
unchecked { ++i; }
}
}
  1. Add configuration options for time parameters:

  • Allow admin to adjust MAX_ORACLE_DELAY based on market conditions

  • Enable fine-tuning of MAX_TIME_DEVIATION for different oracle combinations

  • Implement emergency pause if oracle data becomes too stale

  1. Add event emissions for monitoring:

event OracleDataUpdated(uint40 timestamp, uint40[] oracleTimestamps);

These mitigations would significantly reduce the risk of price manipulation through timestamp inconsistencies while maintaining system flexibility.

Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

invalid_MultiHopOracle_return_oldest_timestamp

Here we’re searching for the weakest element in the chain to know if we can trust the entire chain. That’s why we need the oldest timestamp to check if the all chain returns at least one staled data.

Support

FAQs

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