diff --git a/proto/tendermint/types/types.pb.go b/proto/tendermint/types/types.pb.go index ff6a726e09..137425dc5f 100644 --- a/proto/tendermint/types/types.pb.go +++ b/proto/tendermint/types/types.pb.go @@ -1335,7 +1335,7 @@ func (m *ShareProof) GetNamespaceVersion() uint32 { } // RowProof is a Merkle proof that a set of rows exist in a Merkle tree with a -// given data root. +// given data root. The row range is end exclusive. type RowProof struct { RowRoots [][]byte `protobuf:"bytes,1,rep,name=row_roots,json=rowRoots,proto3" json:"row_roots,omitempty"` Proofs []*crypto.Proof `protobuf:"bytes,2,rep,name=proofs,proto3" json:"proofs,omitempty"` @@ -1419,7 +1419,7 @@ func (m *RowProof) GetEndRow() uint32 { type NMTProof struct { // Start index of this proof. Start int32 `protobuf:"varint,1,opt,name=start,proto3" json:"start,omitempty"` - // End index of this proof. + // End exclusive index of this proof. End int32 `protobuf:"varint,2,opt,name=end,proto3" json:"end,omitempty"` // 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 diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto index dcd23c01d9..51e7549c4f 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -219,7 +219,7 @@ message ShareProof { } // RowProof is a Merkle proof that a set of rows exist in a Merkle tree with a -// given data root. +// given data root. The row range is end exclusive. message RowProof { repeated bytes row_roots = 1; repeated tendermint.crypto.Proof proofs = 2; @@ -235,7 +235,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 diff --git a/rpc/openapi/openapi.yaml b/rpc/openapi/openapi.yaml index 27622e936d..286457258e 100644 --- a/rpc/openapi/openapi.yaml +++ b/rpc/openapi/openapi.yaml @@ -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 diff --git a/types/row_proof.go b/types/row_proof.go index ac5f30c010..d4c0cc6a53 100644 --- a/types/row_proof.go +++ b/types/row_proof.go @@ -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 is the index of the start row. + StartRow uint32 `json:"start_row"` + // EndRow is 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)) diff --git a/types/row_proof_test.go b/types/row_proof_test.go index 7d3f290922..afaf598096 100644 --- a/types/row_proof_test.go +++ b/types/row_proof_test.go @@ -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) { @@ -131,7 +136,7 @@ func validRowProof() RowProof { }, }, StartRow: 0, - EndRow: 0, + EndRow: 1, } }