feat: add BLS12-381 field multiplication and addition tests #2473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This PR addresses the TODO comment in
patch-testing/bls12-381/program/Cargo.toml
(line 28) that requested explicit multiplication and addition tests for BLS12-381 field operations.Solution
The existing test suite already covered more complex operations (sqrt, inverse, EC operations), but basic field arithmetic operations (mul, add) were missing explicit test coverage. This PR adds:
Guest programs (4 new test binaries):
test_mul.rs
: Fp field multiplicationtest_add.rs
: Fp field additiontest_mul_fp2.rs
: Fp2 extension field multiplicationtest_add_fp2.rs
: Fp2 extension field additionHost-side tests (4 new test functions):
test_mul_fp_100
: Validates Fp multiplication with 100 random inputstest_add_fp_100
: Validates Fp addition with 100 random inputstest_mul_fp2_100
: Validates Fp2 multiplication with 100 random inputstest_add_fp2_100
: Validates Fp2 addition with 100 random inputsEach test follows the established pattern of existing field operation tests: generating random field elements, executing operations in the SP1 zkVM, and comparing outputs against expected host-computed results.
All tests have been run locally and pass successfully:
Each test:
BLS12381_FP_ADD
,BLS12381_FP_MUL
,BLS12381_FP2_ADD
,BLS12381_FP2_MUL
) work correctly.PR Checklist