Skip to content

Lesson 3 of 9 · 26m

Oracles, Prices, and External Dependency Risk

Distinguish market price, reported price, and executable price; analyze oracle freshness, liquidity, manipulation cost, and dependency failure.

Most oracle failures are category errors. A protocol needs a resistant reference price for collateral valuation, but uses the price a trader can move for one block. Or a liquidation engine needs the price at which size can actually be sold, but consumes a marginal quote from a thin pool. An oracle is not a number. It is a claim about market reality under adversarial pressure.

Define the economic question first

Before choosing an oracle, write down what decision depends on the value:

collateral valuation        conservative, manipulation-resistant reference price
liquidation threshold       executable exit price under stress
index rebasing              broad market reference, not one venue
mint/redemption parity      backing value and redemption constraints
fee calculation             approximate value, lower manipulation impact

These are different numbers. A decentralized exchange spot price can be the correct input for a swap and catastrophically wrong for borrowing power.

Spot prices are often attacker-controlled inputs

A pool quote depends on current reserves. If an attacker can change reserves and use the resulting quote in the same transaction, your oracle is not independent:

function spotPrice() public view returns (uint256) {
    return reserveQuote * 1e18 / reserveBase;
}

Flash liquidity makes this worse because the attacker no longer needs capital duration. They only need enough capital for the length of a transaction plus fees. Time-weighted average prices raise manipulation cost, but they are not magic: short windows, low liquidity, missing observations, and stale updates can still be exploited.

A reputable oracle does not absolve integration mistakes. You still need to validate freshness, decimals, answer positivity, sequencer status on L2s, heartbeat behavior, and the exact asset pair:

(uint80 roundId, int256 answer, , uint256 updatedAt, uint80 answeredInRound) =
    feed.latestRoundData();
require(answer > 0, "bad price");
require(block.timestamp - updatedAt <= maxStaleness, "stale price");
require(answeredInRound >= roundId, "incomplete round");

The decimals question is not trivia. An 8-decimal USD feed and an 18-decimal token amount must be normalized deliberately; one missing exponent is a ten-order-of-magnitude valuation error.

Dependency failure is part of the trust model

Bridges, price feeds, keepers, stablecoins, liquid staking tokens, reward distributors, and lending markets can all halt, depeg, pause, upgrade, or change semantics. A mature design defines degraded behavior: what happens when the oracle is stale, when a token is paused, when a downstream protocol reverts, and when governance cannot act quickly?

Field notes

  • A manipulation-resistant oracle is expensive to move, not impossible to move. Quantify cost relative to extractable profit.
  • Never use balanceOf or instantaneous pool reserves as a price unless manipulation is irrelevant to the decision.
  • Crosschain oracle latency creates arbitrage and liquidation edges; timestamp and finality assumptions belong in the design.
  • Oracle admin keys are part of access control. If someone can replace the feed, they can often replace reality.
  • Test with decimal fixtures copied from deployed token contracts, not idealized 18-decimal assumptions.

Was this lesson helpful?

Sign in to rate