Architecture Overview
Warp Router implements a modular, delegatecall-based architecture that separates routing logic from protocol-specific settlement implementations. This design enables seamless integration of new protocols while maintaining consistent security guarantees and gas optimizations across all settlement types.System Architecture
The architecture consists of three primary layers:
Router Layer
Adapter Layer
Arbiter Layer
Layer 1: Router
The Router system serves as the central coordination hub for all settlement operations. It combines execution logic (RouterLogic) with adapter lifecycle management (RouterManager) to provide a complete routing solution.Core Components
RouterLogic - Execution Engine
RouterLogic - Execution Engine
- Atomic intent processing across multiple operations
- Gas optimization through adapter caching
- Signature validation for all fill operations
- Reentrancy protection via transient storage
RouterManager - Lifecycle Management
RouterManager - Lifecycle Management
- Semantic Versioning: Enforces version compatibility for safe upgrades
- Hotfix Support: Allows patch-only upgrades for critical fixes
- Role-Based Access: Separate roles for adding (ADD_ROLE) and removing (RM_ROLE) adapters
- Emergency Pause: Can pause all fill operations by setting signer to address(0)
DirectRoutes - Special Operations
DirectRoutes - Special Operations
singleCall: Direct contract interactionmultiCall: Batched contract interactions- Fee collection operations
Operation Types
- Fill Operations
- Claim Operations
Gas Optimization Features
The Router implements advanced optimization techniques:Adapter Caching
Special Selector Bypass
Optimized Encoding
Context Indexing
Security Model
Atomic Signatures
Reentrancy Protection
Role-Based Access
Batch Integrity
Layer 2: Adapters
Adapters are protocol-specific contracts that handle the actual settlement logic for different protocols and chains. They are always executed via delegatecall from the Router, inheriting its storage context and permissions.Adapter Architecture
Implementation Requirements
Return Function Selector
Implement ERC165
supportsInterface:Use onlyViaRouter Modifier
Solver Context Handling
Adapters extract solver-specific data using the_loadRelayerContext() helper:
Example Adapter: IntentExecutorAdapter
The IntentExecutorAdapter demonstrates a simple forwarding pattern:Layer 3: Arbiters
Arbiters are responsible for validating settlements and unlocking funds from user accounts or resource locks. They provide dual protocol support for both TheCompact and Permit2 standards.Arbiter Architecture
Key Responsibilities
Execute Pre-Claim Operations
Execute Pre-Claim Operations
Compute Mandate Hashes
Compute Mandate Hashes
Router-Only Access Control
Router-Only Access Control
Orchestrate Settlement Flow
Orchestrate Settlement Flow
- Validate user signatures
- Execute pre-claim operations with proper gas stipends
- Unlock funds from TheCompact or Permit2
- Transfer assets to designated recipients
- Execute target operations on behalf of users
Settlement Flows
Let’s examine the complete settlement flows for different operation types.Fill Flow
Signature Verification
Adapter Lookup
Delegatecall Execution
Settlement Layer Interaction
Intent Execution
Completion
Claim Flow
Router Invocation
Adapter Execution
Arbiter Coordination
Pre-Claim Operations
Protocol Selection
Fund Transfer
Settlement
Security Architecture
Delegatecall Context
Signature Validation
- Atomic signatures for fill operations
- User signatures for intent execution
- Protocol signatures for resource unlocking
Access Control
- Router validates atomic signatures
- Adapters enforce onlyViaRouter
- Arbiters enforce onlyRouter
Atomicity Guarantees
Security Considerations
For Adapter Developers
For Adapter Developers
- Delegatecall Context: Adapters execute in Router’s storage context - never write to storage slots
- External Calls: Only interact with trusted, well-audited protocols
- Return Values: Always return function selector for validation
- Interface Support: Implement ERC165 for all settlement functions
- No Untrusted Calls: Never make calls to user-provided addresses
For Arbiter Developers
For Arbiter Developers
- Router-Only Access: Enforce onlyRouter modifier on all settlement functions
- Signature Validation: Validate all user signatures before unlocking funds
- Gas Stipends: Properly account for EIP-150’s 63/64 gas forwarding rule
- Mandate Hashes: Compute hashes correctly to prevent signature replay
- Pre-Claim Safety: Execute pre-claim operations with proper error handling
For Solvers/Relayers
For Solvers/Relayers
- Atomic Signatures: Fill operations require valid signatures from atomic signer
- Context Validation: Ensure solver context matches adapter expectations
- Batch Integrity: Design batches carefully to avoid partial execution
- Gas Estimation: Account for pre-claim operation gas stipends
- Protocol Authorization: Ensure proper protocol-level authorizations for claims
Performance Characteristics
Gas Cost Breakdown
Optimization Impact
- First operation: Full SLOAD cost (~2,100 gas)
- Cached operations: Memory read (~3 gas)
- Break-even point: 2 operations with same adapter
- Maximum benefit: Long batches with few adapters
- Avoids SLOAD: ~2,100 gas saved
- Avoids DELEGATECALL: ~700 gas saved
- Avoids context append: ~200 gas saved
- Total savings: ~2,600+ gas per operation