ERC-4337 smart account contracts secured by MPC threshold signatures for AI agent wallets.
┌─────────────────────────────────────────────────────────────────────────────┐
│ MPC SMART ACCOUNT SYSTEM │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
│ │ AI Agent │ │ User │ │ Recovery │ │
│ │ (Share 1) │ │ (Share 2) │ │ Guardian │ │
│ │ │ │ │ │ (Share 3) │ │
│ └────────┬─────────┘ └────────┬─────────┘ └────────┬─────────┘ │
│ │ │ │ │
│ └───────────────┬────────┴────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────┐ │
│ │ MPC Threshold Signing │ │
│ │ (2 of 3) │ │
│ └──────────────┬───────────────┘ │
│ │ │
│ ▼ │
│ ┌───────────────────────────────────────────────────────────────────────┐ │
│ │ MpcSmartAccount │ │
│ │ • ERC-4337 compliant │ │
│ │ • MPC signature validation │ │
│ │ • Built-in spending limits │ │
│ │ • Address whitelisting │ │
│ │ • Time restrictions │ │
│ │ • UUPS upgradeable │ │
│ └───────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────┐ ┌────────────────────────────┐ │
│ │ MpcRecoveryModule │ │ MpcSpendingLimitHook │ │
│ │ • Guardian management │ │ • Per-tx limits │ │
│ │ • Time-delayed recovery │ │ • Daily/weekly limits │ │
│ │ • Key rotation support │ │ • Token-specific limits │ │
│ └────────────────────────────┘ │ • Whitelist enforcement │ │
│ └────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
| Contract | Description |
|---|---|
MpcSmartAccount |
ERC-4337 smart account with MPC signature validation and policy enforcement |
MpcSmartAccountFactory |
Factory for deploying MPC smart account proxies with CREATE2 |
MpcRecoveryModule |
Handles MPC key recovery with time-delayed execution |
MpcSpendingLimitHook |
Spending limit enforcement hook for transaction policies |
- Validates aggregated ECDSA signatures from 2-of-3 threshold signing
- Compatible with DKLs23 MPC protocol
- EIP-1271 signature validation for smart contract wallets
- Daily Spending Limits: Cap total ETH spent per day
- Transaction Limits: Maximum ETH per transaction
- Address Whitelist: Restrict interactions to approved addresses
- Time Restrictions: Allow transactions only during certain hours
- Guardian-initiated key recovery
- Configurable time delay (default 2 days)
- Cancel pending recovery during delay period
- Support for key share rotation
forge installforge build# Run all tests
forge test
# Run with verbosity
forge test -vvv
# Run specific test file
forge test --match-path test/unit/MpcSmartAccount.t.solforge test --gas-report# Start anvil
anvil
# Deploy
forge script script/Deploy.s.sol:DeployScript --rpc-url http://localhost:8545 --broadcastforge script script/Deploy.s.sol:DeployScript \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify// 1. Generate MPC public key off-chain via DKG
bytes memory mpcPublicKey = // ... 33-byte compressed public key
// 2. Get counterfactual address
address predictedAddress = factory.getAddress(
mpcPublicKey,
recoveryModule,
10 ether, // daily limit
0 // salt
);
// 3. Fund the predicted address
payable(predictedAddress).transfer(1 ether);
// 4. Create account (can be done via UserOperation initCode)
MpcSmartAccount account = factory.createAccount(
mpcPublicKey,
recoveryModule,
10 ether,
0
);Transactions are executed through ERC-4337 UserOperations:
// Build UserOperation
const userOp = {
sender: accountAddress,
nonce: await entryPoint.getNonce(accountAddress, 0),
initCode: "0x", // Empty if account exists
callData: account.interface.encodeFunctionData("execute", [
targetAddress,
ethValue,
calldata
]),
// ... gas parameters
signature: "0x" // Will be filled by MPC signing
};
// Sign with MPC
const signature = await mpcSign(userOpHash, [aiAgentShare, userShare]);
userOp.signature = signature;
// Submit to bundler
await bundler.sendUserOperation(userOp);// 1. Guardian initiates recovery
recoveryModule.initiateRecovery(accountAddress, newMpcPublicKey);
// 2. Wait for delay (2 days by default)
// 3. Execute recovery (anyone can call)
recoveryModule.executeRecovery(accountAddress);
// Alternative: Cancel if malicious
account.cancelRecovery(accountAddress); // Only account or guardians- Key Share Distribution: Store key shares on separate devices
- Guardian Selection: Pick diverse and trusted guardians
- Time Delay: Gives time to detect malicious recovery attempts
- Spending Limits: Limits damage from compromised AI agents
- Whitelist: Only allow known-good contracts
MIT