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

Upgrade to v0.4.0 #94

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2e93ba9
updated deps
TakodaS Sep 7, 2023
a4b81ef
implemented canonical serialization
TakodaS Sep 7, 2023
c7ae172
moved sponge and fiat shamir in
TakodaS Sep 8, 2023
4d616f4
changed dependencies to ark_r1cs lib and fixes
TakodaS Sep 11, 2023
5d6d7d0
checkin
TakodaS Sep 11, 2023
aa666b5
serialize mostly done
TakodaS Sep 12, 2023
9bdd8a2
readd old rng mod
TakodaS Sep 12, 2023
71a603b
remove pedanticerrors temporarily
TakodaS Sep 12, 2023
c3dbc05
updated realtive to poly-commit-v0.4
TakodaS Sep 12, 2023
cbf5a4a
implemented poseidon as rng
TakodaS Sep 12, 2023
d860a91
added default and spong methods
TakodaS Sep 12, 2023
66a6786
LabelledCommitment does not implement CanonicalSerialize
TakodaS Sep 12, 2023
9ab0b3e
builds!
TakodaS Sep 12, 2023
e85c8fc
tests building
TakodaS Sep 18, 2023
d805506
to unlabeled commit
TakodaS Sep 18, 2023
1df70b3
outlinign test pass
TakodaS Sep 18, 2023
8a91943
revert to ark poly commit
TakodaS Sep 19, 2023
d1b8e51
bench building
TakodaS Sep 19, 2023
b5071fc
fmt and fix
TakodaS Sep 19, 2023
fed7d03
imports
TakodaS Sep 19, 2023
0c57285
unmodified .gitignore
TakodaS Sep 19, 2023
f07a64d
updated changelog
TakodaS Sep 19, 2023
8b55468
removed unnecessary r1cs-std dependency
TakodaS Sep 19, 2023
a976a89
removed extraneous tracing dep
TakodaS Sep 19, 2023
0e07083
changed order of generics for consistency
TakodaS Sep 19, 2023
f03a658
easy changes
TakodaS Sep 20, 2023
127dc2f
refactor RNG initialization
TakodaS Sep 26, 2023
6f11b89
before test
TakodaS Sep 26, 2023
2a70370
removed some hardcoded poseidon config parameters
TakodaS Sep 26, 2023
a2c56bf
semi implemented sponge methods
TakodaS Sep 26, 2023
cfefa0f
native absorption of field elements
TakodaS Sep 28, 2023
f2152b3
tests passing
TakodaS Sep 28, 2023
6b18bba
benches running
TakodaS Sep 28, 2023
a3d9ba6
removed to_bytes!
TakodaS Sep 28, 2023
3f886a9
cargo fix+fmt
TakodaS Sep 28, 2023
11bd766
removed unnecessary trait
TakodaS Sep 28, 2023
c5ab30b
reintroduce optimization of tests after debugging
TakodaS Sep 28, 2023
788a34e
update changelog
TakodaS Sep 28, 2023
093fdcc
added fast_prove and verify methods
TakodaS Oct 9, 2023
6a071f7
added test of fast_proof and fast_verify
TakodaS Oct 9, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

### Bug fixes

## v0.4.0

- Change dependency to version `0.4.0` of other arkwork-rs crates.
- Fiat-Shamir transformation for the AHP uses the Poseidon sponge function.

## v0.3.0

