merkle

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package merkle provides functionality for creating and manipulating Merkle trees, with a focus on efficient and secure verification of data integrity.

The package offers tools for constructing Merkle trees, managing tree nodes, and generating and verifying Merkle proofs. It includes constants for default tree depth and empty leaf values. Key features include the ability to create new empty trees, set leaf values, retrieve proofs, and calculate the root hash of the tree.

Additionally, the package provides a hash function for big integers and utility functions for navigating the Merkle tree structure, such as obtaining parent and sibling indices and determining whether a node is a right child.

Note: The package assumes the use of 256-bit integers for node values.

Index

Constants

View Source
const TreeDepth = 32

Variables

View Source
var EmptyLeafValue = new(uint256.Int).Mod(
	uint256.MustFromBig(new(big.Int).SetBytes(makeSeedForEmptyLeaf())),
	uint256.MustFromBig(ff.Modulus()),
)

Functions

func GetParentIndex

func GetParentIndex(i int) int

func GetSiblingIndex

func GetSiblingIndex(i int) int

func HashFunc

func HashFunc(input []*big.Int) (*big.Int, error)

func IsRightChild

func IsRightChild(i int) bool

Types

type Proof

type Proof struct {
	Leaf      TreeNode   `json:"leaf"`      // The Merkle tree node, which authenticity is proved by the Path.
	LeafIndex int        `json:"leafIndex"` // Index of the Leaf in the Merkle tree.
	Path      []TreeNode `json:"path"`
}

type Tree

type Tree struct {
	Nodes []TreeNode
}

func NewEmptyTree

func NewEmptyTree(depth int, leafValue *uint256.Int) (*Tree, error)

func (*Tree) GetLeavesAmount

func (t *Tree) GetLeavesAmount() int

func (*Tree) GetProof

func (t *Tree) GetProof(i int) (Proof, error)

func (*Tree) Root

func (t *Tree) Root() TreeNode

func (*Tree) SetLeaf

func (t *Tree) SetLeaf(i int, val TreeNode) error

type TreeNode

type TreeNode struct {
	Value *uint256.Int
}

func (TreeNode) MarshalText

func (n TreeNode) MarshalText() (text []byte, err error)

func (*TreeNode) UnmarshalText

func (n *TreeNode) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL