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-7812 proposes a registry for managing and proving data on-chain.

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

I have also written about other EIPs.

Overview

ERC-7812 proposes a registry for storing provable information on-chain so that its validity can be verified later. Users can record commitments to their private information in the registry and later prove the validity of that information using zero-knowledge proofs. They do not have to disclose the actual information during the proof process.

Developers can also build application-specific management systems on top of the registry to register and process information for particular business use cases. The underlying EvidenceRegistry contract is described as deployed on Ethereum at 0x781268D46a654D020922f115D75dd3D56D287812.

The registry allows different projects and protocols to store and use provable information in a consistent format, with potential benefits for security and privacy.

Motivation

ERC-7812 aims to define how provable information is stored and issued through a standardized on-chain registry that multiple protocols can use.

Many privacy-oriented systems already use zero-knowledge proofs, but they operate independently. Their information is fragmented and difficult to manage or reuse in a common format. ERC-7812 provides a shared mechanism for managing provable information to improve reuse, interoperability, and security.

The registry is designed to be general-purpose rather than tied to a particular use case. It can therefore be applied to identity verification, reputation management, proof of attendance, and other applications. This allows projects to build their own protocols with minimal constraints.

The EIP provides the foundation; specific information formats and commitment structures are expected to be defined in separate EIPs.

Specification

Definitions

What is a Sparse Merkle Tree (SMT)?

A Sparse Merkle Tree is a specialized Merkle tree that stores key-value pairs at specific positions. It stores data deterministically and supports idempotent operations.

Determinism means that the same input always produces the same result. Idempotency means that repeating an operation does not change its result. These properties help maintain data integrity while enabling efficient proofs.

Unlike a conventional Merkle tree, a sparse Merkle tree has many empty (null) nodes. This makes it possible to represent the entire tree without explicitly storing a large number of nodes.

An SMT also uses hash functions to bind the data to its tree representation. The Poseidon hash function is often used to improve compatibility with zero-knowledge proofs. Unlike conventional hash functions such as SHA-256, Poseidon is optimized for computation in ZK circuits, reducing computational costs.

What is a statement?

A statement is structured data representing a fact or piece of evidence. It may be expressed as a string of text or as the root hash (Merkle root) of a Sparse Merkle Tree.

For example, proof that a person attended an event could be recorded as plain text, such as "Alice attended Event X". Alternatively, the information can be hashed and represented by an SMT root, allowing more efficient and secure management. This makes efficient verification possible while protecting the integrity of the data.

What is a commitment?

A commitment is a public value used to prove the validity of a statement without directly disclosing it.

Instead of publishing the statement itself, a technique known as blinding produces a concealed value that can be made public, allowing the original information to remain private while its validity is proven.

Blinding adds randomness to data to make it difficult to infer the original information. A commitment alone does not reveal its underlying statement, but a zero-knowledge proof can demonstrate that the commitment was formed correctly.

For example, directly publishing the claim that a person passed a qualification examination may raise privacy concerns. Blinding the information and registering it as a commitment allows the person to prove that they passed an examination without disclosing details such as the qualification name or examination date, provided the proof circuit establishes the relevant claim.

What is a commitment key?

A commitment key is a secret value used when blinding a statement.

When creating a commitment, the statement is hashed together with a secret random value (a salt), rather than hashed on its own. This secret value is called the commitment key.

If the commitment key is exposed, the underlying statement may become easier to guess, so the key must be protected.

For example, when registering the fact that a user signed a particular contract, simply recording the signature claim would allow anyone to read it. Blinding the data with a commitment key makes it possible to prove that a signature occurred without disclosing the original contract contents.

Overview

The on-chain registry system comprises the EvidenceRegistry, EvidenceDB, and Registrar components, organized into two subsystems. ERC-7812 focuses on the design and standardization of EvidenceRegistry and EvidenceDB.

diagram.png Source: https://eips.ethereum.org/EIPS/eip-7812

