Skip to content

Commit

Permalink
Implement MerkleProofKZGCommitments.
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Apr 23, 2024
1 parent 63355ba commit d257305
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions consensus-types/blocks/kzg.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ func MerkleProofKZGCommitment(body interfaces.ReadOnlyBeaconBlockBody, index int
return proof, nil
}

// MerkleProofKZGCommitments constructs a Merkle proof of inclusion of the KZG
// commitments into the Beacon Block with the given `body`
func MerkleProofKZGCommitments(body interfaces.ReadOnlyBeaconBlockBody) ([][]byte, error) {
bodyVersion := body.Version()
if bodyVersion < version.Deneb {
return nil, errUnsupportedBeaconBlockBody
}

membersRoots, err := topLevelRoots(body)
if err != nil {
return nil, errors.Wrap(err, "top level roots")
}

sparse, err := trie.GenerateTrieFromItems(membersRoots, logBodyLength)
if err != nil {
return nil, errors.Wrap(err, "generate trie from items")
}

proof, err := sparse.MerkleProof(kzgPosition)
if err != nil {
return nil, errors.Wrap(err, "merkle proof")
}

return proof, nil
}

// leavesFromCommitments hashes each commitment to construct a slice of roots
func leavesFromCommitments(commitments [][]byte) [][]byte {
leaves := make([][]byte, len(commitments))
Expand Down

0 comments on commit d257305

Please sign in to comment.