Skip to content

Commit

Permalink
fix: end exclusive parse namespace end share range (backport #2208) (#…
Browse files Browse the repository at this point in the history
…3491)

This is an automatic backport of pull request #2208 done by
[Mergify](https://mergify.com).

Motivated by this [Slack
thread](https://celestia-team.slack.com/archives/C03MP6DPLAD/p1715891011859219).
It seems like we forgot to backport this fix. cc: @rach-id

---------

Co-authored-by: CHAMI Rachid <chamirachid1@gmail.com>
Co-authored-by: Rootul Patel <rootulp@gmail.com>
  • Loading branch information
3 people authored May 16, 2024
1 parent c4ae12c commit 39cc28d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pkg/proof/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,35 @@ func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) {
t.Fatal("no rawProof expected")
}
}

// TestAllSharesInclusionProof creates a proof for all shares in the data
// square. Since we can't prove multiple namespaces at the moment, all the
// shares use the same namespace.
func TestAllSharesInclusionProof(t *testing.T) {
txs := testfactory.GenerateRandomTxs(243, 500)

dataSquare, err := square.Construct(txs.ToSliceOfBytes(), appconsts.LatestVersion, 128)
require.NoError(t, err)
assert.Equal(t, 256, len(dataSquare))

// erasure the data square which we use to create the data root.
eds, err := da.ExtendShares(shares.ToBytes(dataSquare))
require.NoError(t, err)

// create the new data root by creating the data availability header (merkle
// roots of each row and col of the erasure data).
dah, err := da.NewDataAvailabilityHeader(eds)
require.NoError(t, err)
dataRoot := dah.Hash()

actualNamespace, err := proof.ParseNamespace(dataSquare, 0, 256)
require.NoError(t, err)
require.Equal(t, appns.TxNamespace, actualNamespace)
proof, err := proof.NewShareInclusionProof(
dataSquare,
appns.TxNamespace,
shares.NewRange(0, 256),
)
require.NoError(t, err)
assert.NoError(t, proof.Validate(dataRoot))
}
2 changes: 1 addition & 1 deletion pkg/proof/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.N
return appns.Namespace{}, fmt.Errorf("end share %d cannot be lower than starting share %d", endShare, startShare)
}

if endShare >= len(rawShares) {
if endShare > len(rawShares) {
return appns.Namespace{}, fmt.Errorf("end share %d is higher than block shares %d", endShare, len(rawShares))
}

Expand Down

0 comments on commit 39cc28d

Please sign in to comment.