Skip to content

Commit

Permalink
Merge pull request #1 from aulnes/from-wy
Browse files Browse the repository at this point in the history
New pull request
  • Loading branch information
0oyun authored Aug 29, 2024
2 parents fbba9f9 + 215862d commit 1472360
Show file tree
Hide file tree
Showing 54 changed files with 1,148,485 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ Cargo.lock
**/.DS_Store

**/results/*
**/results/
**/results/

/halo2_ecc/data/
3 changes: 2 additions & 1 deletion halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ jemallocator = { version = "=0.5", optional = true }
mimalloc = { version = "=0.1", default-features = false, optional = true }

[features]
default = ["halo2-axiom", "display", "test-utils"]
# default = ["halo2-axiom", "display", "test-utils"]
default = ["halo2-pse", "display", "test-utils"]
asm = ["halo2_proofs_axiom?/asm"]
dev-graph = ["halo2_proofs?/dev-graph", "plotters"] # only works with halo2-pse for now
halo2-pse = ["halo2_proofs/circuit-params"]
Expand Down
2 changes: 1 addition & 1 deletion halo2-base/src/gates/circuit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<F: ScalarField> BaseCircuitBuilder<F> {
let copy_manager = self.core.copy_manager.lock().unwrap();
let cell =
copy_manager.assigned_advices.get(&cell).expect("instance not assigned");
layouter.constrain_instance(*cell, *instance_col, i);
let _ = layouter.constrain_instance(*cell, *instance_col, i);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions halo2-base/src/gates/circuit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// use proptest::strategy::W;
use serde::{Deserialize, Serialize};

use crate::utils::ScalarField;
Expand All @@ -13,6 +14,7 @@ use self::builder::BaseCircuitBuilder;

use super::flex_gate::{FlexGateConfig, FlexGateConfigParams};
use super::range::RangeConfig;
// use super::shuffle::ShuffleConfig;

/// Module that helps auto-build circuits
pub mod builder;
Expand Down Expand Up @@ -67,6 +69,15 @@ pub enum MaybeRangeConfig<F: ScalarField> {
WithRange(RangeConfig<F>),
}


// #[derive(Clone, Debug)]
// pub enum MaybeShuffleConfig<F: ScalarField> {
// /// Config for a circuit that does not use range checks
// WithoutShuffle(FlexGateConfig<F>),
// /// Config for a circuit that does use range checks
// WithShuffle(ShuffleConfig<F>),
// }

impl<F: ScalarField> BaseConfig<F> {
/// Generates a new `BaseConfig` depending on `params`.
/// - It will generate a `RangeConfig` is `params` has `lookup_bits` not None **and** `num_lookup_advice_per_phase` are not all empty or zero (i.e., if `params` indicates that the circuit actually requires a lookup table).
Expand Down Expand Up @@ -170,6 +181,9 @@ impl<F: ScalarField> Circuit<F> for BaseCircuitBuilder<F> {
if let MaybeRangeConfig::WithRange(config) = &config.base {
config.load_lookup_table(&mut layouter).expect("load lookup table should not fail");
}
// if let MaybeShuffleConfig::WithShuffle(config) = &config.base {
// config.load_shuffle(&mut layouter).expect("load shuffle should not fail");
// }
// Only FirstPhase (phase 0)
layouter
.assign_region(
Expand Down
1 change: 1 addition & 0 deletions halo2-base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![warn(clippy::default_numeric_fallback)]
#![warn(missing_docs)]


use getset::CopyGetters;
use itertools::Itertools;
// Different memory allocator options:
Expand Down
2 changes: 1 addition & 1 deletion halo2-base/src/utils/halo2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn constrain_virtual_equals_external<F: Field + Ord>(
match copy_manager.assigned_advices.entry(ctx_cell) {
Entry::Occupied(acell) => {
// The virtual cell has already been assigned, so we can constrain it to equal the external cell.
region.constrain_equal(*acell.get(), external_cell);
let _ = region.constrain_equal(*acell.get(), external_cell);
}
Entry::Vacant(assigned) => {
// The virtual cell **must** be an external cell
Expand Down
20 changes: 14 additions & 6 deletions halo2-base/src/utils/testing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//! Utilities for testing
use std::time::Duration;

use crate::{
gates::{
circuit::{builder::RangeCircuitBuilder, BaseCircuitParams, CircuitBuilderStage},
Expand All @@ -22,7 +24,7 @@ use crate::{
},
Context,
};
use ark_std::{end_timer, perf_trace::TimerInfo, start_timer};
use ark_std::{end_timer, start_timer};
use rand::{rngs::StdRng, SeedableRng};

use super::fs::gen_srs;
Expand Down Expand Up @@ -223,9 +225,12 @@ impl BaseTester {
let vk_time = start_timer!(|| "Generating vkey");
let vk = keygen_vk(&params, &builder).unwrap();
end_timer!(vk_time);
let vk_duration = vk_time.time.elapsed();

let pk_time = start_timer!(|| "Generating pkey");
let pk = keygen_pk(&params, vk, &builder).unwrap();
end_timer!(pk_time);
let pk_duration = pk_time.time.elapsed();

let break_points = builder.break_points();
drop(builder);
Expand All @@ -236,14 +241,17 @@ impl BaseTester {
f(builder.pool(0), &range, logic_input);
let proof = gen_proof(&params, &pk, builder);
end_timer!(proof_time);
let proof_duration = proof_time.time.elapsed();

let proof_size = proof.len();

let verify_time = start_timer!(|| "Verify time");
let verify_start_time = std::time::Instant::now();
check_proof(&params, pk.get_vk(), &proof, self.expect_satisfied);
let verify_duration = verify_start_time.elapsed();
end_timer!(verify_time);

BenchStats { config_params, vk_time, pk_time, proof_time, proof_size, verify_time }
BenchStats { config_params, vk_time: vk_duration, pk_time: pk_duration, proof_time: proof_duration, proof_size, verify_time: verify_duration }
}
}

Expand All @@ -252,13 +260,13 @@ pub struct BenchStats {
/// Config params
pub config_params: BaseCircuitParams,
/// Vkey gen time
pub vk_time: TimerInfo,
pub vk_time: Duration,
/// Pkey gen time
pub pk_time: TimerInfo,
pub pk_time: Duration,
/// Proving time
pub proof_time: TimerInfo,
pub proof_time: Duration,
/// Proof size in bytes
pub proof_size: usize,
/// Verify time
pub verify_time: TimerInfo,
pub verify_time: Duration,
}
5 changes: 4 additions & 1 deletion halo2-ecc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ halo2-base = { version = "=0.4.1", path = "../halo2-base", default-features = fa

# plotting circuit layout
plotters = { version = "0.3.0", optional = true }
hex = "0.4.3"
poseidon = {git = "https://github.com/scroll-tech/poseidon"}

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand All @@ -37,7 +39,8 @@ test-log = "0.2.12"
env_logger = "0.10.0"

[features]
default = ["jemallocator", "halo2-axiom", "display"]
# default = ["jemallocator", "halo2-axiom", "display"]
default = ["jemallocator", "halo2-pse", "display"]
dev-graph = ["halo2-base/dev-graph", "plotters"]
display = ["halo2-base/display"]
asm = ["halo2-base/asm"]
Expand Down
6 changes: 0 additions & 6 deletions halo2-ecc/configs/bn254/bench_bls_signature.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,3 @@
{"strategy":"Simple","degree":20,"num_advice":3,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":19,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":22,"num_advice":1,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":21,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":20}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":200}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":2000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":20000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":40000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":80000}
15 changes: 15 additions & 0 deletions halo2-ecc/configs/bn254/bench_bls_signature_copy.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{"strategy":"Simple","degree":14,"num_advice":211,"num_lookup_advice":27,"num_fixed":1,"lookup_bits":13,"limb_bits":91,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":15,"num_advice":105,"num_lookup_advice":14,"num_fixed":1,"lookup_bits":14,"limb_bits":90,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":16,"num_advice":50,"num_lookup_advice":6,"num_fixed":1,"lookup_bits":15,"limb_bits":90,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":18,"num_advice":13,"num_lookup_advice":2,"num_fixed":1,"lookup_bits":17,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":20,"num_advice":3,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":19,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":22,"num_advice":1,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":21,"limb_bits":88,"num_limbs":3,"num_aggregation":2}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":20}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":200}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":2000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":20000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":40000}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":80000}
24 changes: 24 additions & 0 deletions halo2-ecc/configs/bn254/bench_combine_bls_mt.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":16,"num_origin":32}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":32,"num_origin":64}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":64,"num_origin":128}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":128,"num_origin":256}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":256,"num_origin":512}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":512,"num_origin":1024}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":1024,"num_origin":2048}
{"strategy":"Simple","degree":17,"num_advice":25,"num_lookup_advice":3,"num_fixed":1,"lookup_bits":16,"limb_bits":88,"num_limbs":3,"num_aggregation":2048,"num_origin":4096}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":16,"num_origin":32}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":32,"num_origin":64}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":64,"num_origin":128}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":128,"num_origin":256}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":256,"num_origin":512}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":512,"num_origin":1024}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":1024,"num_origin":2048}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":2048,"num_origin":4096}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":16,"num_origin":32}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":32,"num_origin":64}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":64,"num_origin":128}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":128,"num_origin":256}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":256,"num_origin":512}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":512,"num_origin":1024}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":1024,"num_origin":2048}
{"strategy":"Simple","degree":21,"num_advice":2,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":20,"limb_bits":88,"num_limbs":3,"num_aggregation":2048,"num_origin":4096}
10 changes: 10 additions & 0 deletions halo2-ecc/configs/bn254/bench_merkle_tree.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":16,"num_origin":32}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":32,"num_origin":64}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":64,"num_origin":128}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":128,"num_origin":256}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":256,"num_origin":512}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":512,"num_origin":1024}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":1024,"num_origin":2048}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":2048,"num_origin":4096}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":4096,"num_origin":8192}
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":8192,"num_origin":16384}
1 change: 1 addition & 0 deletions halo2-ecc/configs/bn254/combine_bls_mt.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":16,"num_origin":32}
1 change: 1 addition & 0 deletions halo2-ecc/configs/bn254/merkle_tree_circuit.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"strategy":"Simple","degree":19,"num_advice":6,"num_lookup_advice":1,"num_fixed":1,"lookup_bits":18,"limb_bits":90,"num_limbs":3,"num_aggregation":16,"num_origin":32}
2 changes: 2 additions & 0 deletions halo2-ecc/configs/bn254/shuffle.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{"strategy":"Simple","degree":14,"num_aggregation":2}
{"strategy":"Simple","degree":15,"num_aggregation":2}
Loading

0 comments on commit 1472360

Please sign in to comment.