Skip to content

Commit

Permalink
chore!: make the row proof range end exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Jun 5, 2024
1 parent 86f0d35 commit 514a6c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion proto/tendermint/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions proto/tendermint/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ message Data {
// field number 2 is reserved for intermediate state roots
// field number 3 is reserved for evidence
// field number 4 is reserved for blobs

// SquareSize is the number of rows or columns in the original data square.
uint64 square_size = 5;

Expand Down Expand Up @@ -220,6 +220,7 @@ message ShareProof {

// RowProof is a Merkle proof that a set of rows exist in a Merkle tree with a
// given data root.
// the row range is end exclusive.
message RowProof {
repeated bytes row_roots = 1;
repeated tendermint.crypto.Proof proofs = 2;
Expand All @@ -235,7 +236,7 @@ message RowProof {
message NMTProof {
// Start index of this proof.
int32 start = 1;
// End index of this proof.
// End exclusive index of this proof.
int32 end = 2;
// Nodes that together with the corresponding leaf values can be used to
// recompute the root and verify this proof. Nodes should consist of the max
Expand Down
16 changes: 9 additions & 7 deletions types/row_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ type RowProof struct {
RowRoots []tmbytes.HexBytes `json:"row_roots"`
// Proofs is a list of Merkle proofs where each proof proves that a row
// exists in a Merkle tree with a given data root.
Proofs []*merkle.Proof `json:"proofs"`
StartRow uint32 `json:"start_row"`
EndRow uint32 `json:"end_row"`
Proofs []*merkle.Proof `json:"proofs"`
// StartRow the index of the start row.
StartRow uint32 `json:"start_row"`
// EndRow the end-exclusive index of the end row.
EndRow uint32 `json:"end_row"`
}

// Validate performs checks on the fields of this RowProof. Returns an error if
// the proof is not correctly constructed.
func (rp RowProof) Validate() error {
if rp.EndRow < rp.StartRow {
return fmt.Errorf("end row %d cannot be less than start row %d", rp.EndRow, rp.StartRow)
if rp.EndRow <= rp.StartRow {
return fmt.Errorf("end row %d cannot be less or equal to start row %d", rp.EndRow, rp.StartRow)
}
if int(rp.EndRow-rp.StartRow+1) != len(rp.RowRoots) {
return fmt.Errorf("the number of rows %d must equal the number of row roots %d", int(rp.EndRow-rp.StartRow+1), len(rp.RowRoots))
if int(rp.EndRow-rp.StartRow) != len(rp.RowRoots) {
return fmt.Errorf("the number of rows %d must equal the number of row roots %d", int(rp.EndRow-rp.StartRow), len(rp.RowRoots))
}
if len(rp.Proofs) != len(rp.RowRoots) {
return fmt.Errorf("the number of proofs %d must equal the number of row roots %d", len(rp.Proofs), len(rp.RowRoots))
Expand Down
7 changes: 6 additions & 1 deletion types/row_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func TestRowProofValidate(t *testing.T) {
rp: RowProof{StartRow: 10, EndRow: 5},
wantErr: true,
},
{
name: "start row equal to end row",
rp: RowProof{StartRow: 10, EndRow: 10},
wantErr: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -131,7 +136,7 @@ func validRowProof() RowProof {
},
},
StartRow: 0,
EndRow: 0,
EndRow: 1,
}
}

Expand Down

0 comments on commit 514a6c4

Please sign in to comment.