Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed Jun 17, 2024
1 parent 754a582 commit e2dab67
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 153 deletions.
6 changes: 3 additions & 3 deletions halo2_frontend/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ use crate::plonk::FieldFr;
/// generation, and proof generation.
/// If `compress_selectors` is true, multiple selector columns may be multiplexed.
#[allow(clippy::type_complexity)]
pub fn compile_circuit<EF: FieldFr<Field=F>, F: Field, ConcreteCircuit: Circuit<EF>>(
pub fn compile_circuit<FF: FieldFr<Field=F>, F: Field, ConcreteCircuit: Circuit<FF>>(
k: u32,
circuit: &ConcreteCircuit,
compress_selectors: bool,
) -> Result<
(
CompiledCircuit<F>,
ConcreteCircuit::Config,
ConstraintSystem<EF>,
ConstraintSystem<FF>,
),
Error,
> {
Expand All @@ -65,7 +65,7 @@ pub fn compile_circuit<EF: FieldFr<Field=F>, F: Field, ConcreteCircuit: Circuit<

let mut assembly = plonk::keygen::Assembly {
k,
fixed: vec![vec![EF::ZERO.into(); n]; cs.num_fixed_columns],
fixed: vec![vec![FF::ZERO.into(); n]; cs.num_fixed_columns],
permutation: permutation::Assembly::new(n, &cs.permutation),
selectors: vec![vec![false; n]; cs.num_selectors],
usable_rows: 0..n - (cs.blinding_factors() + 1),
Expand Down
6 changes: 3 additions & 3 deletions halo2_frontend/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ mod util;
mod failure;
pub use failure::{FailureLocation, VerifyFailure};

// pub mod cost;
// pub use cost::CircuitCost;
pub mod cost;
pub use cost::CircuitCost;

#[cfg(feature = "cost-estimator")]
pub mod cost_model;
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<F: FieldFr> Mul<F> for Value<F> {
/// MockProver::<Fp>::run(2, &circuit, vec![]).unwrap_err()
/// });
/// assert_eq!(
/// result.unwrap_err().downcast_ref::<String>().unwrap(),
/// result.unwrap_err().downcast_rF::<String>().unwrap(),
/// "n=4, minimum_rows=8, k=2"
/// );
/// ```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
/// Measures a circuit to determine its costs, and explain what contributes to them.
#[allow(dead_code)]
#[derive(Debug)]
pub struct CircuitCost<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> {
pub struct CircuitCost<G: PrimeGroup, F: FieldFr<Field=G::Scalar>, ConcreteCircuit: Circuit<F>> {
/// Power-of-2 bound on the number of rows in the circuit.
k: u32,
/// Maximum degree of the circuit.
Expand Down Expand Up @@ -53,7 +53,7 @@ pub struct CircuitCost<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> {
num_instance_columns: usize,
num_total_columns: usize,

_marker: PhantomData<(G, ConcreteCircuit)>,
_marker: PhantomData<(G, F, ConcreteCircuit)>,
}

/// Region implementation used by Layout
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<F: FieldFr> Assignment<F> for Layout {
}
}

impl<G: PrimeGroup, FE: FieldFr, ConcreteCircuit: Circuit<G::Scalar>> CircuitCost<G, ConcreteCircuit> {
impl<G: PrimeGroup, FE: FieldFr<Field=G::Scalar>, ConcreteCircuit: Circuit<FE>> CircuitCost<G, FE, ConcreteCircuit> {
/// Measures a circuit with parameter constant `k`.
///
/// Panics if `k` is not large enough for the circuit.
Expand Down Expand Up @@ -556,6 +556,6 @@ mod tests {
Ok(())
}
}
CircuitCost::<Eq, MyCircuit>::measure(K, &MyCircuit).proof_size(1);
CircuitCost::<Eq, _, MyCircuit>::measure(K, &MyCircuit).proof_size(1);
}
}
6 changes: 3 additions & 3 deletions halo2_frontend/src/dev/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::collections::HashSet;
use std::{iter, num::ParseIntError, str::FromStr};

use crate::plonk::Circuit;
use crate::plonk::{Circuit, FieldFr};
use halo2_middleware::ff::{Field, FromUniformBytes};
use serde::Deserialize;
use serde_derive::Serialize;
Expand Down Expand Up @@ -242,7 +242,7 @@ impl CostOptions {

/// Given a Plonk circuit, this function returns a [ModelCircuit]
pub fn from_circuit_to_model_circuit<
F: Ord + Field + FromUniformBytes<64>,
F: Ord + FieldFr + FromUniformBytes<64>,
C: Circuit<F>,
const COMM: usize,
const SCALAR: usize,
Expand All @@ -257,7 +257,7 @@ pub fn from_circuit_to_model_circuit<
}

/// Given a Plonk circuit, this function returns [CostOptions]
pub fn from_circuit_to_cost_model_options<F: Ord + Field + FromUniformBytes<64>, C: Circuit<F>>(
pub fn from_circuit_to_cost_model_options<F: Ord + FieldFr + FromUniformBytes<64>, C: Circuit<F>>(
k: u32,
circuit: &C,
instances: Vec<Vec<F>>,
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/dev/graph.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::plonk::{
Advice, Assigned, Assignment, Challenge, Circuit, Column, ConstraintSystem, Error, Fixed,
FloorPlanner, Instance, Selector,
FloorPlanner, Instance, Selector, FieldFr
};
use halo2_middleware::circuit::Any;
use halo2_middleware::ff::Field;
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/dev/graph/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use plotters::{
use std::collections::HashSet;
use std::ops::Range;

use crate::plonk::{Circuit, Column, ConstraintSystem, FloorPlanner};
use crate::plonk::{Circuit, Column, ConstraintSystem, FloorPlanner, FieldFr};
use crate::{circuit::layouter::RegionColumn, dev::cost::Layout};
use halo2_middleware::circuit::Any;

Expand Down
1 change: 0 additions & 1 deletion halo2_frontend/src/plonk/assigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ mod proptests {
ops::{Add, Mul, Neg, Sub},
};

use group::ff::Field;
use halo2curves::pasta::Fp;
use proptest::{collection::vec, prelude::*, sample::select};
use crate::plonk::FieldFr;
Expand Down
Loading

0 comments on commit e2dab67

Please sign in to comment.