EvidenceRegistry is the entry-point contract for the protocol. Through the registry, arbitrary 32-byte values can be stored in an on-chain database called EvidenceDB and later used to prove the corresponding data. A Registrar defines a particular data structure and stores data in EvidenceDB through EvidenceRegistry.

For a qualification verification use case, for example, a Registrar can manage information indicating that a user passed a particular examination, hash it, and record it in EvidenceDB. Zero-knowledge proofs or Merkle proofs can then be used to verify that the data was recorded correctly.

Data verification using Merkle proofs

Merkle proofs establish whether data is present or absent in EvidenceDB.

A Merkle proof is a cryptographic technique for proving that data is part of a particular Merkle tree.

To prove that a value exists in EvidenceDB, the verifier uses the Merkle root to establish membership in the tree. A Merkle proof can also demonstrate that a value has not been registered in EvidenceDB.

With zero-knowledge proofs, users can prove that particular information exists or does not exist without disclosing the original data. For example, rather than directly publishing qualification details, a user can use a Merkle proof to show a third party that the relevant certificate is registered in EvidenceDB.

Registrars and on-chain ZK verification

Understanding how a Registrar stores data in EvidenceDB makes it possible to implement an on-chain ZK verifier for that data. The verifier can be implemented using Circom, a domain-specific language for ZK circuits, or another technology stack.

The registry system thus uses EvidenceRegistry and EvidenceDB as its foundation, while Registrars provide customizable data management. Different projects can prove and verify data using common infrastructure, improving reuse and interoperability.

EvidenceDB

EvidenceDB is a contract that serves as a database for provable key-value pairs. It needs functions to insert, update, and remove data, while preserving the required idempotency properties.

The data structure used by EvidenceDB must support proofs of both inclusion and exclusion. Merkle trees are commonly used for such proofs; the envisaged design is based on a Sparse Merkle Tree (SMT).

The Proof struct

EvidenceDB defines a Proof struct for data proofs. It contains the following information for proving whether specific data belongs to the Merkle tree.

  • root
    • The Merkle root hash.
    • This hash represents the state of the entire tree and changes whenever the data changes.
  • siblings
    • A list of sibling-node hashes in the Merkle tree.
    • These hashes allow the Merkle root to be reconstructed to verify data membership.
  • existence
    • true if the data being proven exists in the tree; otherwise false.
  • key
    • The key of the data being verified.
  • value
    • The value of the data being verified.
  • auxExistence
    • A flag indicating whether an auxiliary node exists.
  • auxKey
    • The key of the auxiliary node.
  • auxValue
    • The value of the auxiliary node.

The struct enables proofs of whether specific data is present in EvidenceDB.

Main EvidenceDB functions

  • add(bytes32 key, bytes32 value)

Inserts new data into the SMT. Stores value under the specified key.

  • remove(bytes32 key)

Removes data associated with the specified key. To preserve the required idempotency property, the state after removal must match the state before the data was inserted.

  • update(bytes32 key, bytes32 newValue)

Updates the value of existing data. Supplies a new value and updates the corresponding node in the tree.

  • getRoot()

Retrieves the current Merkle root. Because another transaction can change the root before an on-chain operation executes, creating a front-running risk, this function should not be used directly for on-chain verification.

  • getSize()

Retrieves the number of data nodes in EvidenceDB.

  • getMaxHeight()

Retrieves the maximum height of the SMT (the number of branches used in a Merkle proof). The height determines the capacity of the tree.

  • getProof(bytes32 key)

Retrieves a Merkle proof for the specified key. The proof can be used to verify whether specific data is included in the tree.

  • getValue(bytes32 key)

Retrieves the value associated with the specified key. Returns the value if the data exists in EvidenceDB.

Evidence Registry

Merkle root management

EvidenceRegistry must track changes to the Merkle root and emit an event whenever it is updated. The Merkle root is a hash representing the current state of EvidenceDB, and a new root is produced when its data changes.

