depositsnapshot

package
v4.0.5 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: GPL-3.0 Imports: 7 Imported by: 2

Documentation

Overview

Package depositsnapshot implements the EIP-4881 standard for minimal sparse Merkle tree. The format proposed by the EIP allows for the pruning of deposits that are no longer needed to participate fully in consensus. Full EIP-4881 specification can be found here: https://eips.ethereum.org/EIPS/eip-4881

Code generated by gen_zerohashes. DO NOT EDIT.

Index

Constants

View Source
const (
	// DepositContractDepth is the maximum tree depth as defined by EIP-4881.
	DepositContractDepth = 32
)

Variables

View Source
var (
	// ErrEmptyExecutionBlock occurs when the execution block is nil.
	ErrEmptyExecutionBlock = errors.New("empty execution block")
	// ErrInvalidSnapshotRoot occurs when the snapshot root does not match the calculated root.
	ErrInvalidSnapshotRoot = errors.New("snapshot root is invalid")
	// ErrInvalidMixInLength occurs when the value for mix in length is 0.
	ErrInvalidMixInLength = errors.New("mixInLength should be greater than 0")
	// ErrInvalidIndex occurs when the index is less than the number of finalized deposits.
	ErrInvalidIndex = errors.New("index should be greater than finalizedDeposits - 1")
	// ErrNoDeposits occurs when the number of deposits is 0.
	ErrNoDeposits = errors.New("number of deposits should be greater than 0")
	// ErrTooManyDeposits occurs when the number of deposits exceeds the capacity of the tree.
	ErrTooManyDeposits = errors.New("number of deposits should not be greater than the capacity of the tree")
)
View Source
var (
	// ErrFinalizedNodeCannotPushLeaf may occur when attempting to push a leaf to a finalized node. When a node is finalized, it cannot be modified or changed.
	ErrFinalizedNodeCannotPushLeaf = errors.New("can't push a leaf to a finalized node")
	// ErrLeafNodeCannotPushLeaf may occur when attempting to push a leaf to a leaf node.
	ErrLeafNodeCannotPushLeaf = errors.New("can't push a leaf to a leaf node")
	// ErrZeroLevel occurs when the value of level is 0.
	ErrZeroLevel = errors.New("level should be greater than 0")
	// ErrZeroDepth occurs when the value of depth is 0.
	ErrZeroDepth = errors.New("depth should be greater than 0")
)
View Source
var (
	// ErrZeroIndex occurs when the value of index is 0.
	ErrZeroIndex = errors.New("index should be greater than 0")
)
View Source
var Zerohashes = [][32]byte{

	{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},

	{245, 165, 253, 66, 209, 106, 32, 48, 39, 152, 239, 110, 211, 9, 151, 155, 67, 0, 61, 35, 32, 217, 240, 232, 234, 152, 49, 169, 39, 89, 251, 75},

	{219, 86, 17, 78, 0, 253, 212, 193, 248, 92, 137, 43, 243, 90, 201, 168, 146, 137, 170, 236, 177, 235, 208, 169, 108, 222, 96, 106, 116, 139, 93, 113},

	{199, 128, 9, 253, 240, 127, 197, 106, 17, 241, 34, 55, 6, 88, 163, 83, 170, 165, 66, 237, 99, 228, 76, 75, 193, 95, 244, 205, 16, 90, 179, 60},

	{83, 109, 152, 131, 127, 45, 209, 101, 165, 93, 94, 234, 233, 20, 133, 149, 68, 114, 213, 111, 36, 109, 242, 86, 191, 60, 174, 25, 53, 42, 18, 60},

	{158, 253, 224, 82, 170, 21, 66, 159, 174, 5, 186, 212, 208, 177, 215, 198, 77, 166, 77, 3, 215, 161, 133, 74, 88, 140, 44, 184, 67, 12, 13, 48},

	{216, 141, 223, 238, 212, 0, 168, 117, 85, 150, 178, 25, 66, 193, 73, 126, 17, 76, 48, 46, 97, 24, 41, 15, 145, 230, 119, 41, 118, 4, 31, 161},

	{135, 235, 13, 219, 165, 126, 53, 246, 210, 134, 103, 56, 2, 164, 175, 89, 117, 226, 37, 6, 199, 207, 76, 100, 187, 107, 229, 238, 17, 82, 127, 44},

	{38, 132, 100, 118, 253, 95, 197, 74, 93, 67, 56, 81, 103, 201, 81, 68, 242, 100, 63, 83, 60, 200, 91, 185, 209, 107, 120, 47, 141, 125, 177, 147},

	{80, 109, 134, 88, 45, 37, 36, 5, 184, 64, 1, 135, 146, 202, 210, 191, 18, 89, 241, 239, 90, 165, 248, 135, 225, 60, 178, 240, 9, 79, 81, 225},

	{255, 255, 10, 215, 230, 89, 119, 47, 149, 52, 193, 149, 200, 21, 239, 196, 1, 78, 241, 225, 218, 237, 68, 4, 192, 99, 133, 209, 17, 146, 233, 43},

	{108, 240, 65, 39, 219, 5, 68, 28, 216, 51, 16, 122, 82, 190, 133, 40, 104, 137, 14, 67, 23, 230, 160, 42, 180, 118, 131, 170, 117, 150, 66, 32},

	{183, 208, 95, 135, 95, 20, 0, 39, 239, 81, 24, 162, 36, 123, 187, 132, 206, 143, 47, 15, 17, 35, 98, 48, 133, 218, 247, 150, 12, 50, 159, 95},

	{223, 106, 245, 245, 187, 219, 107, 233, 239, 138, 166, 24, 228, 191, 128, 115, 150, 8, 103, 23, 30, 41, 103, 111, 139, 40, 77, 234, 106, 8, 168, 94},

	{181, 141, 144, 15, 94, 24, 46, 60, 80, 239, 116, 150, 158, 161, 108, 119, 38, 197, 73, 117, 124, 194, 53, 35, 195, 105, 88, 125, 167, 41, 55, 132},

	{212, 154, 117, 2, 255, 207, 176, 52, 11, 29, 120, 133, 104, 133, 0, 202, 48, 129, 97, 167, 249, 107, 98, 223, 157, 8, 59, 113, 252, 200, 242, 187},

	{143, 230, 177, 104, 146, 86, 192, 211, 133, 244, 47, 91, 190, 32, 39, 162, 44, 25, 150, 225, 16, 186, 151, 193, 113, 211, 229, 148, 141, 233, 43, 235},

	{141, 13, 99, 195, 158, 186, 222, 133, 9, 224, 174, 60, 156, 56, 118, 251, 95, 161, 18, 190, 24, 249, 5, 236, 172, 254, 203, 146, 5, 118, 3, 171},

	{149, 238, 200, 178, 229, 65, 202, 212, 233, 29, 227, 131, 133, 242, 224, 70, 97, 159, 84, 73, 108, 35, 130, 203, 108, 172, 213, 185, 140, 38, 245, 164},

	{248, 147, 233, 8, 145, 119, 117, 182, 43, 255, 35, 41, 77, 187, 227, 161, 205, 142, 108, 193, 195, 91, 72, 1, 136, 123, 100, 106, 111, 129, 241, 127},

	{205, 219, 167, 181, 146, 227, 19, 51, 147, 193, 97, 148, 250, 199, 67, 26, 191, 47, 84, 133, 237, 113, 29, 178, 130, 24, 60, 129, 158, 8, 235, 170},

	{138, 141, 127, 227, 175, 140, 170, 8, 90, 118, 57, 168, 50, 0, 20, 87, 223, 185, 18, 138, 128, 97, 20, 42, 208, 51, 86, 41, 255, 35, 255, 156},

	{254, 179, 195, 55, 215, 165, 26, 111, 191, 0, 185, 227, 76, 82, 225, 201, 25, 92, 150, 155, 212, 231, 160, 191, 213, 29, 92, 91, 237, 156, 17, 103},

	{231, 31, 10, 168, 60, 195, 46, 223, 190, 250, 159, 77, 62, 1, 116, 202, 133, 24, 46, 236, 159, 58, 9, 246, 166, 192, 223, 99, 119, 165, 16, 215},

	{49, 32, 111, 168, 10, 80, 187, 106, 190, 41, 8, 80, 88, 241, 98, 18, 33, 42, 96, 238, 200, 240, 73, 254, 203, 146, 216, 200, 224, 168, 75, 192},

	{33, 53, 43, 254, 203, 237, 221, 233, 147, 131, 159, 97, 76, 61, 172, 10, 62, 227, 117, 67, 249, 180, 18, 177, 97, 153, 220, 21, 142, 35, 181, 68},

	{97, 158, 49, 39, 36, 187, 109, 124, 49, 83, 237, 157, 231, 145, 215, 100, 163, 102, 179, 137, 175, 19, 197, 139, 248, 168, 217, 4, 129, 164, 103, 101},

	{124, 221, 41, 134, 38, 130, 80, 98, 141, 12, 16, 227, 133, 197, 140, 97, 145, 230, 251, 224, 81, 145, 188, 192, 79, 19, 63, 44, 234, 114, 193, 196},

	{132, 137, 48, 189, 123, 168, 202, 197, 70, 97, 7, 33, 19, 251, 39, 136, 105, 224, 123, 184, 88, 127, 145, 57, 41, 51, 55, 77, 1, 123, 203, 225},

	{136, 105, 255, 44, 34, 178, 140, 193, 5, 16, 217, 133, 50, 146, 128, 51, 40, 190, 79, 176, 232, 4, 149, 232, 187, 141, 39, 31, 91, 136, 150, 54},

	{181, 254, 40, 231, 159, 27, 133, 15, 134, 88, 36, 108, 233, 182, 161, 231, 180, 159, 192, 109, 183, 20, 62, 143, 224, 180, 242, 176, 197, 82, 58, 92},

	{152, 94, 146, 159, 112, 175, 40, 208, 189, 209, 169, 10, 128, 143, 151, 127, 89, 124, 124, 119, 140, 72, 158, 152, 211, 189, 137, 16, 211, 26, 192, 247},
}

