Skip to content

Commit

Permalink
refactor: move the halo2_common::arithmetic to halo2_backend(post…
Browse files Browse the repository at this point in the history
… fe-be split) (#281)

* fix: review & correct the pub types/fields in "halo2_frontend" crate

* fix: review & correct the pub types/fields in "halo2_common" crate

* fix: review & correct the pub types/fields in "halo2_backend" crate

* chore: fmt

* chore: clippy

* fix: roll back the "pub(crate)" in "halo2_backend/src/plonk.rs"

* fix: roll back the "#[allow(unused)]" attrs

* fix: correct the "pub(crate)" in "halo2_backend/poly/kzg/strategy.rs"

* refactor: move the "halo2_common::arithmetic" to "halo2_backend"

* chore: fix clippy warnings

* build: update the rustc to "1.73.0" in "rust-toolchain"

* chore: fix clippy warnings

* chore: add resolver(2) to workspace cargo.toml

* chore: fix the lint warning

* build: set the "getrandom" crate as dependency for "wasm32-*" target
  • Loading branch information
duguorong009 authored Feb 22, 2024
1 parent c08b877 commit 42f8e93
Show file tree
Hide file tree
Showing 17 changed files with 23 additions and 24 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ members = [
"halo2_backend",
"halo2_common",
]
resolver = "2"
2 changes: 1 addition & 1 deletion halo2_backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
serde_json = "1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[features]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! This module provides common utilities, traits and structures for group,
//! field and polynomial arithmetic.

use super::multicore;
use group::{
ff::{BatchInvert, PrimeField},
Curve, Group, GroupOpsOwned, ScalarMulOwned,
};
use halo2_common::multicore;
pub use halo2_middleware::ff::Field;

pub use halo2curves::{CurveAffine, CurveExt};
Expand Down Expand Up @@ -89,7 +89,7 @@ fn multiexp_serial<C: CurveAffine>(coeffs: &[C::Scalar], bases: &[C], acc: &mut
other += a;
other
}
Bucket::Projective(a) => other + &a,
Bucket::Projective(a) => other + a,
}
}
}
Expand Down Expand Up @@ -531,7 +531,7 @@ pub fn powers<F: Field>(base: F) -> impl Iterator<Item = F> {
use rand_core::OsRng;

#[cfg(test)]
use crate::halo2curves::pasta::Fp;
use halo2curves::pasta::Fp;

#[test]
fn test_lagrange_interpolate() {
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod arithmetic;
mod helpers;
pub mod plonk;
pub mod poly;

// Internal re-exports
pub use halo2_common::arithmetic;
pub use halo2_common::circuit;
pub use halo2_common::multicore;
pub use halo2_common::transcript;
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/plonk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use blake2b_simd::Params as Blake2bParams;
use group::ff::{Field, FromUniformBytes, PrimeField};

use crate::arithmetic::CurveAffine;
use crate::helpers::{
self, polynomial_slice_byte_length, read_polynomial_vec, write_polynomial_slice,
SerdeCurveAffine, SerdePrimeField,
Expand All @@ -10,7 +11,6 @@ use crate::poly::{
Polynomial,
};
use evaluation::Evaluator;
use halo2_common::arithmetic::CurveAffine;
use halo2_common::plonk::{Circuit, ConstraintSystem, PinnedConstraintSystem};
use halo2_common::transcript::{EncodedChallenge, Transcript};
use halo2_common::SerdeFormat;
Expand Down
6 changes: 3 additions & 3 deletions halo2_backend/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rand_core::RngCore;
use std::collections::{BTreeSet, HashSet};
use std::{collections::HashMap, iter};

use crate::arithmetic::{eval_polynomial, CurveAffine};
use crate::plonk::lookup::prover::lookup_commit_permuted;
use crate::plonk::permutation::prover::permutation_commit;
use crate::plonk::shuffle::prover::shuffle_commit_product;
Expand All @@ -12,12 +13,11 @@ use crate::poly::{
commitment::{Blind, CommitmentScheme, Params, Prover},
Basis, Coeff, LagrangeCoeff, Polynomial, ProverQuery,
};

use group::prime::PrimeCurveAffine;
use halo2_common::plonk::{
circuit::sealed, ChallengeBeta, ChallengeGamma, ChallengeTheta, ChallengeX, ChallengeY, Error,
};

use group::prime::PrimeCurveAffine;
use halo2_common::arithmetic::{eval_polynomial, CurveAffine};
use halo2_common::transcript::{EncodedChallenge, TranscriptWrite};

/// Collection of instance data used during proving for a single circuit proof.
Expand Down
2 changes: 1 addition & 1 deletion halo2_common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
serde_json = "1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[features]
Expand Down
1 change: 0 additions & 1 deletion halo2_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(unsafe_code)]

pub mod arithmetic;
pub mod circuit;
pub use halo2curves;
pub mod multicore;
Expand Down
1 change: 0 additions & 1 deletion halo2_common/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! [halo]: https://eprint.iacr.org/2019/1021
//! [plonk]: https://eprint.iacr.org/2019/953

use crate::plonk::circuit::Column;
use crate::transcript::ChallengeScalar;
use halo2_middleware::circuit::{Advice, Fixed, Instance};
use halo2_middleware::ff::Field;
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
serde_json = "1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[features]
Expand Down
2 changes: 1 addition & 1 deletion halo2_frontend/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn compile_circuit<F: Field, ConcreteCircuit: Circuit<F>>(
let selectors = std::mem::take(&mut assembly.selectors);
cs.directly_convert_selectors_to_fixed(selectors)
};
fixed.extend(selector_polys.into_iter());
fixed.extend(selector_polys);

let preprocessing = PreprocessingV2 {
permutation: halo2_middleware::permutation::AssemblyMid {
Expand Down
4 changes: 2 additions & 2 deletions halo2_frontend/src/circuit/floor_planner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod single_pass;
mod v1;
pub mod single_pass;
pub mod v1;

pub use halo2_common::circuit::floor_planner::*;
2 changes: 1 addition & 1 deletion halo2_middleware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ proptest = "1"
group = "0.13"
halo2curves = { version = "0.6.0", default-features = false }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[lib]
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ proptest = "1"
dhat = "0.3.2"
serde_json = "1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[features]
Expand Down
6 changes: 3 additions & 3 deletions halo2_proofs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub mod circuit {
AssignedCell, Cell, Chip, Layouter, Region, SimpleFloorPlanner, Value,
};
}
///! This module provides common utilities, traits and structures for group,
///! field and polynomial arithmetic.
/// This module provides common utilities, traits and structures for group,
/// field and polynomial arithmetic.
pub mod arithmetic {
pub use halo2_common::arithmetic::{
pub use halo2_backend::arithmetic::{
best_fft, parallelize, small_multiexp, CurveAffine, CurveExt, Field,
};
}
Expand Down
4 changes: 2 additions & 2 deletions halo2_proofs/tests/plonk_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ fn plonk_api() {
//panic!("{:#?}", pk.get_vk().pinned());
assert_eq!(
format!("{:#?}", pk.get_vk().pinned()),
r#####"PinnedVerificationKey {
r#"PinnedVerificationKey {
base_modulus: "0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001",
scalar_modulus: "0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001",
domain: PinnedEvaluationDomain {
Expand Down Expand Up @@ -1015,7 +1015,7 @@ fn plonk_api() {
(0x3d907e0591343bd285c2c846f3e871a6ac70d80ec29e9500b8cb57f544e60202, 0x1034e48df35830244cabea076be8a16d67d7896e27c6ac22b285d017105da9c3),
],
},
}"#####
}"#
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.67.0
1.73.0

0 comments on commit 42f8e93

Please sign in to comment.