Skip to content

Commit

Permalink
chore: expose generate subtree roots method (#106) (#108)
Browse files Browse the repository at this point in the history
This PR exposes a method to generate the subtree roots. It will be handy
in downstream repos (will be using it in Celestia-node) instead of
re-implementing it.

cherry picked from commit 662d17d
  • Loading branch information
rach-id authored Oct 7, 2024
1 parent c8242f9 commit a618606
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion inclusion/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ type MerkleRootFn func([][]byte) []byte
// [data square layout rationale]: ../../specs/src/specs/data_square_layout.md
// [blob share commitment rules]: ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules
func CreateCommitment(blob *blob.Blob, merkleRootFn MerkleRootFn, subtreeRootThreshold int) ([]byte, error) {
subTreeRoots, err := GenerateSubtreeRoots(blob, subtreeRootThreshold)
if err != nil {
return nil, err
}
return merkleRootFn(subTreeRoots), nil
}

// GenerateSubtreeRoots generates the subtree roots of a blob.
// See [data square layout rationale] and [blob share commitment rules].
//
// [data square layout rationale]: ../../specs/src/specs/data_square_layout.md
// [blob share commitment rules]: ../../specs/src/specs/data_square_layout.md#blob-share-commitment-rules
func GenerateSubtreeRoots(blob *blob.Blob, subtreeRootThreshold int) ([][]byte, error) {
if err := blob.Validate(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,7 +84,7 @@ func CreateCommitment(blob *blob.Blob, merkleRootFn MerkleRootFn, subtreeRootThr
}
subTreeRoots[i] = root
}
return merkleRootFn(subTreeRoots), nil
return subTreeRoots, nil
}

func CreateCommitments(blobs []*blob.Blob, merkleRootFn MerkleRootFn, subtreeRootThreshold int) ([][]byte, error) {
Expand Down

0 comments on commit a618606

Please sign in to comment.