Educational lab · demo funds only · not production DeFi · not financial advice.No real assets, no mainnet keys, no mainnet targeting. Hardhat + client simulation only.
Flash loan riskOracle manipulationTWAP + circuit breaker

Flash Loan Risk Lab

Click through a same-block style lab scenario: flash-borrow demo capital → spike an unsecured spot oracle → attempt to over-borrow from a VulnerableVault (lab success) versus a MitigatedVault that prices with a TWAP window and trips a circuit breaker (blocked).

What goes wrong?

If a lending vault trusts a single spot price that can move inside one atomic transaction (flash loan + thin pool / lab oracle), an attacker can temporarily inflate collateral value, borrow more debt than the honest price allows, then repay the flash loan — leaving the vault short.

What mitigates it?

TWAP-style windows average recent samples so a one-tick spike barely moves the LTV price. A circuit breaker refuses borrows when spot diverges too far from TWAP. Access control limits who can update feeds or pause markets.

Lab spot
$1.00
LabOracle.latestPrice
TWAP
$1.00
5-sample window
Deviation
0 bps
trip > 500 bps
Flash outstanding
0
LAB-COLL demo units

Interactive lab steps

Tip: run 1 → 2 → 3a and 3b. Mirrors Solidity tests in test/FlashLoanRiskLab.js.

VulnerableVault

waiting
  • collateral: 0 LAB-COLL
  • debt liquidity: 1000 LAB-USD
  • attacker borrowed: 0 LAB-USD

Pricing: live spot only · no TWAP · no breaker

MitigatedVault

healthy
  • collateral: 0 LAB-COLL
  • debt liquidity: 1000 LAB-USD
  • circuit open: false

Pricing: TWAP · deviation circuit breaker · owner pause

Event log

  1. 01 Lab ready · demo tokens LAB-COLL / LAB-USD · spot $1 · TWAP seeded at $1

TWAP

Average recent oracle samples so a single-transaction spike cannot rewrite the LTV price.

Circuit breaker

If spot diverges from TWAP beyond 500 bps, refuse new borrows and optionally pause.

Access control

Restrict who can push prices or close circuits. Lab oracle is open on purpose to teach the failure mode.

Evidence panel

Hardhat suite proving Vulnerable drain vs Mitigated block on local demo tokens.

6 passing0 failing2026-09-15npx hardhat test