Commit 747a3ed
FIP-0105: Add Full Support for EIP-2537 (BLS12-381 Precompiles) in the Filecoin EVM (#1669)
* adding bls12_g1_add
* Updated the util functions
* add precompile addresses
* Adding tests and correcting utility functions
* remove padding from input in extract_g1_poin
* add bls12_g1msm fn
* added testcase for bls_add
* added gls12_g1msm scalars
* added tests test_g1_msm_success and test_g1_msm_failures
* adding details about the bug
* Adding the g2_add_function
* Adding the g2_msm_function
* corrected subgroup check testcase in g1msm
* adding testcases for g2_add
* adding testcases for g2_add_fail
* adding testcases for g2_msm
* separated util file
* separates bls12_381 into 7 files
* update g1_add unit tests
* add fp2_to_g2, pairing fn
* Add utility functions to pairing.rs
* Add util functions for map_fp_to_g1 and map_fp2_to_g2
* Fix the Curve-error bug
* corrected the bug in g1_msm and g2_add
* added testcases for map_fp_to_g1
* add successful tests to pairing.rs
* Add more testcases for pairing
* added more tests for g1_msm, and g2_add
* change g1_msm variable names
* add g2msm failure tests
* correct bug in g2_msm
* fixed corresponding bug in g1_msm
* update pairing tests
* added remaining tests
* run cargo fmt --all
* refactor(bls12_381): unify G1ADD and G2ADD precompile implementations with consistent structure and docs
- Applied consistent formatting, inline documentation, and structure to `g1_add.rs` and `g2_add.rs`.
- Renamed internal helpers for clarity (`p1_add_affine`, `p2_add_affine`) and modularity.
- Added `is_infinity`, `*_from_affine`, and `*_to_affine` helpers in both files to mirror each other.
- Converted all doc comments to use idiomatic rustdoc style with Markdown formatting.
- Ensured early return optimizations for infinity cases are consistently applied.
- Linked both precompiles explicitly to EIP-2537 in top-level doc comments.
This improves readability, testability, and future maintainability by making G1 and G2 precompile logic symmetrical and idiomatic.
* refactor(bls12_381): unify is_infinity logic for G1 and G2 MSM and addition precompiles
- Introduced `IsInfinity` trait and a shared `is_infinity` utility function in `bls_util.rs`
- Updated `g1_msm.rs` and `g2_msm.rs` to use the shared `is_infinity` function
- Removed local unsafe infinity checks from `g1_add.rs` and `g2_add.rs`
- Rewrote MSM loops to extract affine points before checking for infinity
- Improved formatting and comments for consistency and clarity across precompiles
This cleanup ensures consistent infinity checking and reduces redundant unsafe code paths.
* refactor(bls12_mapping): standardize map_fp2_to_g2 and map_fp_to_g1 precompiles
- Unified code style and documentation for both mapping precompiles.
- Added markdown formatting in doc comments for clarity and consistency.
- Refactored input validation, padding removal, and field element reading logic.
- Ensured unsafe blocks are properly annotated with safety comments.
- Consistently encode the final curve point for both G1 and G2 as per EIP-2537.
This change improves readability, maintainability, and consistency across BLS12-381 mapping precompiles.
* remove repeatedly defined fns
* correct clippy errors
* recompile cargo.lock
* temporarily removed cargo.lock
* cargo fmt --all
* using input.chunks_exact instead of manual indexing
* using input.chunks_exact instead of manual indexing
* simplify input parsing using chunks_exact and split_at
- Replaced manual offset math in G2 MSM, G2 add, and pairing precompiles with input.chunks_exact + split_at.
- Improved readability and safety by eliminating index arithmetic.
* refactor(pairing): use split_first for safer empty input handling
- Replaced manual empty check and indexing with split_first pattern.
- Avoids potential panic on empty input and improves readability.
- Destructured head and tail for pairing processing without .iter().skip().
- Added comments clarifying behavior and rationale for this change.
* fmt
* install clang in ci
* Revert "install clang in ci"
This reverts commit 1990118.
* install clang in docker
* initial BLS precompile solidity test working
* rename clean up solidity test
* use split_at in g1_add
* cargo fmt fix
* Update BLSPrecompile.sol
* merge pre-megre and master
* cargo fmt
* add remaining fns except pairing
* add pairing tests
* cargo fmt
* add clang for tests
* Update actors/evm/tests/contracts/BLSPrecompile.sol
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update actors/evm/tests/contracts/BLSPrecompile.sol
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update actors/evm/tests/contracts/BLSPrecompile.sol
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update actors/evm/tests/contracts/BLSPrecompile.sol
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update actors/evm/tests/contracts/BLSPrecompile.sol
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls_util.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls_util.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls_util.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* **feat(evm/bls): localize FFI `unsafe`, prefer refs over raw ptrs; minor import cleanup**
This changeset tightens FFI hygiene in the BLS precompile utilities and removes a redundant test import. It replaces raw-pointer parameters with safe references in internal helpers, keeps `unsafe` scoped to the FFI boundary, and simplifies a call site import.
* **`bls_util::fp_to_bytes`**
* **Signature:** `fn fp_to_bytes(out: &mut [u8], input: *const blst_fp)` → `fn fp_to_bytes(out: &mut [u8], input: &blst_fp)`
* **Behavior:** unchanged; `unsafe` is now localized to the FFI call.
* **Docs:** clarified purpose and safety.
* **`bls_util::encode_g1_point`**
* **Signature:** `fn encode_g1_point(input: *const blst_p1_affine) -> Vec<u8>` → `fn encode_g1_point(input: &blst_p1_affine) -> Vec<u8>`
* **Behavior:** unchanged; uses the updated `fp_to_bytes` and no longer requires a raw pointer at call sites.
* **Docs:** clarified purpose and safety.
* **`g2_msm.rs`**
* **Imports:** add `use crate::interpreter::precompiles::bls_util::is_infinity;`
* **Call site:** use the imported `is_infinity` directly (no fully-qualified path).
* **`g1_msm.rs` (tests)**
* **Cleanup:** remove duplicate `use hex_literal::hex;`.
* Keep raw pointers and `unsafe` **inside** the FFI wrapper functions; accept normal Rust references everywhere else. This improves readability, lets the type system carry aliasing/lifetime guarantees, and makes future refactors safer.
* Minor import cleanup eliminates noise in tests.
* Both updated helpers remain within the precompile utilities. Existing call sites that previously passed `&affine` or `&fp` continue to compile with the new signatures. No behavior or encoding changes.
* Updated safety comments to clarify the unsafe blocks
* Update actors/evm/src/interpreter/precompiles/bls12_381/g1_msm.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls12_381/g1_msm.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls12_381/g1_msm.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* added better comments for g1_add
* Update actors/evm/src/interpreter/precompiles/bls12_381/g2_add.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* added better comments in g2_add
* removed unnecessary variables
* bls12-381: fix pairing filter; accept ∞; clarify G2 ABI; tests; CI
- pairing.rs: use logical && (not bitwise &) when skipping pairs with
infinity so we don’t accidentally include a pair when exactly one side
is ∞.
- bls_util.rs:
- encode_g2_point docs: spell out exact layout and endianness
(x.re || x.im || y.re || y.im as 16B zero-pad + 48B BE Fp).
- fp_to_bytes: add debug_assert on buffer length to catch misuse in
debug builds without changing runtime behavior.
- decode_g1_on_curve / decode_g2_on_curve: accept inputs that are
on-curve OR infinity, per EIP-2537; error only if neither.
- tests/basic.rs: for BLS happy-path invocations assert that calls don’t
revert and return no data.
- CI: install clang only on Linux and with --no-install-recommends to
keep GitHub runners lean and portable.
All EVM crate tests pass locally.
* cargo fmt
* Update actors/evm/src/interpreter/precompiles/bls12_381/map_fp2_to_g2.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls12_381/g1_msm.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls12_381/g2_msm.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* Update actors/evm/src/interpreter/precompiles/bls12_381/pairing.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* using is_infinity trait
* add remaining g1_msm tests
* correct g1_msm fail tests
* added missing g2_msm test
* added test names in map_gp_to_g1
* Update actors/evm/src/interpreter/precompiles/bls_util.rs
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>
* removed repeated check in bls_util
* reduced ffi calls in bls_util, removed unnecessary debug_assert_eq
* changed safety comment
* added test names to solidity fns
* cargo fmt
* check c compiler does wasm via @ZenGround0
* format
---------
Co-authored-by: aaravm <aarav.mehta.mat22@itbhu.ac.in>
Co-authored-by: Aarav Mehta <32593731+aaravm@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: ZenGround0 <5515260+ZenGround0@users.noreply.github.com>1 parent fe3e331 commit 747a3ed
File tree
18 files changed
+2979
-10
lines changed- .github/workflows
- actors/evm
- src/interpreter/precompiles
- bls12_381
- tests
- contracts
18 files changed
+2979
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
0 commit comments