EIPs Explained

ERC-1387 · Stagnant · ERC · 2018-09-08

ERC-1387: Merkle Tree Attestations with Privacy enabled

A draft interface for verifying off-chain attestations stored as signed Merkle trees, so a user can prove one fact (such as residency) to a contract without revealing the rest of their credential.

What problem does it solve?

Contracts sometimes need proof of a real-world claim: "this participant lives in Australia", "this buyer is over 18". The obvious approach, an attester writing claims about people on-chain, publishes personal data forever and makes every use of the claim linkable to the same person.

ERC-1387 takes a different route. The attester issues the attestation off-chain as a signed Merkle tree of key/value facts. When the user needs to prove something, they reveal only the single leaf that matters plus the Merkle path, and the contract checks it against the attester's signature on the root.

How it works

  1. An attester (the spec's example is a Justice of the Peace) builds a Merkle tree whose leaves are facts about the user, each mixed with a salt, and signs the root.
  2. The user keeps the tree. To use it, they submit an Attestation containing:
    • the revealed key / val pair (e.g. country / AU) and its salt,
    • the merklePath from that leaf to the root,
    • the attester's signature (v, r, s), the attester address and the recipient.
  3. The contract's validate function recomputes the root from the leaf and path, recovers the signer, and checks it is an attester it trusts.

Because only one leaf is revealed, the rest of the credential stays private. The spec also suggests the user hold several independently signed trees for the same fact, so different uses cannot be linked by the same root.

Sample code

The interface from the draft, in modern Solidity, plus the core Merkle check a validator would perform (leaf and signature encoding are implementation-defined):

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

struct Attestation {
    bytes32[] merklePath;
    bool valid;
    uint8 v;
    bytes32 r;
    bytes32 s;
    address attester;
    address recipient;
    bytes32 salt;
    bytes32 key;
    bytes32 val;
}

interface IMerkleTreeAttestation {
    function validate(Attestation calldata attestation) external returns (bool);
}

library MerkleCheck {
    function root(bytes32 leaf, bytes32[] calldata path) internal pure returns (bytes32 h) {
        h = leaf;
        for (uint256 i = 0; i < path.length; i++) {
            bytes32 p = path[i];
            h = h < p ? keccak256(abi.encodePacked(h, p)) : keccak256(abi.encodePacked(p, h));
        }
    }
}

Things to know

  • Status is Stagnant, and the spec is very short: it gives a struct and one function but does not fix the leaf hashing, tree ordering or signature format. Two implementations of "ERC-1387" may not be compatible.
  • It was designed alongside ERC-1386 (attestation management) and ERC-1388 (attester lists), which cover revocation and deciding which attesters to trust.
  • Privacy is only partial: the revealed fact, the attester and the transaction sender are all public once submitted.

#attestation #identity #merkle #privacy

Details

Authors
Weiwu Zhang <[email protected]>, James Sangalli <[email protected]>
Status
Stagnant
Type
Standards Track / ERC
Created
2018-09-08

Machine-readable: Markdown · JSON