forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(blob): add fixes along with the fuzzers that discovered them
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
- Loading branch information
Showing
18 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package blob | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-node/blob/blobtest" | ||
) | ||
|
||
func FuzzProofEqual(f *testing.F) { | ||
if testing.Short() { | ||
f.Skip("in -short mode") | ||
} | ||
|
||
// 1. Generate the corpus. | ||
squareBlobs, err := blobtest.GenerateV0Blobs([]int{16}, false) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
blobs, err := convertBlobs(squareBlobs...) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
for _, blob := range blobs { | ||
jsonBlob, err := blob.MarshalJSON() | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
f.Add(jsonBlob) | ||
} | ||
|
||
// 2. Run the fuzzer. | ||
f.Fuzz(func(t *testing.T, jsonBlob []byte) { | ||
blob := new(Blob) | ||
_ = blob.UnmarshalJSON(jsonBlob) | ||
}) | ||
} | ||
|
||
type verifyCorpus struct { | ||
CP *CommitmentProof `json:"commitment_proof"` | ||
Root []byte `json:"root"` | ||
SThreshold int `json:"sub_threshold"` | ||
} | ||
|
||
func FuzzCommitmentProofVerify(f *testing.F) { | ||
if testing.Short() { | ||
f.Skip("in -short mode") | ||
} | ||
|
||
path := filepath.Join("testdata", "fuzz-corpus", "verify-*.json") | ||
paths, err := filepath.Glob(path) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
// Add the corpra. | ||
for _, path := range paths { | ||
blob, err := os.ReadFile(path) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
var values []*verifyCorpus | ||
if err := json.Unmarshal(blob, &values); err != nil { | ||
f.Fatal(err) | ||
} | ||
|
||
for _, value := range values { | ||
blob, err := json.Marshal(value) | ||
if err != nil { | ||
f.Fatal(err) | ||
} | ||
f.Add(blob) | ||
} | ||
} | ||
|
||
f.Fuzz(func(t *testing.T, valueJSON []byte) { | ||
val := new(verifyCorpus) | ||
if err := json.Unmarshal(valueJSON, val); err != nil { | ||
return | ||
} | ||
commitProof := val.CP | ||
if commitProof == nil { | ||
return | ||
} | ||
_, _ = commitProof.Verify(val.Root, val.SThreshold) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package blob_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/celestiaorg/celestia-app/v2/pkg/proof" | ||
"github.com/celestiaorg/celestia-node/blob" | ||
"github.com/celestiaorg/nmt" | ||
"github.com/celestiaorg/nmt/pb" | ||
) | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3731. | ||
func TestCommitmentProofRowProofVerifyWithEmptyRoot(t *testing.T) { | ||
cp := &blob.CommitmentProof{ | ||
RowProof: proof.RowProof{ | ||
Proofs: []*proof.Proof{{}}, | ||
}, | ||
} | ||
root := []byte{0xd3, 0x4d, 0x34} | ||
if _, err := cp.Verify(root, 1); err == nil { | ||
t.Fatal("expected a non-nil error") | ||
} | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3730. | ||
func TestCommitmentProofRowProofVerify(t *testing.T) { | ||
cp := &blob.CommitmentProof{ | ||
RowProof: proof.RowProof{ | ||
Proofs: []*proof.Proof{{}}, | ||
}, | ||
} | ||
if _, err := cp.Verify(nil, 1); err == nil { | ||
t.Fatal("expected a non-nil error") | ||
} | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3729. | ||
func TestCommitmentProofVerifySliceBound(t *testing.T) { | ||
proof := nmt.ProtoToProof(pb.Proof{End: 1}) | ||
cp := &blob.CommitmentProof{ | ||
SubtreeRootProofs: []*nmt.Proof{ | ||
&proof, | ||
}, | ||
} | ||
if _, err := cp.Verify(nil, 1); err == nil { | ||
t.Fatal("expected a non-nil error") | ||
} | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3728. | ||
func TestCommitmentProofVerifyZeroSubThreshold(t *testing.T) { | ||
cp := new(blob.CommitmentProof) | ||
if _, err := cp.Verify(nil, 0); err == nil { | ||
t.Fatal("expected a non-nil error") | ||
} | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3727. | ||
func TestBlobUnmarshalRepro(t *testing.T) { | ||
blob := new(blob.Blob) | ||
if err := blob.UnmarshalJSON([]byte("{}")); err == nil { | ||
t.Fatal("expected a non-nil error") | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
blob/testdata/fuzz-corpus/verify-626c6f627320746861742074616b65203220736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...uzz-corpus/verify-626c6f627320746861742074616b65206c657373207468616e2061207368617265.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
blob/testdata/fuzz-corpus/verify-626c6f627320746861742074616b65207e313020736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
blob/testdata/fuzz-corpus/verify-6c6172676520626c6f6273207e31303020736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
blob/testdata/fuzz-corpus/verify-6c6172676520626c6f6273207e31353020736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
blob/testdata/fuzz-corpus/verify-6c6172676520626c6f6273207e33303020736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...stdata/fuzz-corpus/verify-76657279206c6172676520626c6f6273207e3135303020736861726573.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/582528ddfad69eb5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("0") |
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/6a2b4b982dc67bf9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{\"Commitment_proof\":{\"suBtree_root_proofs\":[{\"end\":1}]},\"suB_threshold\":1}") |
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/8093511184ad3e25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{}") |
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/c23296029c66526c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{\"Commitment_proof\":{\"row_proof\":{\"proofs\":[{}]}},\"root\":\"0000\",\"suB_threshold\":1}") |
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/ea1afcc1fa86d415
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{\"Commitment_proof\":{\"row_proof\":{\"proofs\":[{}]}},\"suB_threshold\":1}") |
2 changes: 2 additions & 0 deletions
2
blob/testdata/fuzz/FuzzCommitmentProofVerify/fa5be9420bbacd9a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{\"Commitment_proof\":{}}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
[]byte("{}") |