refactor(precompile): extract common pairing_check_bytes logic in bls12_381#3301
Conversation
There was a problem hiding this comment.
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_commonmodule with a genericpairing_check_bytes_genericfunction - Refactored both
arkworksandblstimplementations 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.
| ReadG1: Fn(&[u8; 48], &[u8; 48]) -> Result<G1, PrecompileError>, | ||
| ReadG2: Fn(&[u8; 48], &[u8; 48], &[u8; 48], &[u8; 48]) -> Result<G2, PrecompileError>, |
There was a problem hiding this comment.
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.
Extracted the common
pairing_check_bytesvalidation logic shared betweenarkworksandblst