-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ERC: Minimal Batch Executor Interface #726
Open
Vectorized
wants to merge
29
commits into
ethereum:master
Choose a base branch
from
Vectorized:minimal-batch-executor-erc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+278
−0
Open
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
3658226
Add ERC
Vectorized 5f7f65b
Edit
Vectorized e9ccf92
Edit
Vectorized 1c4d117
Edit
Vectorized 5eef39b
Fix code
Vectorized 4f72d55
Normify code example
Vectorized 35943d6
Rename to opData
Vectorized dd14d7d
Tidy
Vectorized da0b5cc
Edit to use 7579 style
Vectorized 54e2dbe
Nit
Vectorized 1aff3f6
Normify
Vectorized 5423d22
Edit
Vectorized 8b9f9d2
Fix grammar
Vectorized 43c4269
Update and rename erc-9999.md to erc-7821.md
xinbenlv 05bc842
Edit
Vectorized d82eac8
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized 580b8a7
Update mode magic number
Vectorized 2650252
Merge branch 'master' into minimal-batch-executor-erc
Vectorized f9fa123
Revert back to initial proposal
Vectorized c682383
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized c94285a
Edit
Vectorized aede948
Edit
Vectorized ad51da0
Typo
Vectorized 64d91a3
Update code
Vectorized 4e47631
Smooth out grammar
Vectorized d2258cf
Update ERCS/erc-7821.md
Vectorized 27c86b3
Update with address(0) replacement
Vectorized bd2de27
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized ba2d6c9
Switch back to ERC7579 style
Vectorized File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
--- | ||
eip: 9999 | ||
title: Minimal Batch Executor Interface | ||
description: A minimal batch executor interface for delegations | ||
author: Vectorized (@Vectorized), Jake Moxey (@jxom) | ||
discussions-to: https://ethereum-magicians.org/t/minimal-batch-executor-interface-for-delegations/21776 | ||
status: Draft | ||
type: Standards Track | ||
category: ERC | ||
created: 2024-11-21 | ||
requires: 7702 | ||
--- | ||
|
||
## Abstract | ||
|
||
This proposal defines a minimal batch executor interface for delegations. A delegation is a smart contract that implements logic which other smart contracts can delegate to. This allows batched executions to be prepared in a standardized way. | ||
|
||
## Motivation | ||
|
||
With the advent of [EIP-7702](./eip-7702), it is possible for Externally Owned Account (EOA) to perform atomic batched executions. | ||
|
||
We anticipate that there will be multiple EIP-7702 delegations from multiple major vendors. To enable frontends to be able to detect and prepare a batched transaction that works across multiple vendors, we will need a standardized interface for batched executions. | ||
|
||
In the absence of such a standard, the vendors may choose to create their own proprietary implementations, causing ecosystem fragmentation. Imagine visiting your favorite decentralized exchange and realizing that your EOA delegation is not compatible with their frontend. Which ecosystem fragmentation, the infamous approve and swap workflow will not be fixed. | ||
|
||
Thus the motivation for this standard, which proposes a minimal batch execution interface that is easily implementable, extensible, and performant. | ||
|
||
## Specification | ||
|
||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 and RFC 8174. | ||
|
||
### Overview | ||
|
||
The minimal batch executor interface is defined as follows: | ||
|
||
```solidity | ||
/// @dev Interface for minimal batch executor. | ||
interface IMinimalBatchExecutor { | ||
/// @dev Call struct for the `execute` function. | ||
struct Call { | ||
// | ||
address target; | ||
uint256 value; | ||
bytes data; | ||
} | ||
|
||
/// @dev Executes the `calls` and returns the results. | ||
/// The `results` are the returned data from each call. | ||
/// Reverts and bubbles up error if any call fails. | ||
/// | ||
/// If `authData` is empty, the implementation SHOULD require that | ||
/// `msg.sender == address(this)`. | ||
/// | ||
/// If `authData` is not empty, the implementation SHOULD use the signature | ||
/// encoded in `authData` to determine if the caller can perform the execution. | ||
/// | ||
/// `authData` may be used to store additional data for authentication. | ||
function execute(Call[] calldata calls, bytes calldata authData) | ||
external | ||
payable | ||
returns (bytes[] memory results); | ||
|
||
/// @dev This function is provided for frontends to detect support. | ||
/// Currently, it returns 1. | ||
function minimalBatchExecutorVersion() external pure returns (uint256); | ||
} | ||
``` | ||
|
||
## Rationale | ||
|
||
### `minimalBatchExecutorVersion` for detection | ||
|
||
[ERC-165](./eip-165.md) is a very difficult standard to work with in due to inheritance issues (e.g. diamond inheritance). | ||
|
||
Additionally, we opt not to make the behavior of `execute` to return a magic number for a magic input for ease of implementation. | ||
|
||
### Only a single `execute` function | ||
|
||
There is no need to define a variant for the single call case. | ||
|
||
Having only a single `execute` function greatly simplifies implementation and integration. | ||
|
||
It also reduces bytecode size and lessens the Solidity function dispatch load. | ||
|
||
### Use of `Call` struct instead of custom byte encoding decoding | ||
|
||
Most layer 2s already include calldata compression and forward the calldata savings to users. | ||
|
||
As such, we opt for simplicity to enable maximum compatibility and ease of implementation. | ||
|
||
Using a standard struct also helps with auditability, block explorer integrations, browser wallet integrations, and [EIP-712](./eip-712) signature generations. | ||
|
||
### Usage of a single `authData` bytes argument | ||
|
||
The single `authData` bytes argument also provides all the flexibility that is needed. | ||
|
||
## Backwards Compatibility | ||
|
||
No backwards compatibility issues. | ||
|
||
## Reference Implementation | ||
|
||
```solidity | ||
// SPDX-License-Identifier: CC0-1.0 | ||
pragma solidity ^0.8.4; | ||
|
||
/// @notice Minimal batch executor mixin. | ||
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/accounts/MinimalBatchExecutor.sol) | ||
abstract contract MinimalBatchExecutor { | ||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* STRUCTS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @dev Call struct for the `execute` function. | ||
struct Call { | ||
address target; | ||
uint256 value; | ||
bytes data; | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* FUNCTIONS TO OVERRIDE */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @dev Ensures that `execute` can only be called by the correct caller or `authData`. | ||
function _authorizeExecute(Call[] calldata calls, bytes calldata authData) internal virtual; | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* EXECUTE */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @dev Executes the `calls` and returns the results. | ||
/// Reverts and bubbles up error if any call fails. | ||
function execute(Call[] calldata calls, bytes calldata authData) | ||
public | ||
payable | ||
virtual | ||
returns (bytes[] memory results) | ||
{ | ||
_authorizeExecute(calls, authData); | ||
return _execute(calls); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* SIGNALING */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @dev This function is provided for frontends to detect support. | ||
function minimalBatchExecutorVersion() public pure virtual returns (uint256) { | ||
return 1; // This number may change. | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* INTERNAL HELPERS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @dev Executes the `calls` and returns the results. | ||
/// Reverts and bubbles up error if any call fails. | ||
function _execute(Call[] calldata calls) internal virtual returns (bytes[] memory results) { | ||
results = new bytes[](calls.length); | ||
for (uint256 i; i < calls.length; ++i) { | ||
Call calldata c = calls[i]; | ||
results[i] = _execute(c.target, c.value, c.data); | ||
} | ||
} | ||
|
||
/// @dev Executes the `calls` and returns the result. | ||
/// Reverts and bubbles up error if any call fails. | ||
function _execute(address target, uint256 value, bytes calldata data) | ||
internal | ||
virtual | ||
returns (bytes memory result) | ||
{ | ||
bool success; | ||
(success, result) = target.call{value: value}(data); | ||
if (!success) { | ||
/// @solidity memory-safe-assembly | ||
assembly { | ||
// Bubble up the revert if the call reverts. | ||
revert(add(result, 0x20), mload(result)) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Security Considerations | ||
|
||
### Access controls for `execute` | ||
|
||
Implementations should ensure that `execute` have the proper access controls. | ||
|
||
## Copyright | ||
|
||
Copyright and related rights waived via [CC0](../LICENSE.md). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider using ERC7579 execute function here.
would be a shame if wallets need to integrate another pattern.
the
authData
could be just appended bytes incalldata
to perform the signature check, and ERC-4337 based implementations of this ERC could utilize the same function signature with access controlonlyEntryPoint
while handling the signature validation invalidateUserOp
this would also allow for implementations to utilize try-batched executions or delegatecalls as this is covered by the 7579 execution modes
I admit, appending the
authData
to the calldata is not the prettiest, but would yield great compatibilityminimalBatchExecutorVersion
could also be ERC-7579'ssupportsExecutionMode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This standard will only support regular calls, in an atomic fashion. Delegatecalls won't be supported.
If users want to make multiple try transactions, they can just sign multiple transactions with parallel nonces.
I think it will not be too hard for frontends that have already supported 7579 to support this ERC. They will still need to craft the array of executions.
Side question: Do we actually need ERC-165 for ERC-7579? I would strongly prefer to never use ERC-165.