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

blob: CommitmentProof.Verify should firstly check that root is non-empty before doing all the validation work then crashing #3730

Open
odeke-em opened this issue Sep 15, 2024 · 0 comments · May be fixed by #3732
Labels
bug Something isn't working external Issues created by non node team members

Comments

@odeke-em
Copy link

odeke-em commented Sep 15, 2024

Celestia Node version

1a1286f

Steps to reproduce it

If we run this code repro

package blob_test

import (
        "testing"

        "github.com/celestiaorg/celestia-app/v2/pkg/proof"
        "github.com/celestiaorg/celestia-node/blob" 
)       
        
func TestCommitmentProofRowProofVerify(t *testing.T) {
        cp := &blob.CommitmentProof{
                RowProof: proof.RowProof{
                        Proofs: []*proof.Proof{{}},
                },
        }       
        _, _ = cp.Verify(nil, 1)
}

Expected result

An error and not a panic

Actual result

$ go test -run=TestCommitmentProofRowProofVerify
# github.com/celestiaorg/celestia-node/blob.test
--- FAIL: TestCommitmentProofRowProofVerify (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 9 [running]:
testing.tRunner.func1.2({0x1069be820, 0xc000064c78})
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1632 +0x230
testing.tRunner.func1()
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1635 +0x35e
panic({0x1069be820?, 0xc000064c78?})
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/runtime/panic.go:785 +0x132
github.com/celestiaorg/celestia-app/v2/pkg/proof.RowProof.VerifyProof({{0x0, 0x0, 0x0}, {0xc0010a7f58, 0x1, 0x1}, {0x0, 0x0, 0x0}, 0x0, ...}, ...)
	/Users/emmanuelodeke/go/pkg/mod/github.com/celestiaorg/celestia-app/v2@v2.1.2/pkg/proof/row_proof.go:32 +0x172
github.com/celestiaorg/celestia-node/blob.(*CommitmentProof).Verify(0xc0010a7eb8, {0x0, 0x0, 0x0}, 0x1)
	/Users/emmanuelodeke/go/src/github.com/celestiaorg/celestia-node/blob/commitment_proof.go:146 +0x779
github.com/celestiaorg/celestia-node/blob_test.TestCommitmentProofRowProofVerify(0xc000637860?)
	/Users/emmanuelodeke/go/src/github.com/celestiaorg/celestia-node/blob/repro_test.go:18 +0x94
testing.tRunner(0xc000637860, 0x106b030e0)
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1690 +0xf4
created by testing.(*T).Run in goroutine 1
	/Users/emmanuelodeke/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.0.darwin-amd64/src/testing/testing.go:1743 +0x390
exit status 2
FAIL	github.com/celestiaorg/celestia-node/blob	1.583s

Relevant log output

## Suggested fix

diff --git a/blob/commitment_proof.go b/blob/commitment_proof.go
index 8fa74671..f6af47a9 100644
--- a/blob/commitment_proof.go
+++ b/blob/commitment_proof.go
@@ -2,6 +2,7 @@ package blob
 
 import (
 	"bytes"
+	"errors"
 	"fmt"
 
 	"github.com/celestiaorg/celestia-app/v2/pkg/appconsts"
@@ -85,6 +86,10 @@ func (commitmentProof *CommitmentProof) Validate() error {
 // Expects the commitment proof to be properly formulated and validated
 // using the Validate() function.
 func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold int) (bool, error) {
+	if len(root) == 0 {
+		return false, errors.New("root must be non-empty")
+	}
+
 	nmtHasher := nmt.NewNmtHasher(appconsts.NewBaseHashFunc(), share.NamespaceSize, true)
 
 	// computes the total number of shares proven.
@@ -93,6 +98,10 @@ func (commitmentProof *CommitmentProof) Verify(root []byte, subtreeRootThreshold
 		numberOfShares += proof.End() - proof.Start()
 	}

cc @liamsi @musalbas @rootulp

@odeke-em odeke-em added the bug Something isn't working label Sep 15, 2024
@github-actions github-actions bot added the external Issues created by non node team members label Sep 15, 2024
odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
odeke-em added a commit to orijtech/celestia-node that referenced this issue Sep 16, 2024
This changes adds fuzzers+corpra that found some bugs, along
with tests and reproducers to catch future regressions.

Fixes celestiaorg#3727
Fixes celestiaorg#3728
Fixes celestiaorg#3729
Fixes celestiaorg#3730
Fixes celestiaorg#3731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working external Issues created by non node team members
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant