Skip to content

Add realistic-scale fork tests for full lifecycle and sandwich/DOS cost - #100

Merged
holyfuchs merged 3 commits into
mainfrom
holyfuchs/sandwich-attack
Aug 16, 2026
Merged

Add realistic-scale fork tests for full lifecycle and sandwich/DOS cost#100
holyfuchs merged 3 commits into
mainfrom
holyfuchs/sandwich-attack

Conversation

@holyfuchs

Copy link
Copy Markdown
Member

Added IntegrationFork.t.sol and SandwichFork.t.sol: fork tests against real Morpho, real FlowSwap V3 pools, and real tokens on Flow mainnet (only the market oracle is mocked), at a realistic ~$1M TVL vs. the real ~$20k-liquidity yield/debt pool.

IntegrationFork.t.sol builds the vault from 100 individual $10k deposits (arbed back to clean spot after each), pushes the collateral price +10% and rebalances until back in band, then -10% and rebalances again, then has all 100 users redeem one at a time. Users recover ~99.92% of principal, and each shock re-levers/delevers in a single rebalance() call — the amount needing correction is only ~2.3% of current debt, not a fraction of TVL, because the band's re-entry targets sit close to its bounds.

SandwichFork.t.sol runs the existing 3 attack tests (single-sweep, soft DOS, hard DOS) against the same $1M setup. A single sandwiched rebalance caps attacker profit at ~$38 and vault overpayment at ~1%, independent of TVL. Pushing the pool ≥45bps blocks reconvergence within 100 rebalance calls but costs the attacker ~$820-913. Holding the pool 1% off-spot for 100 rounds fully blocks lever rebalancing for ~$9.21/round — the cheapest sustained DOS found. Documented that the cliff around 40-50bps is the real pool's lumpy, stable-pair-style liquidity distribution, not a maxSlippageBps bug.

@holyfuchs
holyfuchs force-pushed the holyfuchs/sandwich-attack branch from 49bd7ca to 454e97e Compare July 31, 2026 10:39
@holyfuchs
holyfuchs force-pushed the holyfuchs/sandwich-attack branch from 454e97e to 20e59c2 Compare July 31, 2026 10:44
@holyfuchs
holyfuchs marked this pull request as ready for review July 31, 2026 10:49
Comment thread solidity/test/SandwichFork.t.sol Outdated
Comment thread solidity/test/SandwichFork.t.sol
@holyfuchs
holyfuchs force-pushed the holyfuchs/sandwich-attack branch from 3ebeed1 to 3b50c34 Compare August 16, 2026 01:29
@holyfuchs
holyfuchs force-pushed the holyfuchs/sandwich-attack branch from 3b50c34 to e88cb18 Compare August 16, 2026 01:44
@holyfuchs
holyfuchs merged commit ccf14c2 into main Aug 16, 2026
4 checks passed
@holyfuchs
holyfuchs deleted the holyfuchs/sandwich-attack branch August 16, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants