From 7675aaf3e4b8f8e89416c057f242ee7293e136d0 Mon Sep 17 00:00:00 2001 From: Velaciela Date: Sun, 8 Oct 2023 16:16:26 +0000 Subject: [PATCH] temp --- Cargo.lock | 73 +++++++--------------- halo2_proofs/Cargo.toml | 2 +- halo2_proofs/src/arithmetic.rs | 12 ++-- halo2_proofs/src/dev.rs | 4 +- halo2_proofs/src/dev/util.rs | 2 +- halo2_proofs/src/helpers.rs | 5 +- halo2_proofs/src/plonk/prover.rs | 2 +- halo2_proofs/src/plonk/vanishing/prover.rs | 4 +- halo2_proofs/src/poly/domain.rs | 4 +- halo2_proofs/src/poly/multiopen.rs | 8 +-- halo2_proofs/src/transcript/blake2b.rs | 2 +- halo2_proofs/src/transcript/poseidon.rs | 22 ++++--- 12 files changed, 57 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec56f19b08..340d1900ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -666,9 +666,9 @@ dependencies = [ [[package]] name = "ff" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df689201f395c6b90dfe87127685f8dbfc083a5e779e613575d8bd7314300c3e" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ "bitvec", "rand_core", @@ -807,11 +807,10 @@ checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" [[package]] name = "group" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7391856def869c1c81063a03457c676fbcd419709c3dfb33d8d319de484b154d" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "byteorder", "ff", "rand_core", "subtle", @@ -860,7 +859,7 @@ dependencies = [ "ff", "group", "halo2_proofs", - "halo2curves 0.2.1", + "halo2curves", "lazy_static", "plotters", "pprof", @@ -886,7 +885,7 @@ dependencies = [ "getrandom", "group", "gumdrop", - "halo2curves 0.3.1 (git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde)", + "halo2curves", "log", "num-bigint", "num-integer", @@ -903,42 +902,8 @@ dependencies = [ [[package]] name = "halo2curves" -version = "0.2.1" -source = "git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.0#83c72d49762343ffc9576ca11a2aa615efe1029b" -dependencies = [ - "ff", - "group", - "lazy_static", - "num-bigint", - "num-traits", - "pasta_curves", - "rand", - "rand_core", - "static_assertions", - "subtle", -] - -[[package]] -name = "halo2curves" -version = "0.3.1" -source = "git+https://github.com/privacy-scaling-explorations/halo2curves.git?tag=0.3.1#9b67e19bca30a35208b0c1b41c1723771e2c9f49" -dependencies = [ - "ff", - "group", - "lazy_static", - "num-bigint", - "num-traits", - "pasta_curves", - "rand", - "rand_core", - "static_assertions", - "subtle", -] - -[[package]] -name = "halo2curves" -version = "0.3.1" -source = "git+https://github.com/scroll-tech/halo2curves.git?branch=0.3.1-derive-serde#c0ac1935e5da2a620204b5b011be2c924b1e0155" +version = "0.3.2" +source = "git+https://github.com/privacy-scaling-explorations/halo2curves?tag=0.3.2#9f5c50810bbefe779ee5cf1d852b2fe85dc35d5e" dependencies = [ "ff", "group", @@ -949,7 +914,6 @@ dependencies = [ "paste", "rand", "rand_core", - "serde", "static_assertions", "subtle", ] @@ -1090,6 +1054,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] [[package]] name = "libc" @@ -1303,9 +1270,9 @@ dependencies = [ [[package]] name = "pasta_curves" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "369d7785168ad7ff0cbe467d968ca3e19a927d8536b11ef9c21b4e454b15ba42" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" dependencies = [ "blake2b_simd", "ff", @@ -1423,10 +1390,9 @@ dependencies = [ [[package]] name = "poseidon" version = "0.2.0" -source = "git+https://github.com/scroll-tech/poseidon.git?branch=scroll-dev-0220#2fb4a2385bada39b50dce12fe50cb80d2fd33476" +source = "git+https://github.com/privacy-scaling-explorations/poseidon.git?tag=v2023_04_20#807f8f555313f726ca03bdf941f798098f488ba4" dependencies = [ - "group", - "halo2curves 0.3.1 (git+https://github.com/privacy-scaling-explorations/halo2curves.git?tag=0.3.1)", + "halo2curves", "subtle", ] @@ -1733,9 +1699,6 @@ name = "serde" version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" -dependencies = [ - "serde_derive", -] [[package]] name = "serde_cbor" @@ -1808,6 +1771,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/halo2_proofs/Cargo.toml b/halo2_proofs/Cargo.toml index 0fcc9bfde9..c26b8c5227 100644 --- a/halo2_proofs/Cargo.toml +++ b/halo2_proofs/Cargo.toml @@ -55,7 +55,7 @@ blake2b_simd = "1" sha3 = "0.9.1" subtle = "2.3" cfg-if = "0.1" -poseidon = { git = "https://github.com/scroll-tech/poseidon.git", branch = "scroll-dev-0220" } +poseidon = { git = "https://github.com/privacy-scaling-explorations/poseidon.git", tag = "v2023_04_20" } num-integer = "0.1" num-bigint = { version = "0.4", features = ["rand"] } diff --git a/halo2_proofs/src/arithmetic.rs b/halo2_proofs/src/arithmetic.rs index 234ef6db54..e6434d571e 100644 --- a/halo2_proofs/src/arithmetic.rs +++ b/halo2_proofs/src/arithmetic.rs @@ -263,7 +263,7 @@ fn serial_split_fft>( let mut k = 0; while k < n { - let mut w = G::Scalar::ONE; + let mut w = Scalar::ONE; for j in 0..m { let mut t = a[(k + j + m) as usize]; t *= &w; @@ -293,7 +293,7 @@ fn split_radix_fft>( // we use out-place bitreverse here, split_m <= num_threads, so the buffer spase is small // and it's is good for data locality - let mut t1 = vec![G::Scalar::ZERO; split_m]; + let mut t1 = vec![G::identity(); split_m]; // if unsafe code is allowed, a 10% performance improvement can be achieved // let mut t1: Vec = Vec::with_capacity(split_m as usize); // unsafe{ t1.set_len(split_m as usize); } @@ -310,7 +310,7 @@ fn split_radix_fft>( if high_idx > 0 { omega = omega * twiddle_lut[(1 << sparse_degree) + high_idx]; } - let mut w_m = G::Scalar::ONE; + let mut w_m = Scalar::ONE; for i in 0..split_m { t1[i] *= &w_m; tmp[i] = t1[i]; @@ -329,7 +329,7 @@ pub fn generate_twiddle_lookup_table( // dense if is_lut_len_large { - let mut twiddle_lut = vec![F::zero(); (1 << log_n) as usize]; + let mut twiddle_lut = vec![F::ZERO; (1 << log_n) as usize]; parallelize(&mut twiddle_lut, |twiddle_lut, start| { let mut w_n = omega.pow_vartime([start as u64, 0, 0, 0]); for twiddle_lut in twiddle_lut.iter_mut() { @@ -343,7 +343,7 @@ pub fn generate_twiddle_lookup_table( // sparse let low_degree_lut_len = 1 << sparse_degree; let high_degree_lut_len = 1 << (log_n - sparse_degree - without_last_level as u32); - let mut twiddle_lut = vec![F::zero(); (low_degree_lut_len + high_degree_lut_len) as usize]; + let mut twiddle_lut = vec![F::ZERO; (low_degree_lut_len + high_degree_lut_len) as usize]; parallelize( &mut twiddle_lut[..low_degree_lut_len], |twiddle_lut, start| { @@ -378,7 +378,7 @@ pub fn parallel_fft>(a: &mut [G], omega: Scal let twiddle_lut = generate_twiddle_lookup_table(omega, log_n, SPARSE_TWIDDLE_DEGREE, true); // split fft - let mut tmp = vec![G::Scalar::ZERO; n]; + let mut tmp = vec![Scalar::ZERO; n]; // if unsafe code is allowed, a 10% performance improvement can be achieved // let mut tmp: Vec = Vec::with_capacity(n); // unsafe{ tmp.set_len(n); } diff --git a/halo2_proofs/src/dev.rs b/halo2_proofs/src/dev.rs index 34d7f7b1b3..440796bb6d 100644 --- a/halo2_proofs/src/dev.rs +++ b/halo2_proofs/src/dev.rs @@ -97,7 +97,7 @@ impl Region { } /// The value of a particular cell within the circuit. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Eq)] pub enum CellValue { /// An unassigned cell. Unassigned, @@ -110,7 +110,7 @@ pub enum CellValue { Poison(usize), } -impl PartialEq for CellValue { +impl PartialEq for CellValue { fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::Unassigned, Self::Unassigned) => true, diff --git a/halo2_proofs/src/dev/util.rs b/halo2_proofs/src/dev/util.rs index 353f9869f6..f4cd83c34a 100644 --- a/halo2_proofs/src/dev/util.rs +++ b/halo2_proofs/src/dev/util.rs @@ -86,7 +86,7 @@ pub(super) fn load<'a, F: Field, T: ColumnType, Q: Into + Copy>( } */ -pub(super) fn load_slice<'a, F: FieldExt, T: ColumnType, Q: Into + Copy>( +pub(super) fn load_slice<'a, F: Field, T: ColumnType, Q: Into + Copy>( n: i32, row: i32, queries: &'a [(Column, Rotation)], diff --git a/halo2_proofs/src/helpers.rs b/halo2_proofs/src/helpers.rs index f58ec9b100..df918ad1ec 100644 --- a/halo2_proofs/src/helpers.rs +++ b/halo2_proofs/src/helpers.rs @@ -2,7 +2,6 @@ use crate::plonk::{Any, Column}; use crate::poly::Polynomial; use ff::Field; use ff::PrimeField; -use halo2curves::FieldExt; use halo2curves::{pairing::Engine, serde::SerdeObject, CurveAffine}; use num_bigint::BigUint; use std::io; @@ -42,13 +41,13 @@ pub(crate) trait CurveRead: CurveAffine { } impl CurveRead for C {} -pub fn field_to_bn(f: &F) -> BigUint { +pub fn field_to_bn(f: &F) -> BigUint { BigUint::from_bytes_le(f.to_repr().as_ref()) } /// Input a big integer `bn`, compute a field element `f` /// such that `f == bn % F::MODULUS`. -pub fn bn_to_field(bn: &BigUint) -> F { +pub fn bn_to_field(bn: &BigUint) -> F { let mut buf = bn.to_bytes_le(); buf.resize(64, 0u8); diff --git a/halo2_proofs/src/plonk/prover.rs b/halo2_proofs/src/plonk/prover.rs index 0c9edd780d..c522947820 100644 --- a/halo2_proofs/src/plonk/prover.rs +++ b/halo2_proofs/src/plonk/prover.rs @@ -466,7 +466,7 @@ where //*cell = C::Scalar::one(); //} let idx = advice_values.len() - 1; - advice_values[idx] = Scheme::Scalar::one(); + advice_values[idx] = Scheme::Scalar::ONE; } // Compute commitments to advice column polynomials diff --git a/halo2_proofs/src/plonk/vanishing/prover.rs b/halo2_proofs/src/plonk/vanishing/prover.rs index 71d29b180d..d394b8c0de 100644 --- a/halo2_proofs/src/plonk/vanishing/prover.rs +++ b/halo2_proofs/src/plonk/vanishing/prover.rs @@ -50,10 +50,10 @@ impl Argument { transcript: &mut T, ) -> Result, Error> { // Sample a random polynomial of degree n - 1 - let random_poly = domain.constant_lagrange(C::Scalar::one()); + let random_poly = domain.constant_lagrange(C::Scalar::ONE); let random_poly = domain.lagrange_to_coeff(random_poly); // Sample a random blinding factor - let random_blind = Blind(C::Scalar::zero()); + let random_blind = Blind(C::Scalar::ZERO); let c = params.commit(&random_poly, random_blind).to_affine(); // We write the identity point to the transcript which // is the commitment of the zero polynomial. diff --git a/halo2_proofs/src/poly/domain.rs b/halo2_proofs/src/poly/domain.rs index e43934a763..63be6d654f 100644 --- a/halo2_proofs/src/poly/domain.rs +++ b/halo2_proofs/src/poly/domain.rs @@ -458,7 +458,7 @@ impl> EvaluationDomain { parallelize(a, |a, index| { let mut c_power = c.pow_vartime(&[index as u64, 0, 0, 0]); for a in a { - a = a * (&c_power); + *a = *a * (&c_power); c_power = c_power * c; } }); @@ -654,7 +654,7 @@ fn test_l_i() { points.push(domain.omega.pow(&[i, 0, 0, 0])); } for i in 0..8 { - let mut l_i = vec![Scalar::zero(); 8]; + let mut l_i = vec![Scalar::ZERO; 8]; l_i[i] = Scalar::ONE; let l_i = lagrange_interpolate(&points[..], &l_i[..]); l.push(l_i); diff --git a/halo2_proofs/src/poly/multiopen.rs b/halo2_proofs/src/poly/multiopen.rs index 854018e90a..9cff28bde8 100644 --- a/halo2_proofs/src/poly/multiopen.rs +++ b/halo2_proofs/src/poly/multiopen.rs @@ -5,7 +5,7 @@ use super::{commitment::ParamsVerifier, PairMSM}; use crate::{ - arithmetic::{eval_polynomial, CurveAffine, FieldExt}, + arithmetic::{eval_polynomial, CurveAffine}, pairing::arithmetic::{MillerLoopResult, MultiMillerLoop}, poly::{msm::MSM, Coeff, Error, Polynomial}, }; @@ -129,7 +129,7 @@ impl<'r, 'params: 'r, C: CurveAffine> PartialEq for CommitmentReference<'r, C> { } } -trait Query: Sized + Clone { +trait Query: Sized + Clone { type Commitment: PartialEq + Clone; fn get_rotation(&self) -> Rotation; @@ -141,7 +141,7 @@ trait Query: Sized + Clone { #[cfg(test)] mod tests { - use crate::arithmetic::{eval_polynomial, FieldExt}; + use crate::arithmetic::{eval_polynomial}; use crate::pairing::bn256::{Bn256, Fr, G1Affine}; use crate::poly::{ commitment::{Params, ParamsVerifier}, @@ -173,7 +173,7 @@ mod tests { use rand_core::OsRng; use super::*; - use crate::arithmetic::{eval_polynomial, FieldExt}; + use crate::arithmetic::{eval_polynomial}; use crate::poly::{commitment::Params, EvaluationDomain}; use crate::transcript::Challenge255; diff --git a/halo2_proofs/src/transcript/blake2b.rs b/halo2_proofs/src/transcript/blake2b.rs index 99954e6efd..78f59811aa 100644 --- a/halo2_proofs/src/transcript/blake2b.rs +++ b/halo2_proofs/src/transcript/blake2b.rs @@ -5,7 +5,7 @@ use super::{ use blake2b_simd::{Params as Blake2bParams, State as Blake2bState}; use ff::Field; use group::ff::PrimeField; -use halo2curves::{Coordinates, CurveAffine, FieldExt}; +use halo2curves::{Coordinates, CurveAffine}; use num_bigint::BigUint; use std::convert::TryInto; use std::io::{self, Read, Write}; diff --git a/halo2_proofs/src/transcript/poseidon.rs b/halo2_proofs/src/transcript/poseidon.rs index d9da18a440..0b653f2137 100644 --- a/halo2_proofs/src/transcript/poseidon.rs +++ b/halo2_proofs/src/transcript/poseidon.rs @@ -1,8 +1,7 @@ use super::{Challenge255, EncodedChallenge, Transcript, TranscriptRead, TranscriptWrite}; use crate::helpers::base_to_scalar; -use ff::Field; -use group::ff::PrimeField; -use halo2curves::{Coordinates, CurveAffine, FieldExt}; +use group::ff::{FromUniformBytes, PrimeField}; +use halo2curves::{Coordinates, CurveAffine}; use num_bigint::BigUint; use poseidon::Poseidon; use std::convert::TryInto; @@ -15,7 +14,7 @@ const POSEIDON_T: usize = POSEIDON_RATE + 1usize; /// TODO #[derive(Debug, Clone)] pub struct PoseidonRead> { - state: Poseidon, + state: Poseidon, reader: R, _marker: PhantomData<(C, E)>, } @@ -34,6 +33,8 @@ impl> PoseidonRead { impl TranscriptRead> for PoseidonRead> +where + ::ScalarExt: FromUniformBytes<64>, { fn read_point(&mut self) -> io::Result { let mut compressed = C::Repr::default(); @@ -64,8 +65,9 @@ impl TranscriptRead> } } -impl Transcript> - for PoseidonRead> +impl Transcript> for PoseidonRead> +where + ::ScalarExt: FromUniformBytes<64>, { fn squeeze_challenge(&mut self) -> Challenge255 { //self.state.update(&[PREFIX_SQUEEZE]); @@ -101,12 +103,12 @@ impl Transcript> /// TODO #[derive(Debug, Clone)] pub struct PoseidonWrite> { - state: Poseidon, + state: Poseidon, writer: W, _marker: PhantomData<(C, E)>, } -impl> PoseidonWrite { +impl> PoseidonWrite where ::ScalarExt: FromUniformBytes<64> { /// Initialize a transcript given an output buffer. pub fn init(writer: W) -> Self { PoseidonWrite { @@ -125,6 +127,8 @@ impl> PoseidonWrite { impl TranscriptWrite> for PoseidonWrite> +where + ::ScalarExt: FromUniformBytes<64>, { fn write_point(&mut self, point: C) -> io::Result<()> { self.common_point(point)?; @@ -140,6 +144,8 @@ impl TranscriptWrite> impl Transcript> for PoseidonWrite> +where + ::ScalarExt: FromUniformBytes<64>, { fn squeeze_challenge(&mut self) -> Challenge255 { //self.state.update(&[PREFIX_SQUEEZE]);