Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-5750 proposes a convention for adding a dynamically sized bytes argument to a method so that its behavior can be extended.

This article translates, summarizes, and explains the original proposal.

Other ERC proposals are covered here.

Overview

ERC-5750 standardizes the use of unstructured data as a function argument, with future extensibility in mind.

The goal is to establish a common convention for passing additional data to contract functions, making future extensions easier to implement.

An existing example is the trailing data argument of the ERC-721 safeTransferFrom function, as implemented in OpenZeppelin Contracts.

contracts/token/ERC721/ERC721.sol#L167
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
OpenZeppelin/openzeppelin-contractsの元のファイルを開く

Motivation

Passing additional data to methods allows their existing interfaces to accommodate future behavior.

For example, methods such as transfer and vote can use additional data to carry a human-readable reason. Methods exposed by standards following this convention can also use the data to support endorsement proofs, salts, nonces, and commitments in commit-reveal schemes. The data may also be forwarded to callbacks.

There are two main ways to extend an existing function, each raising design questions.

Adding a new method

  • What should the method be named?
  • Which parameters should it accept?
  • Which use cases should its signature support?
  • Should it support offchain signatures?

Reusing existing parameters or adding new ones

  • Should the existing parameters be reused, or should new ones be added?
  • How many parameters are needed?
  • What types and sizes should the parameters have?

Standardizing method extensibility gives developers concrete guidelines for answering these questions.

The proposal aims to maximize backward and forward compatibility. Several existing standards, including ERC-721 and ERC-1155, already use this convention in some methods. Other implementations and EIPs can adopt the same approach when defining interfaces that may need to accommodate new behavior.

For background on ERC-721, see:

https://chaldene.net/erc721

For background on ERC-1155, see:

https://chaldene.net/erc1155

Commit-reveal commitments

A commit-reveal scheme is a cryptographic technique that allows a participant to commit to a value before revealing it. It is used in cryptographic protocols and security-sensitive applications.

Example scenario

Consider Alice, who wants to commit to a message without disclosing it to Bob immediately.

Commit-reveal procedure

  1. Create a commitment

    • Alice keeps the message private while generating a commitment.
    • A common approach is to calculate a hash of the message together with a randomly generated secret salt.
    • For example, Alice might commit to the message Hello, Bob!. The original article illustrates a hash with the value 2ef7bde608ce5404e97d5f042f95f89f1c232871. That value has 40 hexadecimal characters and is not a complete SHA-256 digest; it should not be used as a SHA-256 test vector.
  2. Send the commitment

    • Alice sends the commitment to Bob.
    • She has not yet disclosed the message or salt.
  3. Reveal

    • After Bob receives the commitment, Alice reveals the message Hello, Bob! and the salt when the protocol calls for disclosure.
  4. Verify the commitment

    • Bob recomputes the commitment using the revealed inputs and the same encoding and hash function.
    • He compares the result against the commitment Alice initially supplied.
  5. Receive the message

    • Bob can read the revealed message and verify that it matches the earlier commitment.

Benefits

  • Alice can commit to a message without revealing it immediately.
  • Bob can verify the revealed message against the earlier commitment.
  • With a suitable construction and sufficient randomness, the scheme can conceal the committed value until the reveal phase and prevent undetected changes to that value.

A commitment is not encryption: the revealed message does not need to be decrypted, and hashing a predictable message without a sufficiently random secret may not hide it. Commit-reveal schemes are widely used in cryptographic and blockchain protocols.

Specification

In this proposal, bytes refers to Solidity's dynamically sized byte-array type. Unlike many ERC standards, ERC-5750 defines conformance at the level of individual contract methods rather than entire contracts.

A method with a final parameter of type bytes is a candidate for conformance. Its signature follows this general form.

javascript
function メソッド名(型1 値1, 型2 値2, ... bytes データ)

The original schematic above uses Japanese placeholders for the method name, parameter types, values, and data.

A compliant method must satisfy the eligibility criteria and designate its final bytes field for extending the method's behavior.

If a method has an overloaded sibling with the same name and preceding parameters but without the final bytes argument, the extended method must behave identically to that sibling when the bytes argument is empty.

The convention standardizes both the placement and semantics of the extension parameter, rather than treating every trailing byte array as an extension automatically.

Compliant and noncompliant examples

The following example defines a compliant methodName1 in a contract named Foo.

javascript
contract Foo {
  // @dev This method allows extension behavior via `_data` field;
  function methodName1(uint256 _param1, address _param2, bytes calldata _data);
  function firstNonRelatedMethod(uint256 someValue);
  function secondNonRelatedMethod(uint256 someValue);
}

The next example defines a compliant overload of methodName2. Although the original prose calls this contract Bar, the preserved code names it Foo.

javascript
contract Foo {
  // @dev This is a sibling method to `methodName2(uint256 _param1, address _param2, bytes calldata _data);`
  function methodName2(uint256 _param1, address _param2);

  // @dev This method allows extension behavior via `_data` field;
  //      When passed in an empty array for `_data` field, this method
  //      MUST behave IDENTICAL to
  //      its overloaded sibling `methodName2(uint256 _param1, address _param2);`
  function methodName2(uint256 _param1, address _param2, bytes calldata _data);

  function firstNonRelatedMethod(uint256 someValue);
  function secondNonRelatedMethod(uint256 someValue);
}

