merged_mining_tree

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: ISC Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const HashSizeBytes = 32

Variables

View Source
var (
	ErrInvalidShardPosition   = errors.New("specified shard position does not correspond to the expected tree conf")
	ErrValidation             = errors.New("validation error")
	ErrRootIsNil              = errors.New("root is nil")
	ErrLeafIsNil              = errors.New("leaf is nil")
	ErrInvalidMerkleProofPath = errors.New("invalid merkle proof path")
)
View Source
var (
	// MagicHash.
	// Used to bound the orange tree.
	// See the WP for the details.
	MH = slot{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
)

Functions

This section is empty.

Types

type BinHash

type BinHash [HashSizeBytes]byte

BinHash represents 32 bytes long hash. (agnostic to the hash function)

type SparseMerkleTree

type SparseMerkleTree struct {
	// contains filtered or unexported fields
}

func NewSparseMerkleTree

func NewSparseMerkleTree(shardsCount uint32) (tree *SparseMerkleTree)

func (*SparseMerkleTree) CatalanNumbersCoding

func (tree *SparseMerkleTree) CatalanNumbersCoding() (coding []byte, bitsCoded uint32, err error)

CatalanNumbersCoding returns binary (BigEndian) coded orange tree, that is a subset of the current merkle tree. The coding format is the next: <orange tree structure coding>, <sequence of hashes of the orange tree>. Orange tree structure consists of ~2 bits info per node and 1 bit that defines if the node is MH or not.

This data is packed into bits slice and is aligned to the 8 bits (one byte).

Sequence of hashes of the orange tree is a simple bytes slice which is filled with the hashes of the nodes of the orange tree in the same order as they are located in the structure coding sequence.

func (*SparseMerkleTree) DropShardHash

func (tree *SparseMerkleTree) DropShardHash(position uint32) (err error)

DropShardHash deletes shard's hash into slot with position = "position", making slot empty. Returns ErrInvalidShardPosition in case if passed position does not correspond to current tree structure.

Note: this method is lazy. Setting the shard's hash would not lead to root recalculation until Root() would not be called.

func (*SparseMerkleTree) Height

func (tree *SparseMerkleTree) Height() uint16

Returns height of the tree including root level.

func (*SparseMerkleTree) HeightWithoutRoot

func (tree *SparseMerkleTree) HeightWithoutRoot() uint16

func (*SparseMerkleTree) MarshalOrangeTreeLeafs

func (tree *SparseMerkleTree) MarshalOrangeTreeLeafs() (data []byte)

func (*SparseMerkleTree) MerkleProofPath added in v1.0.6

func (tree *SparseMerkleTree) MerkleProofPath(position uint32) (pathData []byte, err error)

func (*SparseMerkleTree) Root

func (tree *SparseMerkleTree) Root() (root BinHash, err error)

func (*SparseMerkleTree) SetShardHash

func (tree *SparseMerkleTree) SetShardHash(position uint32, hash [32]byte) (err error)

SetShardHash copies shard's hash into slot with position = "position". Returns ErrInvalidShardPosition in case if passed position does not correspond to current tree structure.

Note: this method is lazy. Setting the shard's hash would not lead to root recalculation until Root() would not be called.

func (*SparseMerkleTree) Validate

func (tree *SparseMerkleTree) Validate(
	position uint32, merkleProofPath, expectedShardHash, expectedRoot []byte,
	codingBitsSize uint32, coding, hashes []byte, mmNumber uint32) (err error)

Jump to

Keyboard shortcuts

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