merkle

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package merkle provides Sia-specific Merkle tree utilities.

Index

Constants

View Source
const (
	// SegmentSize is the number of bytes in each leaf node of a sector's Merkle
	// tree. Although "LeafSize" would be a more accurate term, Sia refers to
	// leaves as "segments", so we will follow suit.
	SegmentSize = crypto.HashSize * 2

	// SegmentsPerSector is a convenience value.
	SegmentsPerSector = renterhost.SectorSize / SegmentSize
)

Variables

This section is empty.

Functions

func BuildDiffProof

func BuildDiffProof(actions []renterhost.RPCWriteAction, sectorRoots []crypto.Hash) (treeHashes, leafHashes []crypto.Hash)

BuildDiffProof constructs a diff proof for the specified actions. ActionUpdate is not supported.

func BuildProof

func BuildProof(sector *[renterhost.SectorSize]byte, start, end int, precalc func(i, j int) crypto.Hash) []crypto.Hash

BuildProof constructs a proof for the segment range [start, end). If a non- nil precalc function is provided, it will be used to supply precalculated subtree Merkle roots. For example, if the root of the left half of the Merkle tree is precomputed, precalc should return it for i == 0 and j == SegmentsPerSector/2. If a precalculated root is not available, precalc should return the zero hash.

func BuildSectorRangeProof

func BuildSectorRangeProof(sectorRoots []crypto.Hash, start, end int) []crypto.Hash

BuildSectorRangeProof constructs a proof for the sector range [start, end).

func DiffProofSize

func DiffProofSize(actions []renterhost.RPCWriteAction, numLeaves int) int

DiffProofSize returns the size of a diff proof for the specified actions.

func MetaRoot

func MetaRoot(roots []crypto.Hash) crypto.Hash

MetaRoot calculates the root of a set of existing Merkle roots.

func ProofSize

func ProofSize(n, start, end int) int

ProofSize returns the size of a Merkle proof for the leaf range [start, end) within a tree containing n leaves.

func SectorRoot

func SectorRoot(sector *[renterhost.SectorSize]byte) crypto.Hash

SectorRoot computes the Merkle root of a sector using SegmentSize bytes per leaf.

func VerifyDiffProof

func VerifyDiffProof(actions []renterhost.RPCWriteAction, numLeaves int, treeHashes, leafHashes []crypto.Hash, oldRoot, newRoot crypto.Hash) bool

VerifyDiffProof verifies a proof produced by BuildDiffProof. ActionUpdate is not supported.

func VerifyProof

func VerifyProof(proof []crypto.Hash, segments []byte, start, end int, root crypto.Hash) bool

VerifyProof verifies a proof produced by BuildProof. Only sector-sized proofs can be verified.

func VerifySectorRangeProof

func VerifySectorRangeProof(proof []crypto.Hash, rangeRoots []crypto.Hash, start, end, numRoots int, root crypto.Hash) bool

VerifySectorRangeProof verifies a proof produced by BuildSectorRangeProof.

Types

This section is empty.

Jump to

Keyboard shortcuts

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