Skip to content

Commit 762fc57

Browse files
authored
Updated to arkworks 0.4 (#3)
1 parent 5d23b86 commit 762fc57

18 files changed

+179
-242
lines changed

Cargo.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ark-spartan"
33
# sync up with Arkwork's version
4-
version = "0.3.0"
4+
version = "0.4.0"
55
authors = [
66
# author of original Spartan paper and code base
77
# for which this library is modified from
@@ -32,12 +32,12 @@ thiserror = "1.0"
3232

3333
rand_chacha = { version = "0.3.0", default-features = false }
3434

35-
ark-ec = { version = "^0.3.0", default-features = false }
36-
ark-ff = { version = "^0.3.0", default-features = false }
37-
ark-std = { version = "^0.3.0", default-features = false }
38-
ark-serialize = { version = "^0.3.0", default-features = false, features = [ "derive" ] }
35+
ark-ec = { version = "^0.4.0", default-features = false }
36+
ark-ff = { version = "^0.4.0", default-features = false }
37+
ark-std = { version = "^0.4.0", default-features = false }
38+
ark-serialize = { version = "^0.4.0", default-features = false, features = [ "derive" ] }
3939

40-
ark-bls12-381 = { version = "0.3.0", default-features = false, features = [ "curve" ] }
40+
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = [ "curve" ] }
4141

4242
[dev-dependencies]
4343
criterion = "0.3.1"

benches/nizk.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ extern crate rand;
99
extern crate sha3;
1010

1111
use ark_bls12_381::G1Projective;
12-
use ark_ec::ProjectiveCurve;
12+
use ark_ec::CurveGroup;
1313
use libspartan::{Instance, NIZKGens, NIZK};
1414
use merlin::Transcript;
1515

1616
use criterion::*;
1717

18-
fn nizk_prove_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
18+
fn nizk_prove_benchmark<G: CurveGroup>(c: &mut Criterion) {
1919
for &s in [10, 12, 16].iter() {
2020
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
2121
let mut group = c.benchmark_group("NIZK_prove_benchmark");
@@ -47,7 +47,7 @@ fn nizk_prove_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
4747
}
4848
}
4949

50-
fn nizk_verify_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
50+
fn nizk_verify_benchmark<G: CurveGroup>(c: &mut Criterion) {
5151
for &s in [10, 12, 16].iter() {
5252
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
5353
let mut group = c.benchmark_group("NIZK_verify_benchmark");

benches/snark.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ extern crate libspartan;
33
extern crate merlin;
44

55
use ark_bls12_381::G1Projective;
6-
use ark_ec::ProjectiveCurve;
6+
use ark_ec::CurveGroup;
77
use libspartan::{Instance, SNARKGens, SNARK};
88
use merlin::Transcript;
99

1010
use criterion::*;
1111

12-
fn snark_encode_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
12+
fn snark_encode_benchmark<G: CurveGroup>(c: &mut Criterion) {
1313
for s in 10..21 {
1414
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
1515
let mut group = c.benchmark_group("SNARK_encode_benchmark");
@@ -35,7 +35,7 @@ fn snark_encode_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
3535
}
3636
}
3737

38-
fn snark_prove_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
38+
fn snark_prove_benchmark<G: CurveGroup>(c: &mut Criterion) {
3939
for s in 9..21 {
4040
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
4141
let mut group = c.benchmark_group("SNARK_prove_benchmark");
@@ -74,7 +74,7 @@ fn snark_prove_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
7474
}
7575
}
7676

77-
fn snark_verify_benchmark<G: ProjectiveCurve>(c: &mut Criterion) {
77+
fn snark_verify_benchmark<G: CurveGroup>(c: &mut Criterion) {
7878
for s in 10..21 {
7979
let plot_config = PlotConfiguration::default().summary_scale(AxisScale::Logarithmic);
8080
let mut group = c.benchmark_group("SNARK_verify_benchmark");

profiler/nizk.rs

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

3939
let mut proof_encoded = vec![];
40-
proof.serialize(&mut proof_encoded).unwrap();
40+
proof.serialize_compressed(&mut proof_encoded).unwrap();
4141

4242
let msg_proof_len = format!("NIZK::proof_compressed_len {:?}", proof_encoded.len());
4343
print(&msg_proof_len);

profiler/snark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn main() {
4747
);
4848

4949
let mut proof_encoded = vec![];
50-
proof.serialize(&mut proof_encoded).unwrap();
50+
proof.serialize_compressed(&mut proof_encoded).unwrap();
5151

5252
let msg_proof_len = format!("SNARK::proof_compressed_len {:?}", proof_encoded.len());
5353
print(&msg_proof_len);

src/commitments.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use ark_ec::msm::VariableBaseMSM;
2-
use ark_ec::ProjectiveCurve;
3-
use ark_ff::PrimeField;
1+
use ark_ec::CurveGroup;
2+
use ark_ec::VariableBaseMSM;
43
use ark_std::rand::SeedableRng;
54
use digest::{ExtendableOutput, Input};
65
use rand_chacha::ChaCha20Rng;
@@ -14,12 +13,12 @@ pub struct MultiCommitGens<G> {
1413
pub h: G,
1514
}
1615

17-
impl<G: ProjectiveCurve> MultiCommitGens<G> {
16+
impl<G: CurveGroup> MultiCommitGens<G> {
1817
pub fn new(n: usize, label: &[u8]) -> Self {
1918
let mut shake = Shake256::default();
2019
shake.input(label);
2120
let mut buf = vec![];
22-
G::prime_subgroup_generator().serialize(&mut buf).unwrap();
21+
G::generator().serialize_compressed(&mut buf).unwrap();
2322
shake.input(buf);
2423

2524
let mut reader = shake.xof_result();
@@ -65,26 +64,26 @@ impl<G: ProjectiveCurve> MultiCommitGens<G> {
6564
}
6665
}
6766

68-
pub trait Commitments<G: ProjectiveCurve>: Sized {
67+
pub trait Commitments<G: CurveGroup>: Sized {
6968
fn commit(&self, blind: &G::ScalarField, gens_n: &MultiCommitGens<G>) -> G;
7069
fn batch_commit(inputs: &[Self], blind: &G::ScalarField, gens_n: &MultiCommitGens<G>) -> G;
7170
}
7271

73-
impl<G: ProjectiveCurve> Commitments<G> for G::ScalarField {
72+
impl<G: CurveGroup> Commitments<G> for G::ScalarField {
7473
fn commit(&self, blind: &G::ScalarField, gens_n: &MultiCommitGens<G>) -> G {
7574
assert_eq!(gens_n.n, 1);
7675

77-
gens_n.G[0].mul(self.into_repr()) + gens_n.h.mul(blind.into_repr())
76+
gens_n.G[0] * self + gens_n.h * blind
7877
}
7978

8079
fn batch_commit(inputs: &[Self], blind: &G::ScalarField, gens_n: &MultiCommitGens<G>) -> G {
8180
assert_eq!(gens_n.n, inputs.len());
8281

83-
let mut bases = ProjectiveCurve::batch_normalization_into_affine(gens_n.G.as_ref());
84-
let mut scalars = inputs.iter().map(|x| x.into_repr()).collect::<Vec<_>>();
82+
let mut bases = CurveGroup::normalize_batch(gens_n.G.as_ref());
83+
let mut scalars = inputs.to_vec();
8584
bases.push(gens_n.h.into_affine());
86-
scalars.push(blind.into_repr());
85+
scalars.push(*blind);
8786

88-
VariableBaseMSM::multi_scalar_mul(bases.as_ref(), scalars.as_ref())
87+
VariableBaseMSM::msm(bases.as_ref(), scalars.as_ref()).unwrap()
8988
}
9089
}

src/dense_mlpoly.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use super::math::Math;
55
use super::nizk::{DotProductProofGens, DotProductProofLog};
66
use super::random::RandomTape;
77
use super::transcript::{AppendToTranscript, ProofTranscript};
8-
use ark_ec::msm::VariableBaseMSM;
9-
use ark_ec::ProjectiveCurve;
8+
use ark_ec::CurveGroup;
9+
use ark_ec::VariableBaseMSM;
1010
use ark_ff::PrimeField;
1111
use ark_serialize::*;
1212
use ark_std::Zero;
@@ -27,7 +27,7 @@ pub struct PolyCommitmentGens<G> {
2727
pub gens: DotProductProofGens<G>,
2828
}
2929

30-
impl<G: ProjectiveCurve> PolyCommitmentGens<G> {
30+
impl<G: CurveGroup> PolyCommitmentGens<G> {
3131
// the number of variables in the multilinear polynomial
3232
pub fn new(num_vars: usize, label: &'static [u8]) -> Self {
3333
let (_left, right) = EqPolynomial::<G::ScalarField>::compute_factored_lens(num_vars);
@@ -41,12 +41,12 @@ pub struct PolyCommitmentBlinds<F> {
4141
}
4242

4343
#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
44-
pub struct PolyCommitment<G: ProjectiveCurve> {
44+
pub struct PolyCommitment<G: CurveGroup> {
4545
C: Vec<G>,
4646
}
4747

4848
#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
49-
pub struct ConstPolyCommitment<G: ProjectiveCurve> {
49+
pub struct ConstPolyCommitment<G: CurveGroup> {
5050
C: G,
5151
}
5252

@@ -163,7 +163,7 @@ impl<F: PrimeField> DensePolynomial<F> {
163163
}
164164

165165
#[cfg(not(feature = "multicore"))]
166-
fn commit_inner<G: ProjectiveCurve<ScalarField = F>>(
166+
fn commit_inner<G: CurveGroup<ScalarField = F>>(
167167
&self,
168168
blinds: &[F],
169169
gens: &MultiCommitGens<G>,
@@ -189,7 +189,7 @@ impl<F: PrimeField> DensePolynomial<F> {
189189
random_tape: Option<&mut RandomTape<G>>,
190190
) -> (PolyCommitment<G>, PolyCommitmentBlinds<F>)
191191
where
192-
G: ProjectiveCurve<ScalarField = F>,
192+
G: CurveGroup<ScalarField = F>,
193193
{
194194
let n = self.Z.len();
195195
let ell = self.get_num_vars();
@@ -244,7 +244,7 @@ impl<F: PrimeField> DensePolynomial<F> {
244244
// returns Z(r) in O(n) time
245245
pub fn evaluate<G>(&self, r: &[F]) -> F
246246
where
247-
G: ProjectiveCurve<ScalarField = F>,
247+
G: CurveGroup<ScalarField = F>,
248248
{
249249
// r must have a value for each variable
250250
assert_eq!(r.len(), self.get_num_vars());
@@ -298,7 +298,7 @@ impl<F> Index<usize> for DensePolynomial<F> {
298298
}
299299
}
300300

301-
impl<G: ProjectiveCurve> AppendToTranscript<G> for PolyCommitment<G> {
301+
impl<G: CurveGroup> AppendToTranscript<G> for PolyCommitment<G> {
302302
fn append_to_transcript(&self, label: &'static [u8], transcript: &mut Transcript) {
303303
transcript.append_message(label, b"poly_commitment_begin");
304304
for i in 0..self.C.len() {
@@ -309,11 +309,11 @@ impl<G: ProjectiveCurve> AppendToTranscript<G> for PolyCommitment<G> {
309309
}
310310

311311
#[derive(Debug, CanonicalSerialize, CanonicalDeserialize)]
312-
pub struct PolyEvalProof<G: ProjectiveCurve> {
312+
pub struct PolyEvalProof<G: CurveGroup> {
313313
proof: DotProductProofLog<G>,
314314
}
315315

316-
impl<G: ProjectiveCurve> PolyEvalProof<G> {
316+
impl<G: CurveGroup> PolyEvalProof<G> {
317317
fn protocol_name() -> &'static [u8] {
318318
b"polynomial evaluation proof"
319319
}
@@ -395,10 +395,9 @@ impl<G: ProjectiveCurve> PolyEvalProof<G> {
395395
let (L, R) = eq.compute_factored_evals();
396396

397397
// compute a weighted sum of commitments and L
398-
let C_affine = G::batch_normalization_into_affine(&comm.C);
398+
let C_affine = G::normalize_batch(&comm.C);
399399

400-
let L_repr = L.iter().map(|x| x.into_repr()).collect::<Vec<_>>();
401-
let C_LZ = VariableBaseMSM::multi_scalar_mul(C_affine.as_ref(), L_repr.as_ref());
400+
let C_LZ = VariableBaseMSM::msm(C_affine.as_ref(), L.as_ref()).unwrap();
402401

403402
self
404403
.proof
@@ -429,10 +428,7 @@ mod tests {
429428
use ark_std::One;
430429
use ark_std::UniformRand;
431430

432-
fn evaluate_with_LR<G: ProjectiveCurve>(
433-
Z: &[G::ScalarField],
434-
r: &[G::ScalarField],
435-
) -> G::ScalarField {
431+
fn evaluate_with_LR<G: CurveGroup>(Z: &[G::ScalarField], r: &[G::ScalarField]) -> G::ScalarField {
436432
let eq = EqPolynomial::<G::ScalarField>::new(r.to_vec());
437433
let (L, R) = eq.compute_factored_evals();
438434

@@ -458,7 +454,7 @@ mod tests {
458454
check_polynomial_evaluation_helper::<G1Projective>()
459455
}
460456

461-
fn check_polynomial_evaluation_helper<G: ProjectiveCurve>() {
457+
fn check_polynomial_evaluation_helper<G: CurveGroup>() {
462458
// Z = [1, 2, 1, 4]
463459
let Z = vec![
464460
G::ScalarField::one(),
@@ -551,7 +547,7 @@ mod tests {
551547
check_memoized_chis_helper::<G1Projective>()
552548
}
553549

554-
fn check_memoized_chis_helper<G: ProjectiveCurve>() {
550+
fn check_memoized_chis_helper<G: CurveGroup>() {
555551
let mut prng = test_rng();
556552

557553
let s = 10;
@@ -608,7 +604,7 @@ mod tests {
608604
check_polynomial_commit_helper::<G1Projective>()
609605
}
610606

611-
fn check_polynomial_commit_helper<G: ProjectiveCurve>() {
607+
fn check_polynomial_commit_helper<G: CurveGroup>() {
612608
let Z = vec![
613609
G::ScalarField::one(),
614610
G::ScalarField::from(2u64),

0 commit comments

Comments
 (0)