ERC-2477 Token metadata integrity

Stagnant · Names & metadata · created 2020-01-02

A standard that lets you use a cryptographic hash to verify whether the metadata document a token points to, and its schema, still have the same content as originally.

Why it is needed

ERC-721 and ERC-1155 tokens mostly point to metadata such as name, description, and image via a URL (RFC 3986). Some implementations embed the metadata fully on-chain or use content-addressed schemes like IPFS, but in practice almost all implementations use ordinary URLs. The operator of the server that such a URL points to can change its content at any time, so there has been no way for a wallet or app to verify whether the metadata it just fetched is the same as when the token was first created. Nor can changes to the schema document referenced by the metadata be tracked. In the end, the token itself is verified on-chain, but the off-chain metadata describing the token had to be trusted as-is, with no guarantee.

What to implement

In depth

The two functions and the ERC-165 requirement

The ERC2477 interface defines only two functions: tokenURIIntegrity(uint256 tokenId) and tokenURISchemaIntegrity(uint256 tokenId). Each returns a digest (bytes) and a hashAlgorithm (string). For example, the integrity value corresponding to ERC-721's tokenURI(21) is tokenURIIntegrity(21), and the value corresponding to ERC-1155's uri(16) is tokenURIIntegrity(16). tokenURISchemaIntegrity(32) is the hash of the schema used by the metadata document that tokenURIIntegrity(32) points to. A contract implementing this standard must also implement ERC-165, and the ERC2477 interface identifier is 0x832a7e0e.

When there is no return value, and freedom of hash choice

If the corresponding value does not exist, digest and hashAlgorithm return an empty string. A contract is free to choose whatever hash algorithm or content integrity scheme it wants, and emitting an event when an integrity value is updated is also optional. digest was placed as the first return value because it was expected that, if only one of the two values is used on-chain, digest alone would be the more common case. Unlike SRI, an options parameter was not included, because SRI itself does not yet use options and its future format is unknown.

Five ways (A through E) to bind metadata and schema together

The source describes the scope of integrity application in five stages. A is the pre-EIP-2477 state with no guarantee at all. B has tokenURIIntegrity guarantee only the metadata document. In C, the metadata references the schema with integrity via a JSON Schema extension, and tokenURIIntegrity guarantees the metadata. In D, the metadata links to the schema only by an ordinary reference, while the on-chain tokenURIIntegrity and tokenURISchemaIntegrity separately guarantee the metadata and the schema respectively. E is the strongest approach, where the metadata's schema reference itself has integrity, and on top of that the on-chain tokenURISchemaIntegrity also guarantees the schema.

Schema reference fields: $schema and $schemaIntegrity

A metadata document can point to the schema URI using the JSON-LD "$schema" key, and can additionally indicate the schema document's integrity by putting a digest and hashAlgorithm in a "$schemaIntegrity" object. In the schema presented in the source, both $schema and $schemaIntegrity are required fields. Using this approach lets the metadata document itself grant integrity to the schema reference, as in approaches C or E.

Hash algorithm: clients must support at least sha256

Clients must support at least the sha256 hash algorithm and may additionally support other algorithms. The reason only sha256 is required, unlike SRI which requires sha256, sha384, and sha512 all together, is consideration for on-chain clients. sha256 is simple and cheap to compute on Ethereum, but sha384 and sha512 are more expensive and cumbersome to handle. sha1, the most common option under 256 bits, has already had multiple collisions found and is considered broken, so it was excluded from the choices.

Why the integrity value was not embedded in the URL

An approach of appending a parameter like ?integrity=XXXXX to the end of the metadata URL was also possible but was not adopted. The main reason is that the web as a whole faced the same problem, and the W3C chose the SRI approach of a separate field decoupled from the URL. Other reasons cited include that on-chain, reading a hash field directly is easier than parsing a string, and that some URIs may be hard to modify in that way. The same reasoning applies to tokenURISchemaIntegrity as well.

Scope of application and backward compatibility

It is fully compatible with the metadata extensions of ERC-721 and ERC-1155, and since it is additive to the existing specification, there are no backward compatibility issues. The EIP metadata lists ERC-721 and ERC-1155 as "requires," but this is due to a technical limitation of the EIP metadata format, and in practice it can be used with any token implementation that has a tokenURI(uint id) or similar function. It does not directly apply to tokens without a tokenId, such as ERC-1046 (ERC-20 metadata extension) or ERC-918 (mining-based token standard); it states that if such a standard is finalized, a separate ERC without the tokenId parameter would be needed.

Standard status

This proposal was written on January 2, 2020, and its current status is Stagnant. That means it is no longer being progressed and has halted, so its content may change or be withdrawn, and it has not been finalized as a standard.

Original ERC · ← ERCs