From faf9aceb0aff0e19d85faba304f14b9780e8d93d Mon Sep 17 00:00:00 2001 From: "sm.wu" Date: Wed, 31 Jan 2024 12:32:20 +0800 Subject: [PATCH] wip: upgrade halo2/halo2curve dependency --- Cargo.toml | 5 +++++ rust-toolchain | 2 +- snark-verifier-sdk/Cargo.toml | 4 ++-- snark-verifier/Cargo.toml | 4 ++-- snark-verifier/src/pcs/kzg/accumulation.rs | 6 ++++-- snark-verifier/src/pcs/kzg/decider.rs | 9 ++++++--- snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs | 13 +++++++------ snark-verifier/src/pcs/kzg/multiopen/gwc19.rs | 13 +++++++------ snark-verifier/src/system/halo2/test/kzg.rs | 6 +++--- snark-verifier/src/util/arithmetic.rs | 12 ++++++++++-- 10 files changed, 47 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 31bbef5c..b8384285 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,3 +3,8 @@ members = [ "snark-verifier", "snark-verifier-sdk" ] +resolver = "2" + +[patch.crates-io] +halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v0.3.0" } +halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0" } diff --git a/rust-toolchain b/rust-toolchain index cb908525..7c7053aa 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.69.0 \ No newline at end of file +1.75.0 diff --git a/snark-verifier-sdk/Cargo.toml b/snark-verifier-sdk/Cargo.toml index 2f1ba1a3..0269847f 100644 --- a/snark-verifier-sdk/Cargo.toml +++ b/snark-verifier-sdk/Cargo.toml @@ -20,8 +20,8 @@ ark-std = { version = "0.3.0", features = ["print-trace"], optional = true } snark-verifier = { path = "../snark-verifier", default-features = false } # system_halo2 -halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20" } # not optional for now -halo2curves = { git = 'https://github.com/privacy-scaling-explorations/halo2curves', tag = "0.3.2" } # must be same version as in halo2_proofs +halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0" } # not optional for now +halo2curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0" } # loader_halo2 halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2023_04_20", package = "ecc", optional = true } diff --git a/snark-verifier/Cargo.toml b/snark-verifier/Cargo.toml index 962a57e0..9408e82f 100644 --- a/snark-verifier/Cargo.toml +++ b/snark-verifier/Cargo.toml @@ -11,13 +11,13 @@ num-integer = "0.1.45" num-traits = "0.2.15" rand = "0.8" hex = "0.4" -halo2_curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "0.3.2", package = "halo2curves" } +halo2_curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "v0.6.0", package = "halo2curves" } # parallel rayon = { version = "1.5.3", optional = true } # system_halo2 -halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v2023_04_20", optional = true } +halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2", tag = "v0.3.0", optional = true } # loader_evm sha3 = { version = "0.10", optional = true } diff --git a/snark-verifier/src/pcs/kzg/accumulation.rs b/snark-verifier/src/pcs/kzg/accumulation.rs index 5139d49e..cf84d8df 100644 --- a/snark-verifier/src/pcs/kzg/accumulation.rs +++ b/snark-verifier/src/pcs/kzg/accumulation.rs @@ -19,7 +19,8 @@ pub struct KzgAs(PhantomData<(M, MOS)>); impl AccumulationScheme for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::G1Affine: CurveAffine, + M::Fr: PrimeField, L: Loader, MOS: Clone + Debug, { @@ -140,7 +141,8 @@ where impl AccumulationSchemeProver for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::G1Affine: CurveAffine, + M::Fr: PrimeField, MOS: Clone + Debug, { type ProvingKey = KzgAsProvingKey; diff --git a/snark-verifier/src/pcs/kzg/decider.rs b/snark-verifier/src/pcs/kzg/decider.rs index eb7e84a7..65e90d79 100644 --- a/snark-verifier/src/pcs/kzg/decider.rs +++ b/snark-verifier/src/pcs/kzg/decider.rs @@ -42,6 +42,7 @@ impl AsRef> for KzgDeci } mod native { + use crate::{ loader::native::NativeLoader, pcs::{ @@ -49,7 +50,7 @@ mod native { AccumulationDecider, }, util::{ - arithmetic::{Group, MillerLoopResult, MultiMillerLoop, PrimeField}, + arithmetic::{CurveAffine, Group, MillerLoopResult, MultiMillerLoop, PrimeField}, Itertools, }, Error, @@ -59,7 +60,8 @@ mod native { impl AccumulationDecider for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::G1Affine: CurveAffine, + M::Fr: PrimeField, MOS: Clone + Debug, { type DecidingKey = KzgDecidingKey; @@ -113,7 +115,8 @@ mod evm { impl AccumulationDecider> for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::G1Affine: CurveAffine, + M::Fr: PrimeField, MOS: Clone + Debug, { type DecidingKey = KzgDecidingKey; diff --git a/snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs b/snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs index cbfa0000..a77a0bdb 100644 --- a/snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs +++ b/snark-verifier/src/pcs/kzg/multiopen/bdfg21.rs @@ -27,7 +27,8 @@ pub struct Bdfg21; impl PolynomialCommitmentScheme for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField + Ord, + M::G1Affine: CurveAffine, + M::Fr: PrimeField + Ord, L: Loader, { type VerifyingKey = KzgSuccinctVerifyingKey; @@ -36,7 +37,7 @@ where fn read_proof( _: &KzgSuccinctVerifyingKey, - _: &[Query], + _: &[Query], transcript: &mut T, ) -> Result, Error> where @@ -49,7 +50,7 @@ where svk: &KzgSuccinctVerifyingKey, commitments: &[Msm], z: &L::LoadedScalar, - queries: &[Query], + queries: &[Query], proof: &Bdfg21Proof, ) -> Result { let sets = query_sets(queries); @@ -370,11 +371,11 @@ where impl CostEstimation for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::Fr: PrimeField, { - type Input = Vec>; + type Input = Vec>; - fn estimate_cost(_: &Vec>) -> Cost { + fn estimate_cost(_: &Vec>) -> Cost { Cost { num_commitment: 2, num_msm: 2, diff --git a/snark-verifier/src/pcs/kzg/multiopen/gwc19.rs b/snark-verifier/src/pcs/kzg/multiopen/gwc19.rs index b664d536..6b9148fe 100644 --- a/snark-verifier/src/pcs/kzg/multiopen/gwc19.rs +++ b/snark-verifier/src/pcs/kzg/multiopen/gwc19.rs @@ -23,7 +23,8 @@ pub struct Gwc19; impl PolynomialCommitmentScheme for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::G1Affine: CurveAffine, + M::Fr: PrimeField, L: Loader, { type VerifyingKey = KzgSuccinctVerifyingKey; @@ -32,7 +33,7 @@ where fn read_proof( _: &Self::VerifyingKey, - queries: &[Query], + queries: &[Query], transcript: &mut T, ) -> Result where @@ -45,7 +46,7 @@ where svk: &Self::VerifyingKey, commitments: &[Msm], z: &L::LoadedScalar, - queries: &[Query], + queries: &[Query], proof: &Self::Proof, ) -> Result { let sets = query_sets(queries); @@ -161,11 +162,11 @@ where impl CostEstimation for KzgAs where M: MultiMillerLoop, - M::Scalar: PrimeField, + M::Fr: PrimeField, { - type Input = Vec>; + type Input = Vec>; - fn estimate_cost(queries: &Vec>) -> Cost { + fn estimate_cost(queries: &Vec>) -> Cost { let num_w = query_sets(queries).len(); Cost { num_commitment: num_w, diff --git a/snark-verifier/src/system/halo2/test/kzg.rs b/snark-verifier/src/system/halo2/test/kzg.rs index 107af76e..b7d53dc0 100644 --- a/snark-verifier/src/system/halo2/test/kzg.rs +++ b/snark-verifier/src/system/halo2/test/kzg.rs @@ -21,15 +21,15 @@ pub const BITS: usize = 68; pub fn setup(k: u32) -> ParamsKZG where - M::Scalar: PrimeField, + M::Fr: PrimeField, { ParamsKZG::::setup(k, ChaCha20Rng::from_seed(Default::default())) } pub fn main_gate_with_range_with_mock_kzg_accumulator( -) -> MainGateWithRange +) -> MainGateWithRange where - M::Scalar: PrimeField, + M::Fr: PrimeField, M::G1Affine: SerdeObject, M::G2Affine: SerdeObject, { diff --git a/snark-verifier/src/util/arithmetic.rs b/snark-verifier/src/util/arithmetic.rs index 20c34645..06d93605 100644 --- a/snark-verifier/src/util/arithmetic.rs +++ b/snark-verifier/src/util/arithmetic.rs @@ -14,13 +14,21 @@ pub use halo2_curves::{ ff::{BatchInvert, Field, FromUniformBytes, PrimeField, WithSmallOrderMulGroup}, group::{prime::PrimeCurveAffine, Curve, Group, GroupEncoding}, pairing::MillerLoopResult, + pairing::PairingCurveAffine, Coordinates, CurveAffine, CurveExt, }; /// [`halo2_curves::pairing::MultiMillerLoop`] with [`std::fmt::Debug`]. -pub trait MultiMillerLoop: halo2_curves::pairing::MultiMillerLoop + Debug {} +pub trait MultiMillerLoop: halo2_curves::pairing::MultiMillerLoop + Debug +where + Self::G1Affine: CurveAffine, +{ +} -impl MultiMillerLoop for M {} +impl MultiMillerLoop for M where + Self::G1Affine: CurveAffine +{ +} /// Operations that could be done with field elements. pub trait FieldOps: