Skip to content
Draft
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
12 changes: 8 additions & 4 deletions prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ crate-type = ["lib", "cdylib", "staticlib"]
bls12_381 = { version = "0.8.0", features = ["groups"] }
ff = "0.13.0"
jubjub = "0.10.0"
halo2curves = { version = "0.7.0" }
halo2_proofs = { git = "https://github.com/input-output-hk/halo2", rev = "0bca06e58937fbe213a0530ecac9d8e0fed501d6"}
blstrs = { git = "https://github.com/davidnevadoc/blstrs", rev = "3dfe5bf" }
midnight-curves = { version = "=0.3.0" }
midnight-proofs = { version = "=0.8.0" }

blake2b_simd = "1" # MSRV 1.66.0
paste = "1"
poseidon = { git = "https://github.com/iquerejeta/Poseidon252"}
Expand All @@ -36,4 +36,8 @@ name = "atms"
harness = false

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "katex-header.html" ]
rustdoc-args = [ "--html-in-header", "katex-header.html" ]

[features]
circuit-params = ["midnight-proofs/circuit-params"]

34 changes: 21 additions & 13 deletions prover/benches/atms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use atms_halo2::{
util::RegionCtx,
};
use blake2b_simd::State as Blake2bState;
use blstrs::{Base, JubjubAffine as AffinePoint};
use blstrs::Bls12;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use ff::Field;
use halo2_proofs::plonk::k_from_circuit;
use halo2_proofs::poly::kzg::KZGCommitmentScheme;
use halo2_proofs::utils::SerdeFormat;
use halo2_proofs::{
use midnight_curves::Bls12;
use midnight_curves::{Base, JubjubAffine as AffinePoint};
use midnight_proofs::plonk::k_from_circuit;
use midnight_proofs::poly::kzg::KZGCommitmentScheme;
use midnight_proofs::utils::SerdeFormat;
use midnight_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
plonk::{create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error},
poly::kzg::params::ParamsKZG,
Expand Down Expand Up @@ -45,6 +45,8 @@ struct BenchCircuitAtmsSignature {
impl Circuit<Base> for BenchCircuitAtmsSignature {
type Config = BenchCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand Down Expand Up @@ -76,9 +78,7 @@ impl Circuit<Base> for BenchCircuitAtmsSignature {
.schnorr_gate
.assign_sig(&mut ctx, &Value::known(sig))
} else {
atms_gate
.schnorr_gate
.assign_dummy_sig(&mut ctx)
atms_gate.schnorr_gate.assign_dummy_sig(&mut ctx)
}
})
.collect::<Result<Vec<_>, Error>>()?;
Expand Down Expand Up @@ -180,7 +180,9 @@ fn atms_bench_helper(c: &mut Criterion, num_parties: usize, threshold: usize) {
let kzg_params = ParamsKZG::<Bls12>::unsafe_setup(k, &mut rng);
let mut buf = Vec::new();

kzg_params.write_custom(&mut buf, SerdeFormat::RawBytesUnchecked).expect("Failed to write params");
kzg_params
.write_custom(&mut buf, SerdeFormat::RawBytesUnchecked)
.expect("Failed to write params");

let mut file =
File::create(Path::new(&params_path)).expect("Failed to create sha256_params");
Expand All @@ -191,7 +193,11 @@ fn atms_bench_helper(c: &mut Criterion, num_parties: usize, threshold: usize) {

let params_fs = File::open(Path::new(&params_path)).expect("couldn't load sha256_params");

let kzg_params = ParamsKZG::<Bls12>::read_custom(&mut BufReader::new(params_fs), SerdeFormat::RawBytesUnchecked).expect("Failed to read params");
let kzg_params = ParamsKZG::<Bls12>::read_custom(
&mut BufReader::new(params_fs),
SerdeFormat::RawBytesUnchecked,
)
.expect("Failed to read params");

// let kzg_params: ParamsKZG<Bls12> = ParamsKZG::<Bls12>::unsafe_setup(k, rng.clone());
let vk = keygen_vk(&kzg_params, &circuit).unwrap();
Expand All @@ -202,13 +208,15 @@ fn atms_bench_helper(c: &mut Criterion, num_parties: usize, threshold: usize) {
b.iter(|| {
let mut transcript: CircuitTranscript<Blake2bState> =
CircuitTranscript::<Blake2bState>::init();
let nb_committed_instances = 0;
create_proof::<Base, KZGCommitmentScheme<_>, _, _>(
&kzg_params,
&pk,
&[circuit.clone()],
nb_committed_instances,
&[&[&[pks_comm, msg, Base::from(threshold as u64)]]],
&mut rng,
&mut transcript,
&mut rng,
)
.expect("proof generation should not fail");

Expand All @@ -218,7 +226,7 @@ fn atms_bench_helper(c: &mut Criterion, num_parties: usize, threshold: usize) {
}

fn atms_3_of_6(c: &mut Criterion) {
atms_bench_helper(c,6, 3)
atms_bench_helper(c, 6, 3)
}
fn atms_6_of_9(c: &mut Criterion) {
atms_bench_helper(c, 9, 6)
Expand Down
17 changes: 9 additions & 8 deletions prover/docs/signatures/atms/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
Here we provide an example to demonstrate how ATMS circuit is used.
```rust
use ff::Field;
use halo2_proofs::poly::commitment::Params;
use halo2_proofs::{
use midnight_proofs::poly::commitment::Params;
use midnight_proofs::{
circuit::{Layouter, SimpleFloorPlanner, Value},
plonk::{create_proof, keygen_pk, keygen_vk, Circuit, ConstraintSystem, Error},
poly::{commitment::Guard, kzg::params::ParamsKZG},
transcript::{CircuitTranscript, Transcript},
};
use blstrs::{Bls12, JubjubAffine as AffinePoint, Base, JubjubExtended as ExtendedPoint, JubjubSubgroup as SubgroupPoint};
use midnight_curves::{Bls12, JubjubAffine as AffinePoint, Base, JubjubExtended as ExtendedPoint, JubjubSubgroup as SubgroupPoint};
use rand::prelude::IteratorRandom;
use rand_core::SeedableRng;
use std::fs::{create_dir_all, File};
use std::io::{BufReader, Write};
use std::path::Path;
use group::Group;
use halo2_proofs::dev::MockProver;
use midnight_proofs::dev::MockProver;
use crate::atms_halo2::ecc::chip::EccInstructions;
use crate::atms_halo2::instructions::MainGateInstructions;
use crate::atms_halo2::rescue::{RescueParametersBls, RescueSponge};
use crate::atms_halo2::rescue::{default_padding, RescueParametersBls, RescueSponge};
use crate::atms_halo2::signatures::atms::{AtmsVerifierConfig, AtmsVerifierGate};
use crate::atms_halo2::signatures::primitive::schnorr::Schnorr;
use crate::atms_halo2::signatures::schnorr::SchnorrSig;
Expand All @@ -42,6 +42,8 @@
impl Circuit<Base> for TestCircuitAtmsSignature {
type Config = TestCircuitConfig;
type FloorPlanner = SimpleFloorPlanner;
#[cfg(feature = "circuit-params")]
type Params = ();

fn without_witnesses(&self) -> Self {
Self::default()
Expand Down Expand Up @@ -135,7 +137,6 @@ fn main() {
// const NUM_PARTIES: usize = 2001; // todo: multiple of three so Rescue does not complain. We should do some padding
// const THRESHOLD: usize = 1602;

const K: u32 = 19;
const NUM_PARTIES: usize = 102;
const THRESHOLD: usize = 72;

Expand All @@ -154,7 +155,7 @@ fn main() {
flattened_pks.push(pk.get_u());
}

let pks_comm = RescueSponge::<Base, RescueParametersBls>::hash(&flattened_pks, None);
let pks_comm = RescueSponge::<Base, RescueParametersBls>::hash(&flattened_pks, Some(default_padding::<Base, RescueParametersBls>));

let signing_parties = (0..NUM_PARTIES).choose_multiple(&mut rng, THRESHOLD);
let signatures = (0..NUM_PARTIES)
Expand All @@ -178,7 +179,7 @@ fn main() {
let pi = vec![vec![pks_comm, msg, Base::from(THRESHOLD as u64)]];

let prover =
MockProver::run(K, &circuit, pi).expect("Failed to run ATMS verifier mock prover");
MockProver::run(&circuit, pi).expect("Failed to run ATMS verifier mock prover");

prover.assert_satisfied();
}
Expand Down
4 changes: 2 additions & 2 deletions prover/src/docs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![doc = include_str!("../docs/intro.md")]

#[doc = include_str!("../docs/docs-ecc.md")]
pub mod ecc{}
pub mod ecc {}

#[doc = include_str!("../docs/signatures/atms/intro.md")]
pub mod atms {}
Expand All @@ -19,4 +19,4 @@ pub mod encoding_io {}
pub mod flow {}

#[doc = include_str!("../docs/atms-primitives.md")]
pub mod primitives {}
pub mod primitives {}
6 changes: 2 additions & 4 deletions prover/src/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
//! See the [Elliptic curve cryptography documentation][crate::docs::ecc].
use std::fmt::Debug;

use halo2_proofs::{
use midnight_curves::CurveAffine;
use midnight_proofs::{
circuit::{Chip, Layouter, Value},
plonk::Error,
};
use halo2curves::CurveAffine;


pub mod chip;

Loading
Loading