Simulating MEV Bundles on Ethereum
How MEVGuard validates MEV Blocker order flow, simulates searcher bundles, and calculates deterministic user refunds.
- Web3
- Ethereum
- Python
- Security
The Problem with Toxic Order Flow
In decentralized exchanges like CoW Protocol, protecting users from sandwich attacks and frontrunning requires continuous verification. MEV Blocker routes transactions through private RPC builders, returning backrun value to the user as a refund.
However, verifying whether a searcher bundle violated refund rules requires deterministic replay against historical state.
async def verify_bundle_settlement(w3: AsyncWeb3, block_number: int, tx_hash: HexStr) -> RefundValidation:
receipt = await w3.eth.get_transaction_receipt(tx_hash)
state_diff = await simulate_state_diff(w3, block_number, receipt.transactionIndex)
expected_refund = calculate_backrun_share(state_diff)
return RefundValidation(
tx_hash=tx_hash,
expected=expected_refund,
actual=extract_refund_transfer(receipt),
is_compliant=expected_refund <= extract_refund_transfer(receipt),
)
Scaling On-Chain Ingestion with Multiprocessing
Analyzing millions of historical Ethereum settlement blocks creates severe I/O bottlenecks. In MEVGuard, we solved this through:
- Partitioned Dune Analytics queries: extracting multi-gigabyte trace datasets in chunked SQL windows.
- Multiprocess trace normalizers: parsing raw EVM call traces in parallel worker pools without GIL contention.
- Deterministic state rollback: verifying bundle outcomes against dry-run forks before flagging violations.