Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump ff & group to 0.13 #179

Merged
merged 8 commits into from
Apr 18, 2023
Merged
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
21 changes: 10 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,33 @@ repository = "https://github.com/lurk-lab/neptune"
resolver = "2"

[dependencies]
lazy_static = "1.4.0"
bellperson = { version = "0.24", default-features = false }
bellperson = { version = "0.25", default-features = false }
blake2s_simd = "0.5"
blstrs = { version = "0.6.1", optional = true }
blstrs = { version = "0.7.0", optional = true }
byteorder = "1"
ec-gpu = { version = "0.2.0", optional = true }
ec-gpu-gen = { version = "0.5.2", optional = true }
ff = "0.12.1"
ec-gpu-gen = { version = "0.6.0", optional = true }
ff = "0.13.0"
generic-array = "0.14.6"
itertools = { version = "0.8.2" }
log = "0.4.17"
pasta_curves = { version = "0.5.2", features = ["serde"], package = "fil_pasta_curves" }
pasta_curves = { version = "0.5", features = ["serde"] }
trait-set = "0.3.0"
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
blstrs = "0.6.1"
blstrs = "0.7.0"
criterion = "0.4.0"
rand = "0.8.5"
rand_xorshift = "0.3.0"
serde_json = "1.0.94"
sha2 = "0.9"

[build-dependencies]
blstrs = "0.6.1"
blstrs = "0.7.0"
ec-gpu = { version = "0.2.0", optional = true }
ec-gpu-gen = { version = "0.5.2", optional = true }
pasta_curves = { version = "0.5.2", package = "fil_pasta_curves" }
ec-gpu-gen = { version = "0.6.0", optional = true }
pasta_curves = { version = "0.5", features = ["serde"] }

[[bench]]
name = "hash"
Expand Down Expand Up @@ -71,4 +70,4 @@ pasta = ["pasta_curves/gpu"]
[workspace]
members = [
"gbench",
]
]
2 changes: 1 addition & 1 deletion benches/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ where

let mut group = c.benchmark_group(format!("arity-{}", arity));

let preimage = vec![Fr::one(); arity];
let preimage = vec![Fr::ONE; arity];
let consts = PoseidonConstants::<Fr, A>::new();
group.bench_function("bls", |b| {
b.iter(|| Poseidon::new_with_preimage(&preimage, &consts).hash())
Expand Down
11 changes: 5 additions & 6 deletions gbench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ edition = "2018"
license = "MIT OR Apache-2.0"

[dependencies]
lazy_static = "1.4.0"
bellperson = { version = "0.24.1", default-features = false }
bellperson = { version = "0.25.0", default-features = false }
blake2s_simd = "0.5"
byteorder = "1"
env_logger = "0.7.1"
ff = "0.12.1"
ff = "0.13.0"
generic-array = "0.14.6"
log = "0.4.17"
neptune = { path = "../", default-features = false, features = ["arity8", "arity11", "bls", "pasta"] }
structopt = { version = "0.3", default-features = false }
blstrs = { version = "0.6.1", features = ["gpu"] }
pasta_curves = { version = "0.5.2", features = ["gpu"], package = "fil_pasta_curves" }
blstrs = { version = "0.7.0", features = ["gpu"] }
pasta_curves = { version = "0.5.1", features = ["gpu"]}
ec-gpu = "0.2.0"
ec-gpu-gen = "0.5.2"
ec-gpu-gen = "0.6.0"

[features]
default = ["opencl"]
Expand Down
2 changes: 1 addition & 1 deletion gbench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn bench_column_building<F: PrimeField + GpuName>(
info!("{}: ColumnTreeBuilder created", log_prefix);

// Simplify computing the expected root.
let constant_element = F::zero();
let constant_element = F::ZERO;
let constant_column = GenericArray::<F, U11>::generate(|_| constant_element);

let max_batch_size = if let Some(batcher) = &builder.column_batcher {
Expand Down
6 changes: 3 additions & 3 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<Scalar: PrimeField> Elt<Scalar> {
if enforce {
cs.enforce(
|| "enforce num allocation preserves lc".to_string(),
|_| num.lc(Scalar::one()),
|_| num.lc(Scalar::ONE),
|lc| lc + CS::one(),
|lc| lc + v.get_variable(),
);
Expand All @@ -102,7 +102,7 @@ impl<Scalar: PrimeField> Elt<Scalar> {

fn lc(&self) -> LinearCombination<Scalar> {
match self {
Self::Num(num) => num.lc(Scalar::one()),
Self::Num(num) => num.lc(Scalar::ONE),
Self::Allocated(v) => LinearCombination::<Scalar>::zero() + v.get_variable(),
}
}
Expand Down Expand Up @@ -683,7 +683,7 @@ mod tests {
};
let mut i = 0;

let mut fr_data = vec![Fr::zero(); preimage_length];
let mut fr_data = vec![Fr::ZERO; preimage_length];
let data: Vec<AllocatedNum<Fr>> = (0..preimage_length)
.enumerate()
.map(|_| {
Expand Down
16 changes: 8 additions & 8 deletions src/circuit2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<Scalar: PrimeField> Elt<Scalar> {
if enforce {
cs.enforce(
|| "enforce num allocation preserves lc".to_string(),
|_| num.lc(Scalar::one()),
|_| num.lc(Scalar::ONE),
|lc| lc + CS::one(),
|lc| lc + v.get_variable(),
);
Expand All @@ -74,7 +74,7 @@ impl<Scalar: PrimeField> Elt<Scalar> {

pub fn lc(&self) -> LinearCombination<Scalar> {
match self {
Self::Num(num) => num.lc(Scalar::one()),
Self::Num(num) => num.lc(Scalar::ONE),
Self::Allocated(v) => LinearCombination::<Scalar>::zero() + v.get_variable(),
}
}
Expand Down Expand Up @@ -119,8 +119,8 @@ impl<Scalar: PrimeField> Elt<Scalar> {
AllocatedNum::alloc(&mut cs.namespace(|| "squared num"), || Ok(tmp))?;
cs.enforce(
|| "squaring constraint",
|_| num.lc(Scalar::one()),
|_| num.lc(Scalar::one()),
|_| num.lc(Scalar::ONE),
|_| num.lc(Scalar::ONE),
|lc| lc + allocated.get_variable(),
);
Ok(allocated)
Expand Down Expand Up @@ -225,7 +225,7 @@ where
match self.constants.hash_type {
HashType::ConstantLength(_) | HashType::Encryption => {
for elt in self.elements[self.pos..].iter_mut() {
*elt = Elt::num_from_fr::<CS>(Scalar::zero());
*elt = Elt::num_from_fr::<CS>(Scalar::ZERO);
}
self.pos = self.elements.len();
}
Expand Down Expand Up @@ -413,7 +413,7 @@ where
}

fn initial_elements<CS: ConstraintSystem<Scalar>>() -> Vec<Elt<Scalar>> {
std::iter::repeat(Elt::num_from_fr::<CS>(Scalar::zero()))
std::iter::repeat(Elt::num_from_fr::<CS>(Scalar::ZERO))
.take(A::to_usize() + 1)
.collect()
}
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {

{
let mut cs = TestConstraintSystem::<Fr>::new();
let mut fr_data = vec![Fr::zero(); preimage_length];
let mut fr_data = vec![Fr::ZERO; preimage_length];
let data: Vec<AllocatedNum<Fr>> = data(&mut cs, &mut fr_data);

let out = poseidon_hash_allocated(&mut cs, data.clone(), &constants)
Expand Down Expand Up @@ -809,7 +809,7 @@ mod tests {

{
let mut cs = TestConstraintSystem::<Fr>::new();
let mut fr_data = vec![Fr::zero(); preimage_length];
let mut fr_data = vec![Fr::ZERO; preimage_length];
let data: Vec<AllocatedNum<Fr>> = data(&mut cs, &mut fr_data);

let out =
Expand Down
12 changes: 8 additions & 4 deletions src/column_tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ where

fn reset(&mut self) {
self.fill_index = 0;
self.data.iter_mut().for_each(|place| *place = F::zero());
self.data.iter_mut().for_each(|place| *place = F::ZERO);
}
}
fn as_generic_arrays<A: Arity<F>, F: PrimeField>(vec: &[F]) -> &[GenericArray<F, A>] {
Expand Down Expand Up @@ -117,7 +117,7 @@ where

let builder = Self {
leaf_count,
data: vec![F::zero(); leaf_count],
data: vec![F::ZERO; leaf_count],
fill_index: 0,
column_constants: PoseidonConstants::<F, ColumnArity>::new(),
column_batcher,
Expand All @@ -144,7 +144,11 @@ where
}
}

#[cfg(all(any(feature = "cuda", feature = "opencl"), not(target_os = "macos")))]
#[cfg(all(
feature = "bls",
any(feature = "cuda", feature = "opencl"),
not(target_os = "macos")
))]
#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -186,7 +190,7 @@ mod tests {
ColumnTreeBuilder::<Fr, U11, U8>::new(column_batcher, tree_batcher, leaves).unwrap();

// Simplify computing the expected root.
let constant_element = Fr::zero();
let constant_element = Fr::ZERO;
let constant_column = GenericArray::<Fr, U11>::generate(|_| constant_element);

let max_batch_size = if let Some(batcher) = &builder.column_batcher {
Expand Down
2 changes: 1 addition & 1 deletion src/hash_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<F: PrimeField, A: Arity<F>> HashType<F, A> {
// NOTE: in order to leave room for future `Strength` tags,
// we make identifier a multiple of 2^40 rather than 2^32.
HashType::Custom(ref ctype) => ctype.domain_tag(),
HashType::Sponge => F::zero(),
HashType::Sponge => F::ZERO,
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#[macro_use]
extern crate lazy_static;

pub use crate::poseidon::{Arity, Poseidon};
use crate::round_constants::generate_constants;
Expand Down
18 changes: 9 additions & 9 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn mat_mul<F: PrimeField>(a: &Matrix<F>, b: &Matrix<F>) -> Option<Matrix<F>>
}

fn vec_mul<F: PrimeField>(a: &[F], b: &[F]) -> F {
a.iter().zip(b).fold(F::zero(), |mut acc, (v1, v2)| {
a.iter().zip(b).fold(F::ZERO, |mut acc, (v1, v2)| {
let mut tmp = *v1;
tmp.mul_assign(v2);
acc.add_assign(&tmp);
Expand Down Expand Up @@ -118,7 +118,7 @@ pub fn left_apply_matrix<F: PrimeField>(m: &Matrix<F>, v: &[F]) -> Vec<F> {
"Matrix can only be applied to vector of same size."
);

let mut result = vec![F::zero(); v.len()];
let mut result = vec![F::ZERO; v.len()];

for (result, row) in result.iter_mut().zip(m.iter()) {
for (mat_val, vec_val) in row.iter().zip(v) {
Expand All @@ -139,7 +139,7 @@ pub fn apply_matrix<F: PrimeField>(m: &Matrix<F>, v: &[F]) -> Vec<F> {
"Matrix can only be applied to vector of same size."
);

let mut result = vec![F::zero(); v.len()];
let mut result = vec![F::ZERO; v.len()];
for (j, val) in result.iter_mut().enumerate() {
for (i, row) in m.iter().enumerate() {
let mut tmp = row[j];
Expand Down Expand Up @@ -167,18 +167,18 @@ pub fn transpose<F: PrimeField>(matrix: &Matrix<F>) -> Matrix<F> {

#[allow(clippy::needless_range_loop)]
pub fn make_identity<F: PrimeField>(size: usize) -> Matrix<F> {
let mut result = vec![vec![F::zero(); size]; size];
let mut result = vec![vec![F::ZERO; size]; size];
for i in 0..size {
result[i][i] = F::one();
result[i][i] = F::ONE;
}
result
}

pub fn kronecker_delta<F: PrimeField>(i: usize, j: usize) -> F {
if i == j {
F::one()
F::ONE
} else {
F::zero()
F::ZERO
}
}

Expand Down Expand Up @@ -227,7 +227,7 @@ fn eliminate<F: PrimeField>(
column: usize,
shadow: &mut Matrix<F>,
) -> Option<Matrix<F>> {
let zero = F::zero();
let zero = F::ZERO;
let pivot_index = (0..rows(matrix))
.find(|&i| matrix[i][column] != zero && (0..column).all(|j| matrix[i][j] == zero))?;

Expand Down Expand Up @@ -562,7 +562,7 @@ mod tests {
1,
res.unwrap()
.iter()
.filter(|&row| row[i] != Fr::zero())
.filter(|&row| row[i] != Fr::ZERO)
.count()
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/mds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ fn make_prime<F: PrimeField>(m: &Matrix<F>) -> Matrix<F> {
.enumerate()
.map(|(i, row)| match i {
0 => {
let mut new_row = vec![F::zero(); row.len()];
new_row[0] = F::one();
let mut new_row = vec![F::ZERO; row.len()];
new_row[0] = F::ONE;
new_row
}
_ => {
let mut new_row = vec![F::zero(); row.len()];
let mut new_row = vec![F::ZERO; row.len()];
new_row[1..].copy_from_slice(&row[1..]);
new_row
}
Expand All @@ -184,9 +184,9 @@ fn make_double_prime<F: PrimeField>(m: &Matrix<F>, m_hat_inv: &Matrix<F>) -> Mat
new_row
}
_ => {
let mut new_row = vec![F::zero(); row.len()];
let mut new_row = vec![F::ZERO; row.len()];
new_row[0] = w_hat[i - 1];
new_row[i] = F::one();
new_row[i] = F::ONE;
new_row
}
})
Expand Down
Loading