Skip to content

Commit

Permalink
test for invalid proof ckzg (#1189)
Browse files Browse the repository at this point in the history
* test for invalid proof ckzg

Signed-off-by: nidhi-singh02 <trippin@berachain.com>

* updated lib

Signed-off-by: nidhi-singh02 <trippin@berachain.com>

---------

Signed-off-by: nidhi-singh02 <trippin@berachain.com>
  • Loading branch information
nidhi-singh02 authored May 27, 2024
1 parent 560444e commit 1a91f6b
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion contracts/lib/forge-std
2 changes: 1 addition & 1 deletion contracts/lib/solady
37 changes: 37 additions & 0 deletions mod/da/pkg/kzg/ckzg/ckzg_cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,40 @@ func TestVerifyBlobProofBatch(t *testing.T) {
err = globalVerifier.VerifyBlobProofBatch(args)
require.NoError(t, err)
}

// TestVerifyBlobKZGInvalidProof tests the VerifyBlobProof function for an
// invalid proof
func TestVerifyBlobKZGInvalidProof(t *testing.T) {
validBlob, invalidProof, validCommitment := setupTestData(
t, "test_data_incorrect_proof.json")
testCases := []struct {
name string
blob *eip4844.Blob
proof eip4844.KZGProof
commitment eip4844.KZGCommitment
expectError bool
}{
{
name: "Invalid Proof",
blob: validBlob,
proof: invalidProof,
commitment: validCommitment,
expectError: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := globalVerifier.VerifyBlobProof(
tc.blob,
tc.proof,
tc.commitment,
)
if tc.expectError {
require.Error(t, err, "invalid proof")
} else {
require.NoError(t, err)
}
})
}
}
37 changes: 37 additions & 0 deletions mod/da/pkg/kzg/ckzg/ckzg_no_cgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,40 @@ func TestVerifyBlobProofBatch(t *testing.T) {
err = globalVerifier.VerifyBlobProofBatch(args)
require.Error(t, err, "cgo is not enabled")
}

// TestVerifyBlobKZGInvalidProof tests the VerifyBlobProof function for invalid
// proofs.
func TestVerifyBlobKZGInvalidProof(t *testing.T) {
validBlob, invalidProof, validCommitment := setupTestData(
t, "test_data_incorrect_proof.json")
testCases := []struct {
name string
blob *eip4844.Blob
proof eip4844.KZGProof
commitment eip4844.KZGCommitment
expectError bool
}{
{
name: "Invalid Proof",
blob: validBlob,
proof: invalidProof,
commitment: validCommitment,
expectError: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
err := globalVerifier.VerifyBlobProof(
tc.blob,
tc.proof,
tc.commitment,
)
if tc.expectError {
require.Error(t, err, "invalid proof")
} else {
require.NoError(t, err)
}
})
}
}
7 changes: 7 additions & 0 deletions testing/files/test_data_incorrect_proof.json

Large diffs are not rendered by default.

0 comments on commit 1a91f6b

Please sign in to comment.