System Overview
ZKP2P v2.1 implements a modular, intent-based architecture for trustless peer-to-peer fiat-to-crypto exchanges. The system consists of five main components that work together to facilitate secure, verifiable trades:- Escrow Contract - Liquidity management and deposit custody
- Orchestrator Contract - Intent lifecycle coordination
- Unified Payment Verifier - Multi-platform payment validation
- Registry System - Permission and configuration management
- Protocol Viewer - Read-only state aggregation
Architecture Diagram
Core Components
Escrow Contract
The Escrow contract manages liquidity deposits from makers (liquidity providers) and handles secure fund custody.Deposit Management
Payment Method Config
Intent Locking
Liquidity Reclaim
Key Responsibilities
Deposit Lifecycle Management
Deposit Lifecycle Management
- Token type (USDC)
- Amount range for individual intents (min/max)
- Supported payment methods and currencies
- Optional delegate for deposit management
- Optional intent guardian for expiry extensions
Multi-Currency Support
Multi-Currency Support
- Accept payments from multiple platforms
- Support international currencies
- Set custom conversion rates per currency
- Update rates dynamically based on market conditions
Intent Fund Locking
Intent Fund Locking
lockFunds:- Liquidity is reserved for the specific intent
- Intents expire after a configurable period
- Expired intents are pruned to reclaim liquidity
Dust Collection & Deposit Closure
Dust Collection & Deposit Closure
- Dust threshold prevents tiny balances from remaining
retainOnEmptyflag allows makers to keep deposit config- Protocol collects dust to avoid locked funds
Orchestrator Contract
The Orchestrator coordinates the entire intent lifecycle from creation to settlement.Intent Coordination
Payment Verification
Fee Collection
Hook Execution
Intent Lifecycle
Signal Intent
Off-Chain Payment
Fulfill Intent
Settlement
- Protocol Fee - Sent to protocol fee recipient
- Referrer Fee - Sent to referrer (if specified)
- Net Amount - Sent to taker or post-intent hook
Intent Gating
Orchestrator supports optional signature-based gating:Unified Payment Verifier
The Unified Payment Verifier consolidates verification logic for all payment methods into a single contract.Architecture Benefits
Reduced Complexity
Consistent Interface
Easy Configuration
Lower Gas Costs
Verification Flow
Registry System
The registry system provides modular permission management:Payment Verifier Registry
Payment Verifier Registry
- Venmo (USD)
- PayPal (USD, EUR, GBP)
- Wise (USD, EUR, GBP, SGD, etc.)
- Zelle (USD)
- CashApp (USD)
- Revolut (USD, EUR, GBP)
- MercadoPago (BRL, ARS)
- Monzo (GBP)
Escrow Registry
Escrow Registry
Nullifier Registry
Nullifier Registry
Post Intent Hook Registry
Post Intent Hook Registry
- Across Bridge Hook - Automatically bridge USDC to another chain
- Swap Hook - Convert USDC to another token
- Multi-recipient Hook - Split payment among multiple addresses
Relayer Registry
Relayer Registry
Protocol Viewer
A read-only contract for efficient state aggregation:Complete User Flow
Here’s the end-to-end flow with all components:Step-by-Step Breakdown
Maker Deposits Liquidity
Escrow.createDeposit() with:- 1000 USDC
- Accepted payment methods (Venmo, PayPal)
- Min/max intent amounts (10-500 USDC)
- Supported currencies and rates
depositId.Taker Signals Intent
Orchestrator.signalIntent() with:- Target deposit and amount (100 USDC)
- Payment method (Venmo)
- Currency (USD) and rate (1:1)
- Recipient address
- Validates all parameters
- Generates unique intent hash
- Calls
Escrow.lockFunds()to reserve liquidity - Stores intent parameters for verification
Taker Sends Fiat Payment
Payment Proof Generation
- Attestation service verifies payment via zkTLS
- Extracts payment details (amount, currency, payee, timestamp)
- Creates EIP-712 typed data structure
- Signs with trusted witness keys
- Returns attestation to taker
Taker Fulfills Intent
Orchestrator.fulfillIntent() with attestation.Orchestrator:- Retrieves intent parameters
- Gets verifier from payment registry
- Calls
UnifiedPaymentVerifier.verifyPayment()
- Validates EIP-712 signatures
- Checks payment details match intent
- Verifies timestamp within buffer
- Nullifies payment ID
- Returns verification result
Settlement & Distribution
- Orchestrator calls
Escrow.unlockAndTransfer() - Escrow transfers 100 USDC to Orchestrator
- Orchestrator deducts 1% protocol fee (1 USDC)
- Orchestrator transfers 99 USDC to taker
- Intent is pruned from both contracts
- Funds go to hook contract instead
- Hook executes custom logic (bridge, swap, etc.)
Security Considerations
Reentrancy Protection
ReentrancyGuardPausable Contracts
Access Control
Signature Validation
Nullifier System
Intent Expiration
Pausable Functionality
Both Escrow and Orchestrator implement careful pause logic:Gas Optimization
The architecture includes several gas optimizations:Compiler Settings
Compiler Settings
Storage Packing
Storage Packing
Batch Operations
Batch Operations
View Functions for State Aggregation
View Functions for State Aggregation
Upgrade Path
The modular architecture supports upgrades without full migration:Deploy New Components
Register in System
Gradual Migration
- Old deposits remain on old Escrow
- New deposits use new Escrow
- Both can coexist using registry pattern
Update References
setEscrowRegistry()Extension Points
The architecture provides several extension points:Post Intent Hooks
Custom logic executed after intent fulfillment:Custom Verifiers
New payment methods viaIPaymentVerifier interface: