Skip to content

Commit

Permalink
fix: downgrade Poseidon back to previous version for binary compatibi…
Browse files Browse the repository at this point in the history
…lity (#88)

* fix: downgrade Poseidon back to previous version for binary compatibility

* fix: use new naming for parameter generation function

* chore: remove unused dependencies in deactivated tests

* fix: use correct parameter generation name for benchmarks
  • Loading branch information
bhgomes authored Jun 7, 2022
1 parent e779189 commit ebf9352
Show file tree
Hide file tree
Showing 10 changed files with 504 additions and 39 deletions.
10 changes: 5 additions & 5 deletions manta-benchmark/benches/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_benchmark::payment;
use manta_crypto::rand::{OsRng, Rand};
use manta_pay::parameters::{generate_parameters, SEED};
use manta_pay::parameters;

pub fn prove(c: &mut Criterion) {
fn prove(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let (proving_context, _verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();
let mut rng = OsRng;
group.bench_function("mint prove", |b| {
let asset = black_box(rng.gen());
Expand All @@ -38,10 +38,10 @@ pub fn prove(c: &mut Criterion) {
});
}

pub fn verify(c: &mut Criterion) {
fn verify(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();
let mut rng = OsRng;
let mint = black_box(payment::prove_mint(
&proving_context.mint,
Expand Down
7 changes: 3 additions & 4 deletions manta-benchmark/benches/private_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_benchmark::payment::{self, assert_valid_proof};
use manta_crypto::rand::OsRng;
use manta_pay::parameters::{generate_parameters, SEED};
use manta_pay::parameters;

fn prove(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let (proving_context, _, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap();
group.bench_function("private transfer prove", |b| {
b.iter(|| {
let _ = payment::prove_private_transfer(
Expand All @@ -40,7 +39,7 @@ fn verify(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();
let private_transfer = black_box(payment::prove_private_transfer(
&proving_context,
&parameters,
Expand Down
7 changes: 3 additions & 4 deletions manta-benchmark/benches/reclaim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_benchmark::payment::{self, assert_valid_proof};
use manta_crypto::rand::OsRng;
use manta_pay::parameters::{generate_parameters, SEED};
use manta_pay::parameters;

fn prove(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let (proving_context, _, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
let (proving_context, _, parameters, utxo_accumulator_model) = parameters::generate().unwrap();
group.bench_function("reclaim prove", |b| {
b.iter(|| {
let _ = payment::prove_reclaim(
Expand All @@ -40,7 +39,7 @@ fn verify(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();
let reclaim = black_box(payment::prove_reclaim(
&proving_context,
&parameters,
Expand Down
4 changes: 2 additions & 2 deletions manta-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use manta_pay::{
config::{
MultiProvingContext, MultiVerifyingContext, Parameters, TransferPost, UtxoAccumulatorModel,
},
parameters::{generate_parameters, SEED},
parameters,
};
use wasm_bindgen::prelude::wasm_bindgen;

Expand All @@ -40,7 +40,7 @@ impl Context {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();
Self {
proving_context,
verifying_context,
Expand Down
10 changes: 4 additions & 6 deletions manta-pay/src/bin/generate_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
// TODO: Deduplicate the per-circuit proving context and verifying context serialization code.
// TODO: Print some statistics about the parameters and circuits and into a stats file as well.

use manta_pay::{
config::Parameters,
parameters::{generate_parameters, SEED},
};
use manta_pay::{config::Parameters, parameters};
use manta_util::codec::{Encode, IoWriter};
use std::{
env,
Expand All @@ -31,7 +28,8 @@ use std::{
path::PathBuf,
};

/// Generates the parameters using the [`SEED`] and saves them to the filesystem.
/// Generates the parameters using the [`SEED`](manta_pay::parameters::SEED) and saves them to the
/// filesystem.
#[inline]
pub fn main() -> io::Result<()> {
let target_dir = env::args()
Expand All @@ -46,7 +44,7 @@ pub fn main() -> io::Result<()> {
fs::create_dir_all(&target_dir)?;

let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
generate_parameters(SEED).unwrap();
parameters::generate().unwrap();

let Parameters {
note_encryption_scheme,
Expand Down
9 changes: 6 additions & 3 deletions manta-pay/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::crypto::{
constraint::arkworks::{field_element_as_bytes, groth16, Boolean, Fp, FpVar, R1CS},
ecc,
encryption::aes::{self, FixedNonceAesGcm},
hash::poseidon,
hash::poseidon::compat as poseidon,
key::Blake2sKdf,
};
use alloc::vec::Vec;
Expand Down Expand Up @@ -97,6 +97,9 @@ pub type Proof = groth16::Proof<PairingCurve>;
/// Proof System
pub type ProofSystem = groth16::Groth16<PairingCurve>;

/// Proof System Error
pub type ProofSystemError = groth16::Error;

/// Poseidon Specification
pub struct PoseidonSpec<const ARITY: usize>;

Expand All @@ -109,7 +112,7 @@ pub type Poseidon2Var = poseidon::Hasher<PoseidonSpec<2>, 2, Compiler>;
impl poseidon::arkworks::Specification for PoseidonSpec<2> {
type Field = ConstraintField;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 55;
const PARTIAL_ROUNDS: usize = 57;
const SBOX_EXPONENT: u64 = 5;
}

Expand All @@ -122,7 +125,7 @@ pub type Poseidon4Var = poseidon::Hasher<PoseidonSpec<4>, 4, Compiler>;
impl poseidon::arkworks::Specification for PoseidonSpec<4> {
type Field = ConstraintField;
const FULL_ROUNDS: usize = 8;
const PARTIAL_ROUNDS: usize = 56;
const PARTIAL_ROUNDS: usize = 60;
const SBOX_EXPONENT: u64 = 5;
}

Expand Down
Loading

0 comments on commit ebf9352

Please sign in to comment.