-
Notifications
You must be signed in to change notification settings - Fork 919
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 #3727 Fixes #3728 Fixes #3729 Fixes #3730 Fixes #3731
- Loading branch information
Showing
18 changed files
with
188 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,86 @@ | ||
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) | ||
}) | ||
} | ||
|
||
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,54 @@ | ||
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} | ||
_, _ = cp.Verify(root, 1) | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3730. | ||
func TestCommitmentProofRowProofVerify(t *testing.T) { | ||
cp := &blob.CommitmentProof{ | ||
RowProof: proof.RowProof{ | ||
Proofs: []*proof.Proof{{}}, | ||
}, | ||
} | ||
_, _ = cp.Verify(nil, 1) | ||
} | ||
|
||
// 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, | ||
}, | ||
} | ||
_, _ = cp.Verify(nil, 1) | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3728. | ||
func TestCommitmentProofVerifyZeroSubThreshold(t *testing.T) { | ||
cp := new(blob.CommitmentProof) | ||
_, _ = cp.Verify(nil, 0) | ||
} | ||
|
||
// Reported at https://github.com/celestiaorg/celestia-node/issues/3727. | ||
func TestBlobUnmarshalRepro(t *testing.T) { | ||
blob := new(blob.Blob) | ||
_ = blob.UnmarshalJSON([]byte("{}")) | ||
} |
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("{}") |