The following methodName1 is not compliant because its final argument does not allow the method's behavior to be extended.

javascript
contract Foo {
  // @dev This method DO NOT allow extension behavior via `_data` field;
  function methodName1(uint256 _param1, address _param2, bytes calldata _data);
  function firstNonRelatedMethod(uint256 someValue);
  function secondNonRelatedMethod(uint256 someValue);
}

The following methodName2(uint256 _param1, address _param2, bytes calldata _data) is not compliant because passing an empty _data produces behavior different from its overloaded sibling, methodName2(uint256 _param1, address _param2).

javascript
contract Foo {
  // @dev This is a sibling method to `methodName2(uint256 _param1, address _param2, bytes calldata _data);`
  function methodName2(uint256 _param1, address _param2);

  // @dev This method allows extension behavior via `_data` field;
  //      When passed in an empty array for `_data` field, this method
  //      behave DIFFERENTLY to
  //      its overloaded sibling `methodName2(uint256 _param1, address _param2);`
  function methodName2(uint256 _param1, address _param2, bytes calldata _data);

  function firstNonRelatedMethod(uint256 someValue);
  function secondNonRelatedMethod(uint256 someValue);
}

Rationale

The dynamically sized bytes type provides a flexible container for different kinds of data. Placing it at the end of the parameter list follows the convention used by the proposal for Solidity calldata.

The extension parameter can carry payloads containing different types of encoded data. It occupies the final position in the method's parameter list.

This allows contract implementations to accept additional information without defining a separate top-level parameter for every possible extension. The payload still needs a documented encoding and interpretation. ERC-5750 itself does not standardize every possible payload or automatically make different extensions interoperable.

Backward compatibility

Many existing Ethereum standards already contain methods that follow this convention. Contracts implementing those methods may conform to ERC-5750 in whole or in part.

Examples include the following.

  • ERC-721 already includes the following method.
javascript
function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable;
  • ERC-1155 already includes the following methods.
javascript
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;
  • ERC-777 already includes the following methods.
javascript
function burn(uint256 amount, bytes calldata data) external;
function send(address to, uint256 amount, bytes calldata data) external;

However, not every function with a trailing bytes argument is compliant. Some methods use that argument for an existing essential purpose rather than behavioral extensions.

  • In ERC-2535, the following method is not compliant as presented.
javascript
function diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata) external;
  • There are two possible ways to introduce conformance.
  1. Create a new overload.

    javascript
    function diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata, bytes calldata _data) external;
    • Append a new _data parameter after all the original parameters.
  2. Make the use of bytes memory _calldata extensible.

    • Define how the existing field can support behavioral extensions while preserving its original semantics and applicable compatibility requirements.
  • In ERC-1271, the following method is not compliant as presented.
javascript
function isValidSignature(bytes32 _hash, bytes memory _signature) public view returns (bytes4 magicValue);

Possible approaches to conformance include:

  1. Create a new overload.

    javascript
    function isValidSignature(bytes32 _hash, bytes memory _signature, bytes calldata _data) public view returns (bytes4 magicValue);
    • Append a new _data argument after all the original parameters.
  2. Make the use of bytes memory _signature extensible.

    • Define a compatible way for the existing signature field to support additional behavior.

These examples show how an existing noncompliant method might be extended. Adding an overload changes its function selector and requires callers to use the new interface; it does not retroactively change deployed contract bytecode. Reinterpreting an existing field must also preserve the requirements of the original standard.

Security considerations

When additional data enables a particular extension, the implementation must follow the security practices relevant to that extension. Examples include providing signatures for onchain verification and submitting commitments in commit-reveal protocols.

Security and privacy

Consider the privacy and security implications of additional data. Do not include personal information or confidential values in publicly accessible transaction calldata. Validate and decode untrusted payloads carefully.

Replay protection

Since extension data may be publicly visible, implementations must consider whether it can be reused in unintended contexts. Application-level nonces, domain separation, and expiration rules can help prevent unauthorized reuse of signed data where appropriate.

Transaction ordering attacks

Consider whether another participant can exploit the ordering of transactions containing extension data. An extension should not allow unauthorized operations merely because its input becomes visible before execution.

Following relevant best practices

Apply the security requirements specific to each extension, including the relevant standards and security guidelines. A generic byte-array argument does not itself enforce authorization or integrity.

Additional data should be handled as untrusted input. Each extension needs an explicit format, appropriate validation, and safeguards against the threats relevant to its behavior.

Citation

Zainan Victor Zhou (@xinbenlv), "ERC-5750: General Extensibility for Method Behaviors," Ethereum Improvement Proposals, no. 5750, October 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-5750.

Conclusion

ERC-5750 defines a convention for using a dynamically sized trailing bytes parameter to extend method behavior. The key distinction is that the parameter must actually support behavioral extensions, and an empty payload must preserve the behavior of a corresponding unextended overload when one exists.

Questions are welcome through Twitter direct messages.

Twitter @cardene777

I also publish on the following platforms.

https://chaldene.net/