A decentralized Take Intent processing system built on Ethereum, enabling gasless token authorization and secure escrow transactions through Uniswap Permit2 and ERC6551 Token Bound Accounts.
- Overview
- Key Features
- Architecture
- Technical Implementation
- Core Contracts
- Quick Start
- Development
- Testing
- Deployment
- Security
- Documentation
- Contributing
- License
Lighter EVM Contract is a smart contract system that implements a decentralized transaction intent processing mechanism. The system allows buyers and sellers to express trading intentions through EIP-712 signed intents, execute transactions through relayers, and provides secure fund escrow services.
- Take Intent: A mechanism where users express trading intentions (buy/sell) through signed messages, allowing relayers to execute transactions on their behalf
- Permit2 Integration: Uses Uniswap Permit2 for gasless token authorization and transfers
- Token Bound Accounts: ERC6551-based account system for enhanced user experience
- Escrow System: Secure fund custody with multiple release mechanisms (seller release, verifier release, dispute resolution)
- TransientStorage: EIP-1153 based reentrancy protection for efficient state management
- Gas Optimization: Inline assembly implementations for critical hashing operations
The seller publishes a sell intent and authorizes token transfer via Permit2. The buyer initiates the transaction.
Process:
- Seller signs a token transfer authorization using
Permit2.permitWitnessTransferFromwithIntentParamsas witness - Relayer signs
EscrowParams(escrow parameters) - Buyer executes
execute, transferring seller's tokens to Escrow contract
The buyer publishes a purchase intent. The seller authorizes tokens via Permit2 before executing.
Process:
- Buyer signs
IntentParams - Seller authorizes tokens via Permit2
- Relayer signs
EscrowParams - Seller executes
executeto initiate the transaction
The seller authorizes all tokens to AllowanceHolder at once via Permit2's permit function, supporting batch transactions.
Process:
- Seller authorizes tokens to
AllowanceHoldervia Permit2permit - Seller signs
IntentParams - Relayer signs
EscrowParams - Buyer can execute multiple times, transferring tokens through
AllowanceHolder
- β EIP-712 Signatures: Typed data signatures for better UX and security
- β ERC6551 Support: Token Bound Accounts (TBA) for account abstraction
- β EIP-1153 TransientStorage: Efficient reentrancy protection using transient storage (gas-optimized)
- β Escrow Custody: Multi-stage escrow with dispute resolution
- β Payment Method Registry: Configurable payment methods with window periods
- β User Honour System: Track user reputation and transaction history
- β Waypoint Support: Escrow lifecycle management (payment, cancellation, dispute, resolution)
- β ZK Verification: Zero-knowledge proof verification support (ZkVerifyProofVerifier)
- β Gas-Optimized Hashing: Inline assembly implementations for efficient keccak256 hashing
The project uses a modular multiple inheritance architecture, following the 0x-settler design pattern:
Three Main Business Lines:
-
Take Intent Line:
Context β SettlerAbstract β SettlerBase β Permit2PaymentAbstract β Permit2PaymentTakeIntent β Settler (core execution logic) β MainnetTakeIntent (mainnet implementation) -
Waypoint Line:
Context β SettlerAbstract β SettlerBase β WaypointAbstract β SettlerWaypoint β MainnetWaypoint (mainnet implementation) -
Verifier Line (in development):
Context β VerifierAbstract β ZkVerifyProofVerifier (mainnet implementation)
Core Foundation:
- Context: Base contract providing escrow, relayer, and signature verification
- SettlerBase: Core base contract with TransientStorage-based reentrancy protection, payment method registry, and fee calculations
src/
βββ account/ # ERC6551 Token Bound Account implementation
β βββ LighterAccount.sol # Main account contract with honour system
β βββ AccountV3.sol # ERC6551 account implementation
β βββ ERC6551Registry.sol # ERC6551 registry
β βββ TokenBoundConfig.sol # TBA configuration
βββ allowanceholder/ # Permit2 allowance holder for bulk transactions
β βββ AllowanceHolder.sol
β βββ IAllowanceHolder.sol
βββ chains/ # Chain-specific implementations
β βββ Mainnet/
β βββ TakeIntent.sol # Mainnet take intent implementation
β βββ Waypoint.sol # Mainnet waypoint implementation
β βββ ZkVerifyProofVerifier.sol # ZK proof verifier
β βββ Common.sol # Common utilities
βββ core/ # Core abstract contracts and implementations
β βββ Permit2Payment.sol # Permit2 payment implementation
β βββ Permit2PaymentAbstract.sol # Permit2 payment abstract
β βββ SettlerErrors.sol # Custom error definitions
β βββ WaypointAbstract.sol # Waypoint abstract contract
β βββ VerifierAbstract.sol # Verifier abstract contract
β βββ ZkVerifier.sol # ZK verifier base
βββ interfaces/ # Interface definitions
β βββ ISettlerBase.sol # Core data structures
β βββ ISettlerTakeIntent.sol # Take intent interface
β βββ ISettlerWaypoint.sol # Waypoint interface
β βββ IEscrow.sol # Escrow interface
β βββ IPaymentMethodRegistry.sol # Payment method registry interface
β βββ ...
βββ utils/ # Utility libraries
β βββ ParamsHash.sol # EIP-712 parameter hashing (gas-optimized)
β βββ TransientStorage.sol # EIP-1153 transient storage for reentrancy
β βββ SignatureVerification.sol # Signature verification utilities
β βββ UnsafeMath.sol # Unsafe math operations
β βββ Permit2Helper.sol # Permit2 helper functions
β βββ ...
βββ vendor/ # Third-party vendor libraries
β βββ SafeTransferLib.sol # Safe token transfer library
β βββ FullMath.sol # Full precision math
β βββ ...
βββ Escrow.sol # Escrow contract (fund custody)
βββ Settler.sol # Core settler contract (intent execution)
βββ SettlerBase.sol # Base settler functionality
βββ SettlerAbstract.sol # Abstract settler interface
βββ SettlerWaypoint.sol # Waypoint settler implementation
βββ PaymentMethodRegistry.sol # Payment method registry
βββ ISettlerActions.sol # Action selectors
The project implements several gas optimization techniques:
- EIP-1153 TransientStorage: Uses transient storage (
tload/tstore) instead of permanent storage for reentrancy protection, saving ~20,000 gas per operation - Inline Assembly Hashing: All
ParamsHashfunctions use inline assembly forkeccak256hashing, avoidingabi.encodeoverhead - CalldataDecoder: Optimized calldata decoding without bounds checking (documented trade-off for gas efficiency)
- Batch Operations: Supports bulk transactions through
AllowanceHolderfor efficient token transfers
The system uses a multi-layered reentrancy protection approach:
- TransientStorage: EIP-1153 based protection for transaction-level state
- ReentrancyGuard: OpenZeppelin's
ReentrancyGuardin Escrow contract - State Validation: Ensures payer, witness, and intent state are properly managed
- Foundry Linting: All code follows Foundry linting recommendations
- Gas-Optimized Patterns: Inline assembly where appropriate for critical paths
- Comprehensive Testing: Unit tests for core libraries (ParamsHash, etc.)
- Code Review: Regular code reviews and security analysis
SettlerAbstract: Abstract interface defining_dispatchand_dispatchVIPmethodsSettlerBase: Core base contract providing:- EIP-1153 TransientStorage-based reentrancy protection
- Payment method registry integration
- Fee calculation utilities (
getAmountWithFee,getFeeAmount) - Intent validation and state management
Settler: Core execution contract handling transaction intent execution logic- Implements
_dispatchfor action routing - Supports multiple intent types (seller intent, buyer intent, bulk sell)
- Implements
MainnetTakeIntent: Mainnet implementation inheriting fromSettlerSettlerWaypoint: Waypoint contract for escrow lifecycle management- Handles payment, cancellation, disputes, and resolution
MainnetWaypoint: Mainnet waypoint implementation
LighterAccount: ERC6551 Token Bound Account implementation- Mints Ticket NFTs and creates corresponding TBAs
- Manages user honour system
- Tracks pending transactions and quotas
LighterTicket: ERC721 NFT contract for user ticketsAllowanceHolder: Permit2 authorization holder for bulk transactions
Escrow: Fund escrow contract managing transaction lifecycle- Creates and manages escrow transactions
- Handles payment, release, cancellation, and dispute resolution
- Supports multiple release mechanisms
PaymentMethodsRegistry: Registry for payment methods with configurable windows
ISettlerBase: Core data structures (IntentParams, EscrowParams, EscrowStatus, PaymentMethodConfig)ISettlerTakeIntent: Interface for take intent functionalityISettlerWaypoint: Interface for waypoint functionalityIEscrow: Escrow contract interface with full lifecycle managementISettlerActions: Action selectors for transaction executionIPaymentMethodRegistry: Payment method registry interface
ParamsHash: Gas-optimized EIP-712 parameter hashing using inline assembly- Supports
Range,IntentParams,EscrowParams,TokenPermissions - All hash functions optimized with inline assembly for gas efficiency
- Supports
TransientStorage: EIP-1153 transient storage library for reentrancy protection- Manages payer, witness, intentTypeHash, and tokenPermissions in transient storage
- Provides efficient state management without permanent storage costs
CalldataDecoder: Efficient calldata decoding library (used in SettlerBase)
- Foundry: >= 1.0.0 (Installation Guide)
- Solidity: 0.8.25
- Node.js: >= 18.0.0 (optional, for Hardhat scripts)
# Clone the repository
git clone https://github.com/lighterim/lighter-evm-contract.git
cd lighter-evm-contract
# Install Foundry (if not installed)
curl -L https://foundry.paradigm.xyz | bash
foundryup
# Install dependencies
forge install
# Install Node.js dependencies (optional, for Hardhat)
npm installCreate a .env file in the root directory:
# RPC endpoints
MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
SEPOLIA_RPC_URL=https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY
BASE_MAINNET_RPC_URL=https://mainnet.base.org
BNB_MAINNET_RPC_URL=https://bsc-dataseed.binance.org
# Deployment account
PRIV_KEY=your_private_key_here
DEPLOYER=0xYourDeployerAddress
# Test accounts (optional)
BUYER_PRIVATE_KEY=your_buyer_private_key
SELLER_PRIVATE_KEY=your_seller_private_key
RELAYER_PRIVATE_KEY=your_relayer_private_key# Compile with Foundry
forge build
# Or compile with Hardhat (optional)
npm run compile# Format code
forge fmt
# Check formatting
forge fmt --check# Generate gas report
forge test --gas-report# Generate coverage report
forge coverageforge test# Test Settler functionality
forge test --match-path test/Settler.t.sol -vvvvv
# Test Take Intent
forge test --match-path test/TakeIntent.t.sol -vvvvv
# Test Waypoint
forge test --match-path test/Waypoint.t.sol -vvvvv
# Test unit tests (ParamsHash, etc.)
forge test --match-path test/unit/ -vvvvv
# Test Permit2 transfers
forge test --match-path test/Permit2TransferTest.t.sol -vvvvvTests support testnet fork testing:
# Set RPC URL
export SEPOLIA_RPC_URL=your_rpc_url
# Run fork tests
forge test --match-path test/TakeIntent.t.sol --ffi -vvvvv# Generate coverage report
forge coverage
# Run unit tests
forge test --match-path test/unit/ -vv
# Run integration tests
forge test --match-path test/TakeIntent.t.sol -vv
forge test --match-path test/Waypoint.t.sol -vv- Set up environment variables (see Environment Setup)
- Ensure sufficient balance for deployment
- Configure network in
foundry.tomlorhardhat.config.ts
# Deploy to Sepolia testnet
forge script script/Deploy.s.sol \
--rpc-url $SEPOLIA_RPC_URL \
--broadcast \
--private-key $PRIV_KEY \
--verify# Deploy using Hardhat
npx hardhat run scripts/deploy-sepolia.ts --network sepolia# Verify contract on Etherscan
forge verify-contract \
--rpc-url https://sepolia.drpc.org \
--verifier etherscan \
--verifier-url https://api-sepolia.etherscan.io/api \
$CONTRACT_ADDRESS \
src/account/LighterAccount.sol:LighterAccount \
--constructor-args $(cast abi-encode "constructor(address,address,address,uint256)" $TICKET_CONTRACT $REGISTRY $ACCOUNT_IMPL 0)For detailed deployment instructions, see DEPLOYMENT_README.md.
β οΈ Before Production: Conduct a comprehensive security auditβ οΈ Private Key Management: Never commit private keys to the repositoryβ οΈ Access Control: Review all authorization mechanisms carefullyβ οΈ Test Coverage: Ensure all critical paths have test coverageβ οΈ Reentrancy: Escrow contract usesReentrancyGuardfor protection
- Verifier Branch:
VerifierAbstractand ZK verification are in active development - Signature Replay: Consider adding nonce mechanism for additional protection
- CalldataDecoder: Uses optimized decoding without bounds checking (documented trade-off for gas efficiency)
- Use multi-sig wallets for contract ownership
- Implement time-locked upgrades for critical contracts
- Monitor contract events for suspicious activity
- Regular security audits and code reviews
- Code Review Report - Comprehensive code review
- Security Analysis - Security considerations
- Inheritance Structure - Contract inheritance details
- Local Test Guide - Local testing instructions
- Test Run Guide - Testing guidelines
- ISettlerActions: Action selectors for all supported operations
- ISettlerBase: Core data structures and enums
- IEscrow: Escrow contract interface and events
- Permit2 Documentation
- ERC6551 Standard
- EIP-712 Standard
- EIP-1153 TransientStorage - Transient storage for reentrancy protection
- Foundry Documentation
- Foundry Linting Guide - Code quality and gas optimization
We welcome contributions! Please see our contributing guidelines:
- π Report Bugs: Open an issue with detailed information
- π‘ Suggest Features: Propose new features or improvements
- π Improve Documentation: Help improve our documentation
- π§ Submit Code: Submit pull requests with fixes or features
- β Add Tests: Increase test coverage
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
forge test) - Format code (
forge fmt) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License.
- 0x Project - Referenced 0x-settler architecture design
- Uniswap Permit2 - Token authorization mechanism
- OpenZeppelin - Security contract library
- Foundry - Development framework
- ERC6551 - Token Bound Account reference implementation
- Issues: GitHub Issues
- Discussions: GitHub Discussions