The RootUpdated event records both the previous root (prev) and the current root (curr), making the update observable. This event allows the history of EvidenceDB to be tracked off-chain.

Adding, removing, and updating statements

  • addStatement(bytes32 key, bytes32 value)

Adds a new statement to EvidenceDB. The transaction fails if the statement's key already exists.

  • removeStatement(bytes32 key)

Removes a registered statement from EvidenceDB. The transaction fails if the key being removed does not exist.

  • updateStatement(bytes32 key, bytes32 newValue)

Updates an existing statement to a new value. The transaction fails if the key being updated does not exist.

Statement key isolation

EvidenceRegistry must maintain an independent namespace for each msg.sender. This prevents data collisions when different users use the same key.

The key is transformed as follows.

js
bytes32 isolatedKey = hash(msg.sender, key)

The hash function must be secure for use throughout the protocol. Even if different users supply the same key, different isolatedKey values are generated and managed independently.

For example, if a user at address 0xABC... registers data using the key "user_identity", its isolatedKey is calculated as follows.

bash
isolatedKey = hash(0xABC..., "user_identity")

Another user at address 0xDEF... using the same "user_identity" key obtains a different isolatedKey.

This design isolates data belonging to different users even when they use identical keys, helping maintain security and data consistency.

Merkle root history

EvidenceRegistry must maintain the history of EvidenceDB Merkle roots. This enables verification of previous data states.

  • getRootTimestamp(bytes32 root)

Retrieves the creation timestamp of a specified Merkle root. It returns 0 for a root that does not exist. For the latest root, the original explanation describes returning the block timestamp (block.timestamp).

This allows EvidenceRegistry to track which Merkle roots were valid at particular times.

Hash functions

Hash function selection and requirements

EvidenceRegistry and EvidenceDB must use the same hash function. This maintains data consistency and ensures that the proof process works correctly. Using different hash functions would generate different hashes for the same data and break consistency.

ERC-7812 recommends a ZK-friendly hash function compatible with zero-knowledge proofs. Poseidon is specifically recommended.

What is a ZK-friendly hash function?

A ZK-friendly hash function is designed for efficient computation inside zero-knowledge proof circuits. Conventional hash functions such as SHA-256 and Keccak-256 may be computationally expensive in ZK circuits, increasing proof generation time and resource requirements.

Poseidon is designed for efficient ZK proofs and can substantially reduce the computational cost of proof generation. Using Poseidon can therefore make proof generation more efficient when EvidenceRegistry and EvidenceDB are integrated with ZK proofs.

Constraints of ZK-friendly hash functions

When using a ZK-friendly hash function such as Poseidon, EvidenceRegistry must constrain keys and values to the relevant prime field.

For the BN128 (Barreto-Naehrig 128-bit Curve), for example, data must respect the following upper bound.

text
21888242871839275222246405745257275088548364400416034343698204186575808495617

This number represents the BN128 prime field modulus. Values outside the field's valid range may not be handled as intended by the hash function.

For example, when using 256-bit (32-byte) keys or values, their numerical representations must lie within the permitted field range.

Rationale

The design of ERC-7812 considered two approaches: individual registries for each protocol, and a single shared registry for all protocols. The single-registry approach was chosen for the following reasons.

Cross-chain portability

A single registry minimizes the amount of data that must be transmitted when verifying data across blockchains. Specifically, one SMT root hash (a bytes32 value) can be transmitted to represent the registry state for verification.

With separate registries, protocols might use different data structures on different chains, complicating interoperability.

A shared trust foundation

When all protocols use a common registry, users need to establish trust in only one registry contract.

If each protocol had its own registry, users would have to evaluate each registry independently, increasing risk. A single registry provides a common trust foundation, with potential benefits for transparency and security.

Simpler integration

A single registry allows protocols to use a common system interface, hash function, and proof structure. This reduces the development cost of integrating the system into new projects and enables faster adoption.

Separate registries might use different data structures and proof schemes, increasing integration work and reducing compatibility.

Generality

