Overview
Curated: · Written: · Reviewed:
Oracles & Cross-Chain Interoperability
In one line
An oracle imports an external fact (a price, a timestamp, a random output) and a bridge imports another chain's state or message. Each one moves trust onto named signers, sources or proofs, so reach for them only when on-chain data cannot answer the question, and state exactly what you now trust.
Key definitions
- Feed identity: chain, contract address, base, quote, decimals and heartbeat. Pin all of them per deployment.
- Heartbeat and deviation: a push feed writes on a timer or when price crosses a threshold, so a flat price can be old without being wrong.
- Round validation: answer > 0, updatedAt within maxStaleness, and answeredInRound >= roundId.
- Sequencer uptime feed: reports whether the L2 sequencer is up and since when (startedAt). A grace period after restart gates liquidations.
- Finality: the point after which a source block cannot reorg. Twelve confirmations is a depth, not finality.
- Replay protection: a consumed-identifier check bound to source chain, sender, destination chain, target and nonce.
- Light client: verifies source headers and validator signatures on the destination. You inherit its correctness and update liveness.
Formulas and complexity
A median over n reporters is set by the middle value, so an attacker must control at least half the slots to move it: with 7 slots, 3 forged reporters move nothing while 4 honest reporters hold the true price.
A TWAP averages cumulative price over window w:
Finality on Ethereum: 32 slots per epoch at 12 s per slot, finalized after two epochs, so 64 slots or about 12.8 minutes.
How it works
- Each reporter signs (price, timestamp) and submits. The contract recovers the signer and checks it is registered.
- The aggregator takes the median of the latest slots. A push update fires on deviation or heartbeat.
- The consumer validates the round, staleness, sequencer grace and a sanity range before using the value.
- A bridge proves a source event or header on the destination, marks the identifier consumed, then executes.
When to use and when not to
| Situation | Use | Add controls or avoid |
|---|---|---|
| Liquidation price on L1 | Push feed with staleness check | Spot read from one pool |
| Deep, liquid pair | TWAP as cross-check | TWAP as sole source on a thin pool |
| Asset transfer across chains | Light client, or committee with rate limits | Trusting the relayer to be honest |
| Random outcome for a game | Verifiable randomness bound to a request ID | Block hash or user-supplied seed |
| Liquidations on an L2 | Sequencer uptime feed plus grace period | Price freshness alone |
Traps interviewers probe
- Two feeds means diversified. Fix: trace both to the same exchanges and reporters, then diversify sources and operators.
- Any signed report is accepted. Fix: check the report's feed ID matches the market ID it writes to, and that the signer is registered. Freshness alone does not stop a valid report written to the wrong market.
- Twelve confirmations is finality. Fix: act only on the finalized checkpoint, or price the reorg risk explicitly for the value at stake.
- Replay keyed on nonce alone, or no destination chain ID. Fix: the identifier includes source and destination chain IDs, sender, target, payload hash and nonce, and execution checks block.chainid.
- Falling back to a manipulable price on staleness. Fix: bound deviation from the primary, halt new borrowing and keep repayment open.
Interview tips
Open with the trust boundary: the oracle imports this fact from these sources, so the protocol now trusts these parties for it. Expect these follow-ups: the maximum loss one compromised signer can move; what happens to in-flight messages during an upgrade; how you detect a stale feed before it liquidates someone; what your monitoring shows when two independent endpoints disagree.
Thirty-second outline: name the fact and its source. State the freshness and validation rule and its number. Name the failure mode and what stays open, such as repayment or exit. For cross-chain, state the replay key and the finality rule. Finish with the monitoring signal you would alert on.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.