mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
d17996f8b0
* Update V3 from V4 * Fix build v3 -> v4 * Update ssz * Update beacon_chain.pb.go * Fix formatter import * Update update-mockgen.sh comment to v4 * Fix conflicts. Pass build and tests * Fix test
39 lines
834 B
Go
39 lines
834 B
Go
package stateutil
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/ssz"
|
|
)
|
|
|
|
func ArraysRoot(input [][]byte, length uint64) ([32]byte, error) {
|
|
leaves := make([][32]byte, length)
|
|
for i, chunk := range input {
|
|
copy(leaves[i][:], chunk)
|
|
}
|
|
res, err := merkleize(leaves, length)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
|
|
return res, nil
|
|
}
|
|
|
|
func merkleize(leaves [][32]byte, length uint64) ([32]byte, error) {
|
|
if len(leaves) == 0 {
|
|
return [32]byte{}, errors.New("zero leaves provided")
|
|
}
|
|
if len(leaves) == 1 {
|
|
return leaves[0], nil
|
|
}
|
|
hashLayer := leaves
|
|
layers := make([][][32]byte, ssz.Depth(length)+1)
|
|
layers[0] = hashLayer
|
|
var err error
|
|
_, hashLayer, err = MerkleizeTrieLeaves(layers, hashLayer)
|
|
if err != nil {
|
|
return [32]byte{}, err
|
|
}
|
|
root := hashLayer[0]
|
|
return root, nil
|
|
}
|