diff --git a/pkg/proof/proof_test.go b/pkg/proof/proof_test.go index 405c630929..a8d8ae0756 100644 --- a/pkg/proof/proof_test.go +++ b/pkg/proof/proof_test.go @@ -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)) +} diff --git a/pkg/proof/querier.go b/pkg/proof/querier.go index 7bca88f114..9fca6c5afa 100644 --- a/pkg/proof/querier.go +++ b/pkg/proof/querier.go @@ -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)) }