Skip to content

Commit 1a3c209

Browse files
committed
Merge branch 'snarkpack-integration' into feat/remove-useless
2 parents cdf8bd8 + 71e6762 commit 1a3c209

File tree

17 files changed

+244
-243
lines changed

17 files changed

+244
-243
lines changed

.github/workflows/testudo.yml

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
name: Build and Test Testudo
22

3-
on:
4-
push:
5-
branches: [master]
6-
pull_request:
7-
branches: [master]
8-
# The crate ark-ff uses the macro llvm_asm! when emitting asm which returns an
9-
# error because it was deprecated in favour of asm!. We temporarily overcome
10-
# this problem by setting the environment variable below (until the crate
11-
# is updated).
12-
env:
13-
RUSTFLAGS: "--emit asm -C llvm-args=-x86-asm-syntax=intel"
3+
on: [push, pull_request]
144

155
jobs:
16-
build_nightly:
6+
cargo-test:
177
runs-on: ubuntu-latest
188
steps:
19-
- uses: actions/checkout@v2
20-
- name: Install
21-
run: rustup default nightly
22-
- name: Install rustfmt Components
23-
run: rustup component add rustfmt
24-
# - name: Install clippy
25-
# run: rustup component add clippy
26-
- name: Build
27-
run: cargo build --verbose
28-
- name: Run tests
29-
run: cargo test --release --all-features --verbose
30-
- name: Build examples
31-
run: cargo build --examples --verbose
32-
- name: Check Rustfmt Code Style
33-
run: cargo fmt --all -- --check
34-
# cargo clippy uses cargo check which returns an error when asm is emitted
35-
# we want to emit asm for ark-ff operations so we avoid using clippy for # now
36-
# - name: Check clippy warnings
37-
# run: cargo clippy --all-targets --all-features
9+
- name: Checkout sources
10+
uses: actions/checkout@v2
11+
with:
12+
submodules: recursive
13+
14+
- name: Install toolchain
15+
uses: actions-rs/toolchain@v1
16+
with:
17+
toolchain: stable
18+
profile: minimal
19+
override: true
20+
21+
- uses: Swatinem/rust-cache@v2
22+
with:
23+
shared-key: cache-${{ hashFiles('**/Cargo.lock') }}
24+
cache-on-failure: true
25+
26+
- name: cargo test
27+
run: RUST_LOG=info cargo test --all --all-features -- --nocapture

Cargo.toml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@ itertools = "0.10.0"
1818
colored = "2.0.0"
1919
thiserror = "1.0"
2020
json = "0.12.4"
21-
ark-ff = { version = "^0.3.0", default-features = false }
22-
ark-ec = { version = "^0.3.0", default-features = false }
23-
ark-std = { version = "^0.3.0"}
24-
ark-bls12-377 = { version = "^0.3.0", features = ["r1cs","curve"] }
25-
ark-serialize = { version = "^0.3.0", features = ["derive"] }
26-
ark-sponge = { version = "^0.3.0" , features = ["r1cs"] }
27-
ark-crypto-primitives = { version = "^0.3.0", default-features = true }
28-
ark-r1cs-std = { version = "^0.3.0", default-features = false }
29-
ark-nonnative-field = { version = "0.3.0", default-features = false }
30-
ark-relations = { version = "^0.3.0", default-features = false, optional = true }
21+
ark-ff = { version = "^0.4.0", default-features = false }
22+
ark-ec = { version = "^0.4.0", default-features = false }
23+
ark-std = { version = "^0.4.0"}
24+
ark-bls12-377 = { version = "^0.4.0", features = ["r1cs","curve"] }
25+
ark-serialize = { version = "^0.4.0", features = ["derive"] }
26+
ark-crypto-primitives = {version = "^0.4.0", features = ["sponge","r1cs","snark"] }
27+
ark-r1cs-std = { version = "^0.4.0", default-features = false }
28+
ark-relations = { version = "^0.4.0", default-features = false, optional = true }
29+
ark-snark = { version = "^0.4.0", default-features = false }
3130
ark-groth16 = { version = "^0.3.0", features = ["r1cs"] }
32-
ark-bw6-761 = { version = "^0.3.0" }
33-
ark-poly-commit = { version = "^0.3.0" }
34-
ark-poly = {version = "^0.3.0"}
31+
ark-bw6-761 = { version = "^0.4.0" }
32+
ark-poly-commit = { version = "^0.4.0" }
33+
ark-poly = {version = "^0.4.0"}
3534

