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 25 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
204 changes: 204 additions & 0 deletions ERCS/erc-7821.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
---
eip: 7821
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
Vectorized marked this conversation as resolved.
Show resolved Hide resolved
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 Accounts (EOAs) to perform atomic batched executions.

We anticipate that there will be multiple EIP-7702 delegations from multiple major vendors. To enable frontends to detect and prepare a vendor-agnostic batched transaction, we will need a standardized interface for batched executions.

In the absence of such a standard, vendors may choose to create their own proprietary implementations, causing fragmentation. Imagine visiting your favorite decentralized exchange and realizing that their frontend is still incompatible with your EOA delegation. The infamous approve and swap workflow cannot be fixed just by EIP-7702 alone.

We need a standardized batch executor interface.

Hence the utmost motivation for this proposal, which has been crafted for maximal simplicity, extensibility, performance and compatibility.

## 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 `opData` is empty, the implementation SHOULD require that
/// `msg.sender == address(this)`.
///
/// If `opData` is not empty, the implementation SHOULD use the signature
/// encoded in `opData` to determine if the caller can perform the execution.
///
/// `opData` may be used to store additional data for authentication,
/// paymaster data, gas limits, etc.
function execute(Call[] calldata calls, bytes calldata opData)
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

### New execution interface

We understand that there are already existing batch execution interfaces in the ecosystem, namely [ERC-6900](./eip-6900.md) and [ERC-7579](./eip-7579.md).

These interfaces are very flexible and powerful, but they are way too overkill. Our north star is to enable all decentralized exchanges to implement approve and swap in one transaction.

ERC-6900 has two execution functions.

ERC-7579 requires heavy use of low-level inline-assembly to ensure safe decoding of the `executionCalldata`, as well as proper handling of `mode`.

Even though we are proposing a new interface, we believe that our proposal is so left-curved that it can be implemented and integrated by beginner developers.

Additionally, the execution functions do not share the same selectors as any functions in ERC-6900 and ERC-7579, allowing this standard to be easily added alongside ERC-6900 and ERC-7579.

### `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 `opData` bytes argument

The single `opData` 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.
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 `opData`.
function _authorizeExecute(Call[] calldata calls, bytes calldata opData) internal virtual;

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* EXECUTION OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

/// @dev Executes the `calls` and returns the results.
/// Reverts and bubbles up error if any call fails.
function execute(Call[] calldata calls, bytes calldata opData)
public
payable
virtual
returns (bytes[] memory results)
{
_authorizeExecute(calls, opData);
return _execute(calls);
}

/// @dev This function is provided for frontends to detect support.
function minimalBatchExecutorVersion() public pure virtual returns (uint256) {
return 1; // This number may change in the future.
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* 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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: consider adding a special address (e.g., address(0)) where the contract would execute the transaction to self. This is a neat optimization when you must batch multiple calls on the account contract itself.

This is implemented in Safe's MultiSend contract: https://github.com/safe-global/safe-smart-account/blob/7f79aaf05c33df71d9cb687f0bc8a73fa39d25d5/contracts/libraries/MultiSend.sol#L50C17-L50C57

}
}

/// @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)
{
(bool success, bytes memory result) = target.call{value: value}(data);
if (success) return result;
/// @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