Skip to main content

solana_bls12_381_syscall/
lib.rs

1//! Implementation of the BLS12-381 Elliptic Curve operations for Solana syscalls.
2//!
3//! This crate provides the native implementations for the syscalls defined in
4//! [SIMD-0388](https://github.com/solana-foundation/solana-improvement-documents/pull/388).
5//!
6//! # Supported Operations
7//!
8//! - **Group Operations** (G1 & G2): Addition, Subtraction, Scalar Multiplication.
9//! - **Pairing**: Product of pairings over G1/G2 point pairs (multi-Miller loop + final exponentiation).
10//! - **Validation**: Subgroup and on-curve checks.
11//! - **Decompression**: Converting compressed byte representations to affine points.
12//!
13//! # Encoding and Endianness
14//!
15//! The operations support two encoding formats defined in [`Endianness`]:
16//! 1. **Big-Endian (BE)**: Follows the [Zcash BLS12-381 specification][zcash] and
17//!    [IETF draft][ietf].
18//! 2. **Little-Endian (LE)**: This mirrors the Zcash structure but utilizes little-endian
19//!    byte ordering for base field elements.
20//!
21//! [zcash]: https://github.com/zkcrypto/pairing/tree/master/src/bls12_381#serialization
22//! [ietf]: https://www.ietf.org/archive/id/draft-irtf-cfrg-pairing-friendly-curves-11.html#name-bls-curves-for-the-128-bit-
23
24pub use crate::{
25    addition::{bls12_381_g1_addition_unchecked, bls12_381_g2_addition_unchecked},
26    decompression::{bls12_381_g1_decompress, bls12_381_g2_decompress},
27    encoding::{
28        Endianness, PodG1Compressed, PodG1Point, PodG2Compressed, PodG2Point, PodGtElement,
29        PodScalar,
30    },
31    multiplication::{bls12_381_g1_multiplication, bls12_381_g2_multiplication},
32    pairing::bls12_381_pairing_map,
33    subtraction::{bls12_381_g1_subtraction_unchecked, bls12_381_g2_subtraction_unchecked},
34    validation::{bls12_381_g1_point_validation, bls12_381_g2_point_validation},
35};
36
37pub(crate) mod addition;
38pub(crate) mod decompression;
39pub(crate) mod encoding;
40pub(crate) mod multiplication;
41pub(crate) mod pairing;
42pub(crate) mod subtraction;
43#[cfg(test)]
44pub(crate) mod test_vectors;
45pub(crate) mod validation;
46
47/// Version identifier for the syscall interface.
48///
49/// Modifying the behavior of syscalls is a consensus-critical operation.
50/// Any change in behavior across the network without proper coordination will result
51/// in a network fork.
52///
53/// If a change to the syscall behavior is required:
54/// 1. The change must first be proposed and approved via a
55///    [Solana Improvement Document (SIMD)](https://github.com/solana-foundation/solana-improvement-documents).
56/// 2. Once the SIMD is accepted, a new variant should be added to this enum (e.g., `V1`).
57/// 3. The implementation of every function in this crate must be scoped to handle the
58///    specific logic for each version variant.
59pub enum Version {
60    /// SIMD-388: BLS12-381 Elliptic Curve Syscalls
61    V0,
62}