ERC-7812 supports a wide range of applications without depending on a particular business use case.

Custom Registrars could be developed for the following applications, for example.

  • On-chain management of government-issued passport information
  • Privacy-preserving account management using EIP-4337
  • Management of POAP (Proof of Attendance Protocol) records Although the registry is shared, individual projects can implement their own Registrars for application-specific data proofs and management.

EvidenceDB namespace design

EvidenceDB uses a namespace mechanism to control write access.

This prevents third parties other than an issuer from modifying data belonging to that issuer. For example, if a certification authority issues evidence, the issuer controls that evidence and other users cannot modify it arbitrarily.

This mechanism delegates responsibility for access control to the Registrar. The access control implemented by each Registrar is therefore important.

Merkle root history management

EvidenceRegistry is designed to maintain on-chain Merkle root history with minimal gas consumption. This reduces the burden of integrating EvidenceRegistry into Registrars.

If more detailed history is required, an off-chain service can analyze RootUpdated events.

For example, an off-chain database can monitor EvidenceRegistry events and store previous Merkle roots to retain a detailed history.

Backward Compatibility

There are no compatibility issues identified in the proposal.

Deployment

EvidenceRegistry uses the fixed address 0x781268D46a654D020922f115D75dd3D56D287812. This enables all protocols to reference the same address and verify data consistently.

The contract is deployed using a deterministic deployment proxy. This technique deploys a contract to a predictable address given the appropriate conditions, including the deployer address and deployment salt.

The deployment proxy operates from 0x4e59b44847b379578588920ca78fbf26c0b4956c, and the salt used for deployment is as follows.

text
0x9a533395526948e0860194b5dbd307de82d332d7fb268e02659096f3c904bf9f

The deployment likely uses a mechanism such as CREATE2, described below.

Reference Implementation

SMT implementations in Solidity and Circom

Low-level Sparse Merkle Tree (SMT) implementations in both Solidity and Circom are provided as the foundation for EvidenceRegistry and EvidenceDB.

These implementations allow EvidenceDB to operate efficiently, with statements organized in a Merkle tree. The Circom implementation, in particular, is used to create ZK proofs outside the contract and optimize the proof process.

The SMT height is set to 80. This controls the capacity of the tree and the computational cost of proofs. Because increasing tree height can increase proof costs, 80 was chosen as a balanced value.

Dependencies

  • @openzeppelin/contracts v5.1.0
  • circomlib v2.0.5

EvidenceDB

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.21;

import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

import {IEvidenceDB} from "./interfaces/IEvidenceDB.sol";

import {SparseMerkleTree} from "./libraries/SparseMerkleTree.sol";
import {PoseidonUnit2L, PoseidonUnit3L} from "./libraries/Poseidon.sol";

contract EvidenceDB is IEvidenceDB, Initializable {
    using SparseMerkleTree for SparseMerkleTree.SMT;

    address private _evidenceRegistry;

    SparseMerkleTree.SMT private _tree;

    modifier onlyEvidenceRegistry() {
        _requireEvidenceRegistry();
        _;
    }

    function __EvidenceDB_init(address evidenceRegistry_, uint32 maxDepth_) external initializer {
        _evidenceRegistry = evidenceRegistry_;

        _tree.initialize(maxDepth_);

        _tree.setHashers(_hash2, _hash3);
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function add(bytes32 key_, bytes32 value_) external onlyEvidenceRegistry {
        _tree.add(key_, value_);
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function remove(bytes32 key_) external onlyEvidenceRegistry {
        _tree.remove(key_);
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function update(bytes32 key_, bytes32 newValue_) external onlyEvidenceRegistry {
        _tree.update(key_, newValue_);
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function getRoot() external view returns (bytes32) {
        return _tree.getRoot();
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function getSize() external view returns (uint256) {
        return _tree.getNodesCount();
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function getMaxHeight() external view returns (uint256) {
        return _tree.getMaxDepth();
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function getProof(bytes32 key_) external view returns (Proof memory) {
        return _tree.getProof(key_);
    }

    /**
     * @inheritdoc IEvidenceDB
     */
    function getValue(bytes32 key_) external view returns (bytes32) {
        return _tree.getNodeByKey(key_).value;
    }

    /**
     * @notice Returns the address of the Evidence Registry.
     */
    function getEvidenceRegistry() external view returns (address) {
        return _evidenceRegistry;
    }

    function _requireEvidenceRegistry() private view {
        if (_evidenceRegistry != msg.sender) {
            revert NotFromEvidenceRegistry(msg.sender);
        }
    }

    function _hash2(bytes32 element1_, bytes32 element2_) private pure returns (bytes32) {
        return PoseidonUnit2L.poseidon([element1_, element2_]);
    }

    function _hash3(
        bytes32 element1_,
        bytes32 element2_,
        bytes32 element3_
    ) private pure returns (bytes32) {
        return PoseidonUnit3L.poseidon([element1_, element2_, element3_]);
    }
}

EvidenceRegistry

js
// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.21;

import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";

import {IEvidenceDB} from "./interfaces/IEvidenceDB.sol";
import {IEvidenceRegistry} from "./interfaces/IEvidenceRegistry.sol";

import {PoseidonUnit2L} from "./libraries/Poseidon.sol";

contract EvidenceRegistry is IEvidenceRegistry, Initializable {
    uint256 public constant BABY_JUB_JUB_PRIME_FIELD =
        21888242871839275222246405745257275088548364400416034343698204186575808495617;

    IEvidenceDB private _evidenceDB;

    mapping(bytes32 => uint256) private _rootTimestamps;

    modifier onlyInPrimeField(bytes32 key) {
        _requireInPrimeField(key);
        _;
    }

    modifier onRootUpdate() {
        bytes32 prevRoot_ = _evidenceDB.getRoot();
        _rootTimestamps[prevRoot_] = block.timestamp;
        _;
        emit RootUpdated(prevRoot_, _evidenceDB.getRoot());
    }

    function __EvidenceRegistry_init(address evidenceDB_) external initializer {
        _evidenceDB = IEvidenceDB(evidenceDB_);
    }

    /**
     * @inheritdoc IEvidenceRegistry
     */
    function addStatement(
        bytes32 key_,
        bytes32 value_
    ) external onlyInPrimeField(key_) onlyInPrimeField(value_) onRootUpdate {
        bytes32 isolatedKey_ = _getIsolatedKey(key_);

        if (_evidenceDB.getValue(isolatedKey_) != bytes32(0)) {
            revert KeyAlreadyExists(key_);
        }

        _evidenceDB.add(isolatedKey_, value_);
    }

    /**
     * @inheritdoc IEvidenceRegistry
     */
    function removeStatement(bytes32 key_) external onlyInPrimeField(key_) onRootUpdate {
        bytes32 isolatedKey_ = _getIsolatedKey(key_);

        if (_evidenceDB.getValue(isolatedKey_) == bytes32(0)) {
            revert KeyDoesNotExist(key_);
        }

        _evidenceDB.remove(isolatedKey_);
    }

    /**
     * @inheritdoc IEvidenceRegistry
     */
    function updateStatement(
        bytes32 key_,
        bytes32 newValue_
    ) external onlyInPrimeField(key_) onlyInPrimeField(newValue_) onRootUpdate {
        bytes32 isolatedKey_ = _getIsolatedKey(key_);

        if (_evidenceDB.getValue(isolatedKey_) == bytes32(0)) {
            revert KeyDoesNotExist(key_);
        }

        _evidenceDB.update(isolatedKey_, newValue_);
    }

    /**
     * @inheritdoc IEvidenceRegistry
     */
    function getRootTimestamp(bytes32 root_) external view returns (uint256) {
        if (root_ == bytes32(0)) {
            return 0;
        }

        if (root_ == _evidenceDB.getRoot()) {
            return block.timestamp;
        }

        return _rootTimestamps[root_];
    }

    function getEvidenceDB() external view returns (address) {
        return address(_evidenceDB);
    }

    function _getIsolatedKey(bytes32 key_) internal view returns (bytes32) {
        return PoseidonUnit2L.poseidon([bytes32(uint256(uint160(msg.sender))), key_]);
    }

    function _requireInPrimeField(bytes32 key_) private pure {
        if (uint256(key_) >= BABY_JUB_JUB_PRIME_FIELD) {
            revert NumberNotInPrimeField(key_);
        }
    }
}

EvidenceRegistry Verifier

js
// LICENSE: CC0-1.0
pragma circom 2.1.9;

include "SparseMerkleTree.circom";

template BuildIsolatedKey() {
    signal output isolatedKey;

    signal input address;
    signal input key;

    component hasher = Poseidon(2);
    hasher.inputs[0] <== address;
    hasher.inputs[1] <== key;

    hasher.out ==> isolatedKey;
}

template EvidenceRegistrySMT(levels) {
    // Public Inputs
    signal input root;

    // Private Inputs
    signal input address;
    signal input key;

    signal input value;

    signal input siblings[levels];

    signal input auxKey;
    signal input auxValue;
    signal input auxIsEmpty;

    signal input isExclusion;

    // Build isolated key
    component isolatedKey = BuildIsolatedKey();
    isolatedKey.address <== address;
    isolatedKey.key <== key;

    // Verify Sparse Merkle Tree Proof
    component smtVerifier = SparseMerkleTree(levels);
    smtVerifier.siblings <== siblings;

    smtVerifier.key <== isolatedKey.isolatedKey;
    smtVerifier.value <== value;

    smtVerifier.auxKey <== auxKey;
    smtVerifier.auxValue <== auxValue;
    smtVerifier.auxIsEmpty <== auxIsEmpty;

    smtVerifier.isExclusion <== isExclusion;

    smtVerifier.root <== root;
}

component main {public [root]} = EvidenceRegistrySMT(80);

Security Considerations

Registrar management and proof functionality

Each Registrar must provide both statement management and proof functionality. In particular, when zero-knowledge proofs establish the authenticity of data, incorrectly configured verification can allow malicious proofs to be accepted.

Some zero-knowledge proof systems require an initial configuration process called a trusted setup. This process generates public parameters for the proof circuit. If the setup is not performed securely, an attacker may obtain secret setup material that enables forged proofs, allowing invalid data to appear valid.

Registrar developers should ensure that any trusted setup is secure and consider an independent audit. Proof systems that do not require a trusted setup, such as STARKs, are also an option.

Risks of using getRoot on-chain

EvidenceDB provides getRoot, which retrieves the current Merkle root. However, using it directly on-chain to verify the database state is discouraged.

The reason is the risk of front-running.

If a Registrar reads the latest root through getRoot and performs an operation based on it, another transaction can change the data before that operation executes, deliberately changing the latest root. The Registrar may then process an unintended state.

To avoid this problem, the Registrar should accept the intended root as a function argument and verify it using getRootTimestamp, rather than directly relying on getRoot.

getRootTimestamp returns the creation time of the specified Merkle root, enabling the Registrar to validate the intended root according to its acceptance rules even if a front-running transaction changes the latest root.

Using the appropriate methods helps prevent unauthorized substitution of the state being verified and improves registry security.

Citation

Artem Chystiakov (@arvolear) artem@rarilabs.com, Oleksandr Kurbatov oleksandr@rarilabs.com, Yaroslav Panasenko yaroslav@rarilabs.com, Michael Elliot (@michaelelliot) mike@zkpassport.id, Vitalik Buterin (@vbuterin), "ERC-7812: ZK Identity Registry [DRAFT]," Ethereum Improvement Proposals, no. 7812, November 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7812.

Conclusion

This article covered ERC-7812, a proposal for an on-chain registry for managing and proving data. I hope this explanation was helpful.

If you have questions, feel free to contact me via Twitter DM.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/