Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: make the row proof range end exclusive #1376

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

rach-id marked this conversation as resolved.
Show resolved Hide resolved
// 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.
rach-id marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 2 additions & 0 deletions rpc/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2694,9 +2694,11 @@ components:
startRow:
type: integer
format: uint32
description: start index of the row range
endRow:
type: integer
format: uint32
description: end exclusive index of the row range
Proof:
type: object
description: Binary merkle proof
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.
rach-id marked this conversation as resolved.
Show resolved Hide resolved
StartRow uint32 `json:"start_row"`
// EndRow the end-exclusive index of the end row.
rach-id marked this conversation as resolved.
Show resolved Hide resolved
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
Loading