A modular and secure implementation of EIP-7702 smart contract wallet with multiple execution types and advanced security features.
-
Make sure you have Node.js installed
-
Run
npm install
in the project root to install dependencies -
Install Foundry (which provides the
forge
command) by running:curl -L https://foundry.paradigm.xyz | bash
This implementation provides a flexible smart contract wallet that supports:
- EIP-7702 Type 4 initialization
- Three distinct execution types
- Advanced security features including replay protection and batched transactions
- Modular architecture with separate storage and execution logic
The wallet setup involves two main steps:
-
Set Code:
- Submits an EIP-7702 Type 4 transaction
- Assigns smart contract code to an EOA (Externally Owned Address)
- Transforms the EOA into a smart contract wallet
-
Initialize Contract:
- Calls the
initialize
function in Wallet Core - Sets up proper configuration and state
- Creates and links Core Storage for nonce management
- Calls the
- Direct execution from the wallet itself
- Uses
executeFromSelf
function - Verifies transaction through self-check
- Supports batched transactions via
_batchCall
- Most gas-efficient execution type
- Validator Setup:
- User adds validator to wallet core
- Validator signs transaction off-chain with nonce
- Execution Flow:
- User provides off-chain signature
- Relayer submits transaction via
executeWithValidation
- Core Storage manages nonce for replay protection
- ECDSA validation ensures signature authenticity
-
Session-Based Execution:
- No pre-encoded calls needed
- Uses hook-based validation (
preHook
andpostHook
) - Single signature authorizes entire session
-
Session Parameters:
session_id
validAfter
validUntil
executor
validator
preCheck
postCheck
signature
The implementation follows a modular design:
WalletCore
: Main contract handling execution logicCore Storage
: Manages nonces and validation statesExecutionLogic
: Handles different execution typesValidationLogic
: Manages signature and session validationExecutorLogic
: Implements session-based execution with hooksFallbackHandler
: Provides token receiving capabilities
Contract | Address |
---|---|
WalletCore | 0x80296FF8D1ED46f8e3C7992664D13B833504c2Bb |
CoreStorage | 0x7DAF91DFe55FcAb363416A6E3bceb3Da34ff1d30 |
Contract | Address |
---|---|
WalletCore | 0x80296FF8D1ED46f8e3C7992664D13B833504c2Bb |
CoreStorage | 0x7DAF91DFe55FcAb363416A6E3bceb3Da34ff1d30 |
Deploy and initialize your ERC-7702 wallet:
npx hardhat run scripts/smoke_test/1-setCodeAndInitialize.ts --network <NETWORK>
This script:
- Sets up the EOA as a smart contract wallet
- Initializes core storage and configuration
Send transactions directly from the wallet:
forge script scripts/smoke_test/2-sendTxs.sol --rpc-url <RPC_URL> --broadcast
This demonstrates:
- Self-executed transactions
- Batch call functionality
- Direct interaction with external contracts
Send transactions through a relayer:
forge script scripts/smoke_test/3-sendTxsAsRelayer.sol --rpc-url <RPC_URL> --broadcast
This shows:
- Relayer-based transaction execution
- Signature validation
- Nonce management
- Gas-efficient transaction batching
- All execution types include proper validation
- Nonce management prevents replay attacks
- Session-based execution can be revoked
- Hook-based validation provides additional security layers