Coil DEX
// OFF-CHAIN INTENT DEX · BATCH SETTLEMENT · VYPER 0.4
A production-grade off-chain intent DEX built in Vyper 0.4, settling via batch auctions with partial fills. v6 addresses every critical finding from the v5 security review — including permit frontrun griefing, EIP-1271 smart wallet support, and chain.id replay protection.
Vyper 0.4.0
EIP-712
EIP-1271
EIP-2612
Moccasin
Batch Auctions
Partial Fills
Hypothesis Fuzzing
639
Lines of Vyper
95
Tests
48
Asserts
8
Security Fixes
Architecture
Coil DEX uses an intent-settlement model. Users sign off-chain EIP-712 intents specifying token pairs, amounts, and price limits. An authorized solver assembles optimal batches and submits them on-chain via execute_batch(), which validates signatures, checks allowances, enforces price limits, and settles all transfers atomically.
- Phase 1 (Validate) — Verify signatures (EOA/EIP-1271), check cancellation, enforce price limits, validate cumulative allowances
- Phase 2 (Settle) — Pull buy tokens from solver, transfer sell tokens from users to solver, distribute buy tokens to users, accrue protocol fees
- Permits — Applied with revert_on_failure=False to prevent mempool griefing
v6 Security Fixes
All findings from the v5 review were resolved in this iteration:
| ID |
Finding |
Resolution |
| F1 | Permit frontrun griefing | revert_on_failure=False + staticcall |
| F2 | fill_amt unbounded | assert fill_amt < MAX_AMOUNT |
| F3 | ecrecover zero-owner | assert owner != empty(address) |
| F4 | Cancel fully-filled | assert filled < sell_amount |
| F5 | No EIP-1271 support | isValidSignature + 0x1626ba7e |
| F6 | Static chain.id | Immutable INITIAL_CHAIN_ID |
Test Coverage
- test_admin.py — Ownership, solver auth, fee config, token withdrawal
- test_settlement.py — Full execute_batch flow, all Phase 1 guards
- test_eip1271.py — Smart wallet signature verification
- test_replay.py — chain.id fork replay + nonce replay
- test_invariants.py — Hypothesis stateful fuzzing + balance invariant
Key Features
- Off-chain EIP-712 typed-data signing — gas-free intent creation
- Partial fills with cumulative fill tracking per intent hash
- EIP-1271 smart wallet support (Safe, Argent, Coinbase Smart Wallet)
- Permit frontrun protection — batch never reverts on griefed permits
- Configurable protocol fees (≤1%) with accrued fee accounting