From 16ddfcb94cf8a1364aba6f8ebe4174f08c030e6b Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 21 Jul 2022 17:10:40 -0400 Subject: [PATCH 01/11] make env_logger dev-dependency --- plonky2/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index 9c019640..6f491e1d 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -13,7 +13,6 @@ default-run = "generate_constants" [dependencies] plonky2_field = { path = "../field" } plonky2_util = { path = "../util" } -env_logger = "0.9.0" log = "0.4.14" itertools = "0.10.0" num = { version = "0.4", features = [ "rand" ] } @@ -29,6 +28,7 @@ static_assertions = "1.1.0" [dev-dependencies] criterion = "0.3.5" +env_logger = "0.9.0" tynm = "0.1.6" structopt = "0.3.26" num_cpus = "1.13.1" From 585495d314defc65914d57ae5c1f950576564bd8 Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Wed, 27 Jul 2022 23:53:26 -0400 Subject: [PATCH 02/11] feature-gate stub TimingTree --- plonky2/Cargo.toml | 4 ++++ plonky2/src/fri/oracle.rs | 6 +++--- plonky2/src/fri/prover.rs | 6 +++--- plonky2/src/util/timing.rs | 43 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/plonky2/Cargo.toml b/plonky2/Cargo.toml index 6f491e1d..8542f307 100644 --- a/plonky2/Cargo.toml +++ b/plonky2/Cargo.toml @@ -10,6 +10,10 @@ categories = ["cryptography"] edition = "2021" default-run = "generate_constants" +[features] +default = ["timing"] +timing = [] + [dependencies] plonky2_field = { path = "../field" } plonky2_util = { path = "../util" } diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index 312b458b..7499e696 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -71,7 +71,7 @@ impl, C: GenericConfig, const D: usize> rate_bits: usize, blinding: bool, cap_height: usize, - timing: &mut TimingTree, + _timing: &mut TimingTree, fft_root_table: Option<&FftRootTable>, ) -> Self where @@ -79,7 +79,7 @@ impl, C: GenericConfig, const D: usize> { let degree = polynomials[0].len(); let lde_values = timed!( - timing, + _timing, "FFT + blinding", Self::lde_values(&polynomials, rate_bits, blinding, fft_root_table) ); @@ -87,7 +87,7 @@ impl, C: GenericConfig, const D: usize> let mut leaves = timed!(timing, "transpose LDEs", transpose(&lde_values)); reverse_index_bits_in_place(&mut leaves); let merkle_tree = timed!( - timing, + _timing, "build Merkle tree", MerkleTree::new(leaves, cap_height) ); diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index 6136a9a1..f8467d2b 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -23,7 +23,7 @@ pub fn fri_proof, C: GenericConfig, const lde_polynomial_values: PolynomialValues, challenger: &mut Challenger, fri_params: &FriParams, - timing: &mut TimingTree, + _timing: &mut TimingTree, ) -> FriProof where [(); C::Hasher::HASH_SIZE]:, @@ -33,7 +33,7 @@ where // Commit phase let (trees, final_coeffs) = timed!( - timing, + _timing, "fold codewords in the commitment phase", fri_committed_trees::( lde_polynomial_coeffs, @@ -46,7 +46,7 @@ where // PoW phase let current_hash = challenger.get_hash(); let pow_witness = timed!( - timing, + _timing, "find proof-of-work witness", fri_proof_of_work::(current_hash, &fri_params.config) ); diff --git a/plonky2/src/util/timing.rs b/plonky2/src/util/timing.rs index 4250d688..70f34306 100644 --- a/plonky2/src/util/timing.rs +++ b/plonky2/src/util/timing.rs @@ -1,8 +1,10 @@ +#[cfg(feature = "timing")] use std::time::{Duration, Instant}; use log::{log, Level}; /// The hierarchy of scopes, and the time consumed by each one. Useful for profiling. +#[cfg(feature = "timing")] pub struct TimingTree { /// The name of this scope. name: String, @@ -16,13 +18,25 @@ pub struct TimingTree { children: Vec, } +#[cfg(not(feature = "timing"))] +pub struct TimingTree(Level); + +#[cfg(feature = "timing")] impl Default for TimingTree { fn default() -> Self { TimingTree::new("root", Level::Debug) } } +#[cfg(not(feature = "timing"))] +impl Default for TimingTree { + fn default() -> Self { + TimingTree::new("", Level::Debug) + } +} + impl TimingTree { + #[cfg(feature = "timing")] pub fn new(root_name: &str, level: Level) -> Self { Self { name: root_name.to_string(), @@ -33,18 +47,26 @@ impl TimingTree { } } + #[cfg(not(feature = "timing"))] + pub fn new(_root_name: &str, level: Level) -> Self { + Self(level) + } + /// Whether this scope is still in scope. + #[cfg(feature = "timing")] fn is_open(&self) -> bool { self.exit_time.is_none() } /// A description of the stack of currently-open scopes. + #[cfg(feature = "timing")] pub fn open_stack(&self) -> String { let mut stack = Vec::new(); self.open_stack_helper(&mut stack); stack.join(" > ") } + #[cfg(feature = "timing")] fn open_stack_helper(&self, stack: &mut Vec) { if self.is_open() { stack.push(self.name.clone()); @@ -54,6 +76,7 @@ impl TimingTree { } } + #[cfg(feature = "timing")] pub fn push(&mut self, ctx: &str, mut level: log::Level) { assert!(self.is_open()); @@ -77,6 +100,7 @@ impl TimingTree { } /// Close the deepest open scope from this tree. + #[cfg(feature = "timing")] pub fn pop(&mut self) { assert!(self.is_open()); @@ -90,6 +114,7 @@ impl TimingTree { self.exit_time = Some(Instant::now()); } + #[cfg(feature = "timing")] fn duration(&self) -> Duration { self.exit_time .unwrap_or_else(Instant::now) @@ -97,6 +122,7 @@ impl TimingTree { } /// Filter out children with a low duration. + #[cfg(feature = "timing")] pub fn filter(&self, min_delta: Duration) -> Self { Self { name: self.name.clone(), @@ -112,10 +138,17 @@ impl TimingTree { } } + #[cfg(feature = "timing")] pub fn print(&self) { self.print_helper(0); } + #[cfg(not(feature = "timing"))] + pub fn print(&self) { + log!(self.0, "TimingTree is not supported without the 'timing' feature enabled"); + } + + #[cfg(feature = "timing")] fn print_helper(&self, depth: usize) { let prefix = "| ".repeat(depth); log!( @@ -135,16 +168,26 @@ impl TimingTree { #[macro_export] macro_rules! timed { ($timing_tree:expr, $level:expr, $ctx:expr, $exp:expr) => {{ + #[cfg(feature = "timing")] $timing_tree.push($ctx, $level); + let res = $exp; + + #[cfg(feature = "timing")] $timing_tree.pop(); + res }}; // If no context is specified, default to Debug. ($timing_tree:expr, $ctx:expr, $exp:expr) => {{ + #[cfg(feature = "timing")] $timing_tree.push($ctx, log::Level::Debug); + let res = $exp; + + #[cfg(feature = "timing")] $timing_tree.pop(); + res }}; } From a6931d4555de46940ebb223196c18949ace5aa7f Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Wed, 27 Jul 2022 23:53:33 -0400 Subject: [PATCH 03/11] fmt --- plonky2/src/util/timing.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plonky2/src/util/timing.rs b/plonky2/src/util/timing.rs index 70f34306..d16ceead 100644 --- a/plonky2/src/util/timing.rs +++ b/plonky2/src/util/timing.rs @@ -145,7 +145,10 @@ impl TimingTree { #[cfg(not(feature = "timing"))] pub fn print(&self) { - log!(self.0, "TimingTree is not supported without the 'timing' feature enabled"); + log!( + self.0, + "TimingTree is not supported without the 'timing' feature enabled" + ); } #[cfg(feature = "timing")] From 85111b0f02c9e8753f78583992d2017c7761f9a2 Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Wed, 27 Jul 2022 23:58:16 -0400 Subject: [PATCH 04/11] fix missing underscore --- plonky2/src/fri/oracle.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index 7499e696..c6e3a1ff 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -84,7 +84,7 @@ impl, C: GenericConfig, const D: usize> Self::lde_values(&polynomials, rate_bits, blinding, fft_root_table) ); - let mut leaves = timed!(timing, "transpose LDEs", transpose(&lde_values)); + let mut leaves = timed!(_timing, "transpose LDEs", transpose(&lde_values)); reverse_index_bits_in_place(&mut leaves); let merkle_tree = timed!( _timing, From b7fa5e81c4b08e51e4aad37a26a2342de05848e7 Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 28 Jul 2022 00:08:51 -0400 Subject: [PATCH 05/11] add timing to starky, evm, and system_zero --- system_zero/Cargo.toml | 2 +- system_zero/src/system_zero.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system_zero/Cargo.toml b/system_zero/Cargo.toml index f1cb5729..458ce27a 100644 --- a/system_zero/Cargo.toml +++ b/system_zero/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2" } +plonky2 = { path = "../plonky2", features = ["timing"] } plonky2_util = { path = "../util" } starky = { path = "../starky" } anyhow = "1.0.40" diff --git a/system_zero/src/system_zero.rs b/system_zero/src/system_zero.rs index 19c2df8c..41d39cf7 100644 --- a/system_zero/src/system_zero.rs +++ b/system_zero/src/system_zero.rs @@ -69,7 +69,7 @@ impl, const D: usize> SystemZero { } pub fn generate_trace(&self) -> Vec> { - let mut timing = TimingTree::new("generate trace", log::Level::Debug); + let timing = TimingTree::new("generate trace", log::Level::Debug); // Generate the witness, except for permuted columns in the lookup argument. let trace_rows = timed!( From 9f2fa07e1249852eacb0d8ae5617bf03d17729a6 Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 28 Jul 2022 00:09:11 -0400 Subject: [PATCH 06/11] add rest of files --- evm/Cargo.toml | 2 +- starky/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/evm/Cargo.toml b/evm/Cargo.toml index c10ab104..c5ec7f0b 100644 --- a/evm/Cargo.toml +++ b/evm/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2" } +plonky2 = { path = "../plonky2", features = ["timing"] } plonky2_util = { path = "../util" } anyhow = "1.0.40" env_logger = "0.9.0" diff --git a/starky/Cargo.toml b/starky/Cargo.toml index 4e67856d..3ce62c56 100644 --- a/starky/Cargo.toml +++ b/starky/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2" } +plonky2 = { path = "../plonky2", features = ["timing"]} plonky2_util = { path = "../util" } anyhow = "1.0.40" env_logger = "0.9.0" From fd0af3fa3ebebea54d5e14ee5570e490bbddbcd5 Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 28 Jul 2022 00:21:21 -0400 Subject: [PATCH 07/11] allow unused mut when feature disabled --- evm/src/keccak/keccak_stark.rs | 1 + evm/src/lib.rs | 1 + evm/src/memory/memory_stark.rs | 1 + system_zero/src/system_zero.rs | 3 ++- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/evm/src/keccak/keccak_stark.rs b/evm/src/keccak/keccak_stark.rs index 53dd66ab..de80bf44 100644 --- a/evm/src/keccak/keccak_stark.rs +++ b/evm/src/keccak/keccak_stark.rs @@ -194,6 +194,7 @@ impl, const D: usize> KeccakStark { } pub fn generate_trace(&self, inputs: Vec<[u64; NUM_INPUTS]>) -> Vec> { + #[allow(unused_mut)] let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate the witness, except for permuted columns in the lookup argument. diff --git a/evm/src/lib.rs b/evm/src/lib.rs index 47335db2..1248b3e0 100644 --- a/evm/src/lib.rs +++ b/evm/src/lib.rs @@ -2,6 +2,7 @@ #![allow(clippy::needless_range_loop)] #![allow(clippy::too_many_arguments)] #![allow(clippy::type_complexity)] +#![feature(let_chains)] #![feature(generic_const_exprs)] pub mod all_stark; diff --git a/evm/src/memory/memory_stark.rs b/evm/src/memory/memory_stark.rs index 82e10869..bc38e66d 100644 --- a/evm/src/memory/memory_stark.rs +++ b/evm/src/memory/memory_stark.rs @@ -192,6 +192,7 @@ impl, const D: usize> MemoryStark { } pub(crate) fn generate_trace(&self, memory_ops: Vec) -> Vec> { + #[allow(unused_mut)] let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate most of the trace in row-major form. diff --git a/system_zero/src/system_zero.rs b/system_zero/src/system_zero.rs index 41d39cf7..ce44c283 100644 --- a/system_zero/src/system_zero.rs +++ b/system_zero/src/system_zero.rs @@ -69,7 +69,8 @@ impl, const D: usize> SystemZero { } pub fn generate_trace(&self) -> Vec> { - let timing = TimingTree::new("generate trace", log::Level::Debug); + #[allow(unused_mut)] + let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate the witness, except for permuted columns in the lookup argument. let trace_rows = timed!( From 8ad0924bbb26a6fde6dbc488b877fb6d196eab3c Mon Sep 17 00:00:00 2001 From: Sebastien La Duca Date: Thu, 28 Jul 2022 00:24:54 -0400 Subject: [PATCH 08/11] apparently i need to update rust --- evm/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/evm/src/lib.rs b/evm/src/lib.rs index 1248b3e0..47335db2 100644 --- a/evm/src/lib.rs +++ b/evm/src/lib.rs @@ -2,7 +2,6 @@ #![allow(clippy::needless_range_loop)] #![allow(clippy::too_many_arguments)] #![allow(clippy::type_complexity)] -#![feature(let_chains)] #![feature(generic_const_exprs)] pub mod all_stark; From 3d5a9174fdcfbe47f32b4ae66fa5be4b1498c2f3 Mon Sep 17 00:00:00 2001 From: Sladuca Date: Sat, 6 Aug 2022 11:17:36 -0400 Subject: [PATCH 09/11] remove explicit feature include --- evm/Cargo.toml | 2 +- starky/Cargo.toml | 2 +- system_zero/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/evm/Cargo.toml b/evm/Cargo.toml index c5ec7f0b..c10ab104 100644 --- a/evm/Cargo.toml +++ b/evm/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2", features = ["timing"] } +plonky2 = { path = "../plonky2" } plonky2_util = { path = "../util" } anyhow = "1.0.40" env_logger = "0.9.0" diff --git a/starky/Cargo.toml b/starky/Cargo.toml index 3ce62c56..4e67856d 100644 --- a/starky/Cargo.toml +++ b/starky/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2", features = ["timing"]} +plonky2 = { path = "../plonky2" } plonky2_util = { path = "../util" } anyhow = "1.0.40" env_logger = "0.9.0" diff --git a/system_zero/Cargo.toml b/system_zero/Cargo.toml index 458ce27a..f1cb5729 100644 --- a/system_zero/Cargo.toml +++ b/system_zero/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" [dependencies] -plonky2 = { path = "../plonky2", features = ["timing"] } +plonky2 = { path = "../plonky2" } plonky2_util = { path = "../util" } starky = { path = "../starky" } anyhow = "1.0.40" From 1e5383c63db10f088206c59cbb750f6ca7973d81 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Sat, 6 Aug 2022 22:18:53 -0400 Subject: [PATCH 10/11] Stub push/pop --- plonky2/src/util/timing.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/plonky2/src/util/timing.rs b/plonky2/src/util/timing.rs index d16ceead..42033038 100644 --- a/plonky2/src/util/timing.rs +++ b/plonky2/src/util/timing.rs @@ -99,6 +99,9 @@ impl TimingTree { }) } + #[cfg(not(feature = "timing"))] + pub fn push(&mut self, _ctx: &str, _level: log::Level) {} + /// Close the deepest open scope from this tree. #[cfg(feature = "timing")] pub fn pop(&mut self) { @@ -114,6 +117,9 @@ impl TimingTree { self.exit_time = Some(Instant::now()); } + #[cfg(not(feature = "timing"))] + pub fn pop(&mut self) {} + #[cfg(feature = "timing")] fn duration(&self) -> Duration { self.exit_time @@ -171,26 +177,16 @@ impl TimingTree { #[macro_export] macro_rules! timed { ($timing_tree:expr, $level:expr, $ctx:expr, $exp:expr) => {{ - #[cfg(feature = "timing")] $timing_tree.push($ctx, $level); - let res = $exp; - - #[cfg(feature = "timing")] $timing_tree.pop(); - res }}; // If no context is specified, default to Debug. ($timing_tree:expr, $ctx:expr, $exp:expr) => {{ - #[cfg(feature = "timing")] $timing_tree.push($ctx, log::Level::Debug); - let res = $exp; - - #[cfg(feature = "timing")] $timing_tree.pop(); - res }}; } From 385a990c50f6164f843e48bc2a0a4319097d078c Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Sat, 6 Aug 2022 22:27:17 -0400 Subject: [PATCH 11/11] Unsuppress warnings --- evm/src/keccak/keccak_stark.rs | 1 - evm/src/memory/memory_stark.rs | 1 - plonky2/src/fri/oracle.rs | 8 ++++---- plonky2/src/fri/prover.rs | 6 +++--- system_zero/src/system_zero.rs | 1 - 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/evm/src/keccak/keccak_stark.rs b/evm/src/keccak/keccak_stark.rs index de80bf44..53dd66ab 100644 --- a/evm/src/keccak/keccak_stark.rs +++ b/evm/src/keccak/keccak_stark.rs @@ -194,7 +194,6 @@ impl, const D: usize> KeccakStark { } pub fn generate_trace(&self, inputs: Vec<[u64; NUM_INPUTS]>) -> Vec> { - #[allow(unused_mut)] let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate the witness, except for permuted columns in the lookup argument. diff --git a/evm/src/memory/memory_stark.rs b/evm/src/memory/memory_stark.rs index bc38e66d..82e10869 100644 --- a/evm/src/memory/memory_stark.rs +++ b/evm/src/memory/memory_stark.rs @@ -192,7 +192,6 @@ impl, const D: usize> MemoryStark { } pub(crate) fn generate_trace(&self, memory_ops: Vec) -> Vec> { - #[allow(unused_mut)] let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate most of the trace in row-major form. diff --git a/plonky2/src/fri/oracle.rs b/plonky2/src/fri/oracle.rs index c6e3a1ff..312b458b 100644 --- a/plonky2/src/fri/oracle.rs +++ b/plonky2/src/fri/oracle.rs @@ -71,7 +71,7 @@ impl, C: GenericConfig, const D: usize> rate_bits: usize, blinding: bool, cap_height: usize, - _timing: &mut TimingTree, + timing: &mut TimingTree, fft_root_table: Option<&FftRootTable>, ) -> Self where @@ -79,15 +79,15 @@ impl, C: GenericConfig, const D: usize> { let degree = polynomials[0].len(); let lde_values = timed!( - _timing, + timing, "FFT + blinding", Self::lde_values(&polynomials, rate_bits, blinding, fft_root_table) ); - let mut leaves = timed!(_timing, "transpose LDEs", transpose(&lde_values)); + let mut leaves = timed!(timing, "transpose LDEs", transpose(&lde_values)); reverse_index_bits_in_place(&mut leaves); let merkle_tree = timed!( - _timing, + timing, "build Merkle tree", MerkleTree::new(leaves, cap_height) ); diff --git a/plonky2/src/fri/prover.rs b/plonky2/src/fri/prover.rs index f8467d2b..6136a9a1 100644 --- a/plonky2/src/fri/prover.rs +++ b/plonky2/src/fri/prover.rs @@ -23,7 +23,7 @@ pub fn fri_proof, C: GenericConfig, const lde_polynomial_values: PolynomialValues, challenger: &mut Challenger, fri_params: &FriParams, - _timing: &mut TimingTree, + timing: &mut TimingTree, ) -> FriProof where [(); C::Hasher::HASH_SIZE]:, @@ -33,7 +33,7 @@ where // Commit phase let (trees, final_coeffs) = timed!( - _timing, + timing, "fold codewords in the commitment phase", fri_committed_trees::( lde_polynomial_coeffs, @@ -46,7 +46,7 @@ where // PoW phase let current_hash = challenger.get_hash(); let pow_witness = timed!( - _timing, + timing, "find proof-of-work witness", fri_proof_of_work::(current_hash, &fri_params.config) ); diff --git a/system_zero/src/system_zero.rs b/system_zero/src/system_zero.rs index ce44c283..19c2df8c 100644 --- a/system_zero/src/system_zero.rs +++ b/system_zero/src/system_zero.rs @@ -69,7 +69,6 @@ impl, const D: usize> SystemZero { } pub fn generate_trace(&self) -> Vec> { - #[allow(unused_mut)] let mut timing = TimingTree::new("generate trace", log::Level::Debug); // Generate the witness, except for permuted columns in the lookup argument.