mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 05:18:03 -05:00
Implement Merkle proof spectests (#13146)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,6 @@ go_library(
|
||||
deps = [
|
||||
"//crypto/hash:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//math:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
],
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/v4/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v4/math"
|
||||
protodb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||
)
|
||||
|
||||
@@ -214,18 +213,15 @@ func VerifyMerkleProofWithDepth(root, item []byte, merkleIndex uint64, proof [][
|
||||
if uint64(len(proof)) != depth+1 {
|
||||
return false
|
||||
}
|
||||
if depth >= 64 {
|
||||
return false // PowerOf2 would overflow.
|
||||
}
|
||||
node := bytesutil.ToBytes32(item)
|
||||
for i := uint64(0); i <= depth; i++ {
|
||||
if (merkleIndex / math.PowerOf2(i) % 2) != 0 {
|
||||
if (merkleIndex & 1) == 1 {
|
||||
node = hash.Hash(append(proof[i], node[:]...))
|
||||
} else {
|
||||
node = hash.Hash(append(node[:], proof[i]...))
|
||||
}
|
||||
merkleIndex /= 2
|
||||
}
|
||||
|
||||
return bytes.Equal(root, node[:])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user