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 EIP-5750: Method with Extra Data #5750

Merged
merged 12 commits into from
Oct 15, 2022
88 changes: 88 additions & 0 deletions EIPS/eip-5750.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
eip: 5750
title: Extra Data Parameter in Methods
description: This EIP that defines an extra data parameter in methods.
xinbenlv marked this conversation as resolved.
Show resolved Hide resolved
author: Zainan Victor Zhou (@xinbenlv)
discussions-to: https://ethereum-magicians.org/t/erc-5750-method-with-extra-data/11176
status: Review
type: Standards Track
category: ERC
created: 2022-10-04
---

## Abstract

This EIP that defines an extra data parameter in methods, denoted as `methodName(... bytes calldata _data)`. Compliant method of compliant contract
can use the extra data in structural way to introduce extended behaviors.

## Motivation

The general purpose of having a standard for extra data in a method is to allow further extensions for a existing method interface. For example, the `safeTransferFrom` already

1. At the very least, Methods complying with this EIP, such as `transfer` and `vote` can add reasons in extra data, just like how GovernorBravo's improvement over GovernorAlpha
2. In addition, existing EIPs that has exported methods compliant with this EIP can be extended for behaviors such as using the extra data for endorsements or salt, nonce, commitments for reveal commit.
3. Allowing one method to carry arbitrary calldata for forwarding a function call to another method.

## Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

1. Any compliant contract's compliant method MUST have a `bytes`(dynamic size) as its `LAST` parameter of the method.

```solidity
function methodName(type1 param1, type2, param2 ... bytes calldata data);
```

## Rationale

1. Having a dynamic sized bytes allow for maximum flexibility for arbitrary additional payload
2. Having the bytes specified in the last naturally compatible with the calldata layout of solidity.

## Backwards Compatibility

Many of the existing EIPs already have compliant method and all compliant contracts of such EIPs are already compliant.

Here are an incomplete list

1. In the [EIP-721](./eip-721.md) the following methods are already compliant:

- `function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;` is already compliant

2. In the [EIP-1155](./eip-1155.md) the following methods are already compliant

- `function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes calldata _data) external;`
- `function safeBatchTransferFrom(address _from, address _to, uint256[] calldata _ids, uint256[] calldata _values, bytes calldata _data) external;`

3. In the [EIP-777](./eip-777.md) the following methods are already compliant

- `function burn(uint256 amount, bytes calldata data) external;`
- `function send(address to, uint256 amount, bytes calldata data) external;`

4. In the [EIP-2535](./eip-2535.md) the following methods are already compliant

```solidity
function diamondCut(
FacetCut[] calldata _diamondCut,
address _init,
bytes calldata _calldata
) external;
```

5. In the [EIP-1271](./eip-1271.md) the following methods are already compliant:

```solidity
function isValidSignature(
bytes32 _hash,
bytes memory _signature)
public
view
returns (bytes4 magicValue);
```

## Security Considerations

1. If using the extra data for extended behavior, such as supplying signature for onchain verification, or supplying commitments in a commit-reveal scheme, the security best practice shall be followed for that particular extended behaviors.
2. Compliant contract shall also take into consideration the information of extra data will be shared in public and circulate around mempool, so specific caution shall be paid for replay-attack, front-run/back-run/sandwich attacks.

## Copyright
Copyright and related rights waived via [CC0](../LICENSE.md).