mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
feat: implement PayloadProof function (#14356)
* feat: implement function `PayloadProof` to calculate proof of execution payload * remove comments * feat: implement function to compute field roots of * feat: implement function to compute `BeaconBlock` field roots and add tests * fix dependencies * check if interface implements the assserted type * fix: lint * replace `ok != true` with `!ok` * remove unused parameter from `PayloadProof` * remove test and move `PayloadProof` to `blocks/proofs.go` * remove `PayloadProof` from `fieldtrie` * replace `fieldtrie.ProofFromMerkleLayers` with `trie.ProofFromMerkleLayers` * Update container/trie/sparse_merkle.go * update dependencies --------- Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Radosław Kapka <radoslaw.kapka@gmail.com>
This commit is contained in:
@@ -259,3 +259,18 @@ func (m *SparseMerkleTrie) NumOfItems() int {
|
||||
}
|
||||
return len(m.originalItems)
|
||||
}
|
||||
|
||||
// ProofFromMerkleLayers creates a proof starting at the leaf index of the merkle layers.
|
||||
func ProofFromMerkleLayers(layers [][][]byte, startingLeafIndex int) [][]byte {
|
||||
// The merkle tree structure looks as follows:
|
||||
// [[r1, r2, r3, r4], [parent1, parent2], [root]]
|
||||
proof := make([][]byte, 0)
|
||||
currentIndex := startingLeafIndex
|
||||
for i := 0; i < len(layers)-1; i++ {
|
||||
neighborIdx := currentIndex ^ 1
|
||||
neighbor := layers[i][neighborIdx]
|
||||
proof = append(proof, neighbor)
|
||||
currentIndex = currentIndex / 2
|
||||
}
|
||||
return proof
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user