Commit 2fedb20
feat(contracts): complete Phase 1 on-chain protocol — Stages 1+2+3
Implements the full on-chain layer for Phase 1: escrow, EIP-712 hashing,
LayerZero V2 cross-chain messaging, signed solver auction, and
timeout-based recovery. Internally audited; all R-01 through R-15
findings addressed; Slither clean.
Stage 1 — Contract foundation
- IntentSettler with native-ETH + ERC-20 (incl. USDT-style non-bool)
escrow via OZ SafeERC20, ReentrancyGuard, EIP-712 hashing, packed
IntentMeta storage (saves ~21–46k gas per op)
- cancelIntent (user before deadline, anyone after; refundTo override)
- executeMatching with on-chain price-symmetry validation (accepts both
Pending and Auctioning state — auction is discovery, not lock)
- openAuction with AUCTION_DELAY = 30s
- Intent struct includes refundTo for ERC-7683 alignment
- IntentState enum reserves Locked for Phase 2B async settlement
Stage 2 — LayerZero V2 OApp integration
- Two-leg LZ flow: source executeMatching → EXECUTE_MATCH → dest
_handleExecuteMatch releases tokens + sends CONFIRM → source
_handleConfirm releases tokens
- Versioned payloads (MSG_VERSION = 1) with type discriminator
- refundIfLzTimeout (LZ_TIMEOUT = 6 hours) for stuck Matched intents;
longer window minimises asymmetric-loss race vs. LZ executor retries
- _payNative override allows return-leg fee from contract balance
- R-01 fix: validate _origin.srcEid against intent.destChainId via
registry — defense in depth for Phase 2+ multi-chain
- R-03 fix: lzReceive nonReentrant for token-callback defense
- MockLzEndpoint for deterministic two-chain test harness
Stage 3 — SolverAuction integration + signed proposals
- SolverAuction.setAuctionWindow gated to linked IntentSettler
(closes Stage 1 audit M-03)
- ECDSA-signed proposals over chain-and-contract-bound digest
(closes Stage 1 audit M-04). Domain: "ILP-SolverProposal-v1"
- Packed SolverProposal struct (uint16 solverFeeBps shares slot
with solver address) — saves 1 SSTORE per submitProposal
- Idempotent executeWinningProposal with announced-winner storage
- Decoupled-settlement design: auction is discovery; winning solver
submits a regular counterparty intent on dest, executeMatching
pairs them (no parallel settleWithSolver path needed)
Tests
- 87 unit/fuzz/integration tests; all passing
- 5 stateful invariants × 256 runs × ~500 calls ≈ 640k random call
sequences (escrow accounting × 2, terminal-state stickiness,
settled-flag monotonic, nonce-set monotonic) — all hold
- Full cross-chain round-trip tests for both P2P and solver-auction
paths via MockLzEndpoint
- Explicit testLz_asymmetricLoss_documentedBehavior makes the rare
black-swan failure mode visible to future maintainers
Audits & docs
- Stage 1 audit: docs/STAGE_1_AUDIT.md
- Stage 2 audit: docs/STAGE_2_AUDIT.md
- Stage 3 audit: docs/STAGE_3_AUDIT.md
- Stage 3 final review: docs/STAGE_3_FINAL_REVIEW.md (R-01 to R-15
with bonded-solver Phase 2A spec, HTLC Phase 2B spec, doc
cross-reference, tooling roadmap)
- ARCHITECTURE.md, MVP_SPECIFICATION.md, RISK_ANALYSIS.md updated
to match implementation; legacy SUBMITTED/AUCTIONED/CONFIRMED
naming replaced with canonical enum names
- WHITEPAPER.md: tightened "first" claim to specific P2P-first
differentiator; added Competitive Landscape table (Across, UniswapX,
deBridge, Mayan, Eco, Bungee, 1inch, Garden, CoW); added
"Why direct P2P matching matters" section with full economic +
decentralisation argument; added two-sided P2P liquidity-mining
design with 6 Sybil mitigations drawn from the LooksRare lesson
- README.md: honest positioning, P2P benefits summary, ILP incentive
pointer
- Forward-compatibility verified against Q3 2026 / Q4 2026 / Q1 2027
roadmap including bonded solvers, encrypted intents (Noir-based),
HTLC, intent chaining, additional chains, Superchain native interop
- Tooling: Slither already running per-stage with 0 medium+ findings;
Echidna + Mythril + Halmos + external audit scheduled for Stage 7
before testnet
Status
- forge build: clean (45 contracts)
- forge test: 88/88 passing (~123s including invariants)
- forge fmt --check: clean
- Slither (medium+, --filter-paths "lib/|test/"): 0 findings
- Backend lint+test, frontend lint+build: clean
Phase 1 on-chain layer is functionally complete and ready for Stage 4
(backend services). External audit + Echidna/Mythril/Halmos run in
Stage 7 before any testnet deployment.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent da364cf commit 2fedb20
30 files changed
Lines changed: 4924 additions & 331 deletions
File tree
- contracts
- src
- interfaces
- libraries
- test
- mocks
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
35 | 51 | | |
36 | 52 | | |
37 | 53 | | |
| |||
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
44 | | - | |
| 60 | + | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
30 | 59 | | |
31 | 60 | | |
32 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
33 | 69 | | |
34 | 70 | | |
35 | 71 | | |
36 | 72 | | |
37 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
38 | 78 | | |
39 | 79 | | |
40 | 80 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
45 | 96 | | |
46 | | - | |
| 97 | + | |
0 commit comments