From 39c5f85eac28da494c9718d3d132deca978ad6df Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Thu, 23 Jan 2025 14:50:06 -0800 Subject: [PATCH] fix: Write diagnostics to stderr (vs stdout) Before this change (even when logging was not enabled) SP1 was writing diagnostic messages to stdout, breaking the implicit contract that only the application logic should decide what gets written to stdout. This contract is important, e.g. for passing the output for further processing in shell-driven use cases: ```sh cat ./input-data.json | my-app | another-app ``` This change aims to fix this issue, and to safeguard against it (to a reasonable extent) in the future. I've left alone tests, examples and build scripts, and tried to make the change as narrow as possible and to affect only the production code paths. --- crates/core/executor/src/executor.rs | 10 +++++----- crates/core/executor/src/hook.rs | 2 ++ crates/core/executor/src/lib.rs | 1 + crates/core/executor/src/profiler.rs | 4 ++-- crates/core/executor/src/syscalls/write.rs | 4 ++-- crates/core/machine/src/alu/add_sub/mod.rs | 2 ++ crates/core/machine/src/alu/bitwise/mod.rs | 2 ++ crates/core/machine/src/alu/divrem/mod.rs | 1 + crates/core/machine/src/alu/lt/mod.rs | 1 + crates/core/machine/src/alu/sll/mod.rs | 1 + crates/core/machine/src/alu/sr/mod.rs | 2 ++ crates/core/machine/src/bytes/mod.rs | 2 ++ crates/core/machine/src/bytes/utils.rs | 2 ++ crates/core/machine/src/global/mod.rs | 2 ++ crates/core/machine/src/lib.rs | 1 + crates/core/machine/src/memory/global.rs | 1 + crates/core/machine/src/memory/local.rs | 2 ++ crates/core/machine/src/operations/field/field_den.rs | 2 ++ .../src/operations/field/field_inner_product.rs | 2 ++ crates/core/machine/src/operations/field/field_op.rs | 2 ++ crates/core/machine/src/program/mod.rs | 1 + crates/core/machine/src/riscv/mod.rs | 1 + crates/core/machine/src/shape/mod.rs | 1 + .../src/syscall/precompiles/sha256/extend/mod.rs | 1 + crates/core/machine/src/utils/logger.rs | 1 + crates/cuda/src/lib.rs | 2 ++ crates/curves/src/lib.rs | 2 ++ crates/curves/src/weierstrass/secp256k1.rs | 1 + crates/derive/src/lib.rs | 6 ++++-- crates/primitives/src/lib.rs | 2 ++ crates/prover/src/build.rs | 2 ++ crates/prover/src/lib.rs | 2 ++ crates/prover/src/shapes.rs | 3 ++- crates/recursion/circuit/src/challenger.rs | 2 ++ crates/recursion/circuit/src/lib.rs | 2 ++ crates/recursion/compiler/src/circuit/compiler.rs | 2 ++ crates/recursion/compiler/src/lib.rs | 1 + crates/recursion/core/src/chips/batch_fri.rs | 2 +- crates/recursion/core/src/chips/exp_reverse_bits.rs | 4 +++- crates/recursion/core/src/chips/fri_fold.rs | 4 +++- crates/recursion/core/src/chips/mem/variable.rs | 2 ++ crates/recursion/core/src/chips/public_values.rs | 2 ++ crates/recursion/core/src/lib.rs | 2 ++ crates/recursion/derive/src/lib.rs | 2 ++ crates/recursion/gnark-ffi/src/ffi/native.rs | 2 ++ crates/recursion/gnark-ffi/src/lib.rs | 2 ++ crates/sdk/src/install.rs | 6 +++--- crates/sdk/src/lib.rs | 1 + crates/sdk/src/proof.rs | 2 ++ crates/sdk/src/utils.rs | 2 +- crates/stark/src/lib.rs | 1 + crates/stark/src/lookup/builder.rs | 2 ++ crates/stark/src/lookup/debug.rs | 2 +- crates/stark/src/opts.rs | 2 ++ crates/stark/src/septic_curve.rs | 2 ++ crates/stark/src/septic_extension.rs | 2 ++ crates/verifier/src/lib.rs | 2 ++ crates/zkvm/entrypoint/src/lib.rs | 4 +++- crates/zkvm/entrypoint/src/syscalls/unconstrained.rs | 4 ++-- 59 files changed, 109 insertions(+), 23 deletions(-) diff --git a/crates/core/executor/src/executor.rs b/crates/core/executor/src/executor.rs index 0f2d40296d..8b95844519 100644 --- a/crates/core/executor/src/executor.rs +++ b/crates/core/executor/src/executor.rs @@ -271,12 +271,12 @@ impl<'a> Executor<'a> { }); if let Some(trace_buf) = trace_buf { - println!("Profiling enabled"); + eprintln!("Profiling enabled"); let sample_rate = std::env::var("TRACE_SAMPLE_RATE") .ok() .and_then(|rate| { - println!("Profiling sample rate: {rate}"); + eprintln!("Profiling sample rate: {rate}"); rate.parse::().ok() }) .unwrap_or(1); @@ -1341,7 +1341,7 @@ impl<'a> Executor<'a> { // See https://github.com/riscv-non-isa/riscv-asm-manual/blob/master/riscv-asm.md#instruction-aliases return Err(ExecutionError::Unimplemented()); } else { - println!("unreachable: {:?}", instruction.opcode); + eprintln!("unreachable: {:?}", instruction.opcode); unreachable!() } @@ -2000,10 +2000,10 @@ impl<'a> Executor<'a> { if !buf.is_empty() { match fd { 1 => { - println!("stdout: {buf}"); + eprintln!("stdout: {buf}"); } 2 => { - println!("stderr: {buf}"); + eprintln!("stderr: {buf}"); } _ => {} } diff --git a/crates/core/executor/src/hook.rs b/crates/core/executor/src/hook.rs index c03965ee76..65a239a866 100644 --- a/crates/core/executor/src/hook.rs +++ b/crates/core/executor/src/hook.rs @@ -537,6 +537,8 @@ fn pad_to_be(val: &BigUint, len: usize) -> Vec { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; #[test] diff --git a/crates/core/executor/src/lib.rs b/crates/core/executor/src/lib.rs index b2aa95e25f..cdd6aaa8c0 100644 --- a/crates/core/executor/src/lib.rs +++ b/crates/core/executor/src/lib.rs @@ -18,6 +18,7 @@ #![allow(clippy::missing_errors_doc)] #![allow(clippy::explicit_iter_loop)] #![allow(clippy::struct_excessive_bools)] +#![warn(clippy::print_stdout)] #![warn(missing_docs)] mod air; diff --git a/crates/core/executor/src/profiler.rs b/crates/core/executor/src/profiler.rs index 416993bb3c..dcf26e5787 100644 --- a/crates/core/executor/src/profiler.rs +++ b/crates/core/executor/src/profiler.rs @@ -189,9 +189,9 @@ impl Profiler { pb.finish(); - println!("Writing profile, this can take awhile"); + eprintln!("Writing profile, this can take awhile"); serde_json::to_writer(writer, &profile_builder.to_serializable())?; - println!("Profile written successfully"); + eprintln!("Profile written successfully"); Ok(()) } diff --git a/crates/core/executor/src/syscalls/write.rs b/crates/core/executor/src/syscalls/write.rs index 1812643031..e0c25ead69 100644 --- a/crates/core/executor/src/syscalls/write.rs +++ b/crates/core/executor/src/syscalls/write.rs @@ -51,7 +51,7 @@ impl Syscall for WriteSyscall { // If the string does not match any known command, print it to stdout. let flush_s = update_io_buf(ctx, fd, s); if !flush_s.is_empty() { - flush_s.into_iter().for_each(|line| println!("stdout: {}", line)); + flush_s.into_iter().for_each(|line| eprintln!("stdout: {}", line)); } } } @@ -59,7 +59,7 @@ impl Syscall for WriteSyscall { let s = core::str::from_utf8(slice).unwrap(); let flush_s = update_io_buf(ctx, fd, s); if !flush_s.is_empty() { - flush_s.into_iter().for_each(|line| println!("stderr: {}", line)); + flush_s.into_iter().for_each(|line| eprintln!("stderr: {}", line)); } } else if fd <= LOWEST_ALLOWED_FD { if std::env::var("SP1_ALLOW_DEPRECATED_HOOKS") diff --git a/crates/core/machine/src/alu/add_sub/mod.rs b/crates/core/machine/src/alu/add_sub/mod.rs index c7ef061c59..a42b8f842c 100644 --- a/crates/core/machine/src/alu/add_sub/mod.rs +++ b/crates/core/machine/src/alu/add_sub/mod.rs @@ -273,6 +273,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; use rand::{thread_rng, Rng}; diff --git a/crates/core/machine/src/alu/bitwise/mod.rs b/crates/core/machine/src/alu/bitwise/mod.rs index c876b9d571..04b2887ef0 100644 --- a/crates/core/machine/src/alu/bitwise/mod.rs +++ b/crates/core/machine/src/alu/bitwise/mod.rs @@ -241,6 +241,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; use rand::{thread_rng, Rng}; diff --git a/crates/core/machine/src/alu/divrem/mod.rs b/crates/core/machine/src/alu/divrem/mod.rs index 926be3bbff..b9739a7723 100644 --- a/crates/core/machine/src/alu/divrem/mod.rs +++ b/crates/core/machine/src/alu/divrem/mod.rs @@ -833,6 +833,7 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use crate::{ io::SP1Stdin, diff --git a/crates/core/machine/src/alu/lt/mod.rs b/crates/core/machine/src/alu/lt/mod.rs index 6ddde112e0..9fd0bea67f 100644 --- a/crates/core/machine/src/alu/lt/mod.rs +++ b/crates/core/machine/src/alu/lt/mod.rs @@ -467,6 +467,7 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use std::borrow::BorrowMut; diff --git a/crates/core/machine/src/alu/sll/mod.rs b/crates/core/machine/src/alu/sll/mod.rs index ec18353c68..7996e12d6a 100644 --- a/crates/core/machine/src/alu/sll/mod.rs +++ b/crates/core/machine/src/alu/sll/mod.rs @@ -419,6 +419,7 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use std::borrow::BorrowMut; diff --git a/crates/core/machine/src/alu/sr/mod.rs b/crates/core/machine/src/alu/sr/mod.rs index 8b8813cac0..8348cce5c4 100644 --- a/crates/core/machine/src/alu/sr/mod.rs +++ b/crates/core/machine/src/alu/sr/mod.rs @@ -542,6 +542,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use std::borrow::BorrowMut; use crate::{ diff --git a/crates/core/machine/src/bytes/mod.rs b/crates/core/machine/src/bytes/mod.rs index 07380c9029..b46ac6f9a3 100644 --- a/crates/core/machine/src/bytes/mod.rs +++ b/crates/core/machine/src/bytes/mod.rs @@ -109,6 +109,8 @@ impl ByteChip { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use std::time::Instant; diff --git a/crates/core/machine/src/bytes/utils.rs b/crates/core/machine/src/bytes/utils.rs index 7a56b9ecb4..b3aacb7624 100644 --- a/crates/core/machine/src/bytes/utils.rs +++ b/crates/core/machine/src/bytes/utils.rs @@ -12,6 +12,8 @@ pub const fn shr_carry(input: u8, rotation: u8) -> (u8, u8) { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; /// Tests the `shr_carry` function. diff --git a/crates/core/machine/src/global/mod.rs b/crates/core/machine/src/global/mod.rs index b612a48962..e9c3b0038c 100644 --- a/crates/core/machine/src/global/mod.rs +++ b/crates/core/machine/src/global/mod.rs @@ -262,6 +262,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; use crate::programs::tests::*; use p3_baby_bear::BabyBear; diff --git a/crates/core/machine/src/lib.rs b/crates/core/machine/src/lib.rs index 86b2b6e995..760c95d888 100644 --- a/crates/core/machine/src/lib.rs +++ b/crates/core/machine/src/lib.rs @@ -12,6 +12,7 @@ deprecated, incomplete_features )] +#![warn(clippy::print_stdout)] #![warn(unused_extern_crates)] pub mod air; diff --git a/crates/core/machine/src/memory/global.rs b/crates/core/machine/src/memory/global.rs index 001f523160..40b233a90a 100644 --- a/crates/core/machine/src/memory/global.rs +++ b/crates/core/machine/src/memory/global.rs @@ -433,6 +433,7 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use super::*; use crate::programs::tests::*; diff --git a/crates/core/machine/src/memory/local.rs b/crates/core/machine/src/memory/local.rs index bb7c593505..1d7c8055bd 100644 --- a/crates/core/machine/src/memory/local.rs +++ b/crates/core/machine/src/memory/local.rs @@ -271,6 +271,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use crate::programs::tests::*; use crate::{ memory::MemoryLocalChip, riscv::RiscvAir, diff --git a/crates/core/machine/src/operations/field/field_den.rs b/crates/core/machine/src/operations/field/field_den.rs index a017af496d..b577635828 100644 --- a/crates/core/machine/src/operations/field/field_den.rs +++ b/crates/core/machine/src/operations/field/field_den.rs @@ -141,6 +141,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use num::BigUint; use p3_air::BaseAir; use p3_field::{Field, PrimeField32}; diff --git a/crates/core/machine/src/operations/field/field_inner_product.rs b/crates/core/machine/src/operations/field/field_inner_product.rs index dec6e66d07..ff7a62da1c 100644 --- a/crates/core/machine/src/operations/field/field_inner_product.rs +++ b/crates/core/machine/src/operations/field/field_inner_product.rs @@ -133,6 +133,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use num::BigUint; use p3_air::BaseAir; use p3_field::{Field, PrimeField32}; diff --git a/crates/core/machine/src/operations/field/field_op.rs b/crates/core/machine/src/operations/field/field_op.rs index c9f65a087e..d9f825737d 100644 --- a/crates/core/machine/src/operations/field/field_op.rs +++ b/crates/core/machine/src/operations/field/field_op.rs @@ -375,6 +375,8 @@ impl FieldOpCols { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use num::BigUint; use p3_air::BaseAir; use p3_field::{Field, PrimeField32}; diff --git a/crates/core/machine/src/program/mod.rs b/crates/core/machine/src/program/mod.rs index 89df6b2444..0a1d63375e 100644 --- a/crates/core/machine/src/program/mod.rs +++ b/crates/core/machine/src/program/mod.rs @@ -172,6 +172,7 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use std::sync::Arc; diff --git a/crates/core/machine/src/riscv/mod.rs b/crates/core/machine/src/riscv/mod.rs index 3f6ba21bc4..e8164bb482 100644 --- a/crates/core/machine/src/riscv/mod.rs +++ b/crates/core/machine/src/riscv/mod.rs @@ -634,6 +634,7 @@ impl fmt::Debug for RiscvAir { #[cfg(test)] #[allow(non_snake_case)] +#[allow(clippy::print_stdout)] pub mod tests { use crate::{ diff --git a/crates/core/machine/src/shape/mod.rs b/crates/core/machine/src/shape/mod.rs index 9dea8a723a..010567b6c5 100644 --- a/crates/core/machine/src/shape/mod.rs +++ b/crates/core/machine/src/shape/mod.rs @@ -633,6 +633,7 @@ pub fn create_dummy_record(shape: &Shape) -> ExecutionRecord { #[cfg(test)] pub mod tests { + #![allow(clippy::print_stdout)] use hashbrown::HashSet; use sp1_stark::{Dom, MachineProver, StarkGenericConfig}; diff --git a/crates/core/machine/src/syscall/precompiles/sha256/extend/mod.rs b/crates/core/machine/src/syscall/precompiles/sha256/extend/mod.rs index 1c4ffe9a60..7a705389fe 100644 --- a/crates/core/machine/src/syscall/precompiles/sha256/extend/mod.rs +++ b/crates/core/machine/src/syscall/precompiles/sha256/extend/mod.rs @@ -29,6 +29,7 @@ pub fn sha_extend(w: &mut [u32]) { #[cfg(test)] pub mod extend_tests { + #![allow(clippy::print_stdout)] use p3_baby_bear::BabyBear; diff --git a/crates/core/machine/src/utils/logger.rs b/crates/core/machine/src/utils/logger.rs index e10dd47c0d..3167552758 100644 --- a/crates/core/machine/src/utils/logger.rs +++ b/crates/core/machine/src/utils/logger.rs @@ -37,6 +37,7 @@ pub fn setup_logger() { .with_thread_names(false) .with_env_filter(env_filter) .with_span_events(FmtSpan::CLOSE) + .with_writer(std::io::stderr) .finish() .init(); } diff --git a/crates/cuda/src/lib.rs b/crates/cuda/src/lib.rs index 1b266ccdce..643c7d2f06 100644 --- a/crates/cuda/src/lib.rs +++ b/crates/cuda/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + use std::{ error::Error as StdError, future::Future, diff --git a/crates/curves/src/lib.rs b/crates/curves/src/lib.rs index 4c9301d5ca..504edaa95c 100644 --- a/crates/curves/src/lib.rs +++ b/crates/curves/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + pub mod edwards; pub mod params; // pub mod polynomial; diff --git a/crates/curves/src/weierstrass/secp256k1.rs b/crates/curves/src/weierstrass/secp256k1.rs index d6514caa65..41ee2d90ae 100644 --- a/crates/curves/src/weierstrass/secp256k1.rs +++ b/crates/curves/src/weierstrass/secp256k1.rs @@ -113,6 +113,7 @@ pub fn secp256k1_sqrt(n: &BigUint) -> BigUint { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use super::*; use crate::utils::biguint_from_limbs; diff --git a/crates/derive/src/lib.rs b/crates/derive/src/lib.rs index 81ba6550d9..0c03925666 100644 --- a/crates/derive/src/lib.rs +++ b/crates/derive/src/lib.rs @@ -22,6 +22,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#![warn(clippy::print_stdout)] + extern crate proc_macro; use proc_macro::TokenStream; @@ -322,9 +324,9 @@ pub fn cycle_tracker(_attr: TokenStream, item: TokenStream) -> TokenStream { let result = quote! { #visibility fn #name #generics (#inputs) #output #where_clause { - println!("cycle-tracker-start: {}", stringify!(#name)); + eprintln!("cycle-tracker-start: {}", stringify!(#name)); let result = (|| #block)(); - println!("cycle-tracker-end: {}", stringify!(#name)); + eprintln!("cycle-tracker-end: {}", stringify!(#name)); result } }; diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 53ab9b8652..c8fabfa1d2 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -1,6 +1,8 @@ //! sp1-primitives contains types and functions that are used in both sp1-core and sp1-zkvm. //! Because it is imported in the zkvm entrypoint, it should be kept minimal. +#![warn(clippy::print_stdout)] + use lazy_static::lazy_static; use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear}; use p3_field::AbstractField; diff --git a/crates/prover/src/build.rs b/crates/prover/src/build.rs index ff589c33b9..b6a25c6077 100644 --- a/crates/prover/src/build.rs +++ b/crates/prover/src/build.rs @@ -1,3 +1,5 @@ +#![allow(clippy::print_stdout)] // okay to print to stdout: this is a build script + use std::{borrow::Borrow, path::PathBuf}; use p3_baby_bear::BabyBear; diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index dfa39dba6c..7f60f92a9a 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -10,6 +10,7 @@ #![allow(clippy::too_many_arguments)] #![allow(clippy::new_without_default)] #![allow(clippy::collapsible_else_if)] +#![warn(clippy::print_stdout)] pub mod build; pub mod components; @@ -1316,6 +1317,7 @@ pub fn compress_program_from_input( #[cfg(test)] pub mod tests { + #![allow(clippy::print_stdout)] use std::{ collections::BTreeSet, diff --git a/crates/prover/src/shapes.rs b/crates/prover/src/shapes.rs index 2438ae0704..5acf8de8ee 100644 --- a/crates/prover/src/shapes.rs +++ b/crates/prover/src/shapes.rs @@ -204,7 +204,7 @@ pub fn build_vk_map( let panic_tx = panic_tx.clone(); s.spawn(move || { while let Ok((i, shape)) = shape_rx.lock().unwrap().recv() { - println!("shape: {:?}", shape); + eprintln!("shape: {:?}", shape); let is_shrink = matches!(shape, SP1CompressProgramShape::Shrink(_)); let prover = prover.clone(); let shape_clone = shape.clone(); @@ -466,6 +466,7 @@ impl SP1Prover { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] use super::*; diff --git a/crates/recursion/circuit/src/challenger.rs b/crates/recursion/circuit/src/challenger.rs index 85dab9dec6..4be9da49e2 100644 --- a/crates/recursion/circuit/src/challenger.rs +++ b/crates/recursion/circuit/src/challenger.rs @@ -425,6 +425,8 @@ pub fn split_32(builder: &mut Builder, val: Var, n: usize) - #[cfg(test)] pub(crate) mod tests { + #![allow(clippy::print_stdout)] + use std::iter::zip; use crate::{ diff --git a/crates/recursion/circuit/src/lib.rs b/crates/recursion/circuit/src/lib.rs index ec268151bc..d665baa9bd 100644 --- a/crates/recursion/circuit/src/lib.rs +++ b/crates/recursion/circuit/src/lib.rs @@ -1,5 +1,7 @@ //! Copied from [`sp1_recursion_program`]. +#![warn(clippy::print_stdout)] + use challenger::{ CanCopyChallenger, CanObserveVariable, DuplexChallengerVariable, FieldChallengerVariable, MultiField32ChallengerVariable, SpongeChallengerShape, diff --git a/crates/recursion/compiler/src/circuit/compiler.rs b/crates/recursion/compiler/src/circuit/compiler.rs index 1bb5384aea..8baeff16a3 100644 --- a/crates/recursion/compiler/src/circuit/compiler.rs +++ b/crates/recursion/compiler/src/circuit/compiler.rs @@ -886,6 +886,8 @@ impl> Reg for Address { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use std::{collections::VecDeque, io::BufRead, iter::zip, sync::Arc}; use p3_baby_bear::DiffusionMatrixBabyBear; diff --git a/crates/recursion/compiler/src/lib.rs b/crates/recursion/compiler/src/lib.rs index 9426adf9bf..2d38bc0a46 100644 --- a/crates/recursion/compiler/src/lib.rs +++ b/crates/recursion/compiler/src/lib.rs @@ -1,5 +1,6 @@ #![allow(clippy::type_complexity)] #![allow(clippy::needless_range_loop)] +#![warn(clippy::print_stdout)] extern crate alloc; diff --git a/crates/recursion/core/src/chips/batch_fri.rs b/crates/recursion/core/src/chips/batch_fri.rs index 3533cbb1ef..811b665f8c 100644 --- a/crates/recursion/core/src/chips/batch_fri.rs +++ b/crates/recursion/core/src/chips/batch_fri.rs @@ -171,7 +171,7 @@ impl MachineAir for BatchFRIChip MachineAir for ExpReverseBitsLenCh ); #[cfg(debug_assertions)] - println!( + eprintln!( "exp reverse bits len trace dims is width: {:?}, height: {:?}", trace.width(), trace.height() @@ -319,6 +319,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use crate::{ chips::{exp_reverse_bits::ExpReverseBitsLenChip, test_fixtures}, linear_program, diff --git a/crates/recursion/core/src/chips/fri_fold.rs b/crates/recursion/core/src/chips/fri_fold.rs index 7ffed02202..6545ad3a38 100644 --- a/crates/recursion/core/src/chips/fri_fold.rs +++ b/crates/recursion/core/src/chips/fri_fold.rs @@ -211,7 +211,7 @@ impl MachineAir for FriFoldChip ); #[cfg(debug_assertions)] - println!("fri fold trace dims is width: {:?}, height: {:?}", trace.width(), trace.height()); + eprintln!("fri fold trace dims is width: {:?}, height: {:?}", trace.width(), trace.height()); trace } @@ -345,6 +345,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use crate::{ air::Block, chips::{fri_fold::FriFoldChip, mem::MemoryAccessCols, test_fixtures}, diff --git a/crates/recursion/core/src/chips/mem/variable.rs b/crates/recursion/core/src/chips/mem/variable.rs index 8f57f6a7da..24382d8cc5 100644 --- a/crates/recursion/core/src/chips/mem/variable.rs +++ b/crates/recursion/core/src/chips/mem/variable.rs @@ -154,6 +154,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use p3_field::AbstractField; use p3_matrix::dense::RowMajorMatrix; diff --git a/crates/recursion/core/src/chips/public_values.rs b/crates/recursion/core/src/chips/public_values.rs index ef75c338fe..c01e119f96 100644 --- a/crates/recursion/core/src/chips/public_values.rs +++ b/crates/recursion/core/src/chips/public_values.rs @@ -211,6 +211,8 @@ where #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use crate::{ air::{RecursionPublicValues, NUM_PV_ELMS_TO_HASH, RECURSIVE_PROOF_NUM_PV_ELTS}, chips::{ diff --git a/crates/recursion/core/src/lib.rs b/crates/recursion/core/src/lib.rs index 36a00c4f0c..1a8990e118 100644 --- a/crates/recursion/core/src/lib.rs +++ b/crates/recursion/core/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + use p3_field::PrimeField64; use serde::{Deserialize, Serialize}; use sp1_derive::AlignedBorrow; diff --git a/crates/recursion/derive/src/lib.rs b/crates/recursion/derive/src/lib.rs index da3f93310c..0468163c9c 100644 --- a/crates/recursion/derive/src/lib.rs +++ b/crates/recursion/derive/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + extern crate proc_macro; use proc_macro::TokenStream; diff --git a/crates/recursion/gnark-ffi/src/ffi/native.rs b/crates/recursion/gnark-ffi/src/ffi/native.rs index f21b42aa5c..dbc0650238 100644 --- a/crates/recursion/gnark-ffi/src/ffi/native.rs +++ b/crates/recursion/gnark-ffi/src/ffi/native.rs @@ -253,6 +253,8 @@ impl Groth16Bn254Proof { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use p3_field::AbstractField; use p3_symmetric::Permutation; diff --git a/crates/recursion/gnark-ffi/src/lib.rs b/crates/recursion/gnark-ffi/src/lib.rs index 0aa5c40e60..d08c55fff5 100644 --- a/crates/recursion/gnark-ffi/src/lib.rs +++ b/crates/recursion/gnark-ffi/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + mod babybear; pub mod ffi; diff --git a/crates/sdk/src/install.rs b/crates/sdk/src/install.rs index 51857f32ca..d4d2f67da4 100644 --- a/crates/sdk/src/install.rs +++ b/crates/sdk/src/install.rs @@ -43,7 +43,7 @@ pub fn try_install_circuit_artifacts(artifacts_type: &str) -> PathBuf { }; if build_dir.exists() { - println!( + eprintln!( "[sp1] {} circuit artifacts already seem to exist at {}. if you want to re-download them, delete the directory", artifacts_type, build_dir.display() @@ -51,7 +51,7 @@ pub fn try_install_circuit_artifacts(artifacts_type: &str) -> PathBuf { } else { cfg_if! { if #[cfg(any(feature = "network", feature = "network"))] { - println!( + eprintln!( "[sp1] {} circuit artifacts for version {} do not exist at {}. downloading...", artifacts_type, SP1_CIRCUIT_VERSION, @@ -95,7 +95,7 @@ pub fn install_circuit_artifacts(build_dir: PathBuf, artifacts_type: &str) { .expect("failed to extract tarball"); res.wait().unwrap(); - println!("[sp1] downloaded {} to {:?}", download_url, build_dir.to_str().unwrap(),); + eprintln!("[sp1] downloaded {} to {:?}", download_url, build_dir.to_str().unwrap(),); } /// Download the file with a progress bar that indicates the progress. diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 4d2184e3e0..022f31c45d 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -22,6 +22,7 @@ #![allow(clippy::missing_panics_doc)] #![allow(clippy::missing_errors_doc)] #![allow(clippy::explicit_iter_loop)] +#![warn(clippy::print_stdout)] #![warn(missing_docs)] pub mod artifacts; diff --git a/crates/sdk/src/proof.rs b/crates/sdk/src/proof.rs index e947b70a22..55706a646f 100644 --- a/crates/sdk/src/proof.rs +++ b/crates/sdk/src/proof.rs @@ -217,6 +217,8 @@ impl SP1ProofWithPublicValues { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; #[test] diff --git a/crates/sdk/src/utils.rs b/crates/sdk/src/utils.rs index 42ae861db2..8aa7a3e83e 100644 --- a/crates/sdk/src/utils.rs +++ b/crates/sdk/src/utils.rs @@ -12,7 +12,7 @@ pub(crate) fn sp1_dump(elf: &[u8], stdin: &SP1Stdin) { let stdin = bincode::serialize(&stdin).unwrap(); std::fs::write("stdin.bin", stdin.clone()).unwrap(); - println!("Dumped program.bin and stdin.bin."); + eprintln!("Dumped program.bin and stdin.bin."); // Exit with the success status. std::process::exit(0); } diff --git a/crates/stark/src/lib.rs b/crates/stark/src/lib.rs index f384dc9358..e187a94383 100644 --- a/crates/stark/src/lib.rs +++ b/crates/stark/src/lib.rs @@ -18,6 +18,7 @@ #![allow(clippy::missing_errors_doc)] #![allow(clippy::explicit_iter_loop)] #![allow(clippy::if_not_else)] +#![warn(clippy::print_stdout)] #![warn(missing_docs)] pub mod air; diff --git a/crates/stark/src/lookup/builder.rs b/crates/stark/src/lookup/builder.rs index 153d660483..f5ede96111 100644 --- a/crates/stark/src/lookup/builder.rs +++ b/crates/stark/src/lookup/builder.rs @@ -187,6 +187,8 @@ fn eval_symbolic_to_virtual_pair( #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use std::borrow::Borrow; use p3_air::{Air, BaseAir}; diff --git a/crates/stark/src/lookup/debug.rs b/crates/stark/src/lookup/debug.rs index f1854c1555..df8e5f13c1 100644 --- a/crates/stark/src/lookup/debug.rs +++ b/crates/stark/src/lookup/debug.rs @@ -157,7 +157,7 @@ where if !chip.included(shard) { continue; } - println!("{}", chip.name()); + eprintln!("{}", chip.name()); let (_, count) = debug_interactions::(chip, pkey, shard, interaction_kinds.clone(), scope); total_events += count.len(); diff --git a/crates/stark/src/opts.rs b/crates/stark/src/opts.rs index d1ce531e0f..246c991a12 100644 --- a/crates/stark/src/opts.rs +++ b/crates/stark/src/opts.rs @@ -199,6 +199,8 @@ impl SplitOpts { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use super::*; #[test] diff --git a/crates/stark/src/septic_curve.rs b/crates/stark/src/septic_curve.rs index a69bd445f0..d2d1713f06 100644 --- a/crates/stark/src/septic_curve.rs +++ b/crates/stark/src/septic_curve.rs @@ -234,6 +234,8 @@ impl SepticCurveComplete { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use p3_maybe_rayon::prelude::ParallelIterator; use p3_maybe_rayon::prelude::{IndexedParallelIterator, IntoParallelIterator}; diff --git a/crates/stark/src/septic_extension.rs b/crates/stark/src/septic_extension.rs index 3859937a69..31a7bf2b41 100644 --- a/crates/stark/src/septic_extension.rs +++ b/crates/stark/src/septic_extension.rs @@ -811,6 +811,8 @@ impl IntoIterator for SepticBlock { #[cfg(test)] mod tests { + #![allow(clippy::print_stdout)] + use p3_baby_bear::BabyBear; use super::*; diff --git a/crates/verifier/src/lib.rs b/crates/verifier/src/lib.rs index 351975754a..77361561ed 100644 --- a/crates/verifier/src/lib.rs +++ b/crates/verifier/src/lib.rs @@ -1,6 +1,8 @@ //! This crate provides verifiers for SP1 Groth16 and Plonk BN254 proofs in a no-std environment. //! It is patched for efficient verification within the SP1 zkVM context. +#![warn(clippy::print_stdout)] + #![cfg_attr(not(any(feature = "std", test)), no_std)] extern crate alloc; diff --git a/crates/zkvm/entrypoint/src/lib.rs b/crates/zkvm/entrypoint/src/lib.rs index c010f4af17..fe831fd55a 100644 --- a/crates/zkvm/entrypoint/src/lib.rs +++ b/crates/zkvm/entrypoint/src/lib.rs @@ -1,3 +1,5 @@ +#![warn(clippy::print_stdout)] + #[cfg(all(target_os = "zkvm", feature = "embedded"))] use syscalls::MAX_MEMORY; @@ -221,7 +223,7 @@ macro_rules! entrypoint { if cfg!(target_os = "zkvm") { super::ZKVM_ENTRY() } else { - println!("Not running in zkVM, skipping entrypoint"); + eprintln!("Not running in zkVM, skipping entrypoint"); } } } diff --git a/crates/zkvm/entrypoint/src/syscalls/unconstrained.rs b/crates/zkvm/entrypoint/src/syscalls/unconstrained.rs index 6e09d43b0f..fbba507f37 100644 --- a/crates/zkvm/entrypoint/src/syscalls/unconstrained.rs +++ b/crates/zkvm/entrypoint/src/syscalls/unconstrained.rs @@ -16,7 +16,7 @@ pub fn syscall_enter_unconstrained() -> bool { #[cfg(not(target_os = "zkvm"))] { - println!("Entering unconstrained execution block"); + eprintln!("Entering unconstrained execution block"); continue_unconstrained = 1; } @@ -35,5 +35,5 @@ pub fn syscall_exit_unconstrained() { } #[cfg(not(target_os = "zkvm"))] - println!("Exiting unconstrained execution block"); + eprintln!("Exiting unconstrained execution block"); }