Skip to content

Commit

Permalink
fix: check if the end row is greater than the start row (#1373)
Browse files Browse the repository at this point in the history
## Description

Replica of #1372 to
main

#### PR checklist

- [x] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
  • Loading branch information
rach-id authored Jun 5, 2024
1 parent e33c03c commit 86f0d35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion types/row_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type RowProof struct {
// Validate performs checks on the fields of this RowProof. Returns an error if
// the proof is not correctly constructed.
func (rp RowProof) Validate() error {
// HACKHACK performing subtraction with unsigned integers is unsafe.
if rp.EndRow < rp.StartRow {
return fmt.Errorf("end row %d cannot be less than 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))
}
Expand Down
5 changes: 5 additions & 0 deletions types/row_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func TestRowProofValidate(t *testing.T) {
rp: validRowProof(),
wantErr: false,
},
{
name: "start row greater than end row",
rp: RowProof{StartRow: 10, EndRow: 5},
wantErr: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 86f0d35

Please sign in to comment.