3635

3736
lazy_static = "1.4.0"
@@ -80,7 +79,6 @@ parallel = [ "std", "ark-ff/parallel", "ark-std/parallel", "ark-ec/parallel", "a
8079
std = ["ark-ff/std", "ark-ec/std", "ark-std/std", "ark-relations/std", "ark-serialize/std"]
8180

8281
[patch.crates-io]
83-
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std/", rev = "a2a5ac491ae005ba2afd03fd21b7d3160d794a83"}
84-
ark-poly-commit = {git = "https://github.com/maramihali/poly-commit", branch="pst_g2"}
85-
82+
ark-poly-commit = {git = "https://github.com/cryptonetlab/ark-polycommit", branch="feat/pst_on_g2"}
83+
ark-groth16 = { git = "https://github.com/arkworks-rs/groth16", features = ["r1cs"] }
8684

examples/cubic.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn produce_r1cs() -> (
3838
let mut B: Vec<(usize, usize, Vec<u8>)> = Vec::new();
3939
let mut C: Vec<(usize, usize, Vec<u8>)> = Vec::new();
4040

41-
let one = Scalar::one().into_repr().to_bytes_le();
41+
let one = Scalar::one().into_bigint().to_bytes_le();
4242

4343
// R1CS is a set of three sparse matrices A B C, where is a row for every
4444
// constraint and a column for every entry in z = (vars, 1, inputs)
@@ -67,7 +67,7 @@ fn produce_r1cs() -> (
6767
// constraint 3 entries in (A,B,C)
6868
// constraint 3 is (Z3 + 5) * 1 - I0 = 0.
6969
A.push((3, 3, one.clone()));
70-
A.push((3, num_vars, Scalar::from(5u32).into_repr().to_bytes_le()));
70+
A.push((3, num_vars, Scalar::from(5u32).into_bigint().to_bytes_le()));
7171
B.push((3, num_vars, one.clone()));
7272
C.push((3, num_vars + 1, one));
7373

@@ -82,16 +82,16 @@ fn produce_r1cs() -> (
8282
let i0 = z3 + Scalar::from(5u32); // constraint 3
8383

8484
// create a VarsAssignment
85-
let mut vars = vec![Scalar::zero().into_repr().to_bytes_le(); num_vars];
86-
vars[0] = z0.into_repr().to_bytes_le();
87-
vars[1] = z1.into_repr().to_bytes_le();
88-
vars[2] = z2.into_repr().to_bytes_le();
89-
vars[3] = z3.into_repr().to_bytes_le();
85+
let mut vars = vec![Scalar::zero().into_bigint().to_bytes_le(); num_vars];
86+
vars[0] = z0.into_bigint().to_bytes_le();
87+
vars[1] = z1.into_bigint().to_bytes_le();
88+
vars[2] = z2.into_bigint().to_bytes_le();
89+
vars[3] = z3.into_bigint().to_bytes_le();
9090
let assignment_vars = VarsAssignment::new(&vars).unwrap();
9191

9292
// create an InputsAssignment
93-
let mut inputs = vec![Scalar::zero().into_repr().to_bytes_le(); num_inputs];
94-
inputs[0] = i0.into_repr().to_bytes_le();
93+
let mut inputs = vec![Scalar::zero().into_bigint().to_bytes_le(); num_inputs];
94+
inputs[0] = i0.into_bigint().to_bytes_le();
9595
let assignment_inputs = InputsAssignment::new(&inputs).unwrap();
9696

9797
// check if the instance we created is satisfiable

profiler/nizk.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ pub fn main() {
3737
let proof = NIZK::prove(&inst, vars, &inputs, &gens, &mut prover_transcript);
3838

3939
let mut proof_encoded = Vec::new();
40-
proof.serialize(&mut proof_encoded).unwrap();
40+
proof
41+
.serialize_with_mode(&mut proof_encoded, Compress::Yes)
42+
.unwrap();
4143
let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
4244
print(&msg_proof_len);
4345

profiler/snark.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ pub fn main() {
4848
);
4949

5050
let mut proof_encoded = Vec::new();
51-
proof.serialize(&mut proof_encoded).unwrap();
51+
proof
52+
.serialize_with_mode(&mut proof_encoded, Compress::Yes)
53+
.unwrap();
5254
let msg_proof_len = format!("SNARK::proof_compressed_len {:?}", proof_encoded.len());
5355
print(&msg_proof_len);
5456

src/commitments.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use super::group::{GroupElement, GroupElementAffine, VartimeMultiscalarMul, GROU
22
use super::scalar::Scalar;
33
use crate::group::CompressGroupElement;
44
use crate::parameters::*;
5-
use ark_ec::{AffineCurve, ProjectiveCurve};
6-
use ark_ff::PrimeField;
5+
use ark_ec::{AffineRepr};
76

8-
use ark_sponge::poseidon::PoseidonSponge;
9-
use ark_sponge::CryptographicSponge;
7+
use std::ops::Mul;
8+
9+
use ark_crypto_primitives::sponge::poseidon::PoseidonSponge;
10+
use ark_crypto_primitives::sponge::CryptographicSponge;
1011

1112
#[derive(Debug, Clone)]
1213
pub struct MultiCommitGens {
@@ -29,7 +30,7 @@ impl MultiCommitGens {
2930
let uniform_bytes = sponge.squeeze_bytes(64);
3031
el_aff = GroupElementAffine::from_random_bytes(&uniform_bytes);
3132
}
32-
let el = el_aff.unwrap().mul_by_cofactor_to_projective();
33+
let el = el_aff.unwrap().clear_cofactor().into_group();
3334
gens.push(el);
3435
}
3536

@@ -80,13 +81,13 @@ impl Commitments for Scalar {
8081
impl Commitments for Vec<Scalar> {
8182
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
8283
assert_eq!(gens_n.n, self.len());
83-
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + gens_n.h.mul(blind.into_repr())
84+
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + gens_n.h.mul(blind)
8485
}
8586
}
8687

8788
impl Commitments for [Scalar] {
8889
fn commit(&self, blind: &Scalar, gens_n: &MultiCommitGens) -> GroupElement {
8990
assert_eq!(gens_n.n, self.len());
90-
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + gens_n.h.mul(blind.into_repr())
91+
GroupElement::vartime_multiscalar_mul(self, &gens_n.G) + gens_n.h.mul(blind)
9192
}
9293
}

src/constraints.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,36 @@ use crate::{
1010

1111
use ark_bls12_377::{constraints::PairingVar as IV, Bls12_377 as I, Fr};
1212

13-
use ark_crypto_primitives::{
14-
snark::BooleanInputVar, CircuitSpecificSetupSNARK, SNARKGadget, SNARK,
15-
};
13+
use ark_crypto_primitives::snark::{BooleanInputVar, SNARKGadget};
14+
use ark_snark::{CircuitSpecificSetupSNARK, SNARK};
1615

1716
use ark_ff::{BitIteratorLE, PrimeField, Zero};
1817
use ark_groth16::{
1918
constraints::{Groth16VerifierGadget, PreparedVerifyingKeyVar, ProofVar},
2019
Groth16, PreparedVerifyingKey, Proof as GrothProof,
2120
};
2221

23-
use ark_poly_commit::multilinear_pc::data_structures::Commitment;
22+
use ark_crypto_primitives::sponge::{
23+
constraints::CryptographicSpongeVar,
24+
poseidon::{constraints::PoseidonSpongeVar, PoseidonConfig},
25+
};
26+
use ark_poly_commit::multilinear_pc::data_structures::{Commitment};
2427
use ark_r1cs_std::{
2528
alloc::{AllocVar, AllocationMode},
2629
fields::fp::FpVar,
2730
prelude::{Boolean, EqGadget, FieldVar},
2831
};
2932
use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef, Namespace, SynthesisError};
30-
use ark_sponge::{
31-
constraints::CryptographicSpongeVar,
32-
poseidon::{constraints::PoseidonSpongeVar, PoseidonParameters},
33-
};
3433
use rand::{CryptoRng, Rng};
3534

3635
pub struct PoseidonTranscripVar {
3736
pub cs: ConstraintSystemRef<Fr>,
3837
pub sponge: PoseidonSpongeVar<Fr>,
39-
pub params: PoseidonParameters<Fr>,
38+
pub params: PoseidonConfig<Fr>,
4039
}
4140

4241
impl PoseidonTranscripVar {
43-
fn new(
44-
cs: ConstraintSystemRef<Fr>,
45-
params: &PoseidonParameters<Fr>,
46-
challenge: Option<Fr>,
47-
) -> Self {
42+
fn new(cs: ConstraintSystemRef<Fr>, params: &PoseidonConfig<Fr>, challenge: Option<Fr>) -> Self {
4843
let mut sponge = PoseidonSpongeVar::new(cs.clone(), params);
4944

5045
if let Some(c) = challenge {
@@ -245,7 +240,7 @@ pub struct R1CSVerificationCircuit {
245240
pub input: Vec<Fr>,
246241
pub input_as_sparse_poly: SparsePolynomial,
247242
pub evals: (Fr, Fr, Fr),
248-
pub params: PoseidonParameters<Fr>,
243+
pub params: PoseidonConfig<Fr>,
249244
pub prev_challenge: Fr,
250245
pub claims_phase2: (Scalar, Scalar, Scalar, Scalar),
251246
pub eval_vars_at_ry: Fr,
@@ -411,7 +406,7 @@ pub struct VerifierConfig {
411406
pub input: Vec<Fr>,
412407
pub input_as_sparse_poly: SparsePolynomial,
413408
pub evals: (Fr, Fr, Fr),
414-
pub params: PoseidonParameters<Fr>,
409+
pub params: PoseidonConfig<Fr>,
415410
pub prev_challenge: Fr,
416411
pub claims_phase2: (Fr, Fr, Fr, Fr),
417412
pub eval_vars_at_ry: Fr,
@@ -464,7 +459,7 @@ impl ConstraintSynthesizer<Fq> for VerifierCircuit {
464459
let bits = pubs
465460
.iter()
466461
.map(|c| {
467-
let bits: Vec<bool> = BitIteratorLE::new(c.into_repr().as_ref().to_vec()).collect();
462+
let bits: Vec<bool> = BitIteratorLE::new(c.into_bigint().as_ref().to_vec()).collect();
468463
Vec::new_witness(cs.clone(), || Ok(bits))
469464
})
470465
.collect::<Result<Vec<_>, _>>()?;

src/group.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::errors::ProofVerifyError;
2-
use ark_ec::msm::VariableBaseMSM;
3-
use ark_ff::PrimeField;
2+
use ark_ec::scalar_mul::variable_base::VariableBaseMSM;
3+
use ark_ec::Group;
44

55
use lazy_static::lazy_static;
66

77
use super::scalar::Scalar;
88

9-
use ark_ec::ProjectiveCurve;
9+
use ark_ec::CurveGroup;
1010
use ark_serialize::*;
1111
use core::borrow::Borrow;
1212

@@ -19,7 +19,7 @@ pub type Fr = ark_bls12_377::Fr;
1919
pub struct CompressedGroup(pub Vec<u8>);
2020

2121
lazy_static! {
22-
pub static ref GROUP_BASEPOINT: GroupElement = GroupElement::prime_subgroup_generator();
22+
pub static ref GROUP_BASEPOINT: GroupElement = GroupElement::generator();
2323
}
2424

2525
pub trait CompressGroupElement {
@@ -37,14 +37,16 @@ pub trait UnpackGroupElement {
3737
impl CompressGroupElement for GroupElement {
3838
fn compress(&self) -> CompressedGroup {
3939
let mut point_encoding = Vec::new();
40-
self.serialize(&mut point_encoding).unwrap();
40+
self
41+
.serialize_with_mode(&mut point_encoding, Compress::Yes)
42+
.unwrap();
4143
CompressedGroup(point_encoding)
4244
}
4345
}
4446

4547
impl DecompressGroupElement for GroupElement {
4648
fn decompress(encoded: &CompressedGroup) -> Option<Self> {
47-
let res = GroupElement::deserialize(&*encoded.0);
49+
let res = GroupElement::deserialize_compressed(&*encoded.0);
4850
if let Ok(r) = res {
4951
Some(r)
5052
} else {
@@ -67,14 +69,11 @@ pub trait VartimeMultiscalarMul {
6769

6870
impl VartimeMultiscalarMul for GroupElement {
6971
fn vartime_multiscalar_mul(scalars: &[Scalar], points: &[GroupElement]) -> GroupElement {
70-
let repr_scalars = scalars
71-
.iter()
72-
.map(|S| S.borrow().into_repr())
73-
.collect::<Vec<<Scalar as PrimeField>::BigInt>>();
72+
assert!(scalars.len() == points.len());
7473
let aff_points = points
7574
.iter()
7675
.map(|P| P.borrow().into_affine())
7776
.collect::<Vec<GroupElementAffine>>();
78-
VariableBaseMSM::multi_scalar_mul(aff_points.as_slice(), repr_scalars.as_slice())
77+
<Self as VariableBaseMSM>::msm_unchecked(aff_points.as_slice(), scalars)
7978
}
8079
}

0 commit comments

Comments
 (0)