Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ Cargo.lock

/halo2_ecc/src/bn254/data/
/halo2_ecc/src/secp256k1/data/

*.srs
*.csv
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[workspace]
members = ["halo2-base", "halo2-ecc", "hashes/zkevm"]
members = [
"halo2-base",
"halo2-ecc",
"hashes/zkevm"
]
resolver = "2"

[profile.dev]
Expand Down Expand Up @@ -39,3 +43,6 @@ debug = true
[patch."https://github.com/axiom-crypto/halo2-lib.git"]
halo2-base = { path = "../halo2-lib/halo2-base" }
halo2-ecc = { path = "../halo2-lib/halo2-ecc" }

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "sync-halo2-lib-0.4.0" }
11 changes: 7 additions & 4 deletions halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ getset = "0.1.2"
ark-std = { version = "0.3.0", features = ["print-trace"], optional = true }

# Use Axiom's custom halo2 monorepo for faster proving when feature = "halo2-axiom" is on
halo2_proofs_axiom = { git = "https://github.com/axiom-crypto/halo2.git", package = "halo2_proofs", optional = true }
halo2_proofs_axiom = { git = "https://github.com/axiom-crypto/halo2.git", package = "halo2-axiom", optional = true }
# Use PSE halo2 and halo2curves for compatibility when feature = "halo2-pse" is on
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", rev = "7a21656", optional = true }
# halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "sync-upstream-1007", optional = true }

# This is Scroll's audited poseidon circuit. We only use it for the Native Poseidon spec. We do not use the halo2 circuit at all (and it wouldn't even work because the halo2_proofs tag is not compatbile).
# We forked it to upgrade to ff v0.13 and removed the circuit module
poseidon-rs = { git = "https://github.com/axiom-crypto/poseidon-circuit.git", rev = "1aee4a1" }
poseidon-circuit = { git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "sync-halo2-lib-0.4.0" }
# plotting circuit layout
plotters = { version = "0.3.0", optional = true }
tabbycat = { version = "0.1", features = ["attributes"], optional = true }
Expand All @@ -43,7 +44,7 @@ test-log = "0.2.12"
env_logger = "0.10.0"
proptest = "1.1.0"
# native poseidon for testing
pse-poseidon = { git = "https://github.com/axiom-crypto/pse-poseidon.git" }
poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "sync-halo2-lib-0.4.0" }

# memory allocation
[target.'cfg(not(target_env = "msvc"))'.dependencies]
Expand All @@ -52,13 +53,15 @@ jemallocator = { version = "0.5", optional = true }
mimalloc = { version = "0.1", default-features = false, optional = true }

[features]
default = ["halo2-axiom", "display", "test-utils"]
default = ["halo2-pse", "test-utils"]
# default = ["halo2-pse", "display", "test-utils"]
asm = ["halo2_proofs_axiom?/asm"]
dev-graph = [
"halo2_proofs?/dev-graph",
"halo2_proofs_axiom?/dev-graph",
"plotters",
]
# halo2-pse = []
halo2-pse = ["halo2_proofs/circuit-params"]
halo2-axiom = ["halo2_proofs_axiom"]
display = []
Expand Down
11 changes: 0 additions & 11 deletions halo2-base/proptest-regressions/gates/tests/prop_test.txt

This file was deleted.

1 change: 1 addition & 0 deletions halo2-base/src/gates/circuit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ impl<F: ScalarField> BaseCircuitBuilder<F> {
}

/// Basic statistics
#[derive(Debug)]
pub struct RangeStatistics {
/// Number of advice cells for the basic gate and total constants used
pub gate: GateStatistics,
Expand Down
137 changes: 108 additions & 29 deletions halo2-base/src/gates/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,113 @@ impl<F: ScalarField> BaseConfig<F> {
}
}

