Skip to content

Commit

Permalink
chore: export NewShareInclusionProofFromEDS (#3460)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

Exports `NewShareInclusionProofFromEDS` so that I can use when
generating the proofs in Celestia-node side.
  • Loading branch information
rach-id authored May 14, 2024
1 parent 9631b45 commit 536d0dc
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pkg/proof/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"math"

"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v2/pkg/da"
"github.com/celestiaorg/celestia-app/v2/pkg/wrapper"
Expand Down Expand Up @@ -54,24 +56,36 @@ func getTxNamespace(tx []byte) (ns appns.Namespace) {
return appns.TxNamespace
}

// NewShareInclusionProof returns an NMT inclusion proof for a set of shares
// NewShareInclusionProof takes an ODS, extends it, then
// returns an NMT inclusion proof for a set of shares
// belonging to the same namespace to the data root.
// Expects the share range to be pre-validated.
func NewShareInclusionProof(
dataSquare square.Square,
namespace appns.Namespace,
shareRange shares.Range,
) (ShareProof, error) {
squareSize := dataSquare.Size()
startRow := shareRange.Start / squareSize
endRow := (shareRange.End - 1) / squareSize
startLeaf := shareRange.Start % squareSize
endLeaf := (shareRange.End - 1) % squareSize

eds, err := da.ExtendShares(shares.ToBytes(dataSquare))
if err != nil {
return ShareProof{}, err
}
return NewShareInclusionProofFromEDS(eds, namespace, shareRange)
}

// NewShareInclusionProofFromEDS takes an extended data square,
// and returns an NMT inclusion proof for a set of shares
// belonging to the same namespace to the data root.
// Expects the share range to be pre-validated.
func NewShareInclusionProofFromEDS(
eds *rsmt2d.ExtendedDataSquare,
namespace appns.Namespace,
shareRange shares.Range,
) (ShareProof, error) {
squareSize := square.Size(len(eds.FlattenedODS()))
startRow := shareRange.Start / squareSize
endRow := (shareRange.End - 1) / squareSize
startLeaf := shareRange.Start % squareSize
endLeaf := (shareRange.End - 1) % squareSize

edsRowRoots, err := eds.RowRoots()
if err != nil {
Expand Down

0 comments on commit 536d0dc

Please sign in to comment.