- Change dependency to version `0.3.0` of other arkworks-rs crates.
Expand Down
30 changes: 16 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ark-marlin"
version = "0.3.0"
version = "0.4.0"
authors = [
"Alessandro Chiesa <[email protected]>",
"Mary Maller <[email protected]>",
Expand All @@ -17,28 +17,30 @@ keywords = ["cryptography", "commitments", "zkSNARK"]
categories = ["cryptography"]
include = ["Cargo.toml", "src", "README.md", "LICENSE-APACHE", "LICENSE-MIT"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"

[dependencies]
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 = { version = "^0.3.0", default-features = false }
ark-serialize = { version = "^0.4.0", default-features = false, features = [ "derive" ] }
ark-ff = { version = "^0.4.0", default-features = false }
ark-ec = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }
ark-poly = { version = "^0.4.0", default-features = false }
ark-relations = { version = "^0.4.0", default-features = false }
ark-poly-commit = { version = "^0.4.0", default-features = false }
ark-crypto-primitives = { version = "^0.4.0", default-features = false, features = [ "r1cs" ] }

rayon = { version = "1", optional = true }
digest = { version = "0.9" }
derivative = { version = "2", features = ["use_core"] }

[dev-dependencies]
rand_chacha = { version = "0.3.0", default-features = false }
rand_chacha = { version = "^0.3.0", default-features = false }
blake2 = { version = "0.9", default-features = false }
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"] }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
ark-mnt4-298 = { version = "^0.4.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-298 = { version = "^0.4.0", default-features = false, features = ["r1cs"] }
ark-mnt4-753 = { version = "^0.4.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-753 = { version = "^0.4.0", default-features = false, features = ["r1cs"] }

[profile.release]
opt-level = 3
Expand Down
63 changes: 46 additions & 17 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
// where N is the number of threads you want to use (N = 1 for single-thread).

use ark_bls12_381::{Bls12_381, Fr as BlsFr};
use ark_ec::pairing::Pairing;
use ark_ff::PrimeField;
use ark_marlin::{Marlin, SimpleHashFiatShamirRng};
use ark_marlin::{Marlin, SimplePoseidonRng};
use ark_mnt4_298::{Fr as MNT4Fr, MNT4_298};
use ark_mnt4_753::{Fr as MNT4BigFr, MNT4_753};
use ark_mnt6_298::{Fr as MNT6Fr, MNT6_298};
Expand All @@ -16,8 +17,8 @@ use ark_relations::{
r1cs::{ConstraintSynthesizer, ConstraintSystemRef, SynthesisError},
};
use ark_std::{ops::Mul, UniformRand};
use blake2::Blake2s;
use rand_chacha::ChaChaRng;



const NUM_PROVE_REPEATITIONS: usize = 10;
const NUM_VERIFY_REPEATITIONS: usize = 50;
Expand Down Expand Up @@ -78,14 +79,22 @@ macro_rules! marlin_prove_bench {

let srs = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::universal_setup(65536, 65536, 3 * 65536, rng)
.unwrap();
let (pk, _) = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::index(&srs, c)
.unwrap();

Expand All @@ -94,8 +103,12 @@ macro_rules! marlin_prove_bench {
for _ in 0..NUM_PROVE_REPEATITIONS {
let _ = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::prove(&pk, c.clone(), rng)
.unwrap();
}
Expand All @@ -120,20 +133,32 @@ macro_rules! marlin_verify_bench {

let srs = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::universal_setup(65536, 65536, 3 * 65536, rng)
.unwrap();
let (pk, vk) = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::index(&srs, c)
.unwrap();
let proof = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::prove(&pk, c.clone(), rng)
.unwrap();

Expand All @@ -144,8 +169,12 @@ macro_rules! marlin_verify_bench {
for _ in 0..NUM_VERIFY_REPEATITIONS {
let _ = Marlin::<
$bench_field,
SonicKZG10<$bench_pairing_engine, DensePolynomial<$bench_field>>,
SimpleHashFiatShamirRng<Blake2s, ChaChaRng>,
SonicKZG10<
$bench_pairing_engine,
DensePolynomial<$bench_field>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>,
SimplePoseidonRng<<$bench_pairing_engine as Pairing>::BaseField>,
>::verify(&vk, &vec![v], &proof, rng)
.unwrap();
}
Expand Down
7 changes: 2 additions & 5 deletions src/ahp/constraint_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ use crate::BTreeMap;
use ark_ff::{Field, PrimeField};
use ark_poly::{EvaluationDomain, Evaluations as EvaluationsOnDomain, GeneralEvaluationDomain};
use ark_relations::{lc, r1cs::ConstraintSystemRef};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
use ark_std::{
cfg_iter_mut,
io::{Read, Write},
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::cfg_iter_mut;
use derivative::Derivative;

/* ************************************************************************* */
Expand Down
21 changes: 5 additions & 16 deletions src/ahp/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ use crate::ahp::{
AHPForR1CS, Error, LabeledPolynomial,
};
use crate::Vec;
use ark_ff::PrimeField;
use ark_ff::{Field, PrimeField};
use ark_poly::{EvaluationDomain, GeneralEvaluationDomain};
use ark_relations::r1cs::{
ConstraintSynthesizer, ConstraintSystem, OptimizationGoal, SynthesisError, SynthesisMode,
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError};
use ark_std::{
io::{Read, Write},
marker::PhantomData,
};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::marker::PhantomData;
use derivative::Derivative;

use crate::ahp::constraint_systems::{
Expand All @@ -28,7 +25,7 @@ use crate::ahp::constraint_systems::{
/// entries in any of the constraint matrices.
#[derive(Derivative, CanonicalSerialize, CanonicalDeserialize)]
#[derivative(Clone(bound = ""), Copy(bound = ""))]
pub struct IndexInfo<F> {
pub struct IndexInfo<F: Field> {
/// The total number of variables in the constraint system.
pub num_variables: usize,
/// The number of constraints.
Expand All @@ -42,7 +39,7 @@ pub struct IndexInfo<F> {
f: PhantomData<F>,
}

impl<F> IndexInfo<F> {
impl<F: Field> IndexInfo<F> {
/// Construct a new index info
pub fn new(
num_variables: usize,
Expand All @@ -60,14 +57,6 @@ impl<F> IndexInfo<F> {
}
}

impl<F: PrimeField> ark_ff::ToBytes for IndexInfo<F> {
fn write<W: Write>(&self, mut w: W) -> ark_std::io::Result<()> {
(self.num_variables as u64).write(&mut w)?;
(self.num_constraints as u64).write(&mut w)?;
(self.num_non_zero as u64).write(&mut w)
}
}

impl<F: PrimeField> IndexInfo<F> {
/// The maximum degree of polynomial required to represent this index in the
/// the AHP.
Expand Down
14 changes: 3 additions & 11 deletions src/ahp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ mod tests {
use ark_ff::{One, UniformRand, Zero};
use ark_poly::{
univariate::{DenseOrSparsePolynomial, DensePolynomial},
Polynomial, UVPolynomial,
DenseUVPolynomial, Polynomial,
};

#[test]
Expand Down Expand Up @@ -414,11 +414,7 @@ mod tests {
divisor
.coeffs
.iter()
.filter_map(|f| if !f.is_zero() {
Some(f.into_repr())
} else {
None
})
.filter_map(|f| if !f.is_zero() { Some(f) } else { None })
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.filter_map(|f| if !f.is_zero() { Some(f) } else { None })
.filter(|f| !f.is_zero())

.collect::<Vec<_>>()
);

Expand Down Expand Up @@ -446,11 +442,7 @@ mod tests {
quotient
.coeffs
.iter()
.filter_map(|f| if !f.is_zero() {
Some(f.into_repr())
} else {
None
})
.filter_map(|f| if !f.is_zero() { Some(f) } else { None })
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.filter_map(|f| if !f.is_zero() { Some(f) } else { None })
.filter(|f| if !f.is_zero())

.collect::<Vec<_>>()
);

Expand Down
Loading