Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into sync/0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpwang committed Dec 18, 2023
2 parents 00975be + c7f8867 commit 568d8e5
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "halo2curves-axiom"
version = "0.4.4"
version = "0.5.0"
authors = ["Privacy Scaling Explorations team", "Taiko Labs", "Intrinsic Technologies"]
license = "MIT/Apache-2.0"
edition = "2021"
Expand Down
7 changes: 3 additions & 4 deletions src/derive/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,11 @@ macro_rules! new_curve_impl {
}

paste::paste! {
#[allow(unused_imports)]
use ::serde::de::Error as _;
impl<'de> ::serde::Deserialize<'de> for $name {
fn deserialize<D: ::serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Self, D::Error> {
use ::serde::de::Error as _;
let bytes = if deserializer.is_human_readable() {
::hex::serde::deserialize(deserializer)?
} else {
Expand All @@ -335,12 +334,11 @@ macro_rules! new_curve_impl {
}

paste::paste! {
#[allow(unused_imports)]
use ::serde::de::Error as _;
impl<'de> ::serde::Deserialize<'de> for $name_affine {
fn deserialize<D: ::serde::Deserializer<'de>>(
deserializer: D,
) -> Result<Self, D::Error> {
use ::serde::de::Error as _;
let bytes = if deserializer.is_human_readable() {
::hex::serde::deserialize(deserializer)?
} else {
Expand Down Expand Up @@ -532,6 +530,7 @@ macro_rules! new_curve_impl {
}


#[allow(clippy::redundant_closure_call)]
fn hash_to_curve<'a>(domain_prefix: &'a str) -> Box<dyn Fn(&[u8]) -> Self + 'a> {
$hash_to_curve($curve_id, domain_prefix)
}
Expand Down
2 changes: 1 addition & 1 deletion src/derive/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! field_common {
$crate::ff_ext::jacobi::jacobi::<5>(&self.0, &$modulus.0)
}

#[allow(dead_code)]
#[cfg(feature = "asm")]
const fn montgomery_form(val: [u64; 4], r: $field) -> $field {
// Converts a 4 64-bit limb value into its congruent field representation.
// If `val` representes a 256 bit value then `r` should be R^2,
Expand Down
26 changes: 13 additions & 13 deletions src/ff_ext/inverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ impl<const B: usize, const L: usize> Add for &CInt<B, L> {
type Output = CInt<B, L>;
fn add(self, other: Self) -> Self::Output {
let (mut data, mut carry) = ([0; L], 0);
for i in 0..L {
for (i, d) in data.iter_mut().enumerate().take(L) {
let sum = self.0[i] + other.0[i] + carry;
data[i] = sum & CInt::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down Expand Up @@ -91,12 +91,12 @@ impl<const B: usize, const L: usize> Sub for &CInt<B, L> {
// addition algorithm, where the carry flag is initialized with 1 and
// the chunks of the second argument are bitwise inverted
let (mut data, mut carry) = ([0; L], 1);
for i in 0..L {
for (i, d) in data.iter_mut().enumerate().take(L) {
let sum = self.0[i] + (other.0[i] ^ CInt::<B, L>::MASK) + carry;
data[i] = sum & CInt::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand All @@ -120,12 +120,12 @@ impl<const B: usize, const L: usize> Neg for &CInt<B, L> {
// For the two's complement code the additive negation is the result
// of adding 1 to the bitwise inverted argument's representation
let (mut data, mut carry) = ([0; L], 1);
for i in 0..L {
for (i, d) in data.iter_mut().enumerate().take(L) {
let sum = (self.0[i] ^ CInt::<B, L>::MASK) + carry;
data[i] = sum & CInt::<B, L>::MASK;
*d = sum & CInt::<B, L>::MASK;
carry = sum >> B;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand All @@ -150,7 +150,7 @@ impl<const B: usize, const L: usize> Mul for &CInt<B, L> {
carry = (sum >> B) as u64;
}
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down Expand Up @@ -189,12 +189,12 @@ impl<const B: usize, const L: usize> Mul<i64> for &CInt<B, L> {
} else {
(other, 0, 0)
};
for i in 0..L {
for (i, d) in data.iter_mut().enumerate().take(L) {
let sum = (carry as u128) + ((self.0[i] ^ mask) as u128) * (other as u128);
data[i] = sum as u64 & CInt::<B, L>::MASK;
*d = sum as u64 & CInt::<B, L>::MASK;
carry = (sum >> B) as u64;
}
Self::Output { 0: data }
CInt::<B, L>(data)
}
}

Expand Down
34 changes: 17 additions & 17 deletions src/ff_ext/jacobi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ impl<const L: usize> Shr<u32> for &LInt<L> {
"Cannot shift by 0 or more than 63 bits!"
);
let (mut data, right) = ([0; L], u64::BITS - bits);
for i in 0..(L - 1) {
data[i] = (self.0[i] >> bits) | (self.0[i + 1] << right);

for (i, d) in data.iter_mut().enumerate().take(L - 1) {
*d = (self.0[i] >> bits) | (self.0[i + 1] << right);
}
data[L - 1] = self.0[L - 1] >> bits;
if self.is_negative() {
data[L - 1] |= u64::MAX << right;
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand All @@ -96,10 +97,10 @@ impl<const L: usize> Add for &LInt<L> {
type Output = LInt<L>;
fn add(self, other: Self) -> Self::Output {
let (mut data, mut carry) = ([0; L], false);
for i in 0..L {
(data[i], carry) = Self::Output::sum(self.0[i], other.0[i], carry);
for (i, d) in data.iter_mut().enumerate().take(L) {
(*d, carry) = Self::Output::sum(self.0[i], other.0[i], carry);
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand Down Expand Up @@ -128,10 +129,10 @@ impl<const L: usize> Sub for &LInt<L> {
// addition algorithm, where the carry flag is initialized with "true"
// and the chunks of the second argument are bitwise inverted
let (mut data, mut carry) = ([0; L], true);
for i in 0..L {
(data[i], carry) = Self::Output::sum(self.0[i], !other.0[i], carry);
for (i, d) in data.iter_mut().enumerate().take(L) {
(*d, carry) = Self::Output::sum(self.0[i], !other.0[i], carry);
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand All @@ -155,10 +156,10 @@ impl<const L: usize> Neg for &LInt<L> {
// For the two's complement code the additive negation is the result
// of adding 1 to the bitwise inverted argument's representation
let (mut data, mut carry) = ([0; L], true);
for i in 0..L {
(data[i], carry) = (!self.0[i]).overflowing_add(carry as u64);
for (i, d) in data.iter_mut().enumerate().take(L) {
(*d, carry) = (!self.0[i]).overflowing_add(carry as u64);
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand All @@ -180,7 +181,7 @@ impl<const L: usize> Mul for &LInt<L> {
Self::Output::prodsum(self.0[i], other.0[k], data[i + k], carry);
}
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand Down Expand Up @@ -219,11 +220,10 @@ impl<const L: usize> Mul<i64> for &LInt<L> {
} else {
(other as u64, 0, 0)
};
#[allow(clippy::needless_range_loop)]
for i in 0..L {
(data[i], carry) = Self::Output::prodsum(self.0[i] ^ mask, other, 0, carry);
for (i, d) in data.iter_mut().enumerate().take(L) {
(*d, carry) = Self::Output::prodsum(self.0[i] ^ mask, other, 0, carry);
}
Self::Output { 0: data }
LInt::<L>(data)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &
let mut buckets: Vec<Bucket<C>> = vec![Bucket::None; 1 << (c - 1)];

for (coeff, base) in coeffs.iter().zip(bases.iter()) {
let coeff = get_booth_index(current_window as usize, c, coeff.as_ref());
let coeff = get_booth_index(current_window, c, coeff.as_ref());
if coeff.is_positive() {
buckets[coeff as usize - 1].add_assign(base);
}
Expand Down Expand Up @@ -333,7 +333,7 @@ mod test {
acc = acc.double();
}

let idx = super::get_booth_index(i as usize, window, u.as_ref());
let idx = super::get_booth_index(i, window, u.as_ref());

if idx.is_negative() {
acc += table[idx.unsigned_abs() as usize].neg();
Expand Down
2 changes: 1 addition & 1 deletion src/pluto_eris/fields/fp12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ fn test_frobenius() {
let mut b = a;

for _ in 0..i {
a = a.pow_vartime(&[
a = a.pow_vartime([
0x9ffffcd300000001,
0xa2a7e8c30006b945,
0xe4a7a5fe8fadffd6,
Expand Down
4 changes: 2 additions & 2 deletions src/pluto_eris/fields/fp2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl Field for Fp2 {
};

// Algorithm (not constant time)
let b = self.pow_vartime(&[
let b = self.pow_vartime([
// (p-1)/4 =
// 0x900000000000900004c3800035fdc392a00f29dbd0e499bd10fe69736a29b1ef929e97fa3eb7ff5a8a9fa30c001ae5167ffff34c0000000
0x67ffff34c0000000,
Expand Down Expand Up @@ -747,7 +747,7 @@ fn test_frobenius() {
let mut b = a;

for _ in 0..i {
a = a.pow_vartime(&[
a = a.pow_vartime([
0x9ffffcd300000001,
0xa2a7e8c30006b945,
0xe4a7a5fe8fadffd6,
Expand Down
2 changes: 1 addition & 1 deletion src/pluto_eris/fields/fp6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ fn test_frobenius() {
let mut b = a;

for _ in 0..i {
a = a.pow_vartime(&[
a = a.pow_vartime([
// p
0x9ffffcd300000001,
0xa2a7e8c30006b945,
Expand Down
3 changes: 0 additions & 3 deletions src/pluto_eris/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
//! Supporting evidence: https://github.com/daira/pluto-eris
//! Field constant derivation: https://github.com/davidnevadoc/ec-constants/tree/main/pluto_eris
//! Pairing constants derivation: https://github.com/John-Gong-Math/pluto_eris/blob/main/pluto_pairing.ipynb

// temporarily allow clippy::all to avoid warnings in this module:
#[allow(clippy::all)]
mod curve;
mod engine;
mod fields;
Expand Down

0 comments on commit 568d8e5

Please sign in to comment.