What is a flash-loan-driven oracle manipulation attack on a DeFi protocol, and how would you design the price feed to resist it?
technical-conceptual · Mid level · software-engineering, blockchain-web3
What the interviewer is really asking
Assesses whether the candidate understands how a protocol's choice of price source becomes an attack surface and can reason about concrete oracle-design defenses, not just name 'oracle attack'.
What to say
- Describe the attack: an attacker borrows a huge amount with a flash loan within one transaction, dumps it into a thin on-chain DEX pool to spike or crash the spot price, and then uses that manipulated price as collateral or to drain a lending/derivatives protocol before repaying the loan atomically.
- Pinpoint the root cause: the victim protocol reads an instantaneous spot price from a manipulable on-chain source instead of a robust oracle, so a single block can move the number it trusts.
- Give layered defenses: use a decentralized oracle aggregating off-chain exchange prices (Chainlink/Pyth) so on-chain DEX swings don't move it, fall back to a multi-block TWAP for on-chain pairs, validate staleness and deviation bounds on every read, and add circuit breakers that pause on abnormal moves.
What to avoid
- Treating 'use Chainlink' as the whole answer without explaining why an off-chain-sourced feed is immune to an on-chain flash-loan swap, or where it can still go stale.
- Suggesting the fix is to read the spot price from a single DEX pool 'but a bigger one', which only raises the cost of the same attack.
- Confusing this with reentrancy or front-running; the defining mechanism here is trusting a manipulable price within one atomic transaction.
Example answers
Strong: The attacker takes a flash loan, swings a thin DEX pool's spot price in the same transaction, and the victim protocol prices collateral or a swap off that manipulated number — so they borrow against fake value or drain a pool, then repay the loan atomically. The root problem is reading an instantaneous, manipulable spot price. I'd source prices from a decentralized oracle that aggregates off-chain exchange data, since an on-chain swap can't move that, and back it with a multi-block TWAP for on-chain pairs, plus staleness checks and a deviation circuit breaker so one weird block can't be acted on.
Weak: You just plug in Chainlink and you're safe, because Chainlink is decentralized so nobody can hack the price. Flash loans are really a reentrancy thing, so a reentrancy guard mostly handles it too.