Functions

This section is empty.

Types

type DepositTree

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

DepositTree is the Merkle tree representation of deposits.

func New

func New() *DepositTree

New creates an empty deposit tree.

type DepositTreeSnapshot

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

DepositTreeSnapshot represents the data used to create a deposit tree given a snapshot.

func (*DepositTreeSnapshot) CalculateRoot

func (ds *DepositTreeSnapshot) CalculateRoot() ([32]byte, error)

CalculateRoot returns the root of a deposit tree snapshot.

type FinalizedNode

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

FinalizedNode represents a finalized node and satisfies the MerkleTreeNode interface.

func (*FinalizedNode) Finalize

func (f *FinalizedNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)

Finalize marks deposits of the Merkle tree as finalized.

func (*FinalizedNode) GetFinalized

func (f *FinalizedNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)

GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.

func (*FinalizedNode) GetRoot

func (f *FinalizedNode) GetRoot() [32]byte

GetRoot returns the root of the Merkle tree.

func (*FinalizedNode) IsFull

func (_ *FinalizedNode) IsFull() bool

IsFull returns whether there is space left for deposits. A FinalizedNode will always return true as by definition it is full and deposits can't be added to it.

func (*FinalizedNode) Left

func (_ *FinalizedNode) Left() MerkleTreeNode

