Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:scroll-tech/halo2 into sync-ff-0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Nov 7, 2023
2 parents 3d44389 + 5cf9a37 commit 1cde546
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
**/*.rs.bk
.vscode
**/*.html
.DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ log = "0.4.17"

# timer
ark-std = { version = "0.3.0" }
env_logger = "0.8.0"

# Legacy circuit compatibility
halo2_legacy_pdqsort = { version = "0.1.0", optional = true }

[dev-dependencies]
assert_matches = "1.5"
criterion = "0.3"
env_logger = "0.8.0"
gumdrop = "0.8"
proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
Expand Down
67 changes: 30 additions & 37 deletions halo2_proofs/src/circuit/floor_planner/single_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@ use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::marker::PhantomData;
use std::ops::Range;
use std::sync::{Arc, Mutex};
use std::time::Instant;

use ark_std::{end_timer, start_timer};
use ff::Field;

use ark_std::{end_timer, start_timer};


use crate::{
circuit::{
layouter::{RegionColumn, RegionLayouter, RegionShape, SyncDeps, TableLayouter},
table_layouter::{compute_table_lengths, SimpleTableLayouter},
Cell, Layouter, Region, RegionIndex, RegionStart, Table, Value,
},
multicore,
plonk::{
Advice, Any, Assigned, Assignment, Challenge, Circuit, Column, Error, Fixed, FloorPlanner,
Instance, Selector, TableColumn,
Expand Down Expand Up @@ -82,6 +79,7 @@ impl<'a, F: Field, CS: Assignment<F> + 'a> SingleChipLayouter<'a, F, CS> {
Ok(ret)
}

#[cfg(feature = "parallel_syn")]
fn fork(&self, sub_cs: Vec<&'a mut CS>) -> Result<Vec<Self>, Error> {
Ok(sub_cs
.into_iter()
Expand Down Expand Up @@ -218,6 +216,12 @@ impl<'a, F: Field, CS: Assignment<F> + 'a + SyncDeps> Layouter<F>
N: Fn() -> NR,
NR: Into<String>,
{
use std::time::Instant;

use maybe_rayon::prelude::{
IndexedParallelIterator, IntoParallelIterator, ParallelIterator,
};

let region_index = self.regions.len();
let region_name: String = name().into();
// Get region shapes sequentially
Expand Down Expand Up @@ -261,39 +265,28 @@ impl<'a, F: Field, CS: Assignment<F> + 'a + SyncDeps> Layouter<F>
let ref_sub_cs = sub_cs.iter_mut().collect();
let sub_layouters = self.fork(ref_sub_cs)?;
let regions_2nd_pass = Instant::now();
let ret = crossbeam::scope(|scope| {
let mut handles = vec![];
for (i, (mut assignment, mut sub_layouter)) in assignments
.into_iter()
.zip(sub_layouters.into_iter())
.enumerate()
{
let ret = assignments
.into_par_iter()
.zip(sub_layouters.into_par_iter())
.enumerate()
.map(|(i, (mut assignment, mut sub_layouter))| {
let region_name = format!("{}_{}", region_name, i);
handles.push(scope.spawn(move |_| {
let sub_region_2nd_pass = Instant::now();
sub_layouter.cs.enter_region(|| region_name.clone());
let mut region =
SingleChipLayouterRegion::new(&mut sub_layouter, (region_index + i).into());
let region_ref: &mut dyn RegionLayouter<F> = &mut region;
let result = assignment(region_ref.into());
let constant = region.constants.clone();
sub_layouter.cs.exit_region();
log::debug!(
"region {} 2nd pass synthesis took {:?}",
region_name,
sub_region_2nd_pass.elapsed()
);

(result, constant)
}));
}

handles
.into_iter()
.map(|handle| handle.join().expect("handle.join should never fail"))
.collect::<Vec<_>>()
})
.expect("scope should not fail");
let sub_region_2nd_pass = Instant::now();
sub_layouter.cs.enter_region(|| region_name.clone());
let mut region =
SingleChipLayouterRegion::new(&mut sub_layouter, (region_index + i).into());
let region_ref: &mut dyn RegionLayouter<F> = &mut region;
let result = assignment(region_ref.into());
let constant = region.constants.clone();
sub_layouter.cs.exit_region();
log::debug!(
"region {} 2nd pass synthesis took {:?}",
region_name,
sub_region_2nd_pass.elapsed()
);
(result, constant)
})
.collect::<Vec<_>>();
let cs_merge_time = Instant::now();
let num_sub_cs = sub_cs.len();
self.cs.merge(sub_cs)?;
Expand Down
7 changes: 3 additions & 4 deletions halo2_proofs/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use std::collections::HashSet;
use std::iter;
use std::ops::{Add, Mul, Neg, Range};
use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::Instant;

Check failure on line 8 in halo2_proofs/src/dev.rs

View workflow job for this annotation

GitHub Actions / Clippy (1.56.1)

unused import: `std::time::Instant`

error: unused import: `std::time::Instant` --> halo2_proofs/src/dev.rs:8:5 | 8 | use std::time::Instant; | ^^^^^^^^^^^^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings`

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

View workflow job for this annotation

GitHub Actions / Bitrot check

unused import: `std::time::Instant`

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

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `std::time::Instant`

warning: unused import: `std::time::Instant` --> halo2_proofs/src/dev.rs:8:5 | 8 | use std::time::Instant; | ^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use blake2b_simd::blake2b;
use ff::Field;
use ff::FromUniformBytes;
use ff::{BatchInvert, Field};
use group::Group;

use crate::plonk::permutation::keygen::Assembly;
use crate::{
Expand Down Expand Up @@ -48,7 +47,7 @@ pub use tfp::TracingFloorPlanner;

#[cfg(feature = "dev-graph")]
mod graph;

#[cfg(feature = "dev-graph")]
use crate::circuit::Cell;

Check failure on line 51 in halo2_proofs/src/dev.rs

View workflow job for this annotation

GitHub Actions / Clippy (1.56.1)

unused import: `crate::circuit::Cell`

error: unused import: `crate::circuit::Cell` --> halo2_proofs/src/dev.rs:51:5 | 51 | use crate::circuit::Cell; | ^^^^^^^^^^^^^^^^^^^^

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

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with all features

unused import: `crate::circuit::Cell`

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

View workflow job for this annotation

GitHub Actions / Test on ubuntu-latest with basic features

unused import: `crate::circuit::Cell`

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

View workflow job for this annotation

GitHub Actions / Bitrot check

unused import: `crate::circuit::Cell`

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

View workflow job for this annotation

GitHub Actions / Clippy (beta)

unused import: `crate::circuit::Cell`

warning: unused import: `crate::circuit::Cell` --> halo2_proofs/src/dev.rs:51:5 | 51 | use crate::circuit::Cell; | ^^^^^^^^^^^^^^^^^^^^

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

View workflow job for this annotation

GitHub Actions / Build target wasm32-wasi

unused import: `crate::circuit::Cell`

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

View workflow job for this annotation

GitHub Actions / Build target wasm32-unknown-unknown

unused import: `crate::circuit::Cell`
use crate::helpers::CopyCell;
#[cfg(feature = "dev-graph")]
Expand Down
3 changes: 2 additions & 1 deletion halo2_proofs/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::plonk::{Any, Column};
use crate::poly::Polynomial;
use ff::{Field, FromUniformBytes, PrimeField};
use ff::{FromUniformBytes, PrimeField};
use halo2curves::{serde::SerdeObject, CurveAffine};
use num_bigint::BigUint;
use std::io;
Expand Down Expand Up @@ -88,6 +88,7 @@ macro_rules! two_dim_vec_to_vec_of_slice {
#[cfg(test)]
mod test {
use super::*;
use ff::Field;
use halo2curves::bn256::{Fq, G1Affine};
use rand_core::OsRng;
#[test]
Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ where
})
.collect::<BTreeSet<_>>();

for (circuit_idx, ((circuit, advice), instances)) in circuits
for (_circuit_idx, ((circuit, advice), instances)) in circuits
.iter()
.zip(advice.iter_mut())
.zip(instances)
Expand Down Expand Up @@ -433,7 +433,7 @@ where
{
for (idx, advice_col) in witness.advice_vec.iter().enumerate() {
if pk.vk.cs.advice_column_phase[idx].0 < current_phase.0
&& advice_assignments[circuit_idx][idx].values != advice_col.values
&& advice_assignments[_circuit_idx][idx].values != advice_col.values
{
log::error!(
"advice column {}(at {:?}) changed when {:?}",
Expand All @@ -454,7 +454,7 @@ where
if column_indices.contains(&column_index) {
#[cfg(feature = "phase-check")]
{
advice_assignments[circuit_idx][column_index] = advice.clone();
advice_assignments[_circuit_idx][column_index] = advice.clone();
}
Some(advice)
} else {
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/src/plonk/vanishing/prover.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, iter};
use std::iter;

use ff::Field;
use group::Curve;
Expand Down
1 change: 0 additions & 1 deletion halo2_proofs/src/transcript/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use super::{Challenge255, EncodedChallenge, Transcript, TranscriptRead, Transcri
use crate::helpers::base_to_scalar;
use group::ff::{FromUniformBytes, PrimeField};
use halo2curves::{Coordinates, CurveAffine};
use num_bigint::BigUint;
use poseidon::Poseidon;
use std::convert::TryInto;
use std::io::{self, Read, Write};
Expand Down
10 changes: 8 additions & 2 deletions halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![allow(clippy::many_single_char_names)]
#![allow(clippy::op_ref)]

// use assert_matches::assert_matches;
use ff::{FromUniformBytes, WithSmallOrderMulGroup};
use halo2_proofs::arithmetic::Field;
use halo2_proofs::circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value};
use halo2_proofs::circuit::{Cell, Layouter, SimpleFloorPlanner, Value};
use halo2_proofs::dev::MockProver;
use halo2_proofs::plonk::{
create_proof as create_plonk_proof, keygen_pk, keygen_vk, verify_proof as verify_plonk_proof,
Expand All @@ -22,6 +21,10 @@ use rand_core::{OsRng, RngCore};
use std::marker::PhantomData;
use std::time::Instant;


#[cfg(feature = "parallel_syn")]
use halo2_proofs::circuit::Region;

#[test]
fn plonk_api() {
const K: u32 = 17;
Expand Down Expand Up @@ -372,10 +375,13 @@ fn plonk_api() {
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let cs = StandardPlonk::new(config);

#[cfg(feature = "parallel_syn")]
let mut is_first_pass_vec = vec![true; 8];

let _ = cs.public_input(&mut layouter, || Value::known(F::ONE + F::ONE))?;

#[cfg(feature = "parallel_syn")]
let a: Value<Assigned<_>> = self.a.into();
let parallel_regions_time = Instant::now();
#[cfg(feature = "parallel_syn")]
Expand Down

0 comments on commit 1cde546

Please sign in to comment.