Documentation ¶
Index ¶
- func EmptyLeaf() types.Bytes32
- func GnarkRecoverRoot(api frontend.API, proof GnarkProof, leaf frontend.Variable, h hash.FieldHasher) frontend.Variable
- func GnarkVerifyMerkleProof(api frontend.API, proof GnarkProof, leaf frontend.Variable, ...)
- type Config
- type GnarkProof
- type Proof
- type ProvedClaim
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GnarkRecoverRoot ¶
func GnarkRecoverRoot( api frontend.API, proof GnarkProof, leaf frontend.Variable, h hash.FieldHasher) frontend.Variable
GnarkRecoverRoot is as [RecoverRoot] in a gnark circuit. The provided position is range-checked against the number of siblings in the Merkle proof object.
func GnarkVerifyMerkleProof ¶
func GnarkVerifyMerkleProof( api frontend.API, proof GnarkProof, leaf frontend.Variable, root frontend.Variable, h hash.FieldHasher)
GnarkVerifyMerkleProof asserts the validity of a GnarkProof against a root.
Types ¶
type Config ¶
type Config struct { // HashFunc is a function returning initialized hashers HashFunc func() hashtypes.Hasher // Depth is the depth of the tree Depth int }
Config specifies the parameters of the tree (choice of hash function, depth).
type GnarkProof ¶
GnarkProof mirrors Proof in a gnark circuit.
type Proof ¶
type Proof struct { Path int `json:"leafIndex"` // Position of the leaf Siblings []types.Bytes32 `json:"siblings"` // length 40 }
Proof represents a Merkle proof of membership for the Merkle-tree
func (*Proof) RecoverRoot ¶
RecoverRoot returns the root recovered from the Merkle proof.
type ProvedClaim ¶
ProvedClaim is the composition of a proof with the claim it proves.
type Tree ¶
type Tree struct { // Config of the hash function Config *Config // Root stores the root of the tree Root types.Bytes32 // OccupiedLeaves continuously list of the occupied leaves. For the toy // implementation we track all the leaves. OccupiedLeaves []types.Bytes32 // Occupied not stores all the node with a non-trivial value in the tree. // // Does not include the root. (So there are 39 levels and not 40). // Returns a node at a given level: // - 0 is the level just above the leaves // - 38 is the level just below the root OccupiedNodes [][]types.Bytes32 // EmptyNodes stores the value of the trivial nodes of the SMT (i.e the one // corresponding to empty sub-trees). // // It does not include the "empty root" nor the empty leaf // so the first position contains the empty node for the level one. // So there are 39, and not 40 levels. That way, the indexing stays // consistent with "OccupiedNode" EmptyNodes []types.Bytes32 }
Tree represents a binary sparse Merkle-tree (SMT).
func BuildComplete ¶
BuildComplete builds from scratch a complete Merkle-tree. Requires that the input leaves are powers of 2. The depth of the tree is deduced from the list.
It panics if the number of leaves is a non-power of 2.
func NewEmptyTree ¶
NewEmptyTree creates and returns an empty tree with the provided config.
func (*Tree) MustGetLeaf ¶
MustGetLeaf is as Tree.GetLeaf but panics on errors.
func (*Tree) MustProve ¶
MustProve runs Tree.Prove and panics on error