From 26b715dee98fd19a11582f9c8d7d610676640e2b Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Fri, 4 Aug 2023 21:36:19 +0200 Subject: [PATCH 1/2] fix: end exclusive parse namespace end share range (#2208) ## Overview Fixes the range to support end exclusive share ranges ## Checklist - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords --------- Co-authored-by: Rootul P (cherry picked from commit 0c55a6e08510e56224d805ce3e2fbfa1604783c6) # Conflicts: # pkg/proof/proof_test.go --- pkg/proof/proof_test.go | 33 +++++++++++++++++++++++++++++++++ pkg/proof/querier.go | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/proof/proof_test.go b/pkg/proof/proof_test.go index 405c630929..40abd8376d 100644 --- a/pkg/proof/proof_test.go +++ b/pkg/proof/proof_test.go @@ -225,6 +225,7 @@ func TestNewShareInclusionProof(t *testing.T) { } } +<<<<<<< HEAD // Ensure that we reject negative index values and avoid overflows. // https://github.com/celestiaorg/celestia-app/issues/3140 func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) { @@ -241,4 +242,36 @@ func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) { if len(rawProof) != 0 { 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)) +>>>>>>> 0c55a6e (fix: end exclusive parse namespace end share range (#2208)) } 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)) } From 4f5dc9151b38d800b6e1cbf5838c1d54ff676dc2 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Thu, 16 May 2024 16:39:52 -0400 Subject: [PATCH 2/2] fix: merge conflict --- pkg/proof/proof_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/proof/proof_test.go b/pkg/proof/proof_test.go index 40abd8376d..a8d8ae0756 100644 --- a/pkg/proof/proof_test.go +++ b/pkg/proof/proof_test.go @@ -225,7 +225,6 @@ func TestNewShareInclusionProof(t *testing.T) { } } -<<<<<<< HEAD // Ensure that we reject negative index values and avoid overflows. // https://github.com/celestiaorg/celestia-app/issues/3140 func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) { @@ -242,7 +241,8 @@ func TestQueryTxInclusionProofRejectsNegativeValues(t *testing.T) { if len(rawProof) != 0 { 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. @@ -273,5 +273,4 @@ func TestAllSharesInclusionProof(t *testing.T) { ) require.NoError(t, err) assert.NoError(t, proof.Validate(dataRoot)) ->>>>>>> 0c55a6e (fix: end exclusive parse namespace end share range (#2208)) }