Left returns nil as a finalized node can't have any children.

func (*FinalizedNode) PushLeaf

func (_ *FinalizedNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)

PushLeaf adds a new leaf node at the next available zero node.

func (*FinalizedNode) Right

func (_ *FinalizedNode) Right() MerkleTreeNode

Right returns nil as a finalized node can't have any children.

type InnerNode

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

InnerNode represents an inner node with two children and satisfies the MerkleTreeNode interface.

func (*InnerNode) Finalize

func (n *InnerNode) Finalize(depositsToFinalize uint64, depth uint64) (_ MerkleTreeNode, err error)

Finalize marks deposits of the Merkle tree as finalized.

func (*InnerNode) GetFinalized

func (n *InnerNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)

GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.

func (*InnerNode) GetRoot

func (n *InnerNode) GetRoot() [32]byte

GetRoot returns the root of the Merkle tree.

func (*InnerNode) IsFull

func (n *InnerNode) IsFull() bool

IsFull returns whether there is space left for deposits.

func (*InnerNode) Left

func (n *InnerNode) Left() MerkleTreeNode

Left returns the child node on the left.

func (*InnerNode) PushLeaf

func (n *InnerNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)

PushLeaf adds a new leaf node at the next available zero node.

func (*InnerNode) Right

func (n *InnerNode) Right() MerkleTreeNode