impl<F: ScalarField> BaseCircuitBuilder<F> {
/// Performs the actual computation on the circuit (e.g., witness generation), populating the lookup table and filling in all the advice values for a particular proof.
pub fn synthesize_ref_layouter_phase_0(
&self,
config: BaseConfig<F>,
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
// only load lookup table if we are actually doing lookups
if let MaybeRangeConfig::WithRange(config) = &config.base {
config.load_lookup_table(layouter).expect("load lookup table should not fail");
}
// FirstPhase (phase 0)
layouter
.assign_region(
|| "base phase 0",
|mut region| {
let usable_rows = config.gate().max_rows;
self.core.phase_manager[0].assign_raw(
&(config.gate().basic_gates[0].clone(), usable_rows),
&mut region,
);

// Only assign cells to lookup if we're sure we're doing range lookups
if let MaybeRangeConfig::WithRange(config) = &config.base {
self.assign_lookups_in_phase(config, &mut region, 0);
}
Ok(())
},
)
.unwrap();

Ok(())
}

/// Performs the actual computation on the circuit (e.g., witness generation), populating the lookup table and filling in all the advice values for a particular proof.
pub fn synthesize_ref_layouter_phase_1(
&self,
config: BaseConfig<F>,
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
// SecondPhase (phase 1)
layouter
.assign_region(
|| "base phase 1",
|mut region| {
let usable_rows = config.gate().max_rows;
if self.core.phase_manager.len() > 1 {
self.core.phase_manager[1].assign_raw(
&(config.gate().basic_gates[1].clone(), usable_rows),
&mut region,
);
}

// Only assign cells to lookup if we're sure we're doing range lookups
if let MaybeRangeConfig::WithRange(config) = &config.base {
if self.core.phase_manager.len() > 1 {
self.assign_lookups_in_phase(config, &mut region, 1);
}
}

Ok(())
},
)
.unwrap();

Ok(())
}

/// Performs the actual computation on the circuit (e.g., witness generation), populating the lookup table and filling in all the advice values for a particular proof.
pub fn synthesize_ref_layouter_final(
&self,
config: BaseConfig<F>,
layouter: &mut impl Layouter<F>,
with_instances: bool,
) -> Result<(), Error> {
// finalize
layouter
.assign_region(
|| "constants assignments + copy constraints",
|mut region| {
// Impose equality constraints
if !self.core.witness_gen_only() {
self.core.copy_manager.assign_raw(config.constants(), &mut region);
}
Ok(())
},
)
.unwrap();
if with_instances {
self.assign_instances(&config.instance, layouter.namespace(|| "expose instances"));
}
Ok(())
}

/// Performs the actual computation on the circuit (e.g., witness generation), populating the lookup table and filling in all the advice values for a particular proof.
pub fn synthesize_ref_layouter(
&self,
config: BaseConfig<F>,
layouter: &mut impl Layouter<F>,
) -> Result<(), Error> {
self.synthesize_ref_layouter_phase_0(config.clone(), layouter)?;
self.synthesize_ref_layouter_phase_1(config.clone(), layouter)?;
self.synthesize_ref_layouter_final(config, layouter, true)?;
Ok(())
}
}

impl<F: ScalarField> Circuit<F> for BaseCircuitBuilder<F> {
type Config = BaseConfig<F>;
type FloorPlanner = SimpleFloorPlanner;
Expand Down Expand Up @@ -166,35 +273,7 @@ impl<F: ScalarField> Circuit<F> for BaseCircuitBuilder<F> {
config: Self::Config,
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
// only load lookup table if we are actually doing lookups
if let MaybeRangeConfig::WithRange(config) = &config.base {
config.load_lookup_table(&mut layouter).expect("load lookup table should not fail");
}
// Only FirstPhase (phase 0)
layouter
.assign_region(
|| "BaseCircuitBuilder generated circuit",
|mut region| {
let usable_rows = config.gate().max_rows;
self.core.phase_manager[0].assign_raw(
&(config.gate().basic_gates[0].clone(), usable_rows),
&mut region,
);
// Only assign cells to lookup if we're sure we're doing range lookups
if let MaybeRangeConfig::WithRange(config) = &config.base {
self.assign_lookups_in_phase(config, &mut region, 0);
}
// Impose equality constraints
if !self.core.witness_gen_only() {
self.core.copy_manager.assign_raw(config.constants(), &mut region);
}
Ok(())
},
)
.unwrap();

self.assign_instances(&config.instance, layouter.namespace(|| "expose"));
Ok(())
self.synthesize_ref_layouter(config, &mut layouter)
}
}

Expand Down
1 change: 1 addition & 0 deletions halo2-base/src/gates/flex_gate/threads/multi_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl<F: ScalarField> MultiPhaseCoreManager<F> {
}

/// Basic statistics
#[derive(Debug)]
pub struct GateStatistics {
/// Total advice cell count per phase
pub total_advice_per_phase: Vec<usize>,
Expand Down
4 changes: 2 additions & 2 deletions halo2-base/src/poseidon/hasher/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};

use getset::{CopyGetters, Getters};
use poseidon_rs::poseidon::primitives::Spec as PoseidonSpec; // trait
use poseidon_circuit::poseidon::primitives::Spec as PoseidonSpec; // trait
use std::marker::PhantomData;

// struct so we can use PoseidonSpec trait to generate round constants and MDS matrix
Expand All @@ -21,7 +21,7 @@ pub(crate) struct Poseidon128Pow5Gen<
}

impl<
F: PrimeField,
F: FromUniformBytes<64> + Ord,
const T: usize,
const RATE: usize,
const R_F: usize,
Expand Down
2 changes: 1 addition & 1 deletion halo2-base/src/poseidon/hasher/tests/compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
poseidon::hasher::PoseidonSponge,
utils::ScalarField,
};
use pse_poseidon::Poseidon;
use poseidon::Poseidon;
use rand::Rng;

// make interleaved calls to absorb and squeeze elements and
Expand Down
2 changes: 1 addition & 1 deletion halo2-base/src/poseidon/hasher/tests/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
Context,
};
use itertools::Itertools;
use pse_poseidon::Poseidon;
use poseidon::Poseidon;
use rand::Rng;

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion halo2-ecc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test-log = "0.2.12"
env_logger = "0.10.0"

[features]
default = ["jemallocator", "halo2-axiom", "display"]
default = ["jemallocator", "halo2-pse", "display"]
dev-graph = ["halo2-base/dev-graph"]
display = ["halo2-base/display"]
asm = ["halo2-base/asm"]
Expand Down