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!: improve start/end row proof validation #1476

Draft
wants to merge 4 commits into
base: v0.34.x-celestia
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions types/row_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (rp RowProof) Validate(root []byte) error {
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))
}
if len(rp.Proofs) != 0 &&
staheri14 marked this conversation as resolved.
Show resolved Hide resolved
(int64(rp.StartRow) != rp.Proofs[0].Index ||
int64(rp.EndRow) != rp.Proofs[len(rp.Proofs)-1].Index) {
return fmt.Errorf("invalid start/end row")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] this could be split into two separate checks with two separate errors: one for start row and one for end row. That way the error message is precise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !rp.VerifyProof(root) {
return errors.New("row proof failed to verify")
}
Expand Down
20 changes: 20 additions & 0 deletions types/row_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ func TestRowProofValidate(t *testing.T) {
root: root,
wantErr: true,
},
{
name: "invalid start row",
rp: func() RowProof {
proof := validRowProof()
proof.StartRow += 1
return proof
}(),
root: root,
wantErr: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this test could be improved by verifying that the error is fmt.Errorf("invalid start/end row") in case some other validation check is erroring before the expected error is encountered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine as long as we're attesting that some error happens. Changing this would mean refactoring the whole test + it's not something that's being done consistently in this repo, most tests are just wanting an error.

If you feel strongly about it, I can refactor, no issue

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking on it. It's just a nice to have

},
{
name: "invalid end row",
rp: func() RowProof {
proof := validRowProof()
proof.EndRow += 1
return proof
}(),
root: root,
wantErr: true,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading