ERC-7821 Minimal batch execution interface (Minimal Batch Executor Interface)
Draft · Accounts & wallets · created 2024-11-21
Defines a common execute/supportsExecutionMode function shape across vendors so that an EOA delegated via EIP-7702 can atomically execute multiple calls in a single transaction.
Why it is needed
With the introduction of EIP-7702, personally owned accounts (EOAs) can now receive the logic of a delegation contract and behave like smart contracts. However, if the name and encoding of the function for batching multiple calls differs between delegation vendors, wallets and frontends have to handle each vendor separately. Also, setting up a delegation is itself a transaction that costs gas and carries risk, so changing delegation every time a user moves between websites is impractical. Without a standardized batch execution interface, sequential actions such as approve followed by swap must be sent as two separate transactions, increasing latency and cost.
What to implement
function execute(bytes32 mode, bytes calldata executionData) external payable;: Executes the calls contained in executionData, and if any call fails, reverts and bubbles up that error.function supportsExecutionMode(bytes32 mode) external view returns (bool);: Checks whether this contract supports a given execution mode.
In depth
The execute function and executionData encoding
execute(bytes32 mode, bytes calldata executionData) encodes executionData in two ways for single batch execution. If there is no opData, it is encoded as abi.encode(calls); if opData is present, it is encoded as abi.encode(calls, opData). calls is an array of Call structs (to, value, data), and if to is address(0), it MAY be replaced with address(this) at call time. If any call fails, execute reverts and bubbles up that error.
Three execution modes
mode is a 32-byte value with three defined variants. 0x01000000000000000000... is a single batch that does not support opData, 0x01000000000078210001... is a single batch that supports opData, and 0x01000000000078210002... is batch of batches. supportsExecutionMode(bytes32 mode) must return true only for these three modes, and since support for batch of batches is OPTIONAL, implementations that do not support it MUST return false for modes starting with 0x...78210002.
Batch of batches
In batch of batches mode, executionData is encoded as abi.encode(bytes[]), where each element of the array is the executionData for a single batch. Internally, the implementation recursively passes each element to execute with mode 0x01000000000078210001.... This mode exists to let multiple batches signed by different signers be submitted together in a single transaction without an authorized entrypoint; since an entrypoint can achieve the same effect functionally, it is left optional.
Authorization check method
If opData is empty, the implementation SHOULD require msg.sender == address(this), meaning execution only happens when the account calls itself. If opData is not empty, the implementation SHOULD use the signature encoded within it to determine the caller's execution authority. If msg.sender is an authorized entrypoint, calls from the entrypoint MAY be allowed and opData MAY be used for special logic. Beyond authentication, opData can also be used to carry additional information such as paymaster data or gas limits.
Replacing address(0) with address(this)
If Call.to is address(0), it may be replaced with address(this) at execution time. This is a device for optimizing calldata compression, avoiding the need to repeat the full 20-byte address when specifying the contract itself as the call target.
Relationship to ERC-7579
To improve compatibility with the existing smart account ecosystem, this standard adopts the same execute and supportsExecutionMode function names and execution mode encoding as ERC-7579. However, for minimalism, it does not require implementing ERC-7579's executeFromExecutor function.
A proposal that has not yet been finalized
This ERC is currently in Draft status, and its details may change or discussion may stall going forward.
Things to watch out for
- Access control for the execute function: Implementations must have appropriate access control on the execute function. When opData is empty, access should be restricted to msg.sender == address(this) so only the account itself can call it; when opData is present, the caller's authority must be verified using the signature contained within it.