Skip to content

Commit

Permalink
change mock prover cs, instance to arc type
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamWuGit committed Mar 13, 2024
1 parent a244c33 commit f2c8c08
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::iter;
use std::mem;
use std::ops::{Add, Mul, Neg, Range};
use std::sync::Arc;
use std::time::{Duration, Instant};

Check warning on line 9 in halo2_proofs/src/dev.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused imports: `Duration`, `Instant`

warning: unused imports: `Duration`, `Instant` --> halo2_proofs/src/dev.rs:9:17 | 9 | use std::time::{Duration, Instant}; | ^^^^^^^^ ^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use blake2b_simd::blake2b;
#[cfg(feature = "mock-batch-inv")]
Expand Down Expand Up @@ -427,7 +429,8 @@ impl<F: Field> Mul<F> for Value<F> {
pub struct MockProver<'a, F: Field> {
k: u32,
n: u32,
cs: ConstraintSystem<F>,
// use Arc type to reduce cs.clone when fork lots of time.
cs: Arc<ConstraintSystem<F>>,

/// The regions in the circuit.
regions: Vec<Region>,
Expand All @@ -444,7 +447,8 @@ pub struct MockProver<'a, F: Field> {
// This field is used only if the "phase_check" feature is turned on.
advice_prev: Vec<Vec<CellValue<F>>>,
// The instance cells in the circuit, arranged as [column][row].
instance: Vec<Vec<InstanceValue<F>>>,
// use Arc type to reduce instance.clone when fork lots of time.
instance: Arc<Vec<Vec<InstanceValue<F>>>>,

selectors_vec: Arc<Vec<Vec<bool>>>,
selectors: Vec<&'a mut [bool]>,
Expand Down Expand Up @@ -847,6 +851,9 @@ impl<'a, F: Field> Assignment<F> for MockProver<'a, F> {
let advice_anno = anno().into();
#[cfg(not(feature = "mock-batch-inv"))]
let val_res = to().into_field().evaluate().assign();
#[cfg(feature = "mock-batch-inv")]
panic!("confiugred mock-batch-inv !!!");

#[cfg(feature = "mock-batch-inv")]
let val_res = to().into_field().assign();

Check warning on line 858 in halo2_proofs/src/dev.rs

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unreachable statement

warning: unreachable statement --> halo2_proofs/src/dev.rs:858:9 | 855 | panic!("confiugred mock-batch-inv !!!"); | --------------------------------------- any code following this expression is unreachable ... 858 | let val_res = to().into_field().assign(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | = note: `#[warn(unreachable_code)]` on by default
if val_res.is_err() {
Expand Down Expand Up @@ -1085,12 +1092,22 @@ impl<'a, F: FromUniformBytes<64> + Ord> MockProver<'a, F> {
) -> Result<Self, Error> {
let n = 1 << k;

#[cfg(feature = "mock-batch-inv")]
println!("confiugred mock-batch-inv !!!");
#[cfg(not(feature = "mock-batch-inv"))]
println!("not configured mock-batch-inv !!!");

let cell_value_size = mem::size_of::<CellValue<F>>();
println!("Size of CellValue type: {} bytes", cell_value_size);

let mut cs = ConstraintSystem::default();
#[cfg(feature = "circuit-params")]
let config = ConcreteCircuit::configure_with_params(&mut cs, circuit.params());
#[cfg(not(feature = "circuit-params"))]
let config = ConcreteCircuit::configure(&mut cs);
let cs = cs.chunk_lookups();
let cs = cs;
let cs = Arc::new(cs);

assert!(
n >= cs.minimum_rows(),
Expand Down Expand Up @@ -1122,6 +1139,7 @@ impl<'a, F: FromUniformBytes<64> + Ord> MockProver<'a, F> {
})
.collect::<Vec<_>>();

let instance = Arc::new(instance);
// Fixed columns contain no blinding factors.
let fixed_vec = Arc::new(vec![vec![CellValue::Unassigned; n]; cs.num_fixed_columns]);
let fixed = two_dim_vec_to_vec_of_slice!(fixed_vec);
Expand Down Expand Up @@ -1260,11 +1278,13 @@ impl<'a, F: FromUniformBytes<64> + Ord> MockProver<'a, F> {
ConcreteCircuit::FloorPlanner::synthesize(&mut prover, circuit, config, constants)?;
log::info!("MockProver synthesize took {:?}", syn_time.elapsed());
}

let (cs, selector_polys) = prover
.cs
.compress_selectors(prover.selectors_vec.as_ref().clone());
prover.cs = cs;
let prover_cs = Arc::try_unwrap(prover.cs).unwrap();
// let (cs, selector_polys) = prover
// .cs
// .compress_selectors(prover.selectors_vec.as_ref().clone());
let (cs, selector_polys) =
prover_cs.compress_selectors(prover.selectors_vec.as_ref().clone());
prover.cs = Arc::new(cs);

// batch invert
#[cfg(feature = "mock-batch-inv")]
Expand Down Expand Up @@ -2326,6 +2346,7 @@ mod tests {
use super::{FailureLocation, MockProver, VerifyFailure};
use crate::{
circuit::{Layouter, SimpleFloorPlanner, Value},
dev::CellValue,
plonk::{
sealed::SealedPhase, Advice, Any, Circuit, Column, ConstraintSystem, Error, Expression,
FirstPhase, Fixed, Instance, Selector, TableColumn,
Expand Down

0 comments on commit f2c8c08

Please sign in to comment.