EIPs Explained

ERC-5750 · Final · ERC · 2022-10-04

ERC-5750: General Extensibility for Method Behaviors

A convention that a method's last bytes parameter is reserved for future behaviour extensions, and that passing empty bytes must behave exactly like the overload without it.

What problem does it solve?

Once an interface ships, adding features is awkward. You either invent a new method (new name, new parameters, new integration work) or try to squeeze extra meaning into existing parameters. Neither scales well when you later want to attach a signature, a nonce, a salt, a commitment, or a human-readable reason to a call.

ERC-5750 standardises a simple escape hatch: a trailing bytes parameter that is explicitly reserved for extensions. Several existing standards already have this shape, so the ERC mostly gives a name and a rule to an existing habit.

How it works

Compliance is defined per method, not per contract:

  1. A method whose last parameter is bytes is eligible: function methodName(type1 a, type2 b, ..., bytes data).
  2. A method is compliant if it is eligible and that last bytes is designated for behaviour extensions (not used for its core function).
  3. If the method has an overloaded sibling with the same name and same leading parameters but without the bytes, then calling the compliant version with empty bytes must behave identically to the sibling.

Examples from the spec of methods that already comply:

  • ERC-721 safeTransferFrom(from, to, tokenId, bytes data)
  • ERC-1155 safeTransferFrom(...) and safeBatchTransferFrom(...)
  • ERC-777 send(to, amount, data) and burn(amount, data)

And methods that do not comply, because their trailing bytes is load-bearing:

  • ERC-1271 isValidSignature(bytes32 hash, bytes signature): the bytes is the signature.
  • ERC-2535 diamondCut(..., bytes _calldata): the bytes is the init call.

These could become compliant by adding an overload with an extra trailing bytes data.

Putting the field last keeps it compatible with Solidity's ABI layout, and bytes can carry any encoded payload.

Sample code

A vote function with an extension slot. Empty data behaves like the plain overload; non-empty data carries an optional reason:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Ballot {
    event Voted(address indexed voter, uint256 proposal, string reason);
    mapping(address => bool) public hasVoted;

    // Sibling without extension data
    function vote(uint256 proposal) external {
        _vote(proposal, "");
    }

    // ERC-5750 compliant: last bytes param is for extensions.
    // With data.length == 0 it MUST behave exactly like vote(proposal).
    function vote(uint256 proposal, bytes calldata data) external {
        string memory reason = data.length == 0 ? "" : abi.decode(data, (string));
        _vote(proposal, reason);
    }

    function _vote(uint256 proposal, string memory reason) internal {
        require(!hasVoted[msg.sender], "already voted");
        hasVoted[msg.sender] = true;
        emit Voted(msg.sender, proposal, reason);
    }
}

Calling it from ethers v6 (overloaded functions need the full signature):

import { AbiCoder } from "ethers";
const data = AbiCoder.defaultAbiCoder().encode(["string"], ["Supports the roadmap"]);
await ballot["vote(uint256,bytes)"](1n, data);

Things to know

  • Status: Final.
  • The ERC defines where extension data goes, not what it contains. Each extension (signatures, commit-reveal as in ERC-5732, etc.) must define its own encoding and follow its own security practices.
  • Anything in data is public once it hits the mempool. The spec warns against putting unencrypted personal information there and reminds implementers to consider replay and front-running.
  • The "empty bytes equals the sibling" rule is what makes the pattern safe for existing integrators; breaking it makes the method non-compliant.

#interface #extensibility #calldata #convention

Details

Authors
Zainan Victor Zhou (@xinbenlv)
Status
Final
Type
Standards Track / ERC
Created
2022-10-04
Requires
Required by

Machine-readable: Markdown · JSON