Skip to content

Conversation

thep2p
Copy link
Contributor

@thep2p thep2p commented Oct 11, 2025

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 multiplication
  • test_add.rs: Fp field addition
  • test_mul_fp2.rs: Fp2 extension field multiplication
  • test_add_fp2.rs: Fp2 extension field addition

Host-side tests (4 new test functions):

  • test_mul_fp_100: Validates Fp multiplication with 100 random inputs
  • test_add_fp_100: Validates Fp addition with 100 random inputs
  • test_mul_fp2_100: Validates Fp2 multiplication with 100 random inputs
  • test_add_fp2_100: Validates Fp2 addition with 100 random inputs

Each 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:

cd patch-testing/bls12-381
cargo test

Each test:

  • Generates 100 random field element pairs
  • Executes the corresponding field operation in the zkVM
  • Validates zkVM outputs match host-computed expected results
  • Ensures syscalls (BLS12381_FP_ADD, BLS12381_FP_MUL, BLS12381_FP2_ADD, BLS12381_FP2_MUL) work correctly.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

thep2p and others added 2 commits October 8, 2025 21:19
- Add field multiplication tests for Fp and Fp2
- Add field addition tests for Fp and Fp2
- Update Cargo.toml to register new test binaries
- Addresses TODO comment in patch-testing/bls12-381/program/Cargo.toml

These tests follow the same pattern as existing field operation tests
(inverse, sqrt) and provide coverage for basic field arithmetic operations
that were previously missing.
Adds comprehensive host-side test functions for the new BLS12-381 field
operation programs, providing functional test coverage in addition to the
existing build validation in CI.

New test functions:
- test_add_fp_100: Tests Fp field addition with 100 random inputs
- test_mul_fp_100: Tests Fp field multiplication with 100 random inputs
- test_add_fp2_100: Tests Fp2 extension field addition with 100 random inputs
- test_mul_fp2_100: Tests Fp2 extension field multiplication with 100 random inputs

Each test:
- Generates random field elements using the bls12_381 crate
- Executes the guest program in the SP1 zkVM
- Compares zkVM outputs against expected results computed on the host
- Validates correctness of field operations through the zkVM

Also includes formatting improvements to existing test code (consolidated
import statements).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

1 participant