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

Add sponge module #91

Open
wants to merge 1 commit into
base: constraints
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --release
args: --release -- --test-threads 1

check_no_std:
name: Check no_std
Expand Down
39 changes: 20 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,35 @@ license = "MIT/Apache-2.0"
edition = "2018"

[dependencies]
ark-serialize = { version = "^0.2.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.2.0", default-features = false }
ark-std = { version = "^0.2.0", default-features = false }
ark-poly = { version = "^0.2.0", default-features = false }
ark-relations = { version = "^0.2.0", default-features = false }
ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit", branch = "constraints", default-features = false, features = [ "r1cs" ] }
ark-serialize = { version = "^0.3.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.3.0", default-features = false }
ark-std = { version = "^0.3.0", default-features = false }
ark-poly = { version = "^0.3.0", default-features = false }
ark-relations = { version = "^0.3.0", default-features = false }
ark-poly-commit = { git = "https://github.com/arkworks-rs/poly-commit", branch = "vlopes11/constraints-rng", default-features = false, features = [ "r1cs" ] }
ark-sponge = { version = "^0.3.0", default-features = false }

rand_chacha = { version = "0.2.1", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
rayon = { version = "1", optional = true }
digest = { version = "0.9" }
derivative = { version = "2", features = ["use_core"] }

ark-ec = { version = "^0.2.0", default-features = false }
ark-crypto-primitives = { version = "^0.2.0", default-features = false, features = [ "r1cs" ] }
ark-r1cs-std = { version = "^0.2.0", default-features = false }
ark-nonnative-field = { version = "^0.2.0", default-features = false }
ark-snark = { version = "^0.2.0", default-features = false }
ark-ec = { version = "^0.3.0", default-features = false }
ark-crypto-primitives = { version = "^0.3.0", default-features = false, features = [ "r1cs" ] }
ark-r1cs-std = { version = "^0.3.0", default-features = false }
ark-nonnative-field = { version = "^0.3.0", default-features = false }
ark-snark = { version = "^0.3.0", default-features = false }
hashbrown = "0.9"
tracing = { version = "0.1", default-features = false, features = [ "attributes" ] }
tracing-subscriber = { version = "0.2", default-features = false, optional = true }

[dev-dependencies]
#[dev-dependencies]
blake2 = { version = "0.9", default-features = false }
ark-bls12-381 = { version = "^0.2.0", default-features = false, features = [ "curve" ] }
ark-mnt4-298 = { version = "^0.2.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-298 = { version = "^0.2.0", default-features = false, features = ["r1cs"] }
ark-mnt4-753 = { version = "^0.2.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-753 = { version = "^0.2.0", default-features = false, features = ["r1cs"] }
ark-bls12-381 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
ark-mnt4-298 = { version = "^0.3.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-298 = { version = "^0.3.0", default-features = false, features = ["r1cs"] }
ark-mnt4-753 = { version = "^0.3.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-753 = { version = "^0.3.0", default-features = false, features = ["r1cs"] }

[profile.release]
opt-level = 3
Expand Down Expand Up @@ -76,4 +77,4 @@ parallel = [ "std", "ark-ff/parallel", "ark-poly/parallel", "ark-std/parallel",
name = "marlin-benches"
path = "benches/bench.rs"
harness = false
required-features = ["std"]
required-features = ["std"]
115 changes: 99 additions & 16 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use ark_bls12_381::{Bls12_381, Fq as BlsFq, Fr as BlsFr};
use ark_ff::PrimeField;
use ark_marlin::fiat_shamir::FiatShamirChaChaRng;
use ark_marlin::Marlin;
use ark_marlin::MarlinDefaultConfig;
use ark_marlin::{FiatShamirSpongeRng, PoseidonSpongeWithDefaultRate};
use ark_mnt4_298::{Fq as MNT4Fq, Fr as MNT4Fr, MNT4_298};
use ark_mnt4_753::{Fq as MNT4BigFq, Fr as MNT4BigFr, MNT4_753};
use ark_mnt6_298::{Fq as MNT6Fq, Fr as MNT6Fr, MNT6_298};
Expand All @@ -18,7 +18,6 @@ use ark_relations::{
r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError},
};
use ark_std::{ops::Mul, UniformRand};
use blake2::Blake2s;

const NUM_PROVE_REPEATITIONS: usize = 10;
const NUM_VERIFY_REPEATITIONS: usize = 50;
Expand Down Expand Up @@ -80,16 +79,40 @@ macro_rules! marlin_prove_bench {
let srs = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::universal_setup(65536, 65536, 65536, rng)
.unwrap();
let (pk, _) = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::index(&srs, c)
.unwrap();
Expand All @@ -100,8 +123,20 @@ macro_rules! marlin_prove_bench {
let _ = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::prove(&pk, c.clone(), rng)
.unwrap();
Expand All @@ -128,24 +163,60 @@ macro_rules! marlin_verify_bench {
let srs = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::universal_setup(65536, 65536, 65536, rng)
.unwrap();
let (pk, vk) = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::index(&srs, c)
.unwrap();
let proof = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::prove(&pk, c.clone(), rng)
.unwrap();
Expand All @@ -158,8 +229,20 @@ macro_rules! marlin_verify_bench {
let _ = Marlin::<
$bench_field,
$base_field,
MarlinKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
FiatShamirChaChaRng<$bench_field, $base_field, Blake2s>,
MarlinKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
>,
FiatShamirSpongeRng<
$bench_field,
$base_field,
PoseidonSpongeWithDefaultRate<$base_field>,
>,
MarlinDefaultConfig,
>::verify(&vk, &vec![v], &proof)
.unwrap();
Expand Down
6 changes: 2 additions & 4 deletions src/ahp/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,9 @@ impl<F: PrimeField> AHPForR1CS<F> {
}

/// Output the second round message and the next state.
pub fn prover_second_round<'a, R: RngCore>(
pub fn prover_second_round<'a>(
ver_message: &VerifierFirstMsg<F>,
mut state: ProverState<'a, F>,
_r: &mut R,
hiding: bool,
) -> (ProverMsg<F>, ProverSecondOracles<F>, ProverState<'a, F>) {
let round_time = start_timer!(|| "AHP::Prover::SecondRound");
Expand Down Expand Up @@ -598,10 +597,9 @@ impl<F: PrimeField> AHPForR1CS<F> {
}

/// Output the third round message and the next state.
pub fn prover_third_round<'a, R: RngCore>(
pub fn prover_third_round<'a>(
ver_message: &VerifierSecondMsg<F>,
prover_state: ProverState<'a, F>,
_r: &mut R,
) -> Result<(ProverMsg<F>, ProverThirdOracles<F>), Error> {
let round_time = start_timer!(|| "AHP::Prover::ThirdRound");

Expand Down
10 changes: 4 additions & 6 deletions src/ahp/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::ahp::*;
use crate::fiat_shamir::FiatShamirRng;
use ark_ff::PrimeField;
use ark_nonnative_field::params::OptimizationType;
use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
use ark_poly_commit::QuerySet;

/// State of the AHP verifier
Expand Down Expand Up @@ -56,7 +55,7 @@ impl<F: PrimeField> AHPForR1CS<F> {
let domain_k = GeneralEvaluationDomain::new(index_info.num_non_zero)
.ok_or(SynthesisError::PolynomialDegreeTooLarge)?;

let elems = fs_rng.squeeze_nonnative_field_elements(4, OptimizationType::Weight);
let elems = fs_rng.squeeze_nonnative(4, OptimizationType::Weight);
let alpha = elems[0];
let eta_a = elems[1];
let eta_b = elems[2];
Expand Down Expand Up @@ -86,7 +85,7 @@ impl<F: PrimeField> AHPForR1CS<F> {
mut state: VerifierState<F>,
fs_rng: &mut R,
) -> (VerifierSecondMsg<F>, VerifierState<F>) {
let elems = fs_rng.squeeze_nonnative_field_elements(1, OptimizationType::Weight);
let elems = fs_rng.squeeze_nonnative(1, OptimizationType::Weight);
let beta = elems[0];
assert!(!state.domain_h.evaluate_vanishing_polynomial(beta).is_zero());

Expand All @@ -101,17 +100,16 @@ impl<F: PrimeField> AHPForR1CS<F> {
mut state: VerifierState<F>,
fs_rng: &mut R,
) -> VerifierState<F> {
let elems = fs_rng.squeeze_nonnative_field_elements(1, OptimizationType::Weight);
let elems = fs_rng.squeeze_nonnative(1, OptimizationType::Weight);
let gamma = elems[0];

state.gamma = Some(gamma);
state
}

/// Output the query state and next round state.
pub fn verifier_query_set<'a, FSF: PrimeField, R: FiatShamirRng<F, FSF>>(
pub fn verifier_query_set<'a, FSF: PrimeField>(
state: VerifierState<F>,
_: &'a mut R,
with_vanishing: bool,
) -> (QuerySet<F>, VerifierState<F>) {
let alpha = state.first_round_msg.unwrap().alpha;
Expand Down
Loading