Documentation ¶
Overview ¶
Package merkle provides Merkle tree manipulation functions.
Index ¶
- Variables
- func Rehash(h [][]byte, nf []NodeFetch, hc func(left, right []byte) []byte) ([][]byte, error)
- type ByIndex
- type HStar2
- type HStar2LeafHash
- type Leaves
- type LogVerifierdeprecated
- type NodeFetch
- type PrefetchNodeVisitor
- type RootMismatchErrordeprecated
- type SparseGetNodeFunc
- type SparseMerkleTreeReader
- type SparseSetNodeFunc
- type TXRunner
Constants ¶
This section is empty.
Variables ¶
var ErrNoSuchRevision = errors.New("no such revision")
ErrNoSuchRevision is returned when a request is made for information about a tree revision which does not exist.
var ( // ErrSubtreeOverrun indicates that a subtree exceeds the maximum tree depth. ErrSubtreeOverrun = errors.New("subtree with prefix exceeds maximum tree size") )
Functions ¶
func Rehash ¶ added in v1.3.10
Rehash computes the proof based on the slice of NodeFetch structs, and the corresponding hashes of these nodes. The slices must be of the same length. The hc parameter computes node's hash based on hashes of its children.
Warning: The passed-in slice of hashes can be modified in-place.
Types ¶
type ByIndex ¶
type ByIndex struct{ Leaves }
ByIndex implements sort.Interface by providing Less and using Len and Swap methods from the embedded Leaves value.
type HStar2 ¶
type HStar2 struct {
// contains filtered or unexported fields
}
HStar2 is a recursive implementation for calculating the root hash of a sparse Merkle tree.
func (*HStar2) HStar2Nodes ¶
func (s *HStar2) HStar2Nodes(prefix []byte, subtreeDepth int, values []*HStar2LeafHash, get SparseGetNodeFunc, set SparseSetNodeFunc) ([]byte, error)
HStar2Nodes calculates the root hash of a pre-existing sparse Merkle tree plus the extra values passed in. Get and set are used to fetch and store internal node values. Values must not contain multiple leaves for the same index.
prefix is the location of this subtree within the larger tree. Root is at nil. subtreeDepth is the number of levels in this subtree.
func (*HStar2) HStar2Root ¶
func (s *HStar2) HStar2Root(depth int, values []*HStar2LeafHash) ([]byte, error)
HStar2Root calculates the root of a sparse Merkle tree of a given depth which contains the given set of non-null leaves.
func (*HStar2) Prefetch ¶ added in v1.3.4
func (s *HStar2) Prefetch(prefix []byte, subtreeDepth int, values []*HStar2LeafHash, visit PrefetchNodeVisitor) error
Prefetch does a dry run of HStar2 algorithm, and reports all Merkle tree nodes that it needs through the passed-in visit function.
This function can be useful, for example, if the caller prefers to collect the node IDs and read them from storage in one batch. Then they can run HStar2Nodes in such a way that it reads from the prefetched set.
type HStar2LeafHash ¶
HStar2LeafHash represents a leaf for the HStar2 sparse Merkle tree implementation.
type LogVerifier
deprecated
type LogVerifier = logverifier.LogVerifier
LogVerifier verifies inclusion and consistency proofs for append only logs.
Deprecated: moved to github.com/google/trillian/merkle/logverifier package
func NewLogVerifier
deprecated
func NewLogVerifier(hasher hashers.LogHasher) LogVerifier
NewLogVerifier returns a new LogVerifier for a tree.
Deprecated: moved to github.com/google/trillian/merkle/logverifier package
type NodeFetch ¶
NodeFetch bundles a nodeID with additional information on how to use the node to construct the correct proof.
func CalcConsistencyProofNodeAddresses ¶
CalcConsistencyProofNodeAddresses returns the tree node IDs needed to build a consistency proof between two specified tree sizes. snapshot1 and snapshot2 represent the two tree sizes for which consistency should be proved, treeSize is the actual size of the tree at the revision we are using to fetch nodes (this can be > snapshot2).
The caller is responsible for checking that the input tree sizes correspond to valid tree heads. All returned NodeIDs are tree coordinates within the new tree. It is assumed that they will be fetched from storage at a revision corresponding to the STH associated with the treeSize parameter.
Use Rehash function to compose the proof after the node hashes are fetched.
func CalcInclusionProofNodeAddresses ¶
CalcInclusionProofNodeAddresses returns the tree node IDs needed to build an inclusion proof for a specified leaf and tree size. The snapshot parameter is the tree size being queried for, treeSize is the actual size of the tree at the revision we are using to fetch nodes (this can be > snapshot).
Use Rehash function to compose the proof after the node hashes are fetched.
type PrefetchNodeVisitor ¶ added in v1.3.4
PrefetchNodeVisitor reports coordinates of a Merkle tree node to prefetch.
type RootMismatchError
deprecated
type RootMismatchError = logverifier.RootMismatchError
RootMismatchError occurs when an inclusion proof fails.
Deprecated: moved to github.com/google/trillian/merkle/logverifier package
type SparseGetNodeFunc ¶
SparseGetNodeFunc should return any pre-existing node hash for the node address.
type SparseMerkleTreeReader ¶
type SparseMerkleTreeReader struct {
// contains filtered or unexported fields
}
SparseMerkleTreeReader knows how to read data from a TreeStorage transaction to provide proofs etc.
func NewSparseMerkleTreeReader ¶
func NewSparseMerkleTreeReader(rev int64, h hashers.MapHasher, tx storage.ReadOnlyTreeTX) *SparseMerkleTreeReader
NewSparseMerkleTreeReader returns a new SparseMerkleTreeReader, reading at the specified tree revision, using the passed in MapHasher for calculating and verifying tree hashes read via tx.
func (SparseMerkleTreeReader) BatchInclusionProof ¶ added in v1.3.0
func (s SparseMerkleTreeReader) BatchInclusionProof(ctx context.Context, rev int64, indices [][]byte) (map[string][][]byte, error)
BatchInclusionProof returns an inclusion (or non-inclusion) proof for each of the specified keys at the specified revision. The return value is a map of the string form of the key to the inclusion proof for that key.
func (SparseMerkleTreeReader) InclusionProof ¶
func (s SparseMerkleTreeReader) InclusionProof(ctx context.Context, rev int64, index []byte) ([][]byte, error)
InclusionProof returns an inclusion (or non-inclusion) proof for the specified key at the specified revision. If the revision does not exist it will return ErrNoSuchRevision error.
type SparseSetNodeFunc ¶
SparseSetNodeFunc should store the passed node hash, associating it with the address.
type TXRunner ¶ added in v1.3.0
type TXRunner interface { // RunTX executes f and supplies a transaction object to operate on. RunTX(ctx context.Context, f func(context.Context, storage.MapTreeTX) error) error }
TXRunner supplies the RunTX function. TXRunner can be passed as the last argument to MapStorage.ReadWriteTransaction.
TODO(pavelkalinnikov): This interface violates layering, because it assumes existence of transactions. It must be part of the storage package.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package compact provides compact Merkle tree data structures.
|
Package compact provides compact Merkle tree data structures. |
Package coniks provides CONIKS hashing for maps.
|
Package coniks provides CONIKS hashing for maps. |
hasher
Package hasher provides CONIKS hashing for maps.
|
Package hasher provides CONIKS hashing for maps. |
registry
Package registry provides a global registry for hasher implementations.
|
Package registry provides a global registry for hasher implementations. |
Package maphasher provides hashing for maps.
|
Package maphasher provides hashing for maps. |
Package rfc6962 provides hashing functionality according to RFC6962.
|
Package rfc6962 provides hashing functionality according to RFC6962. |
hasher
Package hasher provides hashing functionality according to RFC6962.
|
Package hasher provides hashing functionality according to RFC6962. |
Package smt contains the implementation of the sparse Merkle tree logic.
|
Package smt contains the implementation of the sparse Merkle tree logic. |
Package testonly contains code and data for testing Merkle trees.
|
Package testonly contains code and data for testing Merkle trees. |