Right returns the child node on the right.

type LeafNode

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

LeafNode represents a leaf node holding a deposit and satisfies the MerkleTreeNode interface.

func (*LeafNode) Finalize

func (l *LeafNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)

Finalize marks deposits of the Merkle tree as finalized.

func (*LeafNode) GetFinalized

func (_ *LeafNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)

GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.

func (*LeafNode) GetRoot

func (l *LeafNode) GetRoot() [32]byte

GetRoot returns the root of the Merkle tree.

func (*LeafNode) IsFull

func (_ *LeafNode) IsFull() bool

IsFull returns whether there is space left for deposits. A LeafNode will always return true as it is the last node in the tree and therefore can't have any deposits added to it.

func (*LeafNode) Left

func (_ *LeafNode) Left() MerkleTreeNode

Left returns nil as a leaf node is the last node and can't have any children.

func (*LeafNode) PushLeaf

func (_ *LeafNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)

PushLeaf adds a new leaf node at the next available zero node.

func (*LeafNode) Right

func (_ *LeafNode) Right() MerkleTreeNode

Right returns nil as a leaf node is the last node and can't have any children.

type MerkleTreeNode

type MerkleTreeNode interface {
	// GetRoot returns the root of the Merkle tree.
	GetRoot() [32]byte
	// IsFull returns whether there is space left for deposits.
	IsFull() bool
	// Finalize marks deposits of the Merkle tree as finalized.
	Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
	// GetFinalized returns the number of deposits and a list of hashes of all the finalized nodes.
	GetFinalized(result [][32]byte) (uint64, [][32]byte)
	// PushLeaf adds a new leaf node at the next available Zero node.
	PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)

	// Right represents the right child of a node.
	Right() MerkleTreeNode
	// Left represents the left child of a node.
	Left() MerkleTreeNode
}

MerkleTreeNode is the interface for a Merkle tree.

type ZeroNode

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

ZeroNode represents an empty node without a deposit and satisfies the MerkleTreeNode interface.

func (*ZeroNode) Finalize

func (_ *ZeroNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)

Finalize marks deposits of the Merkle tree as finalized.

func (*ZeroNode) GetFinalized

func (_ *ZeroNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)

GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.

func (*ZeroNode) GetRoot

func (z *ZeroNode) GetRoot() [32]byte

GetRoot returns the root of the Merkle tree.

func (*ZeroNode) IsFull

func (_ *ZeroNode) IsFull() bool

IsFull returns wh ether there is space left for deposits. A ZeroNode will always return false as a ZeroNode is an empty node that gets replaced by a deposit.

func (*ZeroNode) Left

func (_ *ZeroNode) Left() MerkleTreeNode

Left returns nil as a zero node can't have any children.

func (*ZeroNode) PushLeaf

func (_ *ZeroNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)

PushLeaf adds a new leaf node at the next available zero node.

func (*ZeroNode) Right

func (_ *ZeroNode) Right() MerkleTreeNode

Right returns nil as a zero node can't have any children.

Jump to

Keyboard shortcuts

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