Skip to content
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
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from 6 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3658226
Add ERC
Vectorized Nov 21, 2024
5f7f65b
Edit
Vectorized Nov 21, 2024
e9ccf92
Edit
Vectorized Nov 21, 2024
1c4d117
Edit
Vectorized Nov 21, 2024
5eef39b
Fix code
Vectorized Nov 21, 2024
4f72d55
Normify code example
Vectorized Nov 21, 2024
35943d6
Rename to opData
Vectorized Nov 21, 2024
dd14d7d
Tidy
Vectorized Nov 21, 2024
da0b5cc
Edit to use 7579 style
Vectorized Nov 21, 2024
54e2dbe
Nit
Vectorized Nov 21, 2024
1aff3f6
Normify
Vectorized Nov 21, 2024
5423d22
Edit
Vectorized Nov 21, 2024
8b9f9d2
Fix grammar
Vectorized Nov 21, 2024
43c4269
Update and rename erc-9999.md to erc-7821.md
xinbenlv Nov 21, 2024
05bc842
Edit
Vectorized Nov 21, 2024
d82eac8
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized Nov 21, 2024
580b8a7
Update mode magic number
Vectorized Nov 21, 2024
2650252
Merge branch 'master' into minimal-batch-executor-erc
Vectorized Nov 21, 2024
f9fa123
Revert back to initial proposal
Vectorized Nov 21, 2024
c682383
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized Nov 21, 2024
c94285a
Edit
Vectorized Nov 21, 2024
aede948
Edit
Vectorized Nov 21, 2024
ad51da0
Typo
Vectorized Nov 21, 2024
64d91a3
Update code
Vectorized Nov 21, 2024
4e47631
Smooth out grammar
Vectorized Nov 21, 2024
d2258cf
Update ERCS/erc-7821.md
Vectorized Nov 22, 2024
27c86b3
Update with address(0) replacement
Vectorized Nov 22, 2024
bd2de27
Merge branch 'minimal-batch-executor-erc' of https://github.com/Vecto…
Vectorized Nov 22, 2024
ba2d6c9
Switch back to ERC7579 style
Vectorized Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 195 additions & 0 deletions ERCS/erc-9999.md
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)
Copy link
Contributor

@zeroknots zeroknots Nov 21, 2024

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.

function execute(bytes32 mode, bytes calldata executionCalldata) external;

would be a shame if wallets need to integrate another pattern.

the authData could be just appended bytes in calldata to perform the signature check, and ERC-4337 based implementations of this ERC could utilize the same function signature with access control onlyEntryPoint while handling the signature validation in validateUserOp

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 compatibility

minimalBatchExecutorVersion could also be ERC-7579's supportsExecutionMode

Copy link
Contributor Author

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.

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).
Loading