Skip to content

refactor(precompile): extract common pairing_check_bytes logic in bls12_381#3301

Merged
rakita merged 5 commits intobluealloy:mainfrom
letmehateu:extract-common-pairing_check_bytes
Jan 14, 2026
Merged

refactor(precompile): extract common pairing_check_bytes logic in bls12_381#3301
rakita merged 5 commits intobluealloy:mainfrom
letmehateu:extract-common-pairing_check_bytes

Conversation

@letmehateu
Copy link
Copy Markdown
Contributor

Extracted the common pairing_check_bytes validation logic shared between arkworks and blst

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Jan 13, 2026

Merging this PR will not alter performance

✅ 173 untouched benchmarks


Comparing letmehateu:extract-common-pairing_check_bytes (16bf634) with main (a31fa98)

Open in CodSpeed

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the BLS12-381 pairing check implementation by extracting common byte-level validation logic that was duplicated between the arkworks and blst backend implementations into a shared generic function.

Changes:

  • Created a new pairing_common module with a generic pairing_check_bytes_generic function
  • Refactored both arkworks and blst implementations to use the shared generic function
  • Removed duplicate code handling point-at-infinity filtering and validation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/precompile/src/bls12_381/pairing_common.rs New module containing shared pairing validation logic with generic function that accepts backend-specific parsing and computation functions
crates/precompile/src/bls12_381/blst.rs Replaced duplicate pairing_check_bytes logic with call to shared generic function
crates/precompile/src/bls12_381/arkworks.rs Replaced duplicate pairing_check_bytes logic with call to shared generic function
crates/precompile/src/bls12_381.rs Added pairing_common module declaration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +20
ReadG1: Fn(&[u8; 48], &[u8; 48]) -> Result<G1, PrecompileError>,
ReadG2: Fn(&[u8; 48], &[u8; 48], &[u8; 48], &[u8; 48]) -> Result<G2, PrecompileError>,
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The hardcoded array size 48 should use the FP_LENGTH constant from bls12_381_const module for better maintainability. This would make the code more resilient to changes in field element size and clearer about the intent. Consider importing and using FP_LENGTH in the trait bounds.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

cool, nice refactor!

@rakita rakita merged commit 5eedd20 into bluealloy:main Jan 14, 2026
37 checks passed
@github-actions github-actions bot mentioned this pull request Jan 14, 2026
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.

3 participants