From 0f86c86643dfaf46bceabdf9f310c9fc19573133 Mon Sep 17 00:00:00 2001 From: "Jason.Huang" Date: Tue, 16 Apr 2024 18:21:10 +0800 Subject: [PATCH 1/5] implement Clone for CircuitBuilder --- plonky2/Cargo.toml | 1 + plonky2/examples/square_root.rs | 2 +- plonky2/src/gadgets/arithmetic.rs | 2 +- plonky2/src/gadgets/arithmetic_extension.rs | 2 +- plonky2/src/gadgets/range_check.rs | 2 +- plonky2/src/gadgets/split_base.rs | 2 +- plonky2/src/gadgets/split_join.rs | 4 ++-- plonky2/src/gates/base_sum.rs | 2 +- plonky2/src/gates/coset_interpolation.rs | 2 +- plonky2/src/gates/exponentiation.rs | 2 +- .../src/gates/high_degree_interpolation.rs | 2 +- plonky2/src/gates/low_degree_interpolation.rs | 2 +- plonky2/src/gates/poseidon.rs | 2 +- plonky2/src/gates/random_access.rs | 2 +- plonky2/src/gates/reducing.rs | 2 +- plonky2/src/gates/reducing_extension.rs | 2 +- plonky2/src/iop/generator.rs | 24 +++++++++++++------ plonky2/src/plonk/circuit_builder.rs | 2 +- plonky2/src/plonk/copy_constraint.rs | 2 +- plonky2/src/recursion/dummy_circuit.rs | 2 +- plonky2/src/util/context_tree.rs | 2 +- 21 files changed, 38 insertions(+), 27 deletions(-) diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index 9532e78f9d..a65b8db35c 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -43,6 +43,7 @@ plonky2_field = { version = "0.2.0", path = "../field", default-features = false plonky2_maybe_rayon = { version = "0.2.0", path = "../maybe_rayon", default-features = false } plonky2_util = { version = "0.2.0", path = "../util", default-features = false } cryptography_cuda ={git="ssh://git@github.com/okx/cryptography_cuda.git", rev="d44b861cf241d27688525e7a8f082199a2abcbfa", optional=true, features=["no_cuda"]} +dyn-clone = "1.0.17" [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] getrandom = { version = "0.2", default-features = false, features = ["js"] } diff --git a/plonky2/examples/square_root.rs b/plonky2/examples/square_root.rs index fb970a67c5..a6c22de020 100644 --- a/plonky2/examples/square_root.rs +++ b/plonky2/examples/square_root.rs @@ -23,7 +23,7 @@ use plonky2_field::extension::Extendable; /// A generator used by the prover to calculate the square root (`x`) of a given value /// (`x_squared`), outside of the circuit, in order to supply it as an additional public input. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] struct SquareRootGenerator, const D: usize> { x: Target, x_squared: Target, diff --git a/plonky2/src/gadgets/arithmetic.rs b/plonky2/src/gadgets/arithmetic.rs index e162f1116f..9e4328a102 100644 --- a/plonky2/src/gadgets/arithmetic.rs +++ b/plonky2/src/gadgets/arithmetic.rs @@ -380,7 +380,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct EqualityGenerator { x: Target, y: Target, diff --git a/plonky2/src/gadgets/arithmetic_extension.rs b/plonky2/src/gadgets/arithmetic_extension.rs index afea71df39..f7cf326aae 100644 --- a/plonky2/src/gadgets/arithmetic_extension.rs +++ b/plonky2/src/gadgets/arithmetic_extension.rs @@ -499,7 +499,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct QuotientGeneratorExtension { numerator: ExtensionTarget, denominator: ExtensionTarget, diff --git a/plonky2/src/gadgets/range_check.rs b/plonky2/src/gadgets/range_check.rs index 9a66a6a6c6..27bd8cc469 100644 --- a/plonky2/src/gadgets/range_check.rs +++ b/plonky2/src/gadgets/range_check.rs @@ -57,7 +57,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct LowHighGenerator { integer: Target, n_log: usize, diff --git a/plonky2/src/gadgets/split_base.rs b/plonky2/src/gadgets/split_base.rs index 1cdec86203..184cbc0b89 100644 --- a/plonky2/src/gadgets/split_base.rs +++ b/plonky2/src/gadgets/split_base.rs @@ -80,7 +80,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct BaseSumGenerator { row: usize, limbs: Vec, diff --git a/plonky2/src/gadgets/split_join.rs b/plonky2/src/gadgets/split_join.rs index 2f35b94c77..5865ff90f8 100644 --- a/plonky2/src/gadgets/split_join.rs +++ b/plonky2/src/gadgets/split_join.rs @@ -61,7 +61,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct SplitGenerator { integer: Target, bits: Vec, @@ -103,7 +103,7 @@ impl, const D: usize> SimpleGenerator for Spl } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct WireSplitGenerator { integer: Target, gates: Vec, diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index fbd40a997b..b45eb2e2b9 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -238,7 +238,7 @@ impl, const D: usize, const B: usize> PackedEvaluab } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct BaseSplitGenerator { row: usize, num_limbs: usize, diff --git a/plonky2/src/gates/coset_interpolation.rs b/plonky2/src/gates/coset_interpolation.rs index 3886342490..04f5df52d7 100644 --- a/plonky2/src/gates/coset_interpolation.rs +++ b/plonky2/src/gates/coset_interpolation.rs @@ -400,7 +400,7 @@ impl, const D: usize> Gate for CosetInterpola } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct InterpolationGenerator, const D: usize> { row: usize, gate: CosetInterpolationGate, diff --git a/plonky2/src/gates/exponentiation.rs b/plonky2/src/gates/exponentiation.rs index 44e319391b..f0130adc1c 100644 --- a/plonky2/src/gates/exponentiation.rs +++ b/plonky2/src/gates/exponentiation.rs @@ -312,7 +312,7 @@ impl, const D: usize> PackedEvaluableBase } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct ExponentiationGenerator, const D: usize> { row: usize, gate: ExponentiationGate, diff --git a/plonky2/src/gates/high_degree_interpolation.rs b/plonky2/src/gates/high_degree_interpolation.rs index ef9b09a4c2..a01fb095a7 100644 --- a/plonky2/src/gates/high_degree_interpolation.rs +++ b/plonky2/src/gates/high_degree_interpolation.rs @@ -221,7 +221,7 @@ impl, const D: usize> Gate } } -#[derive(Debug)] +#[derive(Debug, Clone)] struct InterpolationGenerator, const D: usize> { row: usize, gate: HighDegreeInterpolationGate, diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 374c5cd7e1..32f6e2121a 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -520,7 +520,7 @@ function two_adic_subgroup(i) {{ } } -#[derive(Debug)] +#[derive(Debug, Clone)] struct InterpolationGenerator, const D: usize> { row: usize, gate: LowDegreeInterpolationGate, diff --git a/plonky2/src/gates/poseidon.rs b/plonky2/src/gates/poseidon.rs index 67f5646bb6..e4255e1439 100644 --- a/plonky2/src/gates/poseidon.rs +++ b/plonky2/src/gates/poseidon.rs @@ -717,7 +717,7 @@ function MDS_MATRIX_DIAG(i) {{ } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct PoseidonGenerator + Poseidon, const D: usize> { row: usize, _phantom: PhantomData, diff --git a/plonky2/src/gates/random_access.rs b/plonky2/src/gates/random_access.rs index b05ca41c6c..c29276ce45 100644 --- a/plonky2/src/gates/random_access.rs +++ b/plonky2/src/gates/random_access.rs @@ -467,7 +467,7 @@ impl, const D: usize> PackedEvaluableBase } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct RandomAccessGenerator, const D: usize> { row: usize, gate: RandomAccessGate, diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index 0f45e47892..db5ae5b005 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -257,7 +257,7 @@ function r_wires_accs_start(i, num_coeffs) {{ } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct ReducingGenerator { row: usize, gate: ReducingGate, diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index f5de67d0db..d40d181a39 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -254,7 +254,7 @@ function re_wires_accs_start(i, num_coeffs) {{ } } -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct ReducingGenerator { row: usize, gate: ReducingExtensionGate, diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 6cdd75dcf6..141a63a6d6 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -7,6 +7,7 @@ use alloc::{ }; use core::fmt::Debug; use core::marker::PhantomData; +use dyn_clone::DynClone; use crate::field::extension::Extendable; use crate::field::types::Field; @@ -103,8 +104,9 @@ pub fn generate_partial_witness< } /// A generator participates in the generation of the witness. -pub trait WitnessGenerator, const D: usize>: - 'static + Send + Sync + Debug +pub trait WitnessGenerator: 'static + Send + Sync + Debug + DynClone +where + F: RichField + Extendable, { fn id(&self) -> String; @@ -123,13 +125,21 @@ pub trait WitnessGenerator, const D: usize>: where Self: Sized; } +dyn_clone::clone_trait_object!( WitnessGenerator where F: RichField + Extendable); /// A wrapper around an `Box` which implements `PartialEq` /// and `Eq` based on generator IDs. +#[derive(Clone)] pub struct WitnessGeneratorRef, const D: usize>( pub Box>, ); +// impl, const D: usize> Clone for WitnessGeneratorRef { +// fn clone(&self) -> Self { +// Self(dyn_clone::clone_box(&self.0)) +// } +// } + impl, const D: usize> WitnessGeneratorRef { pub fn new>(generator: G) -> WitnessGeneratorRef { WitnessGeneratorRef(Box::new(generator)) @@ -200,7 +210,7 @@ impl GeneratedValues { /// A generator which runs once after a list of dependencies is present in the witness. pub trait SimpleGenerator, const D: usize>: - 'static + Send + Sync + Debug + 'static + Send + Sync + Debug + Clone { fn id(&self) -> String; @@ -225,7 +235,7 @@ pub trait SimpleGenerator, const D: usize>: Self: Sized; } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct SimpleGeneratorAdapter< F: RichField + Extendable, SG: SimpleGenerator + ?Sized, @@ -268,7 +278,7 @@ impl, SG: SimpleGenerator, const D: usize> Wi } /// A generator which copies one wire to another. -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct CopyGenerator { pub(crate) src: Target, pub(crate) dst: Target, @@ -301,7 +311,7 @@ impl, const D: usize> SimpleGenerator for Cop } /// A generator for including a random value -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct RandomValueGenerator { pub(crate) target: Target, } @@ -331,7 +341,7 @@ impl, const D: usize> SimpleGenerator for Ran } /// A generator for testing if a value equals zero -#[derive(Debug, Default)] +#[derive(Debug, Default, Clone)] pub struct NonzeroTestGenerator { pub(crate) to_test: Target, pub(crate) dummy: Target, diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index ecad452192..0d0f412cc1 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -136,7 +136,7 @@ pub struct LookupWire { /// // Verify the proof /// assert!(circuit_data.verify(proof).is_ok()); /// ``` -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CircuitBuilder, const D: usize> { /// Circuit configuration to be used by this [`CircuitBuilder`]. pub config: CircuitConfig, diff --git a/plonky2/src/plonk/copy_constraint.rs b/plonky2/src/plonk/copy_constraint.rs index 309f207d8b..6868650dfe 100644 --- a/plonky2/src/plonk/copy_constraint.rs +++ b/plonky2/src/plonk/copy_constraint.rs @@ -4,7 +4,7 @@ use alloc::string::String; use crate::iop::target::Target; /// A named copy constraint. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct CopyConstraint { pub pair: (Target, Target), pub name: String, diff --git a/plonky2/src/recursion/dummy_circuit.rs b/plonky2/src/recursion/dummy_circuit.rs index dc38924937..56403e5b95 100644 --- a/plonky2/src/recursion/dummy_circuit.rs +++ b/plonky2/src/recursion/dummy_circuit.rs @@ -146,7 +146,7 @@ impl, const D: usize> CircuitBuilder { } } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct DummyProofGenerator where F: RichField + Extendable, diff --git a/plonky2/src/util/context_tree.rs b/plonky2/src/util/context_tree.rs index f3ba5b7282..5a5f3e9840 100644 --- a/plonky2/src/util/context_tree.rs +++ b/plonky2/src/util/context_tree.rs @@ -8,7 +8,7 @@ use alloc::{ use log::{log, Level}; /// The hierarchy of contexts, and the gate count contributed by each one. Useful for debugging. -#[derive(Debug)] +#[derive(Debug, Clone)] pub(crate) struct ContextTree { /// The name of this scope. name: String, From f987fcdd05d4cdc0155da8415fac2a1b285399a7 Mon Sep 17 00:00:00 2001 From: "Jason.Huang" Date: Wed, 17 Apr 2024 17:08:23 +0800 Subject: [PATCH 2/5] cryptography_cuda from workspace --- Cargo.toml | 14 +++++++++++--- field/Cargo.toml | 9 +++++++-- plonky2/Cargo.toml | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c17611bdd6..87c9864296 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,19 @@ [workspace] -members = ["field", "maybe_rayon", "plonky2", "starky", "util", "gen"] +members = ["field", "maybe_rayon", "plonky2", "starky", "util", "gen"] resolver = "2" [workspace.dependencies] -ahash = { version = "0.8.7", default-features = false, features = ["compile-time-rng"] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`. +cryptography_cuda = { git = "ssh://git@github.com/okx/cryptography_cuda.git", rev = "d44b861cf241d27688525e7a8f082199a2abcbfa", features = [ + "no_cuda", +] } +ahash = { version = "0.8.7", default-features = false, features = [ + "compile-time-rng", +] } # NOTE: Be sure to keep this version the same as the dependency in `hashbrown`. anyhow = { version = "1.0.40", default-features = false } -hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "serde"] } # NOTE: When upgrading, see `ahash` dependency. +hashbrown = { version = "0.14.3", default-features = false, features = [ + "ahash", + "serde", +] } # NOTE: When upgrading, see `ahash` dependency. itertools = { version = "0.11.0", default-features = false } log = { version = "0.4.14", default-features = false } num = { version = "0.4", default-features = false, features = ["rand"] } diff --git a/field/Cargo.toml b/field/Cargo.toml index 25cf46ee92..25364f349b 100644 --- a/field/Cargo.toml +++ b/field/Cargo.toml @@ -2,7 +2,12 @@ name = "plonky2_field" description = "Finite field arithmetic" version = "0.2.0" -authors = ["Daniel Lubarov ", "William Borgeaud ", "Jacqueline Nabaglo ", "Hamish Ivey-Law "] +authors = [ + "Daniel Lubarov ", + "William Borgeaud ", + "Jacqueline Nabaglo ", + "Hamish Ivey-Law ", +] edition.workspace = true license.workspace = true homepage.workspace = true @@ -23,7 +28,7 @@ rand = { workspace = true, features = ["getrandom"] } serde = { workspace = true, features = ["alloc"] } static_assertions = { workspace = true } unroll = { workspace = true } -cryptography_cuda ={git="ssh://git@github.com/okx/cryptography_cuda.git", rev="56cee09dd044de44f05c7d54383c6a8cb4078b29", optional=true} +cryptography_cuda = { workspace = true, optional = true } [dev-dependencies] rand = { version = "0.8.5", default-features = false, features = ["getrandom"] } diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index ba88cd2aba..23589c9443 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -46,7 +46,7 @@ once_cell = { version = "1.18.0" } plonky2_field = { version = "0.2.0", path = "../field", default-features = false } plonky2_maybe_rayon = { version = "0.2.0", path = "../maybe_rayon", default-features = false } plonky2_util = { version = "0.2.0", path = "../util", default-features = false } -cryptography_cuda = { git = "ssh://git@github.com/okx/cryptography_cuda.git", rev = "56cee09dd044de44f05c7d54383c6a8cb4078b29", optional = true } +cryptography_cuda = { workspace = true, optional = true } dyn-clone = "1.0.17" [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] From 5c846b9a00ece7099ac925ec497612a3e56e83b1 Mon Sep 17 00:00:00 2001 From: "Jason.Huang" Date: Wed, 17 Apr 2024 17:52:53 +0800 Subject: [PATCH 3/5] remove submodule --- depends/cryptography_cuda | 1 - 1 file changed, 1 deletion(-) delete mode 160000 depends/cryptography_cuda diff --git a/depends/cryptography_cuda b/depends/cryptography_cuda deleted file mode 160000 index c0d84a089b..0000000000 --- a/depends/cryptography_cuda +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c0d84a089bbb9010fdf2afc4714588e3118df340 From c969a58d00f0f62df9ce491dd560a9792257de04 Mon Sep 17 00:00:00 2001 From: "Jason.Huang" Date: Thu, 18 Apr 2024 11:11:41 +0800 Subject: [PATCH 4/5] cargo fmt --- field/build.rs | 7 +- field/examples/fft.rs | 2 - field/src/goldilocks_field.rs | 5 +- field/src/lib.rs | 2 +- field/src/polynomial/mod.rs | 2 +- field/src/secp256k1_base.rs | 1 + field/src/types.rs | 9 +- plonky2/build.rs | 2 +- plonky2/examples/bench_recursion.rs | 2 +- plonky2/src/fri/prover.rs | 3 +- plonky2/src/fri/recursive_verifier.rs | 5 +- plonky2/src/fri/verifier.rs | 2 +- plonky2/src/gadgets/interpolation.rs | 2 - plonky2/src/gates/gate.rs | 9 +- .../src/gates/high_degree_interpolation.rs | 14 +- plonky2/src/gates/interpolation.rs | 15 +- plonky2/src/gates/lookup.rs | 12 +- plonky2/src/gates/lookup_table.rs | 6 +- plonky2/src/gates/low_degree_interpolation.rs | 14 +- plonky2/src/gates/mod.rs | 6 +- plonky2/src/gates/multiplication_extension.rs | 1 - plonky2/src/gates/noop.rs | 1 - plonky2/src/gates/poseidon_mds.rs | 1 - plonky2/src/gates/reducing.rs | 2 - plonky2/src/gates/reducing_extension.rs | 1 - plonky2/src/hash/arch/x86_64/mod.rs | 4 +- .../arch/x86_64/poseidon2_goldilocks_avx2.rs | 9 +- plonky2/src/hash/merkle_proofs.rs | 3 +- plonky2/src/hash/merkle_tree.rs | 16 +- plonky2/src/hash/mod.rs | 4 +- plonky2/src/hash/path_compression.rs | 15 +- plonky2/src/hash/poseidon.rs | 7 +- plonky2/src/hash/poseidon2.rs | 173 ++++++++++++++---- plonky2/src/hash/poseidon_bn128.rs | 8 +- plonky2/src/iop/generator.rs | 1 + plonky2/src/plonk/circuit_builder.rs | 5 +- plonky2/src/plonk/circuit_data.rs | 4 - plonky2/src/plonk/config.rs | 6 +- plonky2/src/plonk/get_challenges.rs | 1 - plonky2/src/plonk/proof.rs | 1 - plonky2/src/plonk/prover.rs | 16 +- plonky2/src/plonk/vanishing_poly.rs | 14 +- plonky2/src/recursion/recursive_verifier.rs | 14 +- plonky2/src/util/serialization/mod.rs | 5 +- plonky2/tests/factorial_test.rs | 6 +- plonky2/tests/fibonacci_test.rs | 4 +- plonky2/tests/range_check_test.rs | 3 +- plonky2/tests/test_utils.rs | 16 +- util/src/lib.rs | 2 +- util/src/pre_compute.rs | 15 +- 50 files changed, 288 insertions(+), 190 deletions(-) diff --git a/field/build.rs b/field/build.rs index e5af9f880d..9830846929 100644 --- a/field/build.rs +++ b/field/build.rs @@ -1,11 +1,11 @@ use std::env; use std::fs::write; -use std::path::{Path}; -#[cfg(feature = "precompile")] -use std::Path::{PathBuf}; +use std::path::Path; use std::process::Command; #[cfg(feature = "precompile")] use std::str::FromStr; +#[cfg(feature = "precompile")] +use std::Path::PathBuf; use anyhow::Context; #[cfg(feature = "precompile")] @@ -29,7 +29,6 @@ fn build_precompile() { _ = write_generated_file(token_stream, "goldilock_root_of_unity.rs"); } fn main() { - #[cfg(feature = "precompile")] build_precompile(); } diff --git a/field/examples/fft.rs b/field/examples/fft.rs index a4a7e72098..59847c555f 100644 --- a/field/examples/fft.rs +++ b/field/examples/fft.rs @@ -2,8 +2,6 @@ use plonky2_field::fft::fft; use plonky2_field::goldilocks_field::GoldilocksField; use plonky2_field::polynomial::PolynomialCoeffs; use plonky2_field::types::Field; - - use rand::random; fn random_fr() -> u64 { diff --git a/field/src/goldilocks_field.rs b/field/src/goldilocks_field.rs index 9182c9e375..a9776aca4f 100644 --- a/field/src/goldilocks_field.rs +++ b/field/src/goldilocks_field.rs @@ -4,16 +4,15 @@ use core::iter::{Product, Sum}; use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; use num::{BigUint, Integer, ToPrimitive}; +#[cfg(feature = "precompile")] +use plonky2_util::log2_strict; use plonky2_util::{assume, branch_hint}; use serde::{Deserialize, Serialize}; -#[cfg(feature = "precompile")] -use plonky2_util::{log2_strict}; #[cfg(feature = "precompile")] use crate::fft::FftRootTable; use crate::ops::Square; use crate::types::{Field, Field64, PrimeField, PrimeField64, Sample}; - #[cfg(feature = "precompile")] use crate::PRE_COMPUTE_ROOT_TABLES; diff --git a/field/src/lib.rs b/field/src/lib.rs index cb543974b1..76d366b0fb 100644 --- a/field/src/lib.rs +++ b/field/src/lib.rs @@ -37,6 +37,7 @@ include!(concat!(env!("OUT_DIR"), "/goldilock_root_of_unity.rs")); #[cfg(feature = "precompile")] use std::collections::HashMap; + #[cfg(feature = "precompile")] use fft::FftRootTable; #[cfg(feature = "precompile")] @@ -79,7 +80,6 @@ lazy_static! { #[cfg(test)] mod test { - #[cfg(feature = "precompile")] #[test] diff --git a/field/src/polynomial/mod.rs b/field/src/polynomial/mod.rs index 125c834d98..c13bbca272 100644 --- a/field/src/polynomial/mod.rs +++ b/field/src/polynomial/mod.rs @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize}; use crate::extension::{Extendable, FieldExtension}; use crate::fft::{fft, fft_with_options, ifft, FftRootTable}; -use crate::types::{Field}; +use crate::types::Field; /// A polynomial in point-value form. /// diff --git a/field/src/secp256k1_base.rs b/field/src/secp256k1_base.rs index abd88f929c..6632a7f83e 100644 --- a/field/src/secp256k1_base.rs +++ b/field/src/secp256k1_base.rs @@ -8,6 +8,7 @@ use itertools::Itertools; use num::bigint::BigUint; use num::{Integer, One}; use serde::{Deserialize, Serialize}; + use crate::types::{Field, PrimeField, Sample}; /// The base field of the secp256k1 elliptic curve. diff --git a/field/src/types.rs b/field/src/types.rs index 7882f3f278..ff2c8983ed 100644 --- a/field/src/types.rs +++ b/field/src/types.rs @@ -7,7 +7,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAss use num::bigint::BigUint; use num::{Integer, One, ToPrimitive, Zero}; -use plonky2_util::{bits_u64}; +use plonky2_util::bits_u64; use rand::rngs::OsRng; use serde::de::DeserializeOwned; use serde::Serialize; @@ -16,8 +16,6 @@ use crate::extension::Frobenius; use crate::fft::FftRootTable; use crate::ops::Square; - - /// Sampling pub trait Sample: Sized { /// Samples a single value using `rng`. @@ -277,10 +275,7 @@ pub trait Field: base.exp_power_of_2(Self::TWO_ADICITY - n_log) } - fn pre_compute_fft_root_table( - _: usize, - ) -> Option<&'static FftRootTable> - { + fn pre_compute_fft_root_table(_: usize) -> Option<&'static FftRootTable> { None } diff --git a/plonky2/build.rs b/plonky2/build.rs index 5fa68a27f0..6b832ce53f 100644 --- a/plonky2/build.rs +++ b/plonky2/build.rs @@ -81,5 +81,5 @@ fn main() { bindings .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); + .expect("Couldn't write bindings!"); } diff --git a/plonky2/examples/bench_recursion.rs b/plonky2/examples/bench_recursion.rs index 6b765747d8..58a9ba72da 100644 --- a/plonky2/examples/bench_recursion.rs +++ b/plonky2/examples/bench_recursion.rs @@ -14,7 +14,6 @@ use core::str::FromStr; use anyhow::{anyhow, Context as _, Result}; use log::{info, Level, LevelFilter}; -use plonky2_maybe_rayon::rayon; use plonky2::gates::noop::NoopGate; use plonky2::hash::hash_types::RichField; use plonky2::iop::witness::{PartialWitness, WitnessWrite}; @@ -27,6 +26,7 @@ use plonky2::plonk::proof::{CompressedProofWithPublicInputs, ProofWithPublicInpu use plonky2::plonk::prover::prove; use plonky2::util::timing::TimingTree; use plonky2_field::extension::Extendable; +use plonky2_maybe_rayon::rayon; use rand::rngs::OsRng; use rand::{RngCore, SeedableRng}; use rand_chacha::ChaCha8Rng; diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index 440e5ebca1..16af536236 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -85,7 +85,8 @@ fn fri_committed_trees, C: GenericConfig, .par_chunks(arity) .map(|chunk: &[F::Extension]| flatten(chunk)) .collect(); - let tree = MerkleTree::::new_from_2d(chunked_values, fri_params.config.cap_height); + let tree = + MerkleTree::::new_from_2d(chunked_values, fri_params.config.cap_height); challenger.observe_cap(&tree.cap); trees.push(tree); diff --git a/plonky2/src/fri/recursive_verifier.rs b/plonky2/src/fri/recursive_verifier.rs index 7b8356184c..038e8f2874 100644 --- a/plonky2/src/fri/recursive_verifier.rs +++ b/plonky2/src/fri/recursive_verifier.rs @@ -10,7 +10,6 @@ use crate::fri::proof::{ }; use crate::fri::structure::{FriBatchInfoTarget, FriInstanceInfoTarget, FriOpeningsTarget}; use crate::fri::{FriConfig, FriParams}; - use crate::gates::gate::Gate; use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate; use crate::gates::interpolation::InterpolationGate; @@ -50,7 +49,7 @@ impl, const D: usize> CircuitBuilder { let start = self.exp_from_bits_const_base(g_inv, x_index_within_coset_bits.iter().rev()); let coset_start = self.mul(start, x); - // NOTE: circom_compatability + // NOTE: circom_compatability // // The answer is gotten by interpolating {(x*g^i, P(x*g^i))} and evaluating at beta. // let interpolation_gate = >::with_max_degree( // arity_bits, @@ -275,7 +274,7 @@ impl, const D: usize> CircuitBuilder { } // sum - // NOTE: circom_compatability + // NOTE: circom_compatability // Multiply the final polynomial by `X`, so that `final_poly` has the maximum degree for // which the LDT will pass. See github.com/mir-protocol/plonky2/pull/436 for details. self.mul_extension(sum, subgroup_x) diff --git a/plonky2/src/fri/verifier.rs b/plonky2/src/fri/verifier.rs index 79ea94b79a..d1efcfa418 100644 --- a/plonky2/src/fri/verifier.rs +++ b/plonky2/src/fri/verifier.rs @@ -159,7 +159,7 @@ pub(crate) fn fri_combine_initial< } // sum - // NOTE: circom_compatability + // NOTE: circom_compatability // Multiply the final polynomial by `X`, so that `final_poly` has the maximum degree for // which the LDT will pass. See github.com/mir-protocol/plonky2/pull/436 for details. sum * subgroup_x diff --git a/plonky2/src/gadgets/interpolation.rs b/plonky2/src/gadgets/interpolation.rs index 9a1f2801e7..1f421f4cd5 100644 --- a/plonky2/src/gadgets/interpolation.rs +++ b/plonky2/src/gadgets/interpolation.rs @@ -3,7 +3,6 @@ use alloc::vec; use plonky2_field::extension::Extendable; - use crate::gates::interpolation::InterpolationGate; use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; @@ -72,7 +71,6 @@ mod tests { use crate::field::extension::FieldExtension; use crate::field::interpolation::interpolant; use crate::field::types::{Field, Sample}; - use crate::gates::high_degree_interpolation::HighDegreeInterpolationGate; use crate::gates::low_degree_interpolation::LowDegreeInterpolationGate; use crate::iop::witness::PartialWitness; diff --git a/plonky2/src/gates/gate.rs b/plonky2/src/gates/gate.rs index 468384068f..2d41aa7ffb 100644 --- a/plonky2/src/gates/gate.rs +++ b/plonky2/src/gates/gate.rs @@ -133,7 +133,7 @@ pub trait Gate, const D: usize>: 'static + Send + S builder: &mut CircuitBuilder, vars: EvaluationTargets, ) -> Vec>; - + fn eval_filtered( &self, mut vars: EvaluationVars, @@ -322,7 +322,12 @@ pub struct PrefixedGate, const D: usize> { } /// A gate's filter designed so that it is non-zero if `s = row`. -pub fn compute_filter(row: usize, group_range: Range, s: K, many_selector: bool) -> K { +pub fn compute_filter( + row: usize, + group_range: Range, + s: K, + many_selector: bool, +) -> K { debug_assert!(group_range.contains(&row)); group_range .filter(|&i| i != row) diff --git a/plonky2/src/gates/high_degree_interpolation.rs b/plonky2/src/gates/high_degree_interpolation.rs index a01fb095a7..3417a5335c 100644 --- a/plonky2/src/gates/high_degree_interpolation.rs +++ b/plonky2/src/gates/high_degree_interpolation.rs @@ -1,4 +1,3 @@ - use alloc::string::String; use alloc::vec::Vec; use alloc::{format, vec}; @@ -94,9 +93,12 @@ impl, const D: usize> Gate fn id(&self) -> String { format!("{self:?}") } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() - } fn deserialize(_src: &mut Buffer, _common_data: &CommonCircuitData) -> IoResult { @@ -235,7 +237,11 @@ impl, const D: usize> SimpleGenerator "InterpolationGenerator".to_string() } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() } diff --git a/plonky2/src/gates/interpolation.rs b/plonky2/src/gates/interpolation.rs index b20bcd2bd7..8d268e3c61 100644 --- a/plonky2/src/gates/interpolation.rs +++ b/plonky2/src/gates/interpolation.rs @@ -1,12 +1,8 @@ - use core::ops::Range; use crate::field::extension::Extendable; use crate::gates::gate::Gate; use crate::hash::hash_types::RichField; - - - use crate::plonk::circuit_data::CommonCircuitData; use crate::util::serialization::{Buffer, IoResult}; /// Trait for gates which interpolate a polynomial, whose points are a (base field) coset of the multiplicative subgroup @@ -19,14 +15,15 @@ pub(crate) trait InterpolationGate, const D: usize> fn id(&self) -> String { // Custom implementation to not have the entire lookup table - format!( - "InterpolationGate", - ) + format!("InterpolationGate",) } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() - } fn deserialize(_src: &mut Buffer, _common_data: &CommonCircuitData) -> IoResult { diff --git a/plonky2/src/gates/lookup.rs b/plonky2/src/gates/lookup.rs index 7e3ceea757..87d289304b 100644 --- a/plonky2/src/gates/lookup.rs +++ b/plonky2/src/gates/lookup.rs @@ -78,7 +78,11 @@ impl, const D: usize> Gate for LookupGate { ) } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { // dst.write_usize(self.num_slots)?; // for (i, lut) in common_data.luts.iter().enumerate() { // if lut == &self.lut { @@ -223,7 +227,11 @@ impl, const D: usize> SimpleGenerator for Loo }; } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() // dst.write_usize(self.row)?; // dst.write_usize(self.slot_nb)?; diff --git a/plonky2/src/gates/lookup_table.rs b/plonky2/src/gates/lookup_table.rs index 48929e5bdf..b6b7977690 100644 --- a/plonky2/src/gates/lookup_table.rs +++ b/plonky2/src/gates/lookup_table.rs @@ -92,7 +92,11 @@ impl, const D: usize> Gate for LookupTableGat ) } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() // dst.write_usize(self.num_slots)?; // dst.write_usize(self.last_lut_row)?; diff --git a/plonky2/src/gates/low_degree_interpolation.rs b/plonky2/src/gates/low_degree_interpolation.rs index 32f6e2121a..0811dd3609 100644 --- a/plonky2/src/gates/low_degree_interpolation.rs +++ b/plonky2/src/gates/low_degree_interpolation.rs @@ -1,4 +1,3 @@ - use alloc::string::String; use alloc::vec::Vec; use alloc::{format, vec}; @@ -87,9 +86,12 @@ impl, const D: usize> Gate for LowDegreeInter fn id(&self) -> String { format!("{self:?}") } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() - } fn deserialize(_src: &mut Buffer, _common_data: &CommonCircuitData) -> IoResult { @@ -534,7 +536,11 @@ impl, const D: usize> SimpleGenerator "InterpolationGenerator".to_string() } - fn serialize(&self, _dst: &mut Vec, _common_data: &CommonCircuitData) -> IoResult<()> { + fn serialize( + &self, + _dst: &mut Vec, + _common_data: &CommonCircuitData, + ) -> IoResult<()> { todo!() // dst.write_usize(self.row)?; // self.gate.serialize(dst, _common_data) diff --git a/plonky2/src/gates/mod.rs b/plonky2/src/gates/mod.rs index 513736d0db..2a552f9e7a 100644 --- a/plonky2/src/gates/mod.rs +++ b/plonky2/src/gates/mod.rs @@ -27,14 +27,14 @@ pub mod arithmetic_base; pub mod arithmetic_extension; pub mod base_sum; pub mod constant; -pub mod interpolation; -pub mod low_degree_interpolation; -pub mod high_degree_interpolation; pub mod coset_interpolation; pub mod exponentiation; pub mod gate; +pub mod high_degree_interpolation; +pub mod interpolation; pub mod lookup; pub mod lookup_table; +pub mod low_degree_interpolation; pub mod multiplication_extension; pub mod noop; pub mod packed_util; diff --git a/plonky2/src/gates/multiplication_extension.rs b/plonky2/src/gates/multiplication_extension.rs index 9cc171c016..d9cf2037d8 100644 --- a/plonky2/src/gates/multiplication_extension.rs +++ b/plonky2/src/gates/multiplication_extension.rs @@ -115,7 +115,6 @@ impl, const D: usize> Gate for MulExtensionGa template_str } - fn eval_unfiltered(&self, vars: EvaluationVars) -> Vec { let const_0 = vars.local_constants[0]; diff --git a/plonky2/src/gates/noop.rs b/plonky2/src/gates/noop.rs index fb07c11952..d1d1d12344 100644 --- a/plonky2/src/gates/noop.rs +++ b/plonky2/src/gates/noop.rs @@ -40,7 +40,6 @@ impl, const D: usize> Gate for NoopGate { unimplemented!() } - fn eval_unfiltered(&self, _vars: EvaluationVars) -> Vec { Vec::new() } diff --git a/plonky2/src/gates/poseidon_mds.rs b/plonky2/src/gates/poseidon_mds.rs index 67b82530b1..cccc52d52b 100644 --- a/plonky2/src/gates/poseidon_mds.rs +++ b/plonky2/src/gates/poseidon_mds.rs @@ -181,7 +181,6 @@ impl + Poseidon, const D: usize> Gate for Pos todo!() } - fn eval_unfiltered(&self, vars: EvaluationVars) -> Vec { let inputs: [_; SPONGE_WIDTH] = (0..SPONGE_WIDTH) .map(|i| vars.get_local_ext_algebra(Self::wires_input(i))) diff --git a/plonky2/src/gates/reducing.rs b/plonky2/src/gates/reducing.rs index db5ae5b005..56f495339a 100644 --- a/plonky2/src/gates/reducing.rs +++ b/plonky2/src/gates/reducing.rs @@ -102,7 +102,6 @@ impl, const D: usize> Gate for ReducingGate String { let mut template_str = format!( "template Reducing$NUM_COEFFS() {{ @@ -176,7 +175,6 @@ function r_wires_accs_start(i, num_coeffs) {{ template_str } - fn eval_unfiltered_base_one( &self, vars: EvaluationVarsBase, diff --git a/plonky2/src/gates/reducing_extension.rs b/plonky2/src/gates/reducing_extension.rs index d40d181a39..f19b296022 100644 --- a/plonky2/src/gates/reducing_extension.rs +++ b/plonky2/src/gates/reducing_extension.rs @@ -81,7 +81,6 @@ impl, const D: usize> Gate for ReducingExtens Ok(Self::new(num_coeffs)) } - fn export_circom_verification_code(&self) -> String { let mut template_str = format!( "template ReducingExtension$NUM_COEFFS() {{ diff --git a/plonky2/src/hash/arch/x86_64/mod.rs b/plonky2/src/hash/arch/x86_64/mod.rs index d3d04807ae..7229fc94fd 100644 --- a/plonky2/src/hash/arch/x86_64/mod.rs +++ b/plonky2/src/hash/arch/x86_64/mod.rs @@ -3,8 +3,8 @@ // // - BMI2 (for MULX and SHRX) // #[cfg(all(target_feature = "avx2", target_feature = "bmi2"))] #[cfg(target_feature = "avx2")] -pub mod poseidon_goldilocks_avx2; +pub mod goldilocks_avx2; #[cfg(target_feature = "avx2")] pub mod poseidon2_goldilocks_avx2; #[cfg(target_feature = "avx2")] -pub mod goldilocks_avx2; \ No newline at end of file +pub mod poseidon_goldilocks_avx2; diff --git a/plonky2/src/hash/arch/x86_64/poseidon2_goldilocks_avx2.rs b/plonky2/src/hash/arch/x86_64/poseidon2_goldilocks_avx2.rs index f36c780d74..fde9bd5863 100644 --- a/plonky2/src/hash/arch/x86_64/poseidon2_goldilocks_avx2.rs +++ b/plonky2/src/hash/arch/x86_64/poseidon2_goldilocks_avx2.rs @@ -1,13 +1,8 @@ use core::arch::x86_64::*; +use super::goldilocks_avx2::{add_avx, add_avx_a_sc, mult_avx}; /// Code taken and adapted from: https://github.com/0xPolygonHermez/goldilocks/blob/master/src/goldilocks_base_field_avx.hpp -use crate::hash::{ - hash_types::RichField, poseidon2::RC12, poseidon2::SPONGE_WIDTH, -}; - -use super::goldilocks_avx2::add_avx; -use super::goldilocks_avx2::add_avx_a_sc; -use super::goldilocks_avx2::mult_avx; +use crate::hash::{hash_types::RichField, poseidon2::RC12, poseidon2::SPONGE_WIDTH}; #[inline(always)] pub fn add_rc_avx(state: &mut [F; SPONGE_WIDTH], rc: &[u64; SPONGE_WIDTH]) diff --git a/plonky2/src/hash/merkle_proofs.rs b/plonky2/src/hash/merkle_proofs.rs index 15b26f20ec..5f1b7cb82d 100644 --- a/plonky2/src/hash/merkle_proofs.rs +++ b/plonky2/src/hash/merkle_proofs.rs @@ -199,7 +199,8 @@ mod tests { let n = 1 << log_n; let cap_height = 1; let leaves = random_data::(n, 7); - let tree = MerkleTree::>::Hasher>::new_from_2d(leaves, cap_height); + let tree = + MerkleTree::>::Hasher>::new_from_2d(leaves, cap_height); let i: usize = OsRng.gen_range(0..n); let proof = tree.prove(i); diff --git a/plonky2/src/hash/merkle_tree.rs b/plonky2/src/hash/merkle_tree.rs index 9cd30ea054..59459fc06a 100644 --- a/plonky2/src/hash/merkle_tree.rs +++ b/plonky2/src/hash/merkle_tree.rs @@ -1024,11 +1024,13 @@ impl> MerkleTree { for i in 0..positions.len() { let subtree_offset = positions[i] / subtree_digests_len; let idx_in_subtree = positions[i] % subtree_digests_len; - let digest_idx = subtree_offset * subtree_digests_len + 2 * (idx_in_subtree + 1); + let digest_idx = + subtree_offset * subtree_digests_len + 2 * (idx_in_subtree + 1); unsafe { let left_digest = digests_buf[digest_idx].assume_init(); let right_digest = digests_buf[digest_idx + 1].assume_init(); - digests_buf[positions[i]].write(H::two_to_one(left_digest, right_digest)); + digests_buf[positions[i]] + .write(H::two_to_one(left_digest, right_digest)); } } } @@ -1383,9 +1385,15 @@ mod tests { #[test] fn test_change_leaf_and_update_range() -> Result<()> { for h in 0..11 { - println!("Run verify_change_leaf_and_update_range_one_by_one() for height {:?}", h); + println!( + "Run verify_change_leaf_and_update_range_one_by_one() for height {:?}", + h + ); verify_change_leaf_and_update_range_one_by_one(1024, 68, h, 32, 48); - println!("Run verify_change_leaf_and_update_range() for height {:?}", h); + println!( + "Run verify_change_leaf_and_update_range() for height {:?}", + h + ); verify_change_leaf_and_update_range(1024, 68, h, 32, 48); } diff --git a/plonky2/src/hash/mod.rs b/plonky2/src/hash/mod.rs index af470cc3cd..1a91d38960 100644 --- a/plonky2/src/hash/mod.rs +++ b/plonky2/src/hash/mod.rs @@ -9,6 +9,6 @@ pub mod merkle_proofs; pub mod merkle_tree; pub mod path_compression; pub mod poseidon; -pub mod poseidon_goldilocks; -pub mod poseidon_bn128; pub mod poseidon2; +pub mod poseidon_bn128; +pub mod poseidon_goldilocks; diff --git a/plonky2/src/hash/path_compression.rs b/plonky2/src/hash/path_compression.rs index 16c10be9e9..5a7f7e1ca4 100644 --- a/plonky2/src/hash/path_compression.rs +++ b/plonky2/src/hash/path_compression.rs @@ -129,8 +129,14 @@ mod tests { type F = >::F; let h = 10; let cap_height = 3; - let vs = (0..1 << h).flat_map(|_| vec![F::rand()]).collect::>(); - let mt = MerkleTree::>::Hasher>::new_from_1d(vs.clone(), 1, cap_height); + let vs = (0..1 << h) + .flat_map(|_| vec![F::rand()]) + .collect::>(); + let mt = MerkleTree::>::Hasher>::new_from_1d( + vs.clone(), + 1, + cap_height, + ); let mut rng = OsRng; let k = rng.gen_range(1..=1 << h); @@ -139,7 +145,10 @@ mod tests { let compressed_proofs = compress_merkle_proofs(cap_height, &indices, &proofs); let decompressed_proofs = decompress_merkle_proofs( - &indices.iter().map(|&i| vec![vs[i].clone()]).collect::>(), + &indices + .iter() + .map(|&i| vec![vs[i].clone()]) + .collect::>(), &indices, &compressed_proofs, h, diff --git a/plonky2/src/hash/poseidon.rs b/plonky2/src/hash/poseidon.rs index 0fb10f62e5..03591217c4 100644 --- a/plonky2/src/hash/poseidon.rs +++ b/plonky2/src/hash/poseidon.rs @@ -8,6 +8,9 @@ use core::fmt::Debug; use plonky2_field::packed::PackedField; use unroll::unroll_for_loops; +#[cfg(target_feature = "avx2")] +use super::arch::x86_64::poseidon_goldilocks_avx2::poseidon_avx; +use super::hash_types::HashOutTarget; use crate::field::extension::{Extendable, FieldExtension}; use crate::field::types::{Field, PrimeField64}; use crate::gates::gate::Gate; @@ -19,10 +22,6 @@ use crate::iop::ext_target::ExtensionTarget; use crate::iop::target::{BoolTarget, Target}; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::config::{AlgebraicHasher, Hasher, HasherType}; -#[cfg(target_feature = "avx2")] -use super::arch::x86_64::poseidon_goldilocks_avx2::{poseidon_avx}; - -use super::hash_types::HashOutTarget; pub const SPONGE_RATE: usize = 8; pub const SPONGE_CAPACITY: usize = 4; diff --git a/plonky2/src/hash/poseidon2.rs b/plonky2/src/hash/poseidon2.rs index bf5543459b..3a5eef810d 100644 --- a/plonky2/src/hash/poseidon2.rs +++ b/plonky2/src/hash/poseidon2.rs @@ -5,12 +5,12 @@ use std::fmt::Debug; use plonky2_field::goldilocks_field::GoldilocksField; +#[cfg(target_feature = "avx2")] +use super::arch::x86_64::goldilocks_avx2::sbox_avx; #[cfg(target_feature = "avx2")] use super::arch::x86_64::poseidon2_goldilocks_avx2::{ - add_rc_avx, internal_layer_avx, matmul_internal_avx, permute_mut_avx + add_rc_avx, internal_layer_avx, matmul_internal_avx, permute_mut_avx, }; -#[cfg(target_feature = "avx2")] -use super::arch::x86_64::goldilocks_avx2::sbox_avx; use super::hash_types::{HashOutTarget, NUM_HASH_OUT_ELTS}; use crate::field::extension::Extendable; use crate::hash::hash_types::{HashOut, RichField}; @@ -177,36 +177,140 @@ pub const RC12: [[u64; 12]; 30] = [ // shifted RC12 pub const RC12S: [[u64; 12]; 30] = [ -[ 10654658252008148806, 12732721046115478915, 11512947417839672150, 1401843886103475302, 7913650470312515876, 7920054924642234216, 366403276608448557, 16959438770370314456, 11440941203916098056, 1171558765729807275, 13835765411871471513, 14555842921774229342, ], -[ 17947898870904357247, 8450415934600084880, 11743359809955831813, 17223059160992196131, 9089082615708530893, 5912719196969379861, 10480482607258205811, 14888821111321440581, 6955365572830490763, 9276227180382669156, 17307827029798646038, 11820434478121422991, ], -[ 12565996948317947059, 16004728232246313244, 13921301609177509515, 13403059269083677479, 8617701609667357251, 9116804684378412089, 3929557962267443389, 15529629088292616235, 14197823950862826729, 2035331642115509393, 9805108118114736012, 9099913990048459796, ], -[ 1026654194469555189, 4098575470952884349, 3797353172044721135, 2193618458570416876, 16445167831650995221, 11831289909755408793, 11815268094046945137, 1262117415450222337, 256814012054134207, 11868513882264716282, 7018927802910386802, 2980366554041532327, ], -[ 14618548234199319318, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 8717764302033564907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 16782764542401538795, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 9773005165759497088, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 6435083291554491876, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 854999840315953784, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 11573240284262856591, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 3882539224779405431, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 3645281165379277818, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 247958278701199998, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 13803661673480182488, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 3999361100096645764, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 13778404612483403359, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 16842502148784698707, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 13771220544101267585, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 14885415569422780440, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 6500501012810503684, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 4362258637902042377, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 16213789966532040281, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 15596630020393660587, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 10229228829583901671, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 8627597988514797083, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ], -[ 5083411456108700237, 3429892838976581081, 1664062632931030693, 16444445019545409268, 730213817001898599, 4274248329223977626, 8916920594649426435, 8088562701233626721, 15909674251279171579, 1969699852088919711, 1010423738946982735, 12585591589417715671, ], -[ 17818773343550962569, 16976783299797802369, 3191846822621445139, 3294079550172100026, 12480380069755374307, 11410841076433680578, 9881047205151486223, 17883341906324984797, 3302726834433602831, 3302481358914233521, 6164789653124775896, 17104338942271114717, ], -[ 12135066448077487289, 15644024288647356214, 9546916967583135861, 2495294439197465417, 11672504105643821400, 8769642145137754752, 5938416915402582158, 13011876837921594175, 10505483810315321379, 18072867201336481358, 17604224438915496998, 11385352261445903168, ], -[ 11663523522544020954, 8298522965235358559, 4597633298275991147, 8290333594259490018, 7845075819942463721, 8741066967122268185, 14908372956393015237, 2392568623827813298, 11746226922035381066, 3360746931218020307, 8617886691769859783, 1598192532018351508, ] + [ + 10654658252008148806, + 12732721046115478915, + 11512947417839672150, + 1401843886103475302, + 7913650470312515876, + 7920054924642234216, + 366403276608448557, + 16959438770370314456, + 11440941203916098056, + 1171558765729807275, + 13835765411871471513, + 14555842921774229342, + ], + [ + 17947898870904357247, + 8450415934600084880, + 11743359809955831813, + 17223059160992196131, + 9089082615708530893, + 5912719196969379861, + 10480482607258205811, + 14888821111321440581, + 6955365572830490763, + 9276227180382669156, + 17307827029798646038, + 11820434478121422991, + ], + [ + 12565996948317947059, + 16004728232246313244, + 13921301609177509515, + 13403059269083677479, + 8617701609667357251, + 9116804684378412089, + 3929557962267443389, + 15529629088292616235, + 14197823950862826729, + 2035331642115509393, + 9805108118114736012, + 9099913990048459796, + ], + [ + 1026654194469555189, + 4098575470952884349, + 3797353172044721135, + 2193618458570416876, + 16445167831650995221, + 11831289909755408793, + 11815268094046945137, + 1262117415450222337, + 256814012054134207, + 11868513882264716282, + 7018927802910386802, + 2980366554041532327, + ], + [14618548234199319318, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [8717764302033564907, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [16782764542401538795, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [9773005165759497088, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [6435083291554491876, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [854999840315953784, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [11573240284262856591, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [3882539224779405431, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [3645281165379277818, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [247958278701199998, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [13803661673480182488, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [3999361100096645764, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [13778404612483403359, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [16842502148784698707, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [13771220544101267585, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [14885415569422780440, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [6500501012810503684, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [4362258637902042377, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [16213789966532040281, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [15596630020393660587, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [10229228829583901671, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [8627597988514797083, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [ + 5083411456108700237, + 3429892838976581081, + 1664062632931030693, + 16444445019545409268, + 730213817001898599, + 4274248329223977626, + 8916920594649426435, + 8088562701233626721, + 15909674251279171579, + 1969699852088919711, + 1010423738946982735, + 12585591589417715671, + ], + [ + 17818773343550962569, + 16976783299797802369, + 3191846822621445139, + 3294079550172100026, + 12480380069755374307, + 11410841076433680578, + 9881047205151486223, + 17883341906324984797, + 3302726834433602831, + 3302481358914233521, + 6164789653124775896, + 17104338942271114717, + ], + [ + 12135066448077487289, + 15644024288647356214, + 9546916967583135861, + 2495294439197465417, + 11672504105643821400, + 8769642145137754752, + 5938416915402582158, + 13011876837921594175, + 10505483810315321379, + 18072867201336481358, + 17604224438915496998, + 11385352261445903168, + ], + [ + 11663523522544020954, + 8298522965235358559, + 4597633298275991147, + 8290333594259490018, + 7845075819942463721, + 8741066967122268185, + 14908372956393015237, + 2392568623827813298, + 11746226922035381066, + 3360746931218020307, + 8617886691769859783, + 1598192532018351508, + ], ]; extern crate alloc; @@ -551,7 +655,8 @@ impl AlgebraicHasher for Poseidon2Hash { _builder: &mut CircuitBuilder, ) -> HashOutTarget where - F: RichField + Extendable { + F: RichField + Extendable, + { todo!() } } diff --git a/plonky2/src/hash/poseidon_bn128.rs b/plonky2/src/hash/poseidon_bn128.rs index ca53956e7c..4f2b89d9e1 100644 --- a/plonky2/src/hash/poseidon_bn128.rs +++ b/plonky2/src/hash/poseidon_bn128.rs @@ -210,11 +210,10 @@ impl GenericConfig<2> for PoseidonBN128GoldilocksConfig { #[cfg(test)] mod tests { use anyhow::Result; - use plonky2_field::types::{Field}; + use plonky2_field::types::Field; + use super::PoseidonBN128Hash; - use crate::plonk::{config::{ - GenericConfig, GenericHashOut, Hasher, PoseidonGoldilocksConfig, - }}; + use crate::plonk::config::{GenericConfig, GenericHashOut, Hasher, PoseidonGoldilocksConfig}; #[test] fn test_poseidon_bn128_hash_no_pad() -> Result<()> { @@ -286,5 +285,4 @@ mod tests { Ok(()) } - } diff --git a/plonky2/src/iop/generator.rs b/plonky2/src/iop/generator.rs index 141a63a6d6..3139309d99 100644 --- a/plonky2/src/iop/generator.rs +++ b/plonky2/src/iop/generator.rs @@ -7,6 +7,7 @@ use alloc::{ }; use core::fmt::Debug; use core::marker::PhantomData; + use dyn_clone::DynClone; use crate::field::extension::Extendable; diff --git a/plonky2/src/plonk/circuit_builder.rs b/plonky2/src/plonk/circuit_builder.rs index 0d0f412cc1..2010a6c974 100644 --- a/plonky2/src/plonk/circuit_builder.rs +++ b/plonky2/src/plonk/circuit_builder.rs @@ -10,7 +10,6 @@ use hashbrown::{HashMap, HashSet}; use itertools::Itertools; use log::{debug, info, warn, Level}; - use crate::field::cosets::get_unique_coset_shifts; use crate::field::extension::{Extendable, FieldExtension}; use crate::field::fft::fft_root_table; @@ -25,11 +24,11 @@ use crate::gates::arithmetic_base::ArithmeticGate; use crate::gates::arithmetic_extension::ArithmeticExtensionGate; use crate::gates::constant::ConstantGate; use crate::gates::gate::{CurrentSlot, Gate, GateInstance, GateRef}; -use crate::gates::lookup::{Lookup}; +use crate::gates::lookup::Lookup; use crate::gates::lookup_table::LookupTable; use crate::gates::noop::NoopGate; use crate::gates::public_input::PublicInputGate; -use crate::gates::selectors::{selector_polynomials}; +use crate::gates::selectors::selector_polynomials; use crate::hash::hash_types::{HashOut, HashOutTarget, MerkleCapTarget, RichField}; use crate::hash::merkle_proofs::MerkleProofTarget; use crate::hash::merkle_tree::MerkleCap; diff --git a/plonky2/src/plonk/circuit_data.rs b/plonky2/src/plonk/circuit_data.rs index f3beae5a88..0d655b406e 100644 --- a/plonky2/src/plonk/circuit_data.rs +++ b/plonky2/src/plonk/circuit_data.rs @@ -21,7 +21,6 @@ use std::collections::BTreeMap; use anyhow::Result; use serde::Serialize; - use crate::field::extension::Extendable; use crate::field::fft::FftRootTable; use crate::field::types::Field; @@ -33,8 +32,6 @@ use crate::fri::structure::{ }; use crate::fri::{FriConfig, FriParams}; use crate::gates::gate::GateRef; - - use crate::gates::selectors::SelectorsInfo; use crate::hash::hash_types::{HashOutTarget, MerkleCapTarget, RichField}; use crate::hash::merkle_tree::MerkleCap; @@ -442,7 +439,6 @@ pub struct CommonCircuitData, const D: usize> { /// The number of partial products needed to compute the `Z` polynomials. pub num_partial_products: usize, - // /// The number of lookup polynomials. // pub num_lookup_polys: usize, diff --git a/plonky2/src/plonk/config.rs b/plonky2/src/plonk/config.rs index 9ca21dad41..97539a1791 100644 --- a/plonky2/src/plonk/config.rs +++ b/plonky2/src/plonk/config.rs @@ -101,9 +101,9 @@ pub trait AlgebraicHasher: Hasher> { ) -> Self::AlgebraicPermutation where F: RichField + Extendable; - - /// Circuit to calculate hash out for public inputs. - fn public_inputs_hash( + + /// Circuit to calculate hash out for public inputs. + fn public_inputs_hash( inputs: Vec, builder: &mut CircuitBuilder, ) -> HashOutTarget diff --git a/plonky2/src/plonk/get_challenges.rs b/plonky2/src/plonk/get_challenges.rs index a718913578..f15b233cb4 100644 --- a/plonky2/src/plonk/get_challenges.rs +++ b/plonky2/src/plonk/get_challenges.rs @@ -3,7 +3,6 @@ use alloc::{vec, vec::Vec}; use hashbrown::HashSet; - use crate::field::extension::Extendable; use crate::field::polynomial::PolynomialCoeffs; use crate::fri::proof::{CompressedFriProof, FriChallenges, FriProof, FriProofTarget}; diff --git a/plonky2/src/plonk/proof.rs b/plonky2/src/plonk/proof.rs index 95f5bc37dd..a5620c5dd1 100644 --- a/plonky2/src/plonk/proof.rs +++ b/plonky2/src/plonk/proof.rs @@ -270,7 +270,6 @@ pub struct ProofChallenges, const D: usize> { // /// Lookup challenges. // pub plonk_deltas: Vec, - /// Point at which the PLONK polynomials are opened. pub plonk_zeta: F::Extension, diff --git a/plonky2/src/plonk/prover.rs b/plonky2/src/plonk/prover.rs index 69e69b1d09..b9e6d3c3e1 100644 --- a/plonky2/src/plonk/prover.rs +++ b/plonky2/src/plonk/prover.rs @@ -2,33 +2,25 @@ #[cfg(not(feature = "std"))] use alloc::{format, vec, vec::Vec}; - use core::mem::swap; use anyhow::{ensure, Result}; - use plonky2_maybe_rayon::*; - use crate::field::extension::Extendable; use crate::field::polynomial::{PolynomialCoeffs, PolynomialValues}; use crate::field::types::Field; use crate::field::zero_poly_coset::ZeroPolyOnCoset; use crate::fri::oracle::PolynomialBatch; - - - use crate::hash::hash_types::RichField; use crate::iop::challenger::Challenger; use crate::iop::generator::generate_partial_witness; - use crate::iop::witness::{MatrixWitness, PartialWitness, PartitionWitness, Witness}; - use crate::plonk::circuit_data::{CommonCircuitData, ProverOnlyCircuitData}; use crate::plonk::config::{GenericConfig, Hasher}; use crate::plonk::plonk_common::PlonkOracle; use crate::plonk::proof::{OpeningSet, Proof, ProofWithPublicInputs}; -use crate::plonk::vanishing_poly::{eval_vanishing_poly_base_batch}; +use crate::plonk::vanishing_poly::eval_vanishing_poly_base_batch; use crate::plonk::vars::EvaluationVarsBaseBatch; use crate::timed; use crate::util::partial_products::{partial_products_and_z_gx, quotient_chunk_products}; @@ -241,7 +233,7 @@ where timing, "commit to partial products, Z's and, if any, lookup polynomials", PolynomialBatch::from_values( - zs_partial_products,// zs_partial_products_lookups, + zs_partial_products, // zs_partial_products_lookups, config.fri_config.rate_bits, config.zero_knowledge && PlonkOracle::ZS_PARTIAL_PRODUCTS.blinding, config.fri_config.cap_height, @@ -351,9 +343,9 @@ where openings, opening_proof, }; - #[cfg(feature="timing")] + #[cfg(feature = "timing")] timing.print(); - + Ok(ProofWithPublicInputs:: { proof, public_inputs, diff --git a/plonky2/src/plonk/vanishing_poly.rs b/plonky2/src/plonk/vanishing_poly.rs index 15de357e3e..ff555ef446 100644 --- a/plonky2/src/plonk/vanishing_poly.rs +++ b/plonky2/src/plonk/vanishing_poly.rs @@ -1,32 +1,22 @@ #[cfg(not(feature = "std"))] use alloc::{format, vec, vec::Vec}; - - - - - - - use crate::field::batch_util::batch_add_inplace; use crate::field::extension::{Extendable, FieldExtension}; use crate::field::types::Field; use crate::field::zero_poly_coset::ZeroPolyOnCoset; - - - use crate::hash::hash_types::RichField; use crate::iop::ext_target::ExtensionTarget; use crate::iop::target::Target; use crate::plonk::circuit_builder::CircuitBuilder; use crate::plonk::circuit_data::CommonCircuitData; +use crate::plonk::config::GenericConfig; use crate::plonk::plonk_common; use crate::plonk::plonk_common::eval_l_0_circuit; use crate::plonk::vars::{EvaluationTargets, EvaluationVars, EvaluationVarsBaseBatch}; use crate::util::partial_products::{check_partial_products, check_partial_products_circuit}; use crate::util::reducing::ReducingFactorTarget; use crate::util::strided_view::PackedStridedView; -use crate::plonk::config::GenericConfig; use crate::with_context; // /// Get the polynomial associated to a lookup table with current challenges. @@ -635,7 +625,6 @@ pub fn evaluate_gate_constraints_base_batch< constraints_batch } - pub fn evaluate_gate_constraints_circuit< F: RichField + Extendable, C: GenericConfig, @@ -799,7 +788,6 @@ pub(crate) fn eval_vanishing_poly_circuit< .collect() } - // Same as `check_lookup_constraints`, but for the recursive case. // pub fn check_lookup_constraints_circuit, const D: usize>( // builder: &mut CircuitBuilder, diff --git a/plonky2/src/recursion/recursive_verifier.rs b/plonky2/src/recursion/recursive_verifier.rs index 1cd3acda19..4f9af85e9c 100644 --- a/plonky2/src/recursion/recursive_verifier.rs +++ b/plonky2/src/recursion/recursive_verifier.rs @@ -82,7 +82,7 @@ impl, const D: usize> CircuitBuilder { let vanishing_polys_zeta = with_context!( self, "evaluate the vanishing polynomial at our challenge point, zeta.", - eval_vanishing_poly_circuit::( + eval_vanishing_poly_circuit::( self, inner_common_data, challenges.plonk_zeta, @@ -149,7 +149,10 @@ impl, const D: usize> CircuitBuilder { } } - fn add_virtual_proof>(&mut self, common_data: &CommonCircuitData) -> ProofTarget { + fn add_virtual_proof>( + &mut self, + common_data: &CommonCircuitData, + ) -> ProofTarget { let config = &common_data.config; let fri_params = &common_data.fri_params; let cap_height = fri_params.config.cap_height; @@ -159,7 +162,7 @@ impl, const D: usize> CircuitBuilder { common_data.num_preprocessed_polys(), config.num_wires + salt, // NOTE: v2 change - common_data.num_zs_partial_products_polys()+ salt, // + common_data.num_all_lookup_polys() , + common_data.num_zs_partial_products_polys() + salt, // + common_data.num_all_lookup_polys() , ]; if common_data.num_quotient_polys() > 0 { @@ -175,7 +178,10 @@ impl, const D: usize> CircuitBuilder { } } - fn add_opening_set>(&mut self, common_data: &CommonCircuitData) -> OpeningSetTarget { + fn add_opening_set>( + &mut self, + common_data: &CommonCircuitData, + ) -> OpeningSetTarget { let config = &common_data.config; let num_challenges = config.num_challenges; let total_partial_products = num_challenges * common_data.num_partial_products; diff --git a/plonky2/src/util/serialization/mod.rs b/plonky2/src/util/serialization/mod.rs index 5e71694c5d..9b94b0c9b2 100644 --- a/plonky2/src/util/serialization/mod.rs +++ b/plonky2/src/util/serialization/mod.rs @@ -335,10 +335,7 @@ pub trait Read { let cap_height = self.read_usize()?; let cap = self.read_merkle_cap::(cap_height)?; Ok(MerkleTree::new_from_fields( - leaves_1d, - leaf_len, - digests, - cap, + leaves_1d, leaf_len, digests, cap, )) } diff --git a/plonky2/tests/factorial_test.rs b/plonky2/tests/factorial_test.rs index b8b596db93..1a493a195e 100644 --- a/plonky2/tests/factorial_test.rs +++ b/plonky2/tests/factorial_test.rs @@ -1,4 +1,3 @@ - use plonky2::field::types::Field; use plonky2::iop::witness::{PartialWitness, WitnessWrite}; use plonky2::plonk::circuit_builder::CircuitBuilder; @@ -11,8 +10,7 @@ use crate::test_utils::init_cuda; pub mod test_utils; #[test] -fn test_factorial_proof(){ - +fn test_factorial_proof() { #[cfg(feature = "cuda")] init_cuda(); @@ -46,5 +44,5 @@ fn test_factorial_proof(){ proof.public_inputs[0], proof.public_inputs[1] ); - let _= data.verify(proof); + let _ = data.verify(proof); } diff --git a/plonky2/tests/fibonacci_test.rs b/plonky2/tests/fibonacci_test.rs index 0e4a1143cb..90478feebb 100644 --- a/plonky2/tests/fibonacci_test.rs +++ b/plonky2/tests/fibonacci_test.rs @@ -3,6 +3,7 @@ use plonky2::iop::witness::{PartialWitness, WitnessWrite}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + #[cfg(feature = "cuda")] use crate::test_utils::init_cuda; #[cfg(feature = "cuda")] @@ -10,7 +11,6 @@ pub mod test_utils; #[test] fn test_fibonacci_proof() { - #[cfg(feature = "cuda")] init_cuda(); @@ -45,4 +45,4 @@ fn test_fibonacci_proof() { ); let _ = data.verify(proof); -} \ No newline at end of file +} diff --git a/plonky2/tests/range_check_test.rs b/plonky2/tests/range_check_test.rs index 7bd2a0ab13..204c0917e6 100644 --- a/plonky2/tests/range_check_test.rs +++ b/plonky2/tests/range_check_test.rs @@ -1,9 +1,9 @@ - use plonky2::field::types::Field; use plonky2::iop::witness::{PartialWitness, WitnessWrite}; use plonky2::plonk::circuit_builder::CircuitBuilder; use plonky2::plonk::circuit_data::CircuitConfig; use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + #[cfg(feature = "cuda")] use crate::test_utils::init_cuda; #[cfg(feature = "cuda")] @@ -34,6 +34,5 @@ fn test_range_check_proof() { let data = builder.build::(); let proof = data.prove(pw).unwrap(); - let _ = data.verify(proof); } diff --git a/plonky2/tests/test_utils.rs b/plonky2/tests/test_utils.rs index 3ba79ccf3e..c4d52c4c04 100644 --- a/plonky2/tests/test_utils.rs +++ b/plonky2/tests/test_utils.rs @@ -1,12 +1,8 @@ #[cfg(feature = "cuda")] pub fn init_cuda() { + use cryptography_cuda::{get_number_of_gpus_rs, init_coset_rs, init_twiddle_factors_rs}; use plonky2_field::goldilocks_field::GoldilocksField; - use plonky2_field::types::Field; - use plonky2_field::types::PrimeField64; - - use cryptography_cuda::{ - get_number_of_gpus_rs, init_twiddle_factors_rs, init_coset_rs, - }; + use plonky2_field::types::{Field, PrimeField64}; let num_of_gpus = get_number_of_gpus_rs(); println!("num of gpus: {:?}", num_of_gpus); @@ -16,11 +12,15 @@ pub fn init_cuda() { let mut device_id = 0; while device_id < num_of_gpus { - init_coset_rs(device_id, 24, GoldilocksField::coset_shift().to_canonical_u64()); + init_coset_rs( + device_id, + 24, + GoldilocksField::coset_shift().to_canonical_u64(), + ); for log_n in &log_ns { // println!("{:?}", log_n); init_twiddle_factors_rs(device_id, *log_n); } device_id = device_id + 1; } -} \ No newline at end of file +} diff --git a/util/src/lib.rs b/util/src/lib.rs index 2458e95711..9bedc6d727 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -10,8 +10,8 @@ use core::ptr::{swap, swap_nonoverlapping}; use crate::transpose_util::transpose_in_place_square; -mod transpose_util; pub mod pre_compute; +mod transpose_util; pub const fn bits_u64(n: u64) -> usize { (64 - n.leading_zeros()) as usize diff --git a/util/src/pre_compute.rs b/util/src/pre_compute.rs index 617762de7f..1e276f0f04 100644 --- a/util/src/pre_compute.rs +++ b/util/src/pre_compute.rs @@ -1,8 +1,8 @@ pub const PRE_COMPUTE_START: usize = 10; pub const PRE_COMPUTE_END: usize = 18; -pub const fn get_pre_compute_size(start:usize, end: usize) -> usize { - let nums = (1 << (end-start + 1)) -1 ; +pub const fn get_pre_compute_size(start: usize, end: usize) -> usize { + let nums = (1 << (end - start + 1)) - 1; let base = 1 << start; return base * nums; } @@ -13,10 +13,9 @@ mod tests { #[test] fn test_get_pre_compute_size() { - assert_eq!(get_pre_compute_size(10,10), 1024); - assert_eq!(get_pre_compute_size(10,11), 3072); - assert_eq!(get_pre_compute_size(14,14), 16384); - assert_eq!(get_pre_compute_size(10,16), 130048); - + assert_eq!(get_pre_compute_size(10, 10), 1024); + assert_eq!(get_pre_compute_size(10, 11), 3072); + assert_eq!(get_pre_compute_size(14, 14), 16384); + assert_eq!(get_pre_compute_size(10, 16), 130048); } -} \ No newline at end of file +} From 8be66eeedccbb35da70a0b25324588a79352e2e7 Mon Sep 17 00:00:00 2001 From: cliff0412 Date: Fri, 19 Apr 2024 11:13:00 +0800 Subject: [PATCH 5/5] update cu --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 87c9864296..f3c625b8a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["field", "maybe_rayon", "plonky2", "starky", "util", "gen"] resolver = "2" [workspace.dependencies] -cryptography_cuda = { git = "ssh://git@github.com/okx/cryptography_cuda.git", rev = "d44b861cf241d27688525e7a8f082199a2abcbfa", features = [ +cryptography_cuda = { git = "ssh://git@github.com/okx/cryptography_cuda.git", rev = "173510160183f3299f4765b30bd4f2c1685353f9", features = [ "no_cuda", ] } ahash = { version = "0.8.7", default-features = false, features = [