Documentation ¶
Overview ¶
Package stateutil defines utility functions to compute state roots using advanced merkle branch caching techniques.
Index ¶
- func AddInMixin(root [32]byte, length uint64) ([32]byte, error)
- func BlockBodyRoot(body *ethpb.BeaconBlockBody) ([32]byte, error)
- func BlockHeaderRoot(header *ethpb.BeaconBlockHeader) ([32]byte, error)
- func BlockRoot(blk *ethpb.BeaconBlock) ([32]byte, error)
- func CheckpointRoot(hasher HashFn, checkpoint *ethpb.Checkpoint) ([32]byte, error)
- func ComputeFieldRoots(state *pb.BeaconState) ([][]byte, error)
- func ConstructProof(hasher Hasher, count uint64, limit uint64, leaf func(i uint64) []byte, ...) (branch [][32]byte)
- func EpochAttestationsRoot(atts []*pb.PendingAttestation) ([32]byte, error)
- func Eth1DataVotesRoot(eth1DataVotes []*ethpb.Eth1Data) ([32]byte, error)
- func Eth1Root(hasher HashFn, eth1Data *ethpb.Eth1Data) ([32]byte, error)
- func ForkRoot(fork *pb.Fork) ([32]byte, error)
- func GetDepth(v uint64) (out uint8)
- func HashTreeRootState(state *pb.BeaconState) ([32]byte, error)
- func HistoricalRootsRoot(historicalRoots [][]byte) ([32]byte, error)
- func Merkleize(hasher Hasher, count uint64, limit uint64, leaf func(i uint64) []byte) (out [32]byte)
- func PendingAttestationRoot(hasher HashFn, att *pb.PendingAttestation) ([32]byte, error)
- func RecomputeFromLayer(changedLeaves [][32]byte, changedIdx []uint64, layer [][]*[32]byte) ([32]byte, [][]*[32]byte, error)
- func RecomputeFromLayerVariable(changedLeaves [][32]byte, changedIdx []uint64, layer [][]*[32]byte) ([32]byte, [][]*[32]byte, error)
- func ReturnTrieLayer(elements [][32]byte, length uint64) [][]*[32]byte
- func ReturnTrieLayerVariable(elements [][32]byte, length uint64) [][]*[32]byte
- func RootsArrayHashTreeRoot(vals [][]byte, length uint64, fieldName string) ([32]byte, error)
- func SlashingsRoot(slashings []uint64) ([32]byte, error)
- func Uint64Root(val uint64) [32]byte
- func ValidatorBalancesRoot(balances []uint64) ([32]byte, error)
- func ValidatorRegistryRoot(vals []*ethpb.Validator) ([32]byte, error)
- func ValidatorRoot(hasher HashFn, validator *ethpb.Validator) ([32]byte, error)
- type HashFn
- type Hasher
- type HasherFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddInMixin ¶ added in v0.3.5
AddInMixin describes a method from which a lenth mixin is added to the provided root.
func BlockBodyRoot ¶ added in v0.3.9
func BlockBodyRoot(body *ethpb.BeaconBlockBody) ([32]byte, error)
BlockBodyRoot returns the hash tree root of the block body.
func BlockHeaderRoot ¶
func BlockHeaderRoot(header *ethpb.BeaconBlockHeader) ([32]byte, error)
BlockHeaderRoot computes the HashTreeRoot Merkleization of a BeaconBlockHeader struct according to the eth2 Simple Serialize specification.
func BlockRoot ¶ added in v0.3.9
func BlockRoot(blk *ethpb.BeaconBlock) ([32]byte, error)
BlockRoot returns the block hash tree root of the provided block.
func CheckpointRoot ¶
func CheckpointRoot(hasher HashFn, checkpoint *ethpb.Checkpoint) ([32]byte, error)
CheckpointRoot computes the HashTreeRoot Merkleization of a InitWithReset struct value according to the eth2 Simple Serialize specification.
func ComputeFieldRoots ¶
func ComputeFieldRoots(state *pb.BeaconState) ([][]byte, error)
ComputeFieldRoots returns the hash tree root computations of every field in the beacon state as a list of 32 byte roots.
func ConstructProof ¶ added in v0.3.9
func ConstructProof(hasher Hasher, count uint64, limit uint64, leaf func(i uint64) []byte, index uint64) (branch [][32]byte)
ConstructProof builds a merkle-branch of the given depth, at the given index (at that depth), for a list of leafs of a balanced binary tree.
func EpochAttestationsRoot ¶
func EpochAttestationsRoot(atts []*pb.PendingAttestation) ([32]byte, error)
EpochAttestationsRoot computes the HashTreeRoot Merkleization of a list of pending attestation values according to the eth2 Simple Serialize specification.
func Eth1DataVotesRoot ¶
Eth1DataVotesRoot computes the HashTreeRoot Merkleization of a list of Eth1Data structs according to the eth2 Simple Serialize specification.
func Eth1Root ¶
Eth1Root computes the HashTreeRoot Merkleization of a BeaconBlockHeader struct according to the eth2 Simple Serialize specification.
func ForkRoot ¶
ForkRoot computes the HashTreeRoot Merkleization of a Fork struct value according to the eth2 Simple Serialize specification.
func GetDepth ¶ added in v0.3.9
GetDepth retrieves the appropriate depth for the provided trie size.
func HashTreeRootState ¶
func HashTreeRootState(state *pb.BeaconState) ([32]byte, error)
HashTreeRootState provides a fully-customized version of ssz.HashTreeRoot for the BeaconState type of the official Ethereum Serenity specification. The reason for this particular function is to optimize for speed and memory allocation at the expense of complete specificity (that is, this function can only be used on the Prysm BeaconState data structure).
func HistoricalRootsRoot ¶
HistoricalRootsRoot computes the HashTreeRoot Merkleization of a list of [32]byte historical block roots according to the eth2 Simple Serialize specification.
func Merkleize ¶ added in v0.3.9
func Merkleize(hasher Hasher, count uint64, limit uint64, leaf func(i uint64) []byte) (out [32]byte)
Merkleize with log(N) space allocation
func PendingAttestationRoot ¶ added in v0.3.5
func PendingAttestationRoot(hasher HashFn, att *pb.PendingAttestation) ([32]byte, error)
PendingAttestationRoot describes a method from which the hash tree root of a pending attestation is returned.
func RecomputeFromLayer ¶ added in v0.3.5
func RecomputeFromLayer(changedLeaves [][32]byte, changedIdx []uint64, layer [][]*[32]byte) ([32]byte, [][]*[32]byte, error)
RecomputeFromLayer recomputes specific branches of a fixed sized trie depending on the provided changed indexes.
func RecomputeFromLayerVariable ¶ added in v0.3.5
func RecomputeFromLayerVariable(changedLeaves [][32]byte, changedIdx []uint64, layer [][]*[32]byte) ([32]byte, [][]*[32]byte, error)
RecomputeFromLayerVariable recomputes specific branches of a variable sized trie depending on the provided changed indexes.
func ReturnTrieLayer ¶ added in v0.3.5
ReturnTrieLayer returns the representation of a merkle trie when provided with the elements of a fixed sized trie and the corresponding depth of it.
func ReturnTrieLayerVariable ¶ added in v0.3.5
ReturnTrieLayerVariable returns the representation of a merkle trie when provided with the elements of a variable sized trie and the corresponding depth of it.
func RootsArrayHashTreeRoot ¶
RootsArrayHashTreeRoot computes the Merkle root of arrays of 32-byte hashes, such as [64][32]byte according to the Simple Serialize specification of eth2.
func SlashingsRoot ¶
SlashingsRoot computes the HashTreeRoot Merkleization of a list of uint64 slashing values according to the eth2 Simple Serialize specification.
func Uint64Root ¶
Uint64Root computes the HashTreeRoot Merkleization of a simple uint64 value according to the eth2 Simple Serialize specification.
func ValidatorBalancesRoot ¶
ValidatorBalancesRoot computes the HashTreeRoot Merkleization of a list of validator uint64 balances according to the eth2 Simple Serialize specification.
func ValidatorRegistryRoot ¶
ValidatorRegistryRoot computes the HashTreeRoot Merkleization of a list of validator structs according to the eth2 Simple Serialize specification.
Types ¶
type Hasher ¶ added in v0.3.9
type Hasher interface { Hash(a []byte) [32]byte Combi(a [32]byte, b [32]byte) [32]byte MixIn(a [32]byte, i uint64) [32]byte }
Hasher describes an interface through which we can perform hash operations on byte arrays,indices,etc.
type HasherFunc ¶ added in v0.3.9
type HasherFunc struct {
// contains filtered or unexported fields
}
func NewHasherFunc ¶ added in v0.3.9
func NewHasherFunc(h HashFn) *HasherFunc
NewHasherFunc is the constructor for the object that fulfills the Hasher interface.
func (*HasherFunc) Combi ¶ added in v0.3.9
func (h *HasherFunc) Combi(a [32]byte, b [32]byte) [32]byte
func (*HasherFunc) Hash ¶ added in v0.3.9
func (h *HasherFunc) Hash(a []byte) [32]byte
Hash utilizes the provided hash function for the object.