From 514a6c43a30ac8ff4fe8114f509dcdd3fb934008 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Wed, 5 Jun 2024 12:02:23 +0400 Subject: [PATCH 1/7] chore!: make the row proof range end exclusive --- proto/tendermint/types/types.pb.go | 3 ++- proto/tendermint/types/types.proto | 5 +++-- types/row_proof.go | 16 +++++++++------- types/row_proof_test.go | 7 ++++++- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/proto/tendermint/types/types.pb.go b/proto/tendermint/types/types.pb.go index ff6a726e09..64c27a7ec7 100644 --- a/proto/tendermint/types/types.pb.go +++ b/proto/tendermint/types/types.pb.go @@ -1336,6 +1336,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. +// 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 +1420,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..9a5b043fcf 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -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; @@ -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; @@ -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 diff --git a/types/row_proof.go b/types/row_proof.go index ac5f30c010..e63b85755e 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 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)) 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, } } From 3a47ca829688e45578cf9fd66f4f517dbd35413f Mon Sep 17 00:00:00 2001 From: sweexordious Date: Wed, 5 Jun 2024 12:06:24 +0400 Subject: [PATCH 2/7] chore: update openapi --- rpc/openapi/openapi.yaml | 2 ++ 1 file changed, 2 insertions(+) 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 From 48637c1ac62aa0e880b7351dbf8b6b8f2748f477 Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 5 Jun 2024 10:06:53 +0200 Subject: [PATCH 3/7] Update proto/tendermint/types/types.proto --- proto/tendermint/types/types.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto index 9a5b043fcf..1dff8fc0ec 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -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; From 9fc16396787d049b6a5a1a9999da65944df5bc0a Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 5 Jun 2024 17:33:08 +0200 Subject: [PATCH 4/7] Update proto/tendermint/types/types.proto Co-authored-by: Rootul P --- proto/tendermint/types/types.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proto/tendermint/types/types.proto b/proto/tendermint/types/types.proto index 1dff8fc0ec..51e7549c4f 100644 --- a/proto/tendermint/types/types.proto +++ b/proto/tendermint/types/types.proto @@ -219,8 +219,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. +// given data root. The row range is end exclusive. message RowProof { repeated bytes row_roots = 1; repeated tendermint.crypto.Proof proofs = 2; From dbf6c8bf047543e9f603fcef51789411172d6473 Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 5 Jun 2024 17:33:14 +0200 Subject: [PATCH 5/7] Update types/row_proof.go Co-authored-by: Rootul P --- types/row_proof.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/row_proof.go b/types/row_proof.go index e63b85755e..8d8f50beb9 100644 --- a/types/row_proof.go +++ b/types/row_proof.go @@ -18,7 +18,7 @@ type RowProof struct { 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 is the end-exclusive index of the end row. EndRow uint32 `json:"end_row"` } From b61fbe1d0940af6217f9b80586a607f01403da49 Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 5 Jun 2024 17:33:19 +0200 Subject: [PATCH 6/7] Update types/row_proof.go Co-authored-by: Rootul P --- types/row_proof.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/row_proof.go b/types/row_proof.go index 8d8f50beb9..d4c0cc6a53 100644 --- a/types/row_proof.go +++ b/types/row_proof.go @@ -16,7 +16,7 @@ type RowProof struct { // 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 the index of the start row. + // 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"` From afd91f38b9b3ed73a5f00e16e8cc97c5d2314103 Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Wed, 5 Jun 2024 17:33:50 +0200 Subject: [PATCH 7/7] Update proto/tendermint/types/types.pb.go --- proto/tendermint/types/types.pb.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/proto/tendermint/types/types.pb.go b/proto/tendermint/types/types.pb.go index 64c27a7ec7..137425dc5f 100644 --- a/proto/tendermint/types/types.pb.go +++ b/proto/tendermint/types/types.pb.go @@ -1335,8 +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. -// the row range is end exclusive. +// 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"`