Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
715 changes: 221 additions & 494 deletions Cargo.lock

Large diffs are not rendered by default.

28 changes: 13 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
members = [
"arith", # definitions of Field, Extensions, SIMDS
"arith/babybear",
"arith/gf2",
"arith/gf2_128",
"arith/goldilocks",
"arith/mersenne31",
# "arith/babybear",
# "arith/gf2",
# "arith/gf2_128",
# "arith/goldilocks",
# "arith/mersenne31",
"arith/polynomials",
"bin", # binary executables
"circuit",
Expand All @@ -25,34 +25,32 @@ members = [
resolver = "2"

[workspace.dependencies]
ark-std = "0.4"
ark-bn254 = "0.4.0"
ark-ec = "0.4.0"
ark-ff = { version = "0.4" }
ark-std = "0.5"
ark-bn254 = "0.5.0"
ark-ec = "0.5.0"
ark-ff = { version = "0.5" }
ark-serialize = "0.5.0"
bytes = "1.6.0"
chrono = "0.4.38"
clap = { version = "4.1", features = ["derive"] }
cfg-if = "1.0"
criterion = { version = "0.5", features = ["html_reports"] }
env_logger = "0.11.3"
halo2curves = { git = "https://github.com/PolyhedraZK/halo2curves", default-features = false, features = [
"bits",
] }
syn = "2.0" # For parsing Rust code
quote = "1.0" # For generating code
proc-macro2 = "1.0" # For working with tokens
itertools = "0.13"
log = "0.4"
mpi = { git = "https://github.com/rsmpi/rsmpi", rev = "61796831954b679cbe267c1b704ddbcb7fef3715" }
rand = "0.8.5"
# mpi = { git = "https://github.com/rsmpi/rsmpi", rev = "61796831954b679cbe267c1b704ddbcb7fef3715" }
# rand = { version = "0.8.5", features = ["std"] }
raw-cpuid = "11.1.0"
rayon = "1.10"
sha2 = "0.10.8"
tiny-keccak = { version = "2.0.2", features = [ "sha3", "keccak" ] }
tokio = { version = "1.38.0", features = ["full"] }
tynm = { version = "0.1.6", default-features = false }
warp = "0.3.7"
thiserror = "1.0.63"
thiserror = { version = "2.0", default-features = false }
ethnum = "1.5.0"
rand_chacha = "0.3.1"
derivative = "2.2.0"
Expand Down
9 changes: 4 additions & 5 deletions arith/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ark-ff.workspace = true
ark-std.workspace = true
criterion.workspace = true
ark-bn254.workspace = true
ethnum.workspace = true
itertools.workspace = true
halo2curves.workspace = true
log.workspace = true
rand.workspace = true
tynm.workspace = true

serdes = { path = "../serdes" }

[features]
halo2_asm = [ "halo2curves/asm" ]
[dev-dependencies]
criterion.workspace = true

[[bench]]
name = "fr"
Expand Down
30 changes: 18 additions & 12 deletions arith/babybear/src/babybear_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ impl Field for BabyBearExt3 {

const FIELD_SIZE: usize = 32 * 3;

const ZERO: Self = BabyBearExt3 {
v: [BabyBear::ZERO, BabyBear::ZERO, BabyBear::ZERO],
};
// const ZERO: Self = BabyBearExt3 {
// v: [BabyBear::zero(), BabyBear::zero(), BabyBear::zero()],
// };

const ONE: Self = BabyBearExt3 {
v: [BabyBear::ONE, BabyBear::ZERO, BabyBear::ZERO],
};
// const ONE: Self = BabyBearExt3 {
// v: [BabyBear::one(), BabyBear::zero(), BabyBear::zero()],
// };

const INV_2: BabyBearExt3 = BabyBearExt3 {
v: [BabyBear::INV_2, BabyBear::new(0), BabyBear::new(0)],
};
// const INV_2: BabyBearExt3 = BabyBearExt3 {
// v: [BabyBear::INV_2, BabyBear::new(0), BabyBear::new(0)],
// };

const MODULUS: U256 = BabyBear::MODULUS;

Expand Down Expand Up @@ -118,9 +118,15 @@ impl ExtensionField for BabyBearExt3 {
/// Extension Field
const W: u32 = 2;

const X: Self = BabyBearExt3 {
v: [BabyBear::ZERO, BabyBear::ONE, BabyBear::ZERO],
};
// const X: Self = BabyBearExt3 {
// v: [BabyBear::zero(), BabyBear::one(), BabyBear::zero()],
// };

fn x() -> Self {
BabyBearExt3 {
v: [BabyBear::zero(), BabyBear::one(), BabyBear::zero()],
}
}

/// Base field for the extension
type BaseField = BabyBear;
Expand Down
30 changes: 18 additions & 12 deletions arith/babybear/src/babybear_ext3x16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ impl ExtensionField for BabyBearExt3x16 {

const W: u32 = 2;

const X: Self = BabyBearExt3x16 {
v: [BabyBearx16::ZERO, BabyBearx16::ONE, BabyBearx16::ZERO],
};
// const X: Self = BabyBearExt3x16 {
// v: [BabyBearx16::zero(), BabyBearx16::one(), BabyBearx16::zero()],
// };

fn x() -> Self {
BabyBearExt3x16 {
v: [BabyBearx16::zero(), BabyBearx16::one(), BabyBearx16::zero()],
}
}

type BaseField = BabyBearx16;

Expand Down Expand Up @@ -176,17 +182,17 @@ impl Field for BabyBearExt3x16 {

const FIELD_SIZE: usize = 32 * 3;

const ZERO: Self = Self {
v: [BabyBearx16::ZERO; 3],
};
// const ZERO: Self = Self {
// v: [BabyBearx16::zero(); 3],
// };

const ONE: Self = Self {
v: [BabyBearx16::ONE, BabyBearx16::ZERO, BabyBearx16::ZERO],
};
// const ONE: Self = Self {
// v: [BabyBearx16::one(), BabyBearx16::zero(), BabyBearx16::zero()],
// };

const INV_2: Self = Self {
v: [BabyBearx16::INV_2, BabyBearx16::ZERO, BabyBearx16::ZERO],
};
// const INV_2: Self = Self {
// v: [BabyBearx16::INV_2, BabyBearx16::zero(), BabyBearx16::zero()],
// };

const MODULUS: U256 = BabyBear::MODULUS;

Expand Down
26 changes: 14 additions & 12 deletions arith/babybear/src/babybearx16/babybear_avx256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const PACKED_0: __m256i = unsafe { transmute([0; 8]) };
// 1 in Montgomery form
const PACKED_1: __m256i = unsafe { transmute([0xffffffe; 8]) };

// 2^-1 Montgomery form
const PACKED_INV_2: __m256i = unsafe { transmute([0x7ffffff; 8]) };
// // 2^-1 Montgomery form
// const PACKED_INV_2: __m256i = unsafe { transmute([0x7ffffff; 8]) };

const PACKED_MOD: __m256i = unsafe { transmute([BABY_BEAR_MOD; 8]) };

Expand Down Expand Up @@ -71,25 +71,27 @@ impl Field for AVXBabyBear {

const SIZE: usize = 512 / 8;

const ZERO: Self = Self {
v: [PACKED_0, PACKED_0],
};
// const ZERO: Self = Self {
// v: [PACKED_0, PACKED_0],
// };

const ONE: Self = Self {
v: [PACKED_1, PACKED_1],
};
// const ONE: Self = Self {
// v: [PACKED_1, PACKED_1],
// };

const INV_2: Self = Self {
v: [PACKED_INV_2, PACKED_INV_2],
};
// const INV_2: Self = Self {
// v: [PACKED_INV_2, PACKED_INV_2],
// };

const FIELD_SIZE: usize = 32;

const MODULUS: U256 = U256([BABY_BEAR_MOD as u128, 0]);

#[inline(always)]
fn zero() -> Self {
Self::ZERO
Self {
v: [PACKED_0, PACKED_0],
}
}

#[inline(always)]
Expand Down
12 changes: 6 additions & 6 deletions arith/babybear/src/babybearx16/babybear_avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const PACKED_0: __m512i = unsafe { transmute([0; BABY_BEAR_PACK_SIZE]) };
// 1 in Montgomery form
const PACKED_1: __m512i = unsafe { transmute([0xffffffe; BABY_BEAR_PACK_SIZE]) };

// 2^-1 Montgomery form
const PACKED_INV_2: __m512i = unsafe { transmute([0x7ffffff; BABY_BEAR_PACK_SIZE]) };
// // 2^-1 Montgomery form
// const PACKED_INV_2: __m512i = unsafe { transmute([0x7ffffff; BABY_BEAR_PACK_SIZE]) };

const PACKED_MOD: __m512i = unsafe { transmute([BABY_BEAR_MOD; BABY_BEAR_PACK_SIZE]) };

Expand Down Expand Up @@ -71,19 +71,19 @@ impl Field for AVXBabyBear {

const SIZE: usize = 512 / 8;

const ZERO: Self = Self { v: PACKED_0 };
// const ZERO: Self = Self { v: PACKED_0 };

const ONE: Self = Self { v: PACKED_1 };
// const ONE: Self = Self { v: PACKED_1 };

const INV_2: Self = Self { v: PACKED_INV_2 };
// const INV_2: Self = Self { v: PACKED_INV_2 };

const FIELD_SIZE: usize = 32;

const MODULUS: U256 = U256([BABY_BEAR_MOD as u128, 0]);

#[inline(always)]
fn zero() -> Self {
Self::ZERO
Self { v: PACKED_0 }
}

#[inline(always)]
Expand Down
12 changes: 6 additions & 6 deletions arith/babybear/src/babybearx16/babybear_neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ impl Field for NeonBabyBear {
const ZERO: Self = Self {
v: unsafe {
transmute::<[BabyBear; BABY_BEAR_PACK_SIZE], [uint32x4_t; 4]>(
[BabyBear::ZERO; BABY_BEAR_PACK_SIZE],
[BabyBear::zero(); BABY_BEAR_PACK_SIZE],
)
},
};

const ONE: Self = Self {
v: unsafe {
transmute::<[BabyBear; BABY_BEAR_PACK_SIZE], [uint32x4_t; 4]>(
[BabyBear::ONE; BABY_BEAR_PACK_SIZE],
[BabyBear::one(); BABY_BEAR_PACK_SIZE],
)
},
};
Expand All @@ -106,15 +106,15 @@ impl Field for NeonBabyBear {
const MODULUS: U256 = BabyBear::MODULUS;

fn zero() -> Self {
Self::ZERO
Self::zero()
}

fn is_zero(&self) -> bool {
*self == Self::ZERO
*self == Self::zero()
}

fn one() -> Self {
Self::ONE
Self::one()
}

fn random_unsafe(mut rng: impl RngCore) -> Self {
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Debug for NeonBabyBear {

impl Default for NeonBabyBear {
fn default() -> Self {
Self::ZERO
Self::zero()
}
}

Expand Down
2 changes: 1 addition & 1 deletion arith/babybear/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn baby_bear_two_inverse() {
let two = BabyBear::new(2);
let two_inverse_canonical: u32 = 1006632961;
let two_inverse = BabyBear::new(two_inverse_canonical);
let one = BabyBear::ONE;
let one = BabyBear::one();
assert_eq!(one, two * two_inverse)
}

Expand Down
2 changes: 1 addition & 1 deletion arith/benches/fft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub fn halo2_serial_fft<F: FFTField>(a: &mut [F], omega: F, log_n: u32) {

// precompute twiddle factors
let twiddles: Vec<_> = (0..(n / 2))
.scan(F::ONE, |w, _| {
.scan(F::one(), |w, _| {
let tw = *w;
*w *= &omega;
Some(tw)
Expand Down
1 change: 0 additions & 1 deletion arith/gf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ arith = { path = "../" }
serdes = { path = "../../serdes" }

ark-std.workspace = true
halo2curves.workspace = true
log.workspace = true
rand.workspace = true
thiserror.workspace = true
Expand Down
8 changes: 4 additions & 4 deletions arith/gf2/src/gf2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ impl Field for GF2 {

const FIELD_SIZE: usize = 1; // in bits

const ZERO: Self = GF2 { v: 0 };
// const ZERO: Self = GF2 { v: 0 };

const ONE: Self = GF2 { v: 1 };
// const ONE: Self = GF2 { v: 1 };

const INV_2: Self = GF2 { v: 0 };
// const INV_2: Self = GF2 { v: 0 };

const MODULUS: U256 = U256([MOD as u128, 0]);

Expand Down Expand Up @@ -124,7 +124,7 @@ impl Field for GF2 {

#[inline(always)]
fn mul_by_6(&self) -> Self {
Self::ZERO
Self::zero()
}

#[inline(always)]
Expand Down
8 changes: 4 additions & 4 deletions arith/gf2/src/gf2x128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl SimdField for GF2x128 {
#[inline(always)]
fn scale(&self, challenge: &Self::Scalar) -> Self {
if challenge.v == 0 {
<Self as Field>::ZERO
<Self as Field>::zero()
} else {
*self
}
Expand All @@ -31,16 +31,16 @@ impl SimdField for GF2x128 {
#[inline(always)]
fn pack_full(base: &Self::Scalar) -> Self {
match base.v {
0 => Self::ZERO,
1 => Self::ONE,
0 => Self::zero(),
1 => Self::one(),
_ => panic!("Invalid value for GF2x128: {}", base.v),
}
}

#[inline(always)]
fn pack(base_vec: &[Self::Scalar]) -> Self {
assert_eq!(base_vec.len(), Self::PACK_SIZE);
let mut packed_to_gf2x64 = [GF2x64::ZERO; Self::PACK_SIZE / GF2x64::PACK_SIZE];
let mut packed_to_gf2x64 = [GF2x64::zero(); Self::PACK_SIZE / GF2x64::PACK_SIZE];
packed_to_gf2x64
.iter_mut()
.zip(base_vec.chunks(GF2x64::PACK_SIZE))
Expand Down
Loading
Loading