Skip to main content

When to Use This Pattern

Monitors oracle price updates to detect and prevent price manipulation within a single transaction, protecting against flash loan attacks and malicious arbitrage. Critical for AMM-based DEXs using oracle prices, lending protocols relying on oracles for collateral valuation, synthetic asset platforms, derivatives protocols using oracles for settlement, and yield farming platforms calculating rewards based on asset prices. Intra-transaction price manipulations can lead to flash loan attacks, theft of funds through manipulated liquidations, or protocol insolvency due to incorrect asset valuations.

What This Pattern Checks

Implements approach to verify oracle price updates using both pre/post state comparison and intra-transaction inspection:
  • _preTx() / _postTx() with Reshiram snapshot reads: Capture oracle price before and after transaction, compare for deviations
  • getCallInputs(): Monitor all price update function calls within transaction
  • registerFnCallTrigger(): Trigger when oracle price update is detected
  • Verify each update’s price parameter against initial price
  • Enforce no price update can deviate more than maximum allowed percentage
The assertion ensures oracle prices remain within acceptable deviation range throughout transaction, detecting and preventing flash loan attacks that attempt to manipulate prices. For more information about cheatcodes, see the Cheatcodes Documentation.

Assertion Pattern

Full examples and mock protocol code are available in credible-std.