Skip to content

feat(bls-12-381): add test vectors for BLS-12-381#224

Open
tob-scott-a wants to merge 4 commits intoC2SP:mainfrom
tob-scott-a:bls-12-381-tests
Open

feat(bls-12-381): add test vectors for BLS-12-381#224
tob-scott-a wants to merge 4 commits intoC2SP:mainfrom
tob-scott-a:bls-12-381-tests

Conversation

@tob-scott-a
Copy link
Contributor

The methodology for generating this test vectors is as follows:

  1. Source several high-quality implementations.
  2. Run mutation testing on each of them.
  3. Have Claude write additional test inputs intended to trigger more behaviors in internal functions not currently exercised by the incumbent test suites.
  4. Re-run the mutation testing framework with the new Wycheproof harness and new JSON files.
  5. Compare before/after.

The end result are a set of static tests that ensure implementations do not have subtle mistakes that the barebones known answer tests do not detect.

Here's an example of the delta in mutation testing coverage provided by the JSON files generated in this PR, against https://github.com/zkcrypto/bls12_381:

File Before Missed After Missed Delta Key Kills
scalar.rs 35 10 -25 ct_eq (&^), arithmetic (square, neg, from_bytes)
fp.rs 46 31 -15 Roundtrip caught field arithmetic corruption
fp2.rs 12 12 0 No change (pow_vartime_extended, sqrt not in deser path)
g1.rs 42 → 59* 54 -5 All from_compressed_unchecked flag mutations killed
g2.rs 29 → 54* 54 0 All from_compressed_unchecked flag mutations killed

*Full file now tested (more mutants in scope).

tob-scott-a and others added 4 commits March 12, 2026 08:20
The methodology for generating this test vectors is as follows:

1. Source several high-quality implementations.
2. Run mutation testing on each of them.
3. Have Claude write additional test inputs intended to trigger more
   behaviors in internal functions not currently exercised by the
   incumbent test suites.
4. Re-run the mutation testing framework with the new Wycheproof harness
   and new JSON files.
5. Compare before/after.

The end result are a set of static tests that ensure implementations do not
have subtle mistakes that the barebones known answer tests do not detect.
Go's json.Marshal HTML-escapes > as \u003e; reformat_json.py expects
literal >= characters.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

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

Thanks! I think this mutation based approach for generating vectors is really cool 🚀

I propose we consider the feedback I left, give it a bit to see if anyone else has input, and then merge. Sound good?

"required": ["pk", "group", "keySize"],
"additionalProperties": false
},
"BlsSigVerifyTestVector": {
Copy link
Member

Choose a reason for hiding this comment

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

I think this could re-use SignatureTestVector from schemas/signature_common.json with the only downside being that we lose the comment explicitly describing the sig as being a BLS signature in compressed form.

WDYT? Is that detail sufficiently important to duplicate the schema content?

@@ -0,0 +1,109 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Leaving a comment here as a convenient place to anchor it

nit: I recommend dropping the _v1 suffix on the new schema filenames.

The other schemas that have this suffix were using it to differentiate from related testvectors/ schemas and that's not a concern for new files (and we removed all the testvectors/ vectors/schemas in #169).

@@ -0,0 +1,109 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Could you also update the README.md algorithm coverage to include BLS-12-381?

Comment on lines +12 to +15
"EdgeCase": {
"bugType": "EDGE_CASE",
"description": "The test vector tests an edge case input."
},
Copy link
Member

Choose a reason for hiding this comment

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

I think the EdgeCase flag is only used in this file for single-byte messages. Would something like MinimalInput be a more expressive flag name? I think it has the advantage of not being the same as the bugType EDGE_CASE.

{
"type": "BlsHashToG2",
"source": {
"name": "c2sp/wycheproof/blsvecgen",
Copy link
Member

Choose a reason for hiding this comment

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

Would something like github/trailofbits/bls be more appropriate here (and in the other source defs)? Or is there a repo where blsvecgen lives?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants