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-6066 proposes a standard method for validating signatures associated with individual ERC-721 or ERC-1155 tokens.

This article translates, summarizes, and expands on the following specification.

More ERC explainers:

Overview

Ethereum applications can use ecrecover() to recover the address associated with an ECDSA signature. Smart contract accounts can expose their own signature validation logic through ERC-1271.

Before ERC-6066, there was no corresponding common interface for validating signatures associated with individual NFTs.

For ERC-1271, see the following article.

ERC-1271: Understanding signature validation by smart contracts

ERC-6066 extends the contract-based validation approach by introducing isValidSignature(tokenId, hash, data). The token ID identifies the token whose authorization is being evaluated.

A verifier can ask the token contract whether a particular message hash and associated data constitute a valid signature for that token.

An NFT does not necessarily possess a private key. The term NFT signature refers to an authorization that the token contract recognizes on behalf of a token, according to its implementation.

ecrecover()

Purpose
  • The Ethereum ecrecover() function recovers a signer address from a message digest and the components of a compatible ECDSA signature.
  • The recovered address can be compared with an expected signer address.
Example

Signing

  • Alice prepares a message, such as "Hello, World!".
  • Alice signs the appropriate message digest using her private key.
  • She sends Bob the message and signature.

Verification

  • Bob reconstructs the message digest using the same signing convention.
  • Bob passes the digest and signature components to ecrecover().
  • If the recovered address matches Alice's expected address, and the signature and digest have been validated according to the application's requirements, Bob can accept the signature.
Summary

ECDSA recovery allows an application to verify that a signature corresponds to a particular Ethereum address. It does not establish the real-world identity of the person controlling the key.

ERC-1271 instead allows a smart contract to define how a signature or other authorization is validated.

Motivation

NFTs became widely used for digital artwork, avatars, and profile pictures, with substantial trading activity. ERC-721 and ERC-1155 tokens can also represent other kinds of rights and relationships.

For ERC-721, see the following article.

https://chaldene.net/erc721

For ERC-1155, see the following article.

https://chaldene.net/erc1155

One possible application is representing organizational offices or roles as NFTs. An authorization can then be associated with a particular role token rather than exclusively with the account of the person holding that office.

Consider a DAO that represents its CEO and COO roles using NFT badges and elects new officeholders every quarter.

If the previous COO signed messages exclusively through a personal EOA, those signatures remain associated with that EOA after the office changes hands.

An NFT-specific authorization mechanism can associate a signature with the office token itself. The token contract determines whether authorizations granted by a previous officeholder remain valid after a transfer.

A DAO-wide multisignature wallet is another possible approach, but role-specific authorization provides a finer-grained way to separate responsibilities. Deploying an individual smart contract account for every office is also possible, although it may introduce additional complexity.

Organizations that use ENS to represent their hierarchy could apply a similar approach to wrapped ENS subdomains represented as NFTs.

Specification

javascript
pragma solidity ^0.8.0;

interface IERC6066 {
    /**
     * @dev MUST return if the signature provided is valid for the provided tokenId and hash
     * @param tokenId   Token ID of the signing NFT
     * @param hash      Hash of the data to be signed
     * @param data      OPTIONAL arbitrary data that may aid verification
     *
     * MUST return the bytes4 magic value 0x12edb34f when function passes.
     * MUST NOT modify state (using STATICCALL for solc < 0.5, view modifier for solc > 0.5)
     * MUST allow external calls
     *
     */
    function isValidSignature(
        uint256 tokenId,
        bytes32 hash,
        bytes calldata data
    ) external view returns (bytes4 magicValue);
}

isValidSignature

javascript
function isValidSignature(
    uint256 tokenId,
    bytes32 hash,
    bytes calldata data
) external view returns (bytes4 magicValue);

Overview

Determines whether a signature or authorization is valid for the specified token ID and message hash.

Details

The function receives the token ID, the hash of the relevant message, and arbitrary additional data that may assist verification.

Successful validation must return the four-byte magic value 0x12edb34f.

The function must not modify state and must permit external calls.

Parameters

  • tokenId
    • The token ID representing the signing NFT.
  • hash
    • The hash of the data being signed.
  • data
    • Arbitrary additional bytes that may assist signature validation. The implementation determines their meaning, and empty bytes may be sufficient.

Return value

  • magicValue
    • The value 0x12edb34f when the authorization is valid.

An ERC-721 or ERC-1155 implementation can expose this function to validate authorizations associated with its tokens.

For example, a token contract may allow an authorized holder to approve a message hash and later report that approval through isValidSignature.

