ERC-7582 · Draft · ERC · 2023-12-25
ERC-7582: Modular Accounts with Delegated Validation
A draft, minimal way to add plugins to ERC-4337 smart accounts: the high 192-bit key of a UserOperation's nonce names a validator contract, and the account hands validation of that operation to it.
What problem does it solve?
Smart contract accounts can in principle do social recovery, spending limits, session keys, scheduled payments and more. In practice each feature needs custom validation logic, and adding it usually means upgrading or migrating the account. Larger modular-account standards exist, but they add many new functions and conventions.
ERC-7582 ("Modular Accounts with Delegated Validation", MADV) takes the opposite approach. It adds no new functions at all. It shows how an account that already implements the ERC-4337 IAccount interface can delegate validation to plugin contracts, using only fields ERC-4337 already has.
How it works
ERC-4337's EntryPoint tracks nonces as a 192-bit key plus a 64-bit sequence. Each key has its own counter, so operations with different keys do not block each other. MADV reuses that key as a pointer:
- The user builds a UserOperation whose
noncehas a non-zero key (so the nonce is greater thantype(uint64).max). - In
validateUserOp, the account extracts a validator identifier from the key. It may be the validator's address directly or a pointer to an address in storage; the account decides. - The account forwards the UserOperation (ideally all of it) to that validator.
- The validator returns standard ERC-4337
validationData, which the account returns to the EntryPoint unchanged. - A nonce with key 0 falls back to the account's normal signature check.
Why the nonce and not the signature field? It costs no extra calldata, getNonce(sender, key) already gives each plugin its own replay counter, and UserOperationEvent logs the nonce, so plugin use can be tracked from existing events.
Sample code
A simplified MADV account (the reference implementation also checks the owner's signature first):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;
import {IAccount} from "account-abstraction/interfaces/IAccount.sol";
import {PackedUserOperation} from "account-abstraction/interfaces/PackedUserOperation.sol";
contract MADVAccount is IAccount {
address public immutable entryPoint;
constructor(address ep) { entryPoint = ep; }
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash,
uint256 missingAccountFunds
) external returns (uint256 validationData) {
require(msg.sender == entryPoint, "not EntryPoint");
if (userOp.nonce > type(uint64).max) {
uint192 key = uint192(userOp.nonce >> 64);
address validator = address(uint160(key)); // key encodes the plugin
// (a real account should check `validator` is installed/allowed)
validationData = IAccount(validator).validateUserOp(userOp, userOpHash, missingAccountFunds);
} else {
validationData = _validateOwnerSignature(userOp, userOpHash);
}
if (missingAccountFunds > 0) {
(bool ok, ) = payable(msg.sender).call{value: missingAccountFunds}("");
(ok);
}
}
function _validateOwnerSignature(PackedUserOperation calldata, bytes32)
internal view virtual returns (uint256) { /* ECDSA check */ return 0; }
}
Off-chain, the next nonce for a plugin is entryPoint.getNonce(account, BigInt(validatorAddress)).
Things to know
- Status: Draft.
- The spec leaves both the identifier-to-validator mapping and any allow-list to the account developer. An account that blindly trusts any address in the key lets anyone choose the validator for its operations, so restrict which validators may be used.
- Validators run inside ERC-4337's validation phase and must follow its rules (storage access and opcode restrictions) or bundlers will drop the operation.
- For richer module systems with installation, hooks and execution modules, see ERC-7579 and ERC-6900.