Skip to content

Commit

Permalink
fix: end exclusive parse namespace end share range (#2208)
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

Fixes the range to support end exclusive share ranges 

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [ ] 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 <[email protected]>
  • Loading branch information
rach-id and rootulp authored Aug 4, 2023
1 parent 70b0624 commit 0c55a6e
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 @@ -221,3 +221,35 @@ func TestNewShareInclusionProof(t *testing.T) {
})
}
}

// 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 @@ -133,7 +133,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 0c55a6e

Please sign in to comment.