Supporting ERC-6066 requires an explicit implementation of the validation function. ERC-721 or ERC-1155 compatibility alone does not establish ERC-6066 support.

For ERC-1155, multiple accounts may hold units of the same token ID. The implementation must define whose authorization is sufficient and how it relates to the token's holders.

Rationale

ERC-6066 deliberately avoids prescribing a single signature-generation mechanism. Like ERC-1271, it defines an interface for validation while allowing implementations to select their own authorization logic.

The proposal draws on Gnosis Safe's contract-signature approach. The additional bytes argument allows implementations to provide verification information when needed, in line with the extensibility conventions discussed in ERC-5750.

For ERC-5750, see the following article.

ERC-5750: Extending method behavior with additional data parameters

The data argument is part of the function's required ABI. Its contents are optional in the sense that some validation schemes can accept empty bytes or ignore the argument.

Backward compatibility

Contract-based authorization does not have to follow the same generation process as a conventional cryptographic signature.

For example, an implementation may store a Boolean flag indicating whether a particular message hash has been approved. The validator then checks that stored approval and returns the prescribed magic value.

The Boolean approach is one possible implementation, not a restriction imposed by ERC-6066. Implementations can also use cryptographic signatures, multisignature policies, or other authorization rules.

Although the internal representation may be a Boolean value, the external validation interface returns a bytes4 magic value rather than a Boolean.

Reference implementation

The following example combines ERC-721 with the ERC-6066 validation interface.

javascript
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "./interfaces/IERC6066.sol";

contract ERC6066Reference is ERC721, IERC6066 {
    // type(IERC6066).interfaceId
    bytes4 public constant MAGICVALUE = 0x12edb34f;
    bytes4 public constant BADVALUE = 0xffffffff;

    mapping(uint256 => mapping(bytes32 => bool)) internal _signatures;

    error ENotTokenOwner();

    /**
     * @dev Checks if the sender owns NFT with ID tokenId
     * @param tokenId   Token ID of the signing NFT
     */
    modifier onlyTokenOwner(uint256 tokenId) {
        if (ownerOf(tokenId) != _msgSender()) revert ENotTokenOwner();
        _;
    }

    constructor(string memory name_, string memory symbol_)
        ERC721(name_, symbol_)
    {}

    /**
     * @dev SHOULD sign the provided hash with NFT of tokenId given sender owns said NFT
     * @param tokenId   Token ID of the signing NFT
     * @param hash      Hash of the data to be signed
     */
    function sign(uint256 tokenId, bytes32 hash)
        external
        onlyTokenOwner(tokenId)
    {
        _signatures[tokenId][hash] = true;
    }

    /**
     * @dev MUST return if the signature provided is valid for the provided tokenId, hash, and optionally data
     */
    function isValidSignature(uint256 tokenId, bytes32 hash, bytes calldata data)
        external
        view
        override
        returns (bytes4 magicValue)
    {
        // The data parameter is unused in this example
        return _signatures[tokenId][hash] ? MAGICVALUE : BADVALUE;
    }

    /**
     * @dev ERC-165 support
     */
    function supportsInterface(
        bytes4 interfaceId
    ) public view virtual override returns (bool) {
        return
            interfaceId == type(IERC6066).interfaceId ||
            super.supportsInterface(interfaceId);
    }
}

The reference contract allows the current owner of a token to call sign, which records approval of the supplied hash under that token ID. The validation function subsequently checks the stored approval.

This code is preserved from the original article. It is an illustrative implementation and has not been independently compiled or audited.

In particular, the example does not provide a revocation function or clear existing approvals upon token transfer or burning. As written, an earlier approval remains stored under the token ID. Applications must explicitly decide whether such persistence is intended and implement appropriate invalidation and token-existence checks where required.

Security considerations

Contract-based signature validity may change over time. Developers and users should account for the possibility that an authorization can be revoked or become invalid according to the contract's state and policy.

A successful validation at one block does not guarantee that the same authorization will remain valid at a later block.

The interface does not itself require a particular revocation mechanism. Implementations and consuming applications must define the relevant authorization lifetime, ownership-transfer behavior, and replay protection.

A valid signature or approval also does not, by itself, establish that the associated operation has not already been executed.

Citation

Jack Boyuan Xu (@boyuanx), "ERC-6066: Signature Validation Method for NFTs," Ethereum Improvement Proposals, no. 6066, November 2022. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6066.

Conclusion

ERC-6066 defines a common validation interface for signatures and authorizations associated with individual NFTs, allowing a token contract to specify how authorization is evaluated for a given token ID.

Questions are welcome via Twitter @cardene777.

Other publications:

https://chaldene.net/