mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
57bcbaa21f
* Correct naming of hash func in Eth2 * Customizable mode of operation for Caplin
27 lines
688 B
Go
27 lines
688 B
Go
package utils
|
|
|
|
import (
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
)
|
|
|
|
// Check if leaf at index verifies against the Merkle root and branch
|
|
func IsValidMerkleBranch(leaf libcommon.Hash, branch []libcommon.Hash, depth uint64, index uint64, root [32]byte) bool {
|
|
value := leaf
|
|
for i := uint64(0); i < depth; i++ {
|
|
if (index / PowerOf2(i) % 2) == 1 {
|
|
value = Sha256(append(branch[i][:], value[:]...))
|
|
} else {
|
|
value = Sha256(append(value[:], branch[i][:]...))
|
|
}
|
|
}
|
|
return value == root
|
|
}
|
|
|
|
func PreparateRootsForHashing(roots []libcommon.Hash) [][32]byte {
|
|
ret := make([][32]byte, len(roots))
|
|
for i := range roots {
|
|
copy(ret[i][:], roots[i][:])
|
|
}
|
|
return ret
|
|
}
|