Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync with v0.4.1-rc #239

Merged
merged 126 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
282ee8e
fix: change all `1` to `1u64` to prevent unexpected overflow (#72)
jonathanpwang Jun 3, 2023
8b9bdc2
[Fix] Panic when dealing with identity point (#71)
jonathanpwang Jun 6, 2023
05cfc1c
fix: redundant check in `ec_sub_unequal`
jonathanpwang Jun 7, 2023
0be26d4
Add SafeType (#26)
nyunyunyunyu May 23, 2023
d3ed3a9
feat(CI): switch to larger runner
jonathanpwang Jun 9, 2023
e4b956b
fix(builder): handle empty ctx with only equality constraints
jonathanpwang Jun 9, 2023
5293793
feat: add SafeAddress and SafeUint160 (#85)
PatStiles Jun 14, 2023
ca8e11c
Release 0.3.0 (#86)
jonathanpwang Jun 20, 2023
4060f2a
chore: fix halo2_proofs_axiom SHA commit
jonathanpwang Jun 20, 2023
f6b22ab
Merge release v0.3.0 into develop (#90)
jonathanpwang Jul 7, 2023
da451da
feat: `FpChip::range_check` now works with `max_bits < n * (k-1)` (#91)
jonathanpwang Jul 7, 2023
70c5cc0
fix(test): zkevm-keccak test should have `first_pass = SKIP_FIRST_PAS…
jonathanpwang Jul 20, 2023
08a16ce
Feat: test suite (#92)
jonathanpwang Jul 20, 2023
d1beb92
chore: make `bit_length` const function
jonathanpwang Jul 21, 2023
160f503
feat: add debugging functions (#99)
jonathanpwang Jul 26, 2023
081d475
chore: remove cfg(test) for debug functions
jonathanpwang Jul 26, 2023
2b3dd5d
feat(halo2-base): add `GateChip::pow_var` (#103)
jonathanpwang Aug 6, 2023
0b16812
Use halo2curves v0.4.0 and ff v0.13 (#107)
jonathanpwang Aug 15, 2023
3408b7a
Add `sub_mul` to GateInstructions (#102)
mmagician Aug 8, 2023
a62ae5d
fix(test): `select_from_idx` wasn't calling the right function (#105)
mmagician Aug 9, 2023
7100c23
chore: add back RangeCircuitBuilder::config (#111)
jonathanpwang Aug 17, 2023
49aeedd
fix: `RangeCircuitBuilder::config` remember `lookup_bits`
jonathanpwang Aug 17, 2023
a7b5433
[Feat] Add Poseidon Hasher Chip (#110)
nyunyunyunyu Aug 17, 2023
f724c9b
feat: add VariableByteArray (#88)
PatStiles Aug 18, 2023
3bacff7
chore: reduce CI real prover load
jonathanpwang Aug 18, 2023
cd9b6a4
Rename PoseidonHasherChip to PoseidonHasher (#113)
nyunyunyunyu Aug 18, 2023
25e211a
chore(safe_types): add conversion `SafeType` to/from `FixLenBytes`
jonathanpwang Aug 21, 2023
b58046c
chore(safe_type): add `unsafe_to_safe_type` unsafe conversion fn
jonathanpwang Aug 21, 2023
204a699
feat: add `select_array_by_indicator` to `GateInstructions` (#115)
jonathanpwang Aug 21, 2023
1c33fbc
cleanup: use test-utils for benching (#112)
jonathanpwang Aug 22, 2023
83ca65e
fix(safe_types): `VarLenBytes` should allow `len == MAX_LEN` (#117)
jonathanpwang Aug 22, 2023
7b23747
[feat] Add Poseidon Chip (#114)
nyunyunyunyu Aug 22, 2023
9798c85
[chore] Reorg Folder Structure of hashes/zkevm (#118)
nyunyunyunyu Aug 22, 2023
9fac2a8
[fix] CI for zkevm hashes (#119)
nyunyunyunyu Aug 23, 2023
154cd8c
[chore] Split keccak implementation into multiple files (#120)
nyunyunyunyu Aug 23, 2023
89da366
feat: keccak constant visibility changes (#121)
MonkeyKing-1 Aug 24, 2023
eb4fe65
[feat] Keccak Raw Output (#122)
nyunyunyunyu Aug 27, 2023
15bca77
Virtual region managers and dynamic lookup support (#123)
jonathanpwang Aug 27, 2023
f4c7e2a
Use `raw_assign_{advice,fixed}` in keccak (#125)
jonathanpwang Aug 28, 2023
7831b00
[feat] PoseidonHasher supports multiple inputs in compact format (#127)
nyunyunyunyu Aug 28, 2023
7bdf089
[feat] Expose Keccack Raw Inputs in Bytes instead of Input RLCs (#124)
nyunyunyunyu Aug 29, 2023
d07b0d4
Bump `zkevm-hashes` to v0.1.4
jonathanpwang Aug 29, 2023
6c80289
chore: clippy fix
jonathanpwang Aug 29, 2023
f2cf3e8
Generic vertical gate assignment (#129)
jonathanpwang Aug 29, 2023
be52d1d
Add `deep_clone` to `BaseCircuitBuilder` (#131)
jonathanpwang Sep 1, 2023
edd239f
fix: `SingleCorePhaseManager` should not create thread in constructor
jonathanpwang Sep 2, 2023
f39fef3
chore: make `new_context` public
jonathanpwang Sep 3, 2023
608b8f2
Convenience functions and fixes for multi-phase (#133)
jonathanpwang Sep 4, 2023
2b03c17
chore: add `BaseCircuitBuilder::set_k` fn
jonathanpwang Sep 5, 2023
64c8123
fix: `CopyConstraintManager::clear` was dropping
jonathanpwang Sep 5, 2023
04a40d4
feat: impl `From<SafeByte>` for `AssignedValue`
jonathanpwang Sep 5, 2023
671f0cc
chore(poseidon): add `derive` statements
jonathanpwang Sep 5, 2023
d27e46a
fix(copy_constraints): backend permutation argument depends on order
jonathanpwang Sep 6, 2023
a1fec64
feat: add `left_pad` functions for var length arrays (#137)
jonathanpwang Sep 6, 2023
72b53bf
chore: use `PrimeField` for `OptimizedPoseidonSpec` (#139)
jonathanpwang Sep 8, 2023
0acc05a
chore: add getter functions to Poseidon spec (#140)
jonathanpwang Sep 8, 2023
61fda9d
feat: use `(TypeId, usize)` instead of `usize` for lookup tag (#142)
jonathanpwang Sep 9, 2023
58155d7
chore: add `ContextTag` type alias
jonathanpwang Sep 9, 2023
3a35050
feat(base): add `GateInstructions::inner_product_left` function (#143)
jonathanpwang Sep 9, 2023
9377d90
[feat] Keccak Coprocessor Leaf Circuit (#130)
nyunyunyunyu Sep 9, 2023
54044c9
[feat] App Circuit Utils for Keccak Coprocessor (#141)
nyunyunyunyu Sep 9, 2023
14bec5a
[chore] Fix fmt (#144)
nyunyunyunyu Sep 10, 2023
c2a9341
chore: add misc utility functions (#146)
jonathanpwang Sep 10, 2023
482bed6
feat(keccak): add `ingestion` module for Rust native input formatting…
jonathanpwang Sep 10, 2023
41ea795
chore(keccak): use `snark-verifier` native Poseidon for encoding (#148)
jonathanpwang Sep 10, 2023
1ea4f84
feat: optimize leaf poseidon with `hash_compact_chunk_inputs` (#149)
jonathanpwang Sep 11, 2023
2ccfc43
[chore] cleanup code (#150)
jonathanpwang Sep 11, 2023
18057d3
chore: get halo2-pse working again
jonathanpwang Sep 11, 2023
46c5769
Merge branch 'main' into release-0.4.0-rc0
jonathanpwang Sep 11, 2023
eb5b284
chore: fix fmt
jonathanpwang Sep 11, 2023
92277ce
[Doc] Keccak Doc (#145)
nyunyunyunyu Sep 11, 2023
1bf36b1
chore: pin snark-verifier branch
jonathanpwang Sep 11, 2023
12f190a
[fix] max_rows in BaseCircuitBuilder in Keccak Leaf Circuit (#152)
nyunyunyunyu Sep 12, 2023
9a2fc70
[chore] Remove Unnecessary Lookup in Keccak Coprocessor Leaf Circuit …
nyunyunyunyu Sep 18, 2023
17d297b
Revert "chore: pin snark-verifier branch"
jonathanpwang Sep 11, 2023
26b81a3
[rename] (coprocessor, leaf) -> (component, shard) (#161)
jonathanpwang Sep 18, 2023
712d889
[rename] (coprocessor, leaf) -> (component, shard) (#161)
jonathanpwang Sep 18, 2023
e36c45b
[fix] Multiple Phase Lookup (#162)
nyunyunyunyu Sep 19, 2023
d3828a4
[fix] Multiple Phase Lookup (#162)
nyunyunyunyu Sep 19, 2023
215fe1c
[chore] add conversion `SafePrimitive` to `QuantumCell::Existing` (#169)
jonathanpwang Sep 26, 2023
524c818
fix: bad import on halo2-pse
jonathanpwang Sep 26, 2023
7acbe4d
[chore] add conversion `SafePrimitive` to `QuantumCell::Existing` (#169)
jonathanpwang Sep 26, 2023
5a43f96
fix: bad import on halo2-pse
jonathanpwang Sep 26, 2023
4cd0844
chore: make `{Fixed,Var}LenBytes*` constructor public
jonathanpwang Sep 26, 2023
3f84ec2
chore: make `{Fixed,Var}LenBytes*` constructor public
jonathanpwang Sep 26, 2023
16fa9e5
chore(keccak): `format_requests` always returns true capacity (#171)
jonathanpwang Sep 28, 2023
dff0e63
[chore] derive `Hash` for `BaseCircuitParams` (#172)
jonathanpwang Sep 29, 2023
8a5d469
[chore] impl `AsRef, AsMut` for `BaseCircuitBuilder` to self (#173)
jonathanpwang Oct 1, 2023
addfbec
[chore] impl `AsRef, AsMut` for `BaseConfig` to self (#174)
jonathanpwang Oct 1, 2023
9e6c9a1
[chore] Add getters to `KeccakComponentShardCircuit` (#178)
jonathanpwang Oct 7, 2023
fef7316
[chore] Expose Keccak Packing (#180)
nyunyunyunyu Oct 10, 2023
5411321
[chore] Expose Keccak Format (#181)
nyunyunyunyu Oct 11, 2023
bf71f0e
[feat] basic dynamic lookup table gadget (#182)
jonathanpwang Oct 11, 2023
9ff8994
[chore] expose `spec` in `PoseidonHasher` (#183)
jonathanpwang Oct 16, 2023
ff0cadf
[chore] fix halo2-pse build error (#184)
jonathanpwang Oct 18, 2023
582f671
[feat] expose keccak table loading/packing functions for external cra…
jonathanpwang Oct 20, 2023
eef553c
[chore] add getters to `PoseidonCompactChunkInput` (#196)
jonathanpwang Oct 20, 2023
ca498e5
[chore] fix deref after using CopyGetters (#197)
jonathanpwang Oct 21, 2023
2e996ae
[feat] implement `CircuitExt` for `KeccakComponentShardCircuit` (#198)
jonathanpwang Oct 22, 2023
ee822b9
Merge branch 'release-0.4.0-rc' into develop
jonathanpwang Oct 23, 2023
267123f
chore: fix `snark-verifier-sdk` version
jonathanpwang Oct 23, 2023
4ba2efc
[chore] add `cargo audit` to CI (#207)
jonathanpwang Nov 2, 2023
d4bf2fa
[fix] `FieldChip::range_check` should take `FieldPoint` instead of `U…
jonathanpwang Nov 2, 2023
4bc9f0a
[feat] update docs (#211)
jonathanpwang Nov 3, 2023
4e78e40
[chore] fix dev graph tests (#212)
jonathanpwang Nov 3, 2023
a30e3b1
[fix] `BasicDynLookupConfig` needs selector on advice table to preven…
jonathanpwang Nov 3, 2023
6cc92c6
[feat] add keccak circuit tests against Known Answer Test vectors (#213)
jonathanpwang Nov 3, 2023
cba20ed
[chore] fix documentation (#215)
jonathanpwang Nov 3, 2023
67e3a0e
[chore] fix doc comment (#216)
jonathanpwang Nov 3, 2023
5e2706f
chore: fix halo2-pse compile
jonathanpwang Nov 12, 2023
70d6d8a
fix: `TypeId` in `ContextTag` not stable across builds (#217)
jonathanpwang Nov 13, 2023
dacb885
Merge branch 'release-0.4.0-rc' into release-0.4.1-rc
jonathanpwang Nov 13, 2023
b880af1
chore: fix RAM test to use `&str` type id
jonathanpwang Nov 13, 2023
adb9694
[chore] add crate prefix to `type_id`s (#218)
jonathanpwang Nov 14, 2023
b6a5750
chore: use halo2-axiom from crates.io
jonathanpwang Nov 16, 2023
d45800d
chore: use poseidon-primitives from crates.io
jonathanpwang Nov 16, 2023
26a4504
chore: Bump halo2-axiom to v0.4
jonathanpwang Nov 20, 2023
12e07e1
chore: add `get_mut` for keccak circuit params
jonathanpwang Nov 20, 2023
b6625fa
[fix] soundness bug in `BasicDynLookupConfig::assign_virtual_table_to…
jonathanpwang Nov 30, 2023
fe3e439
[chore] make `KeccakComponentShardCircuit` `inputs` into `RefCell` (#…
jonathanpwang Dec 10, 2023
ae6f378
chore: fix keccak capacity check (#232)
jonathanpwang Dec 10, 2023
4acc096
chore: add utility traits to aid in proving key generation (#227)
jonathanpwang Dec 13, 2023
aae4ae0
[chore] `get_pinning_after_keygen` uses `self` (#235)
jonathanpwang Dec 15, 2023
f323d89
fix(docs): `div_unsafe` docs (#237)
shuklaayush Dec 16, 2023
10b3a5e
Merge branch 'release-0.4.1-rc' into ce-merge
jonathanpwang Dec 21, 2023
3bdcfda
chore: fix merge
jonathanpwang Dec 21, 2023
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ cargo test --release --no-default-features --features "halo2-axiom, mimalloc" --
- [halo2-rsa](https://github.com/zkemail/halo2-rsa/tree/feat/new_bigint)
- [halo2-fri-gadget](https://github.com/maxgillett/halo2-fri-gadget) -- FRI verifier in halo2.
- [eth-voice-recovery](https://github.com/SoraSuegami/voice_recovery_circuit)
- [zkevm signature verification circuit](https://github.com/scroll-tech/zkevm-circuits/tree/develop/zkevm-circuits/src/sig_circuit.rs)
<<<<<<< HEAD
- # [zkevm signature verification circuit](https://github.com/scroll-tech/zkevm-circuits/tree/develop/zkevm-circuits/src/sig_circuit.rs)
- [zkevm tx-circuit](https://github.com/scroll-tech/zkevm-circuits/tree/develop/zkevm-circuits/src/tx_circuit)
> > > > > > > release-0.4.1-rc
- [webauthn-halo2](https://github.com/zkwebauthn/webauthn-halo2) -- Proving and verifying WebAuthn with halo2.
- [Fixed Point Arithmetic](https://github.com/DCMMC/halo2-scaffold/tree/main/src/gadget) -- Fixed point arithmetic library in halo2.
12 changes: 6 additions & 6 deletions halo2-base/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "halo2-base"
version = "0.4.0"
version = "0.4.1"
edition = "2021"

[dependencies]
Expand Down Expand Up @@ -29,7 +29,7 @@ poseidon-rs = { package = "poseidon-primitives", version = "=0.1.1" }
plotters = { version = "0.3.0", optional = true }

# test-utils
rand={ version="0.8", optional=true }
rand = { version = "0.8", optional = true }

[dev-dependencies]
ark-std = { version = "0.3.0", features = ["print-trace"] }
Expand All @@ -46,9 +46,9 @@ pse-poseidon = { git = "https://github.com/axiom-crypto/pse-poseidon.git" }

# memory allocation
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator={ version="=0.5", optional=true }
jemallocator = { version = "=0.5", optional = true }

mimalloc={ version="=0.1", default-features=false, optional=true }
mimalloc = { version = "=0.1", default-features = false, optional = true }

[features]
default = ["halo2-axiom", "display", "test-utils"]
Expand All @@ -61,8 +61,8 @@ profile = ["halo2_proofs_axiom?/profile"]
test-utils = ["dep:rand", "ark-std"]

[[bench]]
name="mul"
harness=false
name = "mul"
harness = false

[[bench]]
name = "inner_product"
Expand Down
10 changes: 8 additions & 2 deletions halo2-base/src/gates/flex_gate/threads/single_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,15 @@ pub fn assign_with_constraints<F: ScalarField, const ROTATIONS: usize>(
.assign_advice(|| "", column, row_offset, || value.map(|v| *v))
.unwrap()
.cell();
copy_manager
if let Some(old_cell) = copy_manager
.assigned_advices
.insert(ContextCell::new(ctx.type_id, ctx.context_id, i), cell);
.insert(ContextCell::new(ctx.type_id, ctx.context_id, i), cell)
{
assert!(
old_cell.row_offset == cell.row_offset && old_cell.column == cell.column,
"Trying to overwrite virtual cell with a different raw cell"
);
}

// If selector enabled and row_offset is valid add break point, account for break point overlap, and enforce equality constraint for gate outputs.
// ⚠️ This assumes overlap is of form: gate enabled at `i - delta` and `i`, where `delta = ROTATIONS - 1`. We currently do not support `delta < ROTATIONS - 1`.
Expand Down
128 changes: 99 additions & 29 deletions halo2-base/src/utils/halo2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::collections::hash_map::Entry;

use crate::ff::Field;
use crate::halo2_proofs::{
circuit::{AssignedCell, Cell, Region, Value},
plonk::{Advice, Assigned, Column, Fixed},
plonk::{Advice, Assigned, Circuit, Column, Fixed},
};
use crate::virtual_region::copy_constraints::{CopyConstraintManager, SharedCopyConstraintManager};
use crate::virtual_region::copy_constraints::{CopyConstraintManager, EXTERNAL_CELL_TYPE_ID};
use crate::AssignedValue;

/// Raw (physical) assigned cell in Plonkish arithmetization.
Expand Down Expand Up @@ -74,30 +76,11 @@ pub fn raw_constrain_equal<F: Field>(region: &mut Region<F>, left: Cell, right:
region.constrain_equal(left, right).unwrap();
}

/// Assign virtual cell to raw halo2 cell in column `column` at row offset `offset` within the `region`.
/// Stores the mapping between `virtual_cell` and the raw assigned cell in `copy_manager`, if provided.
///
/// `copy_manager` **must** be provided unless you are only doing witness generation
/// without constraints.
pub fn assign_virtual_to_raw<'v, F: Field + Ord>(
region: &mut Region<F>,
column: Column<Advice>,
offset: usize,
virtual_cell: AssignedValue<F>,
copy_manager: Option<&SharedCopyConstraintManager<F>>,
) -> Halo2AssignedCell<'v, F> {
let raw = raw_assign_advice(region, column, offset, Value::known(virtual_cell.value));
if let Some(copy_manager) = copy_manager {
let mut copy_manager = copy_manager.lock().unwrap();
let cell = virtual_cell.cell.unwrap();
copy_manager.assigned_advices.insert(cell, raw.cell());
drop(copy_manager);
}
raw
}

/// Constrains that `virtual` is equal to `external`. The `virtual` cell must have
/// **already** been raw assigned, with the raw assigned cell stored in `copy_manager`.
/// Constrains that `virtual_cell` is equal to `external_cell`. The `virtual_cell` must have
/// already been raw assigned with the raw assigned cell stored in `copy_manager`
/// **unless** it is marked an external-only cell with type id [EXTERNAL_CELL_TYPE_ID].
/// * When the virtual cell has already been assigned, the assigned cell is constrained to be equal to the external cell.
/// * When the virtual cell has not been assigned **and** it is marked as an external cell, it is assigned to `external_cell` and the mapping is stored in `copy_manager`.
///
/// This should only be called when `witness_gen_only` is false, otherwise it will panic.
///
Expand All @@ -107,9 +90,96 @@ pub fn constrain_virtual_equals_external<F: Field + Ord>(
region: &mut Region<F>,
virtual_cell: AssignedValue<F>,
external_cell: Cell,
copy_manager: &CopyConstraintManager<F>,
copy_manager: &mut CopyConstraintManager<F>,
) {
let ctx_cell = virtual_cell.cell.unwrap();
let acell = copy_manager.assigned_advices.get(&ctx_cell).expect("cell not assigned");
region.constrain_equal(*acell, external_cell);
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);
}
Entry::Vacant(assigned) => {
// The virtual cell **must** be an external cell
assert_eq!(ctx_cell.type_id, EXTERNAL_CELL_TYPE_ID);
// We map the virtual cell to point to the raw external cell in `copy_manager`
assigned.insert(external_cell);
}
}
}

/// This trait should be implemented on the minimal circuit configuration data necessary to
/// completely determine a circuit (independent of circuit inputs).
/// This is used to generate a _dummy_ instantiation of a concrete `Circuit` type for the purposes of key generation.
/// This dummy instantiation just needs to have the correct arithmetization format, but the witnesses do not need to
/// satisfy constraints.
pub trait KeygenCircuitIntent<F: Field> {
/// Concrete circuit type
type ConcreteCircuit: Circuit<F>;
/// Additional data that "pins" down the circuit. These can always to deterministically rederived from `Self`, but
/// storing the `Pinning` saves recomputations in future proof generations.
type Pinning;

/// The intent must include the log_2 domain size of the circuit.
/// This is used to get the correct trusted setup file.
fn get_k(&self) -> u32;

/// Builds a _dummy_ instantiation of `Self::ConcreteCircuit` for the purposes of key generation.
/// This dummy instantiation just needs to have the correct arithmetization format, but the witnesses do not need to
/// satisfy constraints.
fn build_keygen_circuit(self) -> Self::ConcreteCircuit;

/// Pinning is only fully computed after `synthesize` has been run during keygen
fn get_pinning_after_keygen(
self,
kzg_params: &ParamsKZG<Bn256>,
circuit: &Self::ConcreteCircuit,
) -> Self::Pinning;
}

use halo2_proofs_axiom::halo2curves::bn256::Bn256;
use halo2_proofs_axiom::poly::kzg::commitment::ParamsKZG;
pub use keygen::ProvingKeyGenerator;

mod keygen {
use halo2_proofs_axiom::poly::commitment::Params;

use crate::halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{self, ProvingKey},
poly::kzg::commitment::ParamsKZG,
};

use super::KeygenCircuitIntent;

/// Trait for creating a proving key and a pinning for a circuit from minimal circuit configuration data.
pub trait ProvingKeyGenerator {
/// Create proving key and pinning.
fn create_pk_and_pinning(
self,
kzg_params: &ParamsKZG<Bn256>,
) -> (ProvingKey<G1Affine>, serde_json::Value);
}

impl<CI> ProvingKeyGenerator for CI
where
CI: KeygenCircuitIntent<Fr> + Clone,
CI::Pinning: serde::Serialize,
{
fn create_pk_and_pinning(
self,
kzg_params: &ParamsKZG<Bn256>,
) -> (ProvingKey<G1Affine>, serde_json::Value) {
assert_eq!(kzg_params.k(), self.get_k());
let circuit = self.clone().build_keygen_circuit();
#[cfg(feature = "halo2-axiom")]
let pk = plonk::keygen_pk2(kzg_params, &circuit, false).unwrap();
#[cfg(not(feature = "halo2-axiom"))]
let pk = {
let vk = plonk::keygen_vk_custom(kzg_params, &circuit, false).unwrap();
plonk::keygen_pk(kzg_params, vk, &circuit).unwrap()
};
let pinning = self.get_pinning_after_keygen(kzg_params, &circuit);
(pk, serde_json::to_value(pinning).unwrap())
}
}
}
13 changes: 10 additions & 3 deletions halo2-base/src/virtual_region/copy_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use crate::{ff::Field, ContextCell};

use super::manager::VirtualRegionManager;

/// Type ID to distinguish external raw Halo2 cells. **This Type ID must be unique.**
pub const EXTERNAL_CELL_TYPE_ID: &str = "halo2-base:External Raw Halo2 Cell";

/// Thread-safe shared global manager for all copy constraints.
pub type SharedCopyConstraintManager<F> = Arc<Mutex<CopyConstraintManager<F>>>;

Expand Down Expand Up @@ -86,11 +89,15 @@ impl<F: Field + Ord> CopyConstraintManager<F> {
}

fn load_external_cell_impl(&mut self, cell: Option<Cell>) -> ContextCell {
let context_cell =
ContextCell::new("halo2-base:External Raw Halo2 Cell", 0, self.external_cell_count);
let context_cell = ContextCell::new(EXTERNAL_CELL_TYPE_ID, 0, self.external_cell_count);
self.external_cell_count += 1;
if let Some(cell) = cell {
self.assigned_advices.insert(context_cell, cell);
if let Some(old_cell) = self.assigned_advices.insert(context_cell, cell) {
assert!(
old_cell.row_offset == cell.row_offset && old_cell.column == cell.column,
"External cell already assigned"
)
}
}
context_cell
}
Expand Down
5 changes: 3 additions & 2 deletions halo2-base/src/virtual_region/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ impl<F: Field + Ord, const ADVICE_COLS: usize> VirtualRegionManager<F>
type Config = Vec<[Column<Advice>; ADVICE_COLS]>;

fn assign_raw(&self, config: &Self::Config, region: &mut Region<F>) {
let copy_manager = (!self.witness_gen_only).then(|| self.copy_manager().lock().unwrap());
let mut copy_manager =
(!self.witness_gen_only).then(|| self.copy_manager().lock().unwrap());
let cells_to_lookup = self.cells_to_lookup.lock().unwrap();
// Copy the cells to the config columns, going left to right, then top to bottom.
// Will panic if out of rows
Expand All @@ -139,7 +140,7 @@ impl<F: Field + Ord, const ADVICE_COLS: usize> VirtualRegionManager<F>
for (advice, &column) in advices.iter().zip(config[lookup_col].iter()) {
let bcell =
raw_assign_advice(region, column, lookup_offset, Value::known(advice.value));
if let Some(copy_manager) = copy_manager.as_ref() {
if let Some(copy_manager) = copy_manager.as_mut() {
constrain_virtual_equals_external(region, *advice, bcell.cell(), copy_manager);
}
}
Expand Down
25 changes: 15 additions & 10 deletions halo2-base/src/virtual_region/lookups/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use crate::{
poly::Rotation,
},
utils::{
halo2::{
assign_virtual_to_raw, constrain_virtual_equals_external, raw_assign_advice,
raw_assign_fixed,
},
halo2::{constrain_virtual_equals_external, raw_assign_advice, raw_assign_fixed},
ScalarField,
},
virtual_region::copy_constraints::SharedCopyConstraintManager,
Expand Down Expand Up @@ -83,7 +80,7 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
Self { table_is_enabled, table, to_lookup }
}

/// Assign managed lookups
/// Assign managed lookups. The `keys` must have already been raw assigned beforehand.
///
/// `copy_manager` **must** be provided unless you are only doing witness generation
/// without constraints.
Expand Down Expand Up @@ -114,6 +111,8 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
.unwrap();
}

/// Assign managed lookups. The `keys` must have already been raw assigned beforehand.
///
/// `copy_manager` **must** be provided unless you are only doing witness generation
/// without constraints.
pub fn assign_virtual_to_lookup_to_raw_from_offset<F: ScalarField>(
Expand All @@ -123,7 +122,7 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
mut offset: usize,
copy_manager: Option<&SharedCopyConstraintManager<F>>,
) {
let copy_manager = copy_manager.map(|c| c.lock().unwrap());
let mut copy_manager = copy_manager.map(|c| c.lock().unwrap());
// Copied from `LookupAnyManager::assign_raw` but modified to set `key_is_enabled` to 1.
// Copy the cells to the config columns, going left to right, then top to bottom.
// Will panic if out of rows
Expand All @@ -138,7 +137,7 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
raw_assign_fixed(region, key_is_enabled_col, offset, F::ONE);
for (advice, column) in zip(key, key_col) {
let bcell = raw_assign_advice(region, column, offset, Value::known(advice.value));
if let Some(copy_manager) = copy_manager.as_ref() {
if let Some(copy_manager) = copy_manager.as_mut() {
constrain_virtual_equals_external(region, advice, bcell.cell(), copy_manager);
}
}
Expand All @@ -147,7 +146,7 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
}
}

/// Assign virtual table to raw.
/// Assign virtual table to raw. The `rows` must have already been raw assigned beforehand.
///
/// `copy_manager` **must** be provided unless you are only doing witness generation
/// without constraints.
Expand Down Expand Up @@ -178,6 +177,8 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
.unwrap();
}

/// Assign virtual table to raw. The `rows` must have already been raw assigned beforehand.
///
/// `copy_manager` **must** be provided unless you are only doing witness generation
/// without constraints.
pub fn assign_virtual_table_to_raw_from_offset<F: ScalarField>(
Expand All @@ -187,11 +188,15 @@ impl<const KEY_COL: usize> BasicDynLookupConfig<KEY_COL> {
mut offset: usize,
copy_manager: Option<&SharedCopyConstraintManager<F>>,
) {
let mut copy_manager = copy_manager.map(|c| c.lock().unwrap());
for row in rows {
// Enable this row in the table
raw_assign_fixed(region, self.table_is_enabled, offset, F::ONE);
for (col, virtual_cell) in self.table.into_iter().zip(row) {
assign_virtual_to_raw(region, col, offset, virtual_cell, copy_manager);
for (advice, column) in zip(row, self.table) {
let bcell = raw_assign_advice(region, column, offset, Value::known(advice.value));
if let Some(copy_manager) = copy_manager.as_mut() {
constrain_virtual_equals_external(region, advice, bcell.cell(), copy_manager);
}
}
offset += 1;
}
Expand Down
Loading
Loading