Skip to content

Commit

Permalink
patch: G1Projective ops, fp6 compile to default target
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Jan 3, 2025
1 parent 10da64a commit 4182270
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ impl_binops_multiplicative_mixed!(Scalar, G1Affine, G1Projective);
impl_binops_multiplicative_mixed!(Scalar, G1Projective, G1Projective);

#[inline(always)]
#[cfg(not(target_os = "zkvm"))]
fn mul_by_3b(a: Fp) -> Fp {
let a = a + a; // 2
let a = a + a; // 4
Expand Down Expand Up @@ -837,6 +838,7 @@ impl G1Projective {
}

/// Multiply `self` by `crate::BLS_X`, using double and add.
#[cfg(not(target_os = "zkvm"))]
fn mul_by_x(&self) -> G1Projective {
let mut xself = G1Projective::identity();
// NOTE: in BLS12-381 we can just skip the first bit.
Expand All @@ -857,6 +859,27 @@ impl G1Projective {
xself
}

#[cfg(target_os = "zkvm")]
fn mul_by_x(&self) -> G1Projective {
let mut xself = G1Affine::identity();

let mut x = crate::BLS_X >> 1;
let mut tmp = G1Affine::from(*self);
while x != 0 {
tmp = tmp.double();

if x % 2 == 1 {
xself = &xself + tmp;
}
x >>= 1;
}
// finally, flip the sign
if crate::BLS_X_IS_NEGATIVE {
xself = -xself;
}
xself.into()
}

/// Multiplies by $(1 - z)$, where $z$ is the parameter of BLS12-381, which
/// [suffices to clear](https://ia.cr/2019/403) the cofactor and map
/// elliptic curve points to elements of $\mathbb{G}\_1$.
Expand Down

0 comments on commit 4182270

Please sign in to comment.