Skip to content

Commit

Permalink
fix: add an extra check when the data commitment first block is 0 (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id authored Mar 21, 2023
1 parent 3f3b7cc commit 1ee0909
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rpc/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func TestDataCommitment(t *testing.T) {

// check if data commitment is not nil.
// Checking if the commitment is correct is done in `core/blocks_test.go`.
dataCommitment, err := c.DataCommitment(ctx, 0, uint64(expectedHeight))
dataCommitment, err := c.DataCommitment(ctx, 1, uint64(expectedHeight))
require.NotNil(t, dataCommitment, "data commitment shouldn't be nul.")
require.Nil(t, err, "%+v when creating data commitment.", err)
}
Expand Down
3 changes: 3 additions & 0 deletions rpc/core/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func generateHeightsList(beginBlock uint64, endBlock uint64) []int64 {
// validateDataCommitmentRange runs basic checks on the asc sorted list of heights
// that will be used subsequently in generating data commitments over the defined set of heights.
func validateDataCommitmentRange(firstBlock uint64, lastBlock uint64) error {
if firstBlock == 0 {
return fmt.Errorf("the first block is 0")
}
env := GetEnvironment()
heightsRange := lastBlock - firstBlock + 1
if heightsRange > uint64(consts.DataCommitmentBlocksLimit) {
Expand Down
2 changes: 2 additions & 0 deletions rpc/core/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func TestDataCommitmentResults(t *testing.T) {
{2727, 2828, false},
{10, 9, false},
{0, 1000, false},
{0, 10, false},
{10, 8, false},
}

Expand Down Expand Up @@ -225,6 +226,7 @@ func TestDataRootInclusionProofResults(t *testing.T) {
expectPass bool
}{
{8, 10, 15, false},
{10, 0, 15, false},
{10, 10, 15, true},
{13, 10, 15, true},
{15, 10, 15, true},
Expand Down

0 comments on commit 1ee0909

Please sign in to comment.