Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed Jun 17, 2024
1 parent f3843ee commit c8c7ff9
Show file tree
Hide file tree
Showing 26 changed files with 234 additions and 160 deletions.
2 changes: 1 addition & 1 deletion halo2_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = """
Halo2 backend implementation. This package implements the halo2 proof system which includes setup (key generation), proving and verifying.
"""
Expand Down
2 changes: 1 addition & 1 deletion halo2_debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = """
Halo2 Debug. This package contains utilities for debugging and testing within
the halo2 ecosystem.
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = """
Halo2 frontend implementation. This package implements an API to write circuits, handles witness generation and contains the MockProver.
"""
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/circuit/table_layouter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ mod tests {
meta.lookup("", |cells| {
let a = cells.query_advice(a, Rotation::cur());

vec![(a.clone(), table.0), (a, table.1)]
vec![(a, table.0), (a, table.1)]
});

Self::Config { table }
Expand Down
15 changes: 6 additions & 9 deletions halo2_frontend/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<F: FieldFront> Mul<F> for Value<F> {
/// use halo2_frontend::{
/// circuit::{Layouter, SimpleFloorPlanner, Value},
/// dev::{FailureLocation, MockProver, VerifyFailure},
/// plonk::{circuit::Column, Circuit, ConstraintSystem, Error, Advice, Selector},
/// plonk::{circuit::Column, Circuit, ConstraintSystem, Error, Advice, Selector, FieldFront},
/// };
/// use halo2_middleware::circuit::{Any, ColumnMid};
/// use halo2_middleware::poly::Rotation;
Expand All @@ -206,7 +206,7 @@ impl<F: FieldFront> Mul<F> for Value<F> {
/// b: Value<u64>,
/// }
///
/// impl<F: PrimeField> Circuit<F> for MyCircuit {
/// impl<F: FieldFront + From<u64>> Circuit<F> for MyCircuit {
/// type Config = MyConfig;
/// type FloorPlanner = SimpleFloorPlanner;
/// #[cfg(feature = "circuit-params")]
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<F: FieldFront> Mul<F> for Value<F> {
/// MockProver::<Fp>::run(2, &circuit, vec![]).unwrap_err()
/// });
/// assert_eq!(
/// result.unwrap_err().downcast_rF::<String>().unwrap(),
/// result.unwrap_err().downcast_ref::<String>().unwrap(),
/// "n=4, minimum_rows=8, k=2"
/// );
/// ```
Expand Down Expand Up @@ -1376,13 +1376,10 @@ mod tests {

// If q is enabled, a must be in the table.
// When q is not enabled, lookup the default value instead.
let not_q = Expression::Constant(Fp::one()) - q.clone();
let not_q = Expression::Constant(Fp::one()) - q;
let default = Expression::Constant(Fp::from(2));
vec![
(
q.clone() * a.clone() + not_q.clone() * default.clone(),
table,
),
(q * a + not_q * default, table),
(q * a + not_q * default, advice_table),
]
});
Expand Down Expand Up @@ -1540,7 +1537,7 @@ mod tests {

// If q is enabled, a must be in the table.
// When q is not enabled, lookup the default value instead.
let not_q = Expression::Constant(Fp::one()) - q.clone();
let not_q = Expression::Constant(Fp::one()) - q;
let default = Expression::Constant(Fp::from(2));
vec![(q * a + not_q * default, table)]
});
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/dev/gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct Gate {
/// use halo2_frontend::{
/// circuit::{Layouter, SimpleFloorPlanner},
/// dev::CircuitGates,
/// plonk::{Circuit, ConstraintSystem, Error},
/// plonk::{Circuit, ConstraintSystem, Error, FieldFront},
/// };
/// use halo2curves::pasta::pallas;
///
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/dev/tfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
/// use halo2_frontend::{
/// circuit::{floor_planner, Layouter, Value},
/// dev::TracingFloorPlanner,
/// plonk::{Circuit, ConstraintSystem, Error},
/// plonk::{Circuit, ConstraintSystem, Error, FieldFront},
/// };
///
/// # struct MyCircuit<F: FieldFront> {
Expand Down
4 changes: 2 additions & 2 deletions halo2_frontend/src/plonk/circuit/compress_selectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ where
// which is non-zero only on rows where `combination_assignment` is set to
// `assigned_root`. In particular, rows set to 0 correspond to all selectors
// being disabled.
let mut expression = query.clone();
let mut expression = query;
let mut root = F::ONE;
for _ in 0..combination_len {
if root != assigned_root {
expression = expression * (Expression::Constant(root) - query.clone());
expression = expression * (Expression::Constant(root) - query);
}
root += F::ONE;
}
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/plonk/circuit/constraint_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ impl<F: FieldFront> ConstraintSystem<F> {
assert!(!selector.is_simple());
}

selector_replacements[selector.0].clone()
selector_replacements[selector.0]
},
&|query| Expression::Fixed(query),
&|query| Expression::Advice(query),
Expand Down
32 changes: 15 additions & 17 deletions halo2_frontend/src/plonk/circuit/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl SealedPhase for ThirdPhase {
/// row when required:
/// ```
/// use halo2_frontend::circuit::{Chip, Layouter, Value};
/// use halo2_frontend::plonk::{Advice, Fixed, Error, Column, Selector};
/// use halo2_frontend::plonk::{Advice, Fixed, Error, Column, Selector, FieldFront};
/// use halo2_middleware::ff::Field;
///
/// struct Config {
Expand Down Expand Up @@ -476,14 +476,14 @@ pub trait FieldFront: Field {
fn alloc(expr: Expression<Self>) -> ExprRef<Self>;
fn get(ref_: &ExprRef<Self>) -> Expression<Self>;
fn into_field(self) -> Self::Field;
fn into_field_fr(f: Self::Field) -> Self;
fn into_fieldfront(f: Self::Field) -> Self;
}

#[derive(Clone, Copy, Eq, PartialEq)]
pub struct ExprRef<F>(usize, std::marker::PhantomData<F>);
impl<F: FieldFront> Into<ExprRef<F>> for Expression<F> {
fn into(self) -> ExprRef<F> {
F::alloc(self)
impl<F: FieldFront> From<Expression<F>> for ExprRef<F> {
fn from(val: Expression<F>) -> Self {
F::alloc(val)
}
}

Expand Down Expand Up @@ -1183,12 +1183,10 @@ impl<F: FieldFront> Product<Self> for Expression<F> {
}

#[allow(non_camel_case_types)]
#[derive(Default)]
pub struct ExprArena<F: FieldFront>(Vec<Expression<F>>);

impl<F: FieldFront> ExprArena<F> {
pub fn new() -> Self {
Self(Vec::new())
}
pub fn push(&mut self, expr: Expression<F>) -> crate::plonk::ExprRef<F> {
let index = self.0.len();
self.0.push(expr);
Expand All @@ -1205,28 +1203,27 @@ macro_rules! expression_arena {
fn $arena() -> &'static std::sync::RwLock<ExprArena<$field>> {
static LINES: std::sync::OnceLock<std::sync::RwLock<ExprArena<$field>>> =
std::sync::OnceLock::new();
LINES.get_or_init(|| std::sync::RwLock::new(ExprArena::new()))
LINES.get_or_init(|| std::sync::RwLock::new(ExprArena::default()))
}

impl crate::plonk::FieldFront for $field {
impl $crate::plonk::FieldFront for $field {
type Field = $field;
fn into_field(self) -> Self::Field {
self
}
fn into_field_fr(f: Self::Field) -> Self {
fn into_fieldfront(f: Self::Field) -> Self {
f
}
fn alloc(expr: crate::plonk::Expression<Self>) -> crate::plonk::ExprRef<Self> {
fn alloc(expr: $crate::plonk::Expression<Self>) -> $crate::plonk::ExprRef<Self> {
$arena().write().unwrap().push(expr)
}
fn get(ref_: &crate::plonk::ExprRef<Self>) -> crate::plonk::Expression<Self> {
fn get(ref_: &$crate::plonk::ExprRef<Self>) -> $crate::plonk::Expression<Self> {
*$arena().read().unwrap().get(*ref_)
}
}

impl Into<crate::plonk::ExprRef<$field>> for $field {
fn into(self) -> crate::plonk::ExprRef<$field> {
crate::plonk::FieldFront::alloc(crate::plonk::Expression::Constant(self))
impl From<$field> for $crate::plonk::ExprRef<$field> {
fn from(f: $field) -> Self {
$crate::plonk::FieldFront::alloc($crate::plonk::Expression::Constant(f))
}
}
};
Expand All @@ -1236,6 +1233,7 @@ macro_rules! expression_arena {
expression_arena!(arena_bn256_fr, halo2curves::bn256::Fr);
expression_arena!(arena_bn256_fq, halo2curves::bn256::Fq);
expression_arena!(arena_pasta_fp, halo2curves::pasta::Fp);
expression_arena!(arena_pasta_fq, halo2curves::pasta::Fq);

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion halo2_middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = """
Halo2 middleware. This package contains the types and traits required for the frontend-backend interaction.
"""
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
"Privacy Scaling Explorations team",
]
edition = "2021"
rust-version = "1.66.0"
rust-version = "1.70.0"
description = """
Fast PLONK-based zero-knowledge proving system with no trusted setup
"""
Expand Down
3 changes: 1 addition & 2 deletions halo2_proofs/benches/dev_lookup.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#[macro_use]
extern crate criterion;

use ff::{Field, PrimeField};
use halo2_frontend::plonk::FieldFront;
use halo2_proofs::circuit::{Layouter, SimpleFloorPlanner, Value};
use halo2_proofs::dev::MockProver;
Expand Down Expand Up @@ -45,7 +44,7 @@ fn criterion_benchmark(c: &mut Criterion) {

meta.lookup("lookup", |meta| {
let selector = meta.query_selector(config.selector);
let not_selector = Expression::Constant(F::ONE) - selector.clone();
let not_selector = Expression::Constant(F::ONE) - selector;
let advice = meta.query_advice(config.advice, Rotation::cur());
vec![(selector * advice + not_selector, config.table)]
});
Expand Down
11 changes: 9 additions & 2 deletions halo2_proofs/benches/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let sc = meta.query_fixed(sc, Rotation::cur());
let sm = meta.query_fixed(sm, Rotation::cur());

vec![a.clone() * sa + b.clone() * sb + a * b * sm - (c * sc)]
vec![a * sa + b * sb + a * b * sm - (c * sc)]
});

PlonkConfig {
Expand Down Expand Up @@ -311,7 +311,14 @@ fn criterion_benchmark(c: &mut Criterion) {
fn verifier(params: &ParamsIPA<EqAffine>, vk: &VerifyingKey<EqAffine>, proof: &[u8]) {
let strategy = SingleStrategy::new(params);
let mut transcript = Blake2bRead::<_, _, Challenge255<_>>::init(proof);
assert!(verify_proof(params, vk, strategy, &[vec![vec![]]], &mut transcript).is_ok());
assert!(verify_proof::<_, _, _, _, _, halo2curves::pasta::Fp>(
params,
vk,
strategy,
&[vec![vec![]]],
&mut transcript
)
.is_ok());
}

let k_range = 8..=16;
Expand Down
11 changes: 7 additions & 4 deletions halo2_proofs/examples/circuit-layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use ff::Field;
use halo2_proofs::{
circuit::{Cell, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{Advice, Assigned, Circuit, Column, ConstraintSystem, ErrorFront, Fixed, TableColumn},
plonk::{
Advice, Assigned, Circuit, Column, ConstraintSystem, ErrorFront, FieldFront, Fixed,
TableColumn,
},
poly::Rotation,
};
use halo2curves::pasta::Fp;
Expand All @@ -28,7 +31,7 @@ struct PlonkConfig {
sl: TableColumn,
}

trait StandardCs<FF: Field> {
trait StandardCs<FF: FieldFront> {
fn raw_multiply<F>(
&self,
region: &mut Region<FF>,
Expand Down Expand Up @@ -57,7 +60,7 @@ struct StandardPlonk<F: FieldFront> {
_marker: PhantomData<F>,
}

impl<FF: Field> StandardPlonk<FF> {
impl<FF: FieldFront> StandardPlonk<FF> {
fn new(config: PlonkConfig) -> Self {
StandardPlonk {
config,
Expand All @@ -66,7 +69,7 @@ impl<FF: Field> StandardPlonk<FF> {
}
}

impl<FF: Field> StandardCs<FF> for StandardPlonk<FF> {
impl<FF: FieldFront> StandardCs<FF> for StandardPlonk<FF> {
fn raw_multiply<F>(
&self,
region: &mut Region<FF>,
Expand Down
1 change: 0 additions & 1 deletion halo2_proofs/examples/simple-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::marker::PhantomData;

use halo2_frontend::plonk::FieldFront;
use halo2_proofs::{
arithmetic::Field,
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{Advice, Circuit, Column, ConstraintSystem, ErrorFront, Fixed, Instance, Selector},
poly::Rotation,
Expand Down
1 change: 0 additions & 1 deletion halo2_proofs/examples/vector-mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::marker::PhantomData;

use halo2_frontend::plonk::FieldFront;
use halo2_proofs::{
arithmetic::Field,
circuit::{AssignedCell, Chip, Layouter, Region, SimpleFloorPlanner, Value},
plonk::{Advice, Circuit, Column, ConstraintSystem, ErrorFront, Instance, Selector},
poly::Rotation,
Expand Down
8 changes: 2 additions & 6 deletions halo2_proofs/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,11 @@
mod error;
mod keygen;
mod prover;
mod verifier {
pub use halo2_backend::plonk::verifier::verify_proof;
}

use halo2_frontend::{circuit::compile_circuit, plonk::FieldFront};
pub use halo2_frontend::{circuit::compile_circuit, plonk::FieldFront};
pub use keygen::{keygen_pk, keygen_pk_custom, keygen_vk, keygen_vk_custom};

pub use prover::{create_proof, create_proof_with_engine};
pub use verifier::verify_proof;
pub use prover::{create_proof, create_proof_with_engine, verify_proof};

pub use error::Error;
pub use halo2_backend::plonk::{Error as ErrorBack, ProvingKey, VerifyingKey};
Expand Down
Loading

0 comments on commit c8c7ff9

Please sign in to comment.