Skip to content

Commit

Permalink
chore: export NewShareInclusionProofFromEDS (#3461)
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

Manually backports #3460
to v1.x because there were so many diffs between the two branches.
  • Loading branch information
rach-id committed May 10, 2024
1 parent e52c552 commit c4ae12c
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 @@ -5,6 +5,8 @@ import (
"errors"
"fmt"

"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/da"
appns "github.com/celestiaorg/celestia-app/pkg/namespace"
Expand Down Expand Up @@ -51,24 +53,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,
) (types.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 types.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,
) (types.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 c4ae12c

Please sign in to comment.