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

Integrate arkworks patch for deserializing group elements #56

Closed
wants to merge 6 commits into from
Closed
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
lfs: 'true'
Comment on lines -40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be dropped at least for main

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitive

ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", rev = "2ca3bd7" }

ark-ff = { git = "https://github.com/arkworks-rs/algebra/", rev = "c92be0e" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", rev = "c92be0e" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", rev = "c92be0e" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/", rev = "c92be0e" }
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra/", rev = "c92be0e" }
ark-ff = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-ec = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-serialize = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-poly = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }
ark-test-curves = { git = "https://github.com/arkworks-rs/algebra/", rev = "2a80c54" }

ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit/", rev = "c724fa6" }
ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit/", rev = "12f5529" }

# note bls is using a different commit from the other curves
ark-bn254 = { git = "https://github.com/arkworks-rs/curves/", rev = "8c0256a" }
Expand Down
4 changes: 2 additions & 2 deletions prover/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub fn load_srs(file: &str) -> Result<SRS, ProofError> {
let f = File::open(file)?;
let mut dec = Decoder::new(&f)?;
// The `unchecked` here refers to a check that the point is in the correct
// prime-order subgroup of the curve group: this is automatic for the
// prime-order subgroup of the curve group: this is automatic for the
// `bn254` and `grumpkin` curves, which are prime order (as is always the)
// case for a cycle of curves).
// case for a cycle of curves).
let srs = SRS::deserialize_compressed_unchecked(&mut dec)?;
Ok(srs)
}
Expand Down
35 changes: 11 additions & 24 deletions spartan/src/polycommitments/zeromorph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use ark_ec::{pairing::Pairing, scalar_mul::fixed_base::FixedBase, AffineRepr, CurveGroup};
use ark_ff::PrimeField;
use ark_ec::{pairing::Pairing, scalar_mul::ScalarMul, AffineRepr, CurveGroup};
use ark_poly::{univariate::DensePolynomial as DenseUnivarPolynomial, DenseUVPolynomial};
use ark_poly_commit::{
error::Error,
kzg10::{Commitment as KZGCommitment, KZG10},
PCUniversalParams,
};
use ark_std::{
collections::BTreeMap, end_timer, marker::PhantomData, ops::Mul, rand::RngCore, start_timer,
vec::Vec, One, UniformRand, Zero,
end_timer, marker::PhantomData, ops::Mul, rand::RngCore, start_timer, vec::Vec, One, UniformRand,
Zero,
};
use merlin::Transcript;

Expand Down Expand Up @@ -277,43 +276,31 @@ where
let beta = E::ScalarField::rand(rng);
let g = E::G1::rand(rng);
let h = E::G2::rand(rng);

// powers_of_beta = [1, b, ..., b^(max_degree + 1)], len = max_degree + 2
let mut powers_of_beta = vec![E::ScalarField::one()];

let mut cur = beta;
for _ in 0..max_degree {
for _ in 0..=max_degree {
powers_of_beta.push(cur);
cur *= &beta;
}

let window_size = FixedBase::get_mul_window_size(max_degree + 1);

let scalar_bits = E::ScalarField::MODULUS_BIT_SIZE as usize;
let g_time = start_timer!(|| "Generating powers of G");
let g_table = FixedBase::get_window_table(scalar_bits, window_size, g);
let powers_of_g =
FixedBase::msm::<E::G1>(scalar_bits, window_size, &g_table, &powers_of_beta);
let powers_of_g = g.batch_mul(&powers_of_beta[0..max_degree + 1]);
end_timer!(g_time);

let powers_of_g = E::G1::normalize_batch(&powers_of_g);

let powers_of_h_time = start_timer!(|| "Generating powers of h in G2");
let shift_powers_of_tau_h = {
let mut shift_powers_of_beta = vec![powers_of_beta[max_degree] * beta];
for n in 1..=max_num_poly_vars {
// powers_of_beta[k] = beta^k and N_max = max_degree + 1; we want shift_powers_of_beta[n] = beta^(N_max - 2^n + 1)
shift_powers_of_beta.push(powers_of_beta[max_degree + 1 - Math::pow2(n) + 1]);
}
let window_size = FixedBase::get_mul_window_size(max_num_poly_vars + 1);
let h_table = FixedBase::get_window_table(scalar_bits, window_size, h);
let powers_of_h =
FixedBase::msm::<E::G2>(scalar_bits, window_size, &h_table, &shift_powers_of_beta);

let affines = E::G2::normalize_batch(&powers_of_h);
let mut affines_map = BTreeMap::new();
affines.into_iter().enumerate().for_each(|(i, a)| {
affines_map.insert(i, a);
});
affines_map
h.batch_mul(&shift_powers_of_beta)
.into_iter()
.enumerate()
.collect()
};

end_timer!(powers_of_h_time);
Expand Down
4 changes: 2 additions & 2 deletions supernova/src/ml_sumcheck/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::collections::HashMap;

use ark_crypto_primitives::sponge::Absorb;
use ark_ff::{Field, PrimeField};
use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
use ark_poly::{DenseMultilinearExtension, MultilinearExtension, Polynomial};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::{cmp::max, rc::Rc};

Expand Down Expand Up @@ -118,7 +118,7 @@ impl<F: Field> ListOfProductsOfPolynomials<F> {
.map(|(c, p)| {
*c * p
.iter()
.map(|&i| self.flattened_ml_extensions[i].evaluate(point).unwrap())
.map(|&i| self.flattened_ml_extensions[i].evaluate(&point.to_vec()))
.product::<F>()
})
.sum()
Expand Down