diff --git a/Cargo.lock b/Cargo.lock index eab07e05d0..65a9348276 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2428,6 +2428,7 @@ dependencies = [ "clap", "colored", "indexmap", + "log", "num-format", "once_cell", "parking_lot", @@ -2468,6 +2469,7 @@ dependencies = [ "hex", "itertools", "lazy_static", + "log", "parking_lot", "rand 0.8.5", "rand_chacha 0.3.1", @@ -2517,6 +2519,7 @@ name = "snarkvm-circuit-account" version = "0.11.7" dependencies = [ "anyhow", + "log", "snarkvm-circuit-algorithms", "snarkvm-circuit-network", "snarkvm-circuit-types", @@ -2529,6 +2532,7 @@ name = "snarkvm-circuit-algorithms" version = "0.11.7" dependencies = [ "anyhow", + "log", "snarkvm-circuit-types", "snarkvm-console-algorithms", "snarkvm-curves", @@ -2541,6 +2545,7 @@ name = "snarkvm-circuit-collections" version = "0.11.7" dependencies = [ "anyhow", + "log", "snarkvm-circuit-algorithms", "snarkvm-circuit-network", "snarkvm-circuit-types", @@ -2557,6 +2562,7 @@ dependencies = [ "criterion", "indexmap", "itertools", + "log", "nom", "num-traits", "once_cell", @@ -2591,6 +2597,7 @@ name = "snarkvm-circuit-program" version = "0.11.7" dependencies = [ "anyhow", + "log", "rand 0.8.5", "snarkvm-circuit-account", "snarkvm-circuit-collections", @@ -2605,6 +2612,7 @@ dependencies = [ name = "snarkvm-circuit-types" version = "0.11.7" dependencies = [ + "log", "snarkvm-circuit-environment", "snarkvm-circuit-types-address", "snarkvm-circuit-types-boolean", @@ -2619,6 +2627,7 @@ dependencies = [ name = "snarkvm-circuit-types-address" version = "0.11.7" dependencies = [ + "log", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", "snarkvm-circuit-types-field", @@ -2632,6 +2641,7 @@ name = "snarkvm-circuit-types-boolean" version = "0.11.7" dependencies = [ "criterion", + "log", "snarkvm-circuit-environment", "snarkvm-console-types-boolean", ] @@ -2640,6 +2650,7 @@ dependencies = [ name = "snarkvm-circuit-types-field" version = "0.11.7" dependencies = [ + "log", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", "snarkvm-console-types-field", @@ -2649,6 +2660,7 @@ dependencies = [ name = "snarkvm-circuit-types-group" version = "0.11.7" dependencies = [ + "log", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", "snarkvm-circuit-types-field", @@ -2661,6 +2673,7 @@ dependencies = [ name = "snarkvm-circuit-types-integers" version = "0.11.7" dependencies = [ + "log", "paste", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2673,6 +2686,7 @@ dependencies = [ name = "snarkvm-circuit-types-scalar" version = "0.11.7" dependencies = [ + "log", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", "snarkvm-circuit-types-field", @@ -2683,6 +2697,7 @@ dependencies = [ name = "snarkvm-circuit-types-string" version = "0.11.7" dependencies = [ + "log", "rand 0.8.5", "snarkvm-circuit-environment", "snarkvm-circuit-types-boolean", @@ -2712,6 +2727,7 @@ dependencies = [ "bs58", "criterion", "ed25519-dalek", + "log", "serde_json", "snarkvm-console-network", "snarkvm-console-types", @@ -2741,6 +2757,7 @@ dependencies = [ "aleo-std", "criterion", "indexmap", + "log", "rayon", "snarkvm-console-algorithms", "snarkvm-console-network", @@ -2793,6 +2810,7 @@ dependencies = [ "enum_index", "enum_index_derive", "indexmap", + "log", "num-derive", "num-traits", "once_cell", @@ -2958,6 +2976,7 @@ dependencies = [ "itertools", "js-sys", "lazy_static", + "log", "paste", "rand 0.8.5", "serde_json", @@ -2982,6 +3001,7 @@ dependencies = [ "fxhash", "indexmap", "itertools", + "log", "snarkvm-curves", "snarkvm-fields", "snarkvm-utilities", @@ -3052,6 +3072,7 @@ version = "0.11.7" dependencies = [ "bincode", "colored", + "log", "once_cell", "serde_json", "snarkvm-algorithms", @@ -3066,6 +3087,7 @@ dependencies = [ "aleo-std", "anyhow", "bincode", + "log", "num-bigint", "num_cpus", "rand 0.8.5", diff --git a/Cargo.toml b/Cargo.toml index 276cf9a796..9cb291c517 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -239,6 +239,9 @@ optional = true version = "2.6" features = [ "json" ] +[dependencies.log] +version = "0.4.14" + [dev-dependencies.bincode] version = "1.3" diff --git a/algorithms/Cargo.toml b/algorithms/Cargo.toml index 2e3db5d14a..38aa9b1d16 100644 --- a/algorithms/Cargo.toml +++ b/algorithms/Cargo.toml @@ -145,6 +145,9 @@ version = "1.0" version = "0.4" optional = true +[dependencies.log] +version = "0.4.14" + [dev-dependencies.expect-test] version = "1.4.1" diff --git a/algorithms/src/snark/marlin/ahp/indexer/indexer.rs b/algorithms/src/snark/marlin/ahp/indexer/indexer.rs index e7d9ae2e1f..41799b19aa 100644 --- a/algorithms/src/snark/marlin/ahp/indexer/indexer.rs +++ b/algorithms/src/snark/marlin/ahp/indexer/indexer.rs @@ -27,6 +27,7 @@ use crate::{ MarlinMode, }, }; +use log::{trace, warn}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::{errors::SynthesisError, ConstraintSynthesizer, ConstraintSystem}; use snarkvm_utilities::cfg_into_iter; @@ -36,8 +37,6 @@ use std::collections::BTreeMap; #[cfg(not(feature = "serial"))] use rayon::prelude::*; -#[cfg(not(feature = "std"))] -use snarkvm_utilities::println; use super::Matrix; @@ -151,22 +150,20 @@ impl AHPForR1CS { let num_non_zero_c = num_non_zero(&c); let num_variables = num_padded_public_variables + num_private_variables; - if cfg!(debug_assertions) { - println!("Number of padded public variables: {num_padded_public_variables}"); - println!("Number of private variables: {num_private_variables}"); - println!("Number of num_constraints: {num_constraints}"); - println!("Number of non-zero entries in A: {num_non_zero_a}"); - println!("Number of non-zero entries in B: {num_non_zero_b}"); - println!("Number of non-zero entries in C: {num_non_zero_c}"); - } + trace!("Number of padded public variables: {num_padded_public_variables}"); + trace!("Number of private variables: {num_private_variables}"); + trace!("Number of num_constraints: {num_constraints}"); + trace!("Number of non-zero entries in A: {num_non_zero_a}"); + trace!("Number of non-zero entries in B: {num_non_zero_b}"); + trace!("Number of non-zero entries in C: {num_non_zero_c}"); if num_constraints != num_variables { - eprintln!("Number of padded public variables: {num_padded_public_variables}"); - eprintln!("Number of private variables: {num_private_variables}"); - eprintln!("Number of num_constraints: {num_constraints}"); - eprintln!("Number of non-zero entries in A: {num_non_zero_a}"); - eprintln!("Number of non-zero entries in B: {num_non_zero_b}"); - eprintln!("Number of non-zero entries in C: {num_non_zero_c}"); + warn!("Number of padded public variables: {num_padded_public_variables}"); + warn!("Number of private variables: {num_private_variables}"); + warn!("Number of num_constraints: {num_constraints}"); + warn!("Number of non-zero entries in A: {num_non_zero_a}"); + warn!("Number of non-zero entries in B: {num_non_zero_b}"); + warn!("Number of non-zero entries in C: {num_non_zero_c}"); return Err(AHPError::NonSquareMatrix); } diff --git a/algorithms/src/snark/marlin/ahp/prover/round_functions/mod.rs b/algorithms/src/snark/marlin/ahp/prover/round_functions/mod.rs index 86ebcc1989..bf85391c6e 100644 --- a/algorithms/src/snark/marlin/ahp/prover/round_functions/mod.rs +++ b/algorithms/src/snark/marlin/ahp/prover/round_functions/mod.rs @@ -17,13 +17,12 @@ use crate::snark::marlin::{ prover, MarlinMode, }; +use log::trace; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSynthesizer; use std::collections::BTreeMap; use snarkvm_utilities::cfg_iter; -#[cfg(not(feature = "std"))] -use snarkvm_utilities::println; #[cfg(not(feature = "serial"))] use rayon::prelude::*; @@ -78,14 +77,12 @@ impl AHPForR1CS { assert!(padded_public_variables[0].is_one()); assert_eq!(private_variables.len(), num_private_variables); - if cfg!(debug_assertions) { - println!("Number of padded public variables in Prover::Init: {num_public_variables}"); - println!("Number of private variables: {num_private_variables}"); - println!("Number of constraints: {num_constraints}"); - println!("Number of non-zero entries in A: {num_non_zero_a}"); - println!("Number of non-zero entries in B: {num_non_zero_b}"); - println!("Number of non-zero entries in C: {num_non_zero_c}"); - } + trace!("Number of padded public variables in Prover::Init: {num_public_variables}"); + trace!("Number of private variables: {num_private_variables}"); + trace!("Number of constraints: {num_constraints}"); + trace!("Number of non-zero entries in A: {num_non_zero_a}"); + trace!("Number of non-zero entries in B: {num_non_zero_b}"); + trace!("Number of non-zero entries in C: {num_non_zero_c}"); if circuit.index_info.num_constraints != num_constraints || circuit.index_info.num_variables != (num_public_variables + num_private_variables) diff --git a/algorithms/src/snark/marlin/marlin.rs b/algorithms/src/snark/marlin/marlin.rs index 681c015e43..af9f434d00 100644 --- a/algorithms/src/snark/marlin/marlin.rs +++ b/algorithms/src/snark/marlin/marlin.rs @@ -43,6 +43,7 @@ use crate::{ SRS, }; use itertools::Itertools; +use log::{trace, warn}; use rand::{CryptoRng, Rng}; use snarkvm_curves::PairingEngine; use snarkvm_fields::{One, PrimeField, ToConstraintField, Zero}; @@ -51,9 +52,6 @@ use snarkvm_utilities::{to_bytes_le, ToBytes}; use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc}; -#[cfg(not(feature = "std"))] -use snarkvm_utilities::println; - use core::{ marker::PhantomData, sync::atomic::{AtomicBool, Ordering}, @@ -636,7 +634,7 @@ where #[cfg(debug_assertions)] if !Self::verify_batch(fs_parameters, &vk_to_inputs, &proof)? { - println!("Invalid proof") + trace!("Invalid proof") } end_timer!(prover_time); @@ -701,7 +699,7 @@ where new_input.extend_from_slice(&input); new_input.resize(input.len().max(input_domain.size()), E::Fr::zero()); if cfg!(debug_assertions) { - println!("Number of padded public variables: {}", new_input.len()); + trace!("Number of padded public variables: {}", new_input.len()); } let unformatted = prover::ConstraintSystem::unformat_public_input(&new_input); (new_input, unformatted) @@ -727,7 +725,7 @@ where !proof.pc_proof.is_hiding() & comms.mask_poly.is_none() }; if !proof_has_correct_zk_mode { - eprintln!( + warn!( "Found `mask_poly` in the first round when not expected, or proof has incorrect hiding mode ({})", proof.pc_proof.is_hiding() ); @@ -911,7 +909,7 @@ where if !evaluations_are_correct { #[cfg(debug_assertions)] - eprintln!("SonicKZG10::Check failed"); + warn!("SonicKZG10::Check failed"); } end_timer!(verifier_time, || format!( " SonicKZG10::Check for AHP Verifier linear equations: {}", diff --git a/algorithms/src/snark/marlin/tests.rs b/algorithms/src/snark/marlin/tests.rs index 622f813f58..c96143bfcd 100644 --- a/algorithms/src/snark/marlin/tests.rs +++ b/algorithms/src/snark/marlin/tests.rs @@ -82,7 +82,7 @@ mod marlin { let index_keys = $marlin_inst::batch_circuit_setup(&universal_srs, unique_instances.as_slice()).unwrap(); - println!("Called circuit setup"); + println!("Called circuit setup"); let mut pks_to_constraints = BTreeMap::new(); let mut vks_to_inputs = BTreeMap::new(); @@ -103,7 +103,7 @@ mod marlin { let proof = $marlin_inst::prove_batch(&fs_parameters, &pks_to_constraints, rng).unwrap(); - println!("Called prover"); + println!("Called prover"); assert!( $marlin_inst::verify_batch(&fs_parameters, &vks_to_inputs, &proof).unwrap(), diff --git a/circuit/account/Cargo.toml b/circuit/account/Cargo.toml index d08ba0fd68..b9f61fd12f 100644 --- a/circuit/account/Cargo.toml +++ b/circuit/account/Cargo.toml @@ -24,6 +24,9 @@ version = "=0.11.7" path = "../types" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-utilities] path = "../../utilities" diff --git a/circuit/algorithms/Cargo.toml b/circuit/algorithms/Cargo.toml index 10691e08f3..4155478488 100644 --- a/circuit/algorithms/Cargo.toml +++ b/circuit/algorithms/Cargo.toml @@ -21,6 +21,9 @@ path = "../../fields" version = "=0.11.7" default-features = false +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-curves] path = "../../curves" default-features = false diff --git a/circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs b/circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs index a519628879..b510b4d7e7 100644 --- a/circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs +++ b/circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs @@ -146,7 +146,8 @@ impl HashUncompres // Otherwise, call `montgomery_add` to add to the accumulating sum. Some((sum_x, sum_y)) => { // Sum the new Montgomery point into the accumulating sum. - sum = Some(montgomery_add((sum_x, sum_y), (&montgomery_x, &montgomery_y))); // 3 constraints + sum = Some(montgomery_add((sum_x, sum_y), (&montgomery_x, &montgomery_y))); + // 3 constraints } } }); @@ -157,7 +158,8 @@ impl HashUncompres // Convert the accumulated sum into a point on the twisted Edwards curve. let edwards_x = sum_x.div_unchecked(sum_y); // 1 constraint (`sum_y` is never 0) let edwards_y = (sum_x - &one).div_unchecked(&(sum_x + &one)); // 1 constraint (numerator & denominator are never both 0) - Group::from_xy_coordinates_unchecked(edwards_x, edwards_y) // 0 constraints (this is safe) + Group::from_xy_coordinates_unchecked(edwards_x, edwards_y) + // 0 constraints (this is safe) } None => E::halt("Invalid iteration of BHP detected, a window was not evaluated"), } diff --git a/circuit/algorithms/src/pedersen/commit.rs b/circuit/algorithms/src/pedersen/commit.rs index 157504b7f2..702ee9f339 100644 --- a/circuit/algorithms/src/pedersen/commit.rs +++ b/circuit/algorithms/src/pedersen/commit.rs @@ -157,7 +157,7 @@ mod tests { second: C, rng: &mut TestRng, ) { - println!("Checking homomorphic addition on {first} + {second}"); + log::trace!("Checking homomorphic addition on {first} + {second}"); // Sample the circuit randomizers. let first_randomizer: Scalar<_> = Inject::new(Mode::Private, Uniform::rand(rng)); diff --git a/circuit/algorithms/src/pedersen/commit_uncompressed.rs b/circuit/algorithms/src/pedersen/commit_uncompressed.rs index b0f539e069..4f428cc3cd 100644 --- a/circuit/algorithms/src/pedersen/commit_uncompressed.rs +++ b/circuit/algorithms/src/pedersen/commit_uncompressed.rs @@ -163,7 +163,7 @@ mod tests { second: C, rng: &mut TestRng, ) { - println!("Checking homomorphic addition on {first} + {second}"); + log::trace!("Checking homomorphic addition on {first} + {second}"); // Sample the circuit randomizers. let first_randomizer: Scalar<_> = Inject::new(Mode::Private, Uniform::rand(rng)); diff --git a/circuit/collections/Cargo.toml b/circuit/collections/Cargo.toml index 38a4b90ce8..30d01ea821 100644 --- a/circuit/collections/Cargo.toml +++ b/circuit/collections/Cargo.toml @@ -20,6 +20,9 @@ version = "=0.11.7" path = "../types" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-circuit-network] path = "../network" diff --git a/circuit/environment/Cargo.toml b/circuit/environment/Cargo.toml index 6418f11fb2..340e08c72e 100644 --- a/circuit/environment/Cargo.toml +++ b/circuit/environment/Cargo.toml @@ -56,6 +56,9 @@ version = "0.2" [dependencies.once_cell] version = "1.17.2" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-algorithms] path = "../../algorithms" features = [ "polycommit_full", "snark" ] diff --git a/circuit/environment/src/helpers/constraint.rs b/circuit/environment/src/helpers/constraint.rs index ecb8a7ee32..2d90c06097 100644 --- a/circuit/environment/src/helpers/constraint.rs +++ b/circuit/environment/src/helpers/constraint.rs @@ -40,7 +40,7 @@ impl Constraint { match a * b == c { true => true, false => { - eprintln!("Failed constraint at {scope}:\n\t({a} * {b}) != {c}"); + log::warn!("Failed constraint at {scope}:\n\t({a} * {b}) != {c}"); false } } diff --git a/circuit/environment/src/helpers/count.rs b/circuit/environment/src/helpers/count.rs index 88dfbf558a..6c7d0186f6 100644 --- a/circuit/environment/src/helpers/count.rs +++ b/circuit/environment/src/helpers/count.rs @@ -111,7 +111,7 @@ impl + Sub + Mul }; if !outcome { - eprintln!("Metrics claims the count should be {self:?}, found {candidate:?} during synthesis"); + log::warn!("Metrics claims the count should be {self:?}, found {candidate:?} during synthesis"); } outcome diff --git a/circuit/environment/src/helpers/linear_combination.rs b/circuit/environment/src/helpers/linear_combination.rs index 6232f360be..5aa94d9c2d 100644 --- a/circuit/environment/src/helpers/linear_combination.rs +++ b/circuit/environment/src/helpers/linear_combination.rs @@ -13,6 +13,7 @@ // limitations under the License. use crate::{Mode, *}; +use log::warn; use snarkvm_fields::PrimeField; use core::{ @@ -95,13 +96,13 @@ impl LinearCombination { // Enforce property 2. // Note: This branch is triggered if ANY term is not (zero or one). if self.terms.iter().any(|(v, _)| !(v.value().is_zero() || v.value().is_one())) { - eprintln!("Property 2 of the `Boolean` type was violated in {self}"); + warn!("Property 2 of the `Boolean` type was violated in {self}"); return false; } // Enforce property 3. if !(self.value.is_zero() || self.value.is_one()) { - eprintln!("Property 3 of the `Boolean` type was violated"); + warn!("Property 3 of the `Boolean` type was violated"); return false; } @@ -109,7 +110,7 @@ impl LinearCombination { } else { // Property 1 of the `Boolean` type was violated. // Both self.constant and self.terms contain elements. - eprintln!("Both LC::constant and LC::terms contain elements, which is a violation"); + warn!("Both LC::constant and LC::terms contain elements, which is a violation"); false } } diff --git a/circuit/environment/src/macros/scope.rs b/circuit/environment/src/macros/scope.rs index 07290ec0cd..24177a2d25 100644 --- a/circuit/environment/src/macros/scope.rs +++ b/circuit/environment/src/macros/scope.rs @@ -22,7 +22,7 @@ macro_rules! scope { #[macro_export] macro_rules! print_scope { () => {{ - println!( + log::trace!( "Circuit::scope(Constants: {:?}, Public: {:?}, Private: {:?}, Constraints: {:?})\n", Circuit::num_constants_in_scope(), Circuit::num_public_in_scope(), diff --git a/circuit/program/Cargo.toml b/circuit/program/Cargo.toml index 836f6dc6d4..86cbaa1220 100644 --- a/circuit/program/Cargo.toml +++ b/circuit/program/Cargo.toml @@ -32,6 +32,9 @@ version = "=0.11.7" path = "../../utilities" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.console] package = "snarkvm-console-program" path = "../../console/program" diff --git a/circuit/types/Cargo.toml b/circuit/types/Cargo.toml index d1f76d9fbe..42771d0487 100644 --- a/circuit/types/Cargo.toml +++ b/circuit/types/Cargo.toml @@ -37,3 +37,6 @@ version = "=0.11.7" [dependencies.snarkvm-circuit-types-string] path = "./string" version = "=0.11.7" + +[dependencies.log] +version = "0.4.14" diff --git a/circuit/types/address/Cargo.toml b/circuit/types/address/Cargo.toml index ee0f429a68..e0caf9784e 100644 --- a/circuit/types/address/Cargo.toml +++ b/circuit/types/address/Cargo.toml @@ -32,6 +32,9 @@ version = "=0.11.7" path = "../scalar" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [features] default = [ "enable_console" ] enable_console = [ "console" ] diff --git a/circuit/types/boolean/Cargo.toml b/circuit/types/boolean/Cargo.toml index e4c61c8ad3..1fab9985df 100644 --- a/circuit/types/boolean/Cargo.toml +++ b/circuit/types/boolean/Cargo.toml @@ -21,6 +21,9 @@ optional = true path = "../../environment" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.criterion] version = "0.5" diff --git a/circuit/types/boolean/src/helpers/adder.rs b/circuit/types/boolean/src/helpers/adder.rs index eb9d6064f5..7a056f4654 100644 --- a/circuit/types/boolean/src/helpers/adder.rs +++ b/circuit/types/boolean/src/helpers/adder.rs @@ -256,7 +256,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Public, Mode::Constant, 0, 0, 0, 0); check_true_add_false_with_true(Mode::Constant, Mode::Public, Mode::Constant, 0, 0, 1, 1); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Public, Mode::Constant, 0, 0, 0, 0); - check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Constant, 0, 0, 1, 1); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Constant, 0, 0, 1, 1); + // <- Differs } #[test] @@ -268,7 +269,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Public, Mode::Public, 0, 0, 3, 3); // <- Differs check_true_add_false_with_true(Mode::Constant, Mode::Public, Mode::Public, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Public, Mode::Public, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Public, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Public, 0, 0, 3, 3); + // <- Differs } #[test] @@ -280,7 +282,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Public, Mode::Private, 0, 0, 3, 3); // <- Differs check_true_add_false_with_true(Mode::Constant, Mode::Public, Mode::Private, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Public, Mode::Private, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Private, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Public, Mode::Private, 0, 0, 3, 3); + // <- Differs } #[test] @@ -292,7 +295,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Private, Mode::Constant, 0, 0, 0, 0); check_true_add_false_with_true(Mode::Constant, Mode::Private, Mode::Constant, 0, 0, 1, 1); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Private, Mode::Constant, 0, 0, 0, 0); - check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Constant, 0, 0, 1, 1); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Constant, 0, 0, 1, 1); + // <- Differs } #[test] @@ -304,7 +308,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Private, Mode::Public, 0, 0, 3, 3); // <- Differs check_true_add_false_with_true(Mode::Constant, Mode::Private, Mode::Public, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Private, Mode::Public, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Public, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Public, 0, 0, 3, 3); + // <- Differs } #[test] @@ -316,7 +321,8 @@ mod tests { check_true_add_false_with_false(Mode::Constant, Mode::Private, Mode::Private, 0, 0, 3, 3); // <- Differs check_true_add_false_with_true(Mode::Constant, Mode::Private, Mode::Private, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Constant, Mode::Private, Mode::Private, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Private, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Constant, Mode::Private, Mode::Private, 0, 0, 3, 3); + // <- Differs } #[test] @@ -328,7 +334,8 @@ mod tests { check_true_add_false_with_false(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); check_true_add_false_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); check_true_add_true_with_false(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); - check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 1, 1); // <- Differs + check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 1, 1); + // <- Differs } #[test] @@ -340,7 +347,8 @@ mod tests { check_true_add_false_with_false(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 2, 2); check_true_add_false_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 2, 2); check_true_add_true_with_false(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); + // <- Differs } #[test] @@ -352,7 +360,8 @@ mod tests { check_true_add_false_with_false(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 2, 2); check_true_add_false_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 2, 2); check_true_add_true_with_false(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); // <- Differs - check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); + // <- Differs } #[test] @@ -364,7 +373,8 @@ mod tests { check_true_add_false_with_false(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 2, 2); check_true_add_false_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 2, 2); - check_true_add_true_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); + // <- Differs } #[test] @@ -400,7 +410,8 @@ mod tests { check_true_add_false_with_false(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 2, 2); check_true_add_false_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); // <- Differs check_true_add_true_with_false(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 2, 2); - check_true_add_true_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); // <- Differs + check_true_add_true_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); + // <- Differs } #[test] diff --git a/circuit/types/boolean/src/helpers/subtractor.rs b/circuit/types/boolean/src/helpers/subtractor.rs index 6981d2058c..6e21267f91 100644 --- a/circuit/types/boolean/src/helpers/subtractor.rs +++ b/circuit/types/boolean/src/helpers/subtractor.rs @@ -328,7 +328,8 @@ mod tests { check_true_sub_false_with_false(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); check_true_sub_false_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); check_true_sub_true_with_false(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 0, 0); - check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 1, 1); // <- Differs + check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Constant, 0, 0, 1, 1); + // <- Differs } #[test] @@ -340,7 +341,8 @@ mod tests { check_true_sub_false_with_false(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 2, 2); check_true_sub_false_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 2, 2); check_true_sub_true_with_false(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); // <- Differs - check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); // <- Differs + check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Public, 0, 0, 3, 3); + // <- Differs } #[test] @@ -352,7 +354,8 @@ mod tests { check_true_sub_false_with_false(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 2, 2); check_true_sub_false_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 2, 2); check_true_sub_true_with_false(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); // <- Differs - check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); // <- Differs + check_true_sub_true_with_true(Mode::Public, Mode::Constant, Mode::Private, 0, 0, 3, 3); + // <- Differs } #[test] @@ -364,7 +367,8 @@ mod tests { check_true_sub_false_with_false(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 2, 2); check_true_sub_false_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); // <- Differs check_true_sub_true_with_false(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 2, 2); - check_true_sub_true_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); // <- Differs + check_true_sub_true_with_true(Mode::Public, Mode::Public, Mode::Constant, 0, 0, 3, 3); + // <- Differs } #[test] @@ -400,7 +404,8 @@ mod tests { check_true_sub_false_with_false(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 2, 2); check_true_sub_false_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); // <- Differs check_true_sub_true_with_false(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 2, 2); - check_true_sub_true_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); // <- Differs + check_true_sub_true_with_true(Mode::Public, Mode::Private, Mode::Constant, 0, 0, 3, 3); + // <- Differs } #[test] diff --git a/circuit/types/field/Cargo.toml b/circuit/types/field/Cargo.toml index 1e072d0f46..132f0879a6 100644 --- a/circuit/types/field/Cargo.toml +++ b/circuit/types/field/Cargo.toml @@ -20,6 +20,9 @@ version = "=0.11.7" path = "../boolean" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [features] default = [ "enable_console" ] enable_console = [ "console" ] diff --git a/circuit/types/group/Cargo.toml b/circuit/types/group/Cargo.toml index 5000df205f..6eabccecb8 100644 --- a/circuit/types/group/Cargo.toml +++ b/circuit/types/group/Cargo.toml @@ -28,6 +28,9 @@ version = "=0.11.7" path = "../scalar" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-utilities] path = "../../../utilities" default-features = false diff --git a/circuit/types/integers/Cargo.toml b/circuit/types/integers/Cargo.toml index 597959710f..03d21e5106 100644 --- a/circuit/types/integers/Cargo.toml +++ b/circuit/types/integers/Cargo.toml @@ -24,6 +24,9 @@ version = "=0.11.7" path = "../field" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-utilities] path = "../../../utilities" default-features = false diff --git a/circuit/types/scalar/Cargo.toml b/circuit/types/scalar/Cargo.toml index ac0514f256..f341f426db 100644 --- a/circuit/types/scalar/Cargo.toml +++ b/circuit/types/scalar/Cargo.toml @@ -24,6 +24,9 @@ version = "=0.11.7" path = "../field" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [features] default = [ "enable_console" ] enable_console = [ "console" ] diff --git a/circuit/types/string/Cargo.toml b/circuit/types/string/Cargo.toml index c0fdc15991..e9e379ba49 100644 --- a/circuit/types/string/Cargo.toml +++ b/circuit/types/string/Cargo.toml @@ -28,6 +28,9 @@ version = "=0.11.7" path = "../integers" version = "=0.11.7" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-utilities] path = "../../../utilities" default-features = false diff --git a/console/account/Cargo.toml b/console/account/Cargo.toml index 41db2abbf5..79ce766f26 100644 --- a/console/account/Cargo.toml +++ b/console/account/Cargo.toml @@ -28,6 +28,9 @@ version = "0.5" version = "1.0" optional = true +[dependencies.log] +version = "0.4.14" + [dev-dependencies.bincode] version = "1.3" diff --git a/console/account/src/signature/verify.rs b/console/account/src/signature/verify.rs index c0b97bb2e4..80a86635d1 100644 --- a/console/account/src/signature/verify.rs +++ b/console/account/src/signature/verify.rs @@ -20,7 +20,7 @@ impl Signature { pub fn verify(&self, address: &Address, message: &[Field]) -> bool { // Ensure the number of field elements does not exceed the maximum allowed size. if message.len() > N::MAX_DATA_SIZE_IN_FIELDS as usize { - eprintln!("Cannot sign the signature: the signed message exceeds maximum allowed size"); + log::warn!("Cannot sign the signature: the signed message exceeds maximum allowed size"); return false; } @@ -69,7 +69,7 @@ impl Signature { match message.chunks(Field::::size_in_data_bits()).map(Field::from_bits_le).collect::>>() { Ok(fields) => self.verify(address, &fields), Err(error) => { - eprintln!("Failed to verify signature: {error}"); + log::warn!("Failed to verify signature: {error}"); false } } diff --git a/console/collections/Cargo.toml b/console/collections/Cargo.toml index 6445ef6b1e..9567246255 100644 --- a/console/collections/Cargo.toml +++ b/console/collections/Cargo.toml @@ -28,6 +28,9 @@ default-features = false [dependencies.rayon] version = "1" +[dependencies.log] +version = "0.4.14" + [dev-dependencies.snarkvm-console-network] path = "../network" diff --git a/console/collections/src/merkle_tree/path/mod.rs b/console/collections/src/merkle_tree/path/mod.rs index b867a10b77..7efead99a4 100644 --- a/console/collections/src/merkle_tree/path/mod.rs +++ b/console/collections/src/merkle_tree/path/mod.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use log::warn; + use super::*; #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -61,12 +63,12 @@ impl MerklePath { ) -> bool { // Ensure the leaf index is within the tree depth. if (*self.leaf_index as u128) >= (1u128 << DEPTH) { - eprintln!("Found an out of bounds Merkle leaf index"); + warn!("Found an out of bounds Merkle leaf index"); return false; } // Ensure the path length matches the expected depth. else if self.siblings.len() != DEPTH as usize { - eprintln!("Found an incorrect Merkle path length"); + warn!("Found an incorrect Merkle path length"); return false; } @@ -74,7 +76,7 @@ impl MerklePath { let mut current_hash = match leaf_hasher.hash_leaf(leaf) { Ok(candidate_leaf_hash) => candidate_leaf_hash, Err(error) => { - eprintln!("Failed to hash the Merkle leaf during verification: {error}"); + warn!("Failed to hash the Merkle leaf during verification: {error}"); return false; } }; @@ -95,7 +97,7 @@ impl MerklePath { match path_hasher.hash_children(&left, &right) { Ok(hash) => current_hash = hash, Err(error) => { - eprintln!("Failed to hash the Merkle path during verification: {error}"); + warn!("Failed to hash the Merkle path during verification: {error}"); return false; } } diff --git a/console/program/Cargo.toml b/console/program/Cargo.toml index 0fa0feedfd..72017f18a5 100644 --- a/console/program/Cargo.toml +++ b/console/program/Cargo.toml @@ -52,5 +52,8 @@ version = "1.17.2" version = "1.0" features = [ "preserve_order" ] +[dependencies.log] +version = "0.4.14" + [dev-dependencies.bincode] version = "1.3" diff --git a/console/program/src/request/verify.rs b/console/program/src/request/verify.rs index 5089f03522..293daace3b 100644 --- a/console/program/src/request/verify.rs +++ b/console/program/src/request/verify.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::*; +use log::warn; impl Request { /// Returns `true` if the request is valid, and `false` otherwise. @@ -26,7 +27,7 @@ impl Request { let tpk = N::g_scalar_multiply(&self.tsk); // Ensure the transition public key matches with the derived one from the signature. if tpk != self.to_tpk() { - eprintln!("Invalid transition public key in request."); + warn!("Invalid transition public key in request."); return false; } @@ -34,7 +35,7 @@ impl Request { let tvk = (*self.caller * self.tsk).to_x_coordinate(); // Ensure the computed transition view key matches. if tvk != self.tvk { - eprintln!("Invalid transition view key in request."); + warn!("Invalid transition view key in request."); return false; } @@ -43,12 +44,12 @@ impl Request { Ok(tcm) => { // Ensure the computed transition commitment matches. if tcm != self.tcm { - eprintln!("Invalid transition commitment in request."); + warn!("Invalid transition commitment in request."); return false; } } Err(error) => { - eprintln!("Failed to compute transition commitment in request verification: {error}"); + warn!("Failed to compute transition commitment in request verification: {error}"); return false; } } @@ -66,7 +67,7 @@ impl Request { ) { Ok(function_id) => function_id, Err(error) => { - eprintln!("Failed to construct the function ID: {error}"); + warn!("Failed to construct the function ID: {error}"); return false; } }; @@ -208,7 +209,7 @@ impl Request { Ok(()) }, ) { - eprintln!("Request verification failed on input checks: {error}"); + warn!("Request verification failed on input checks: {error}"); return false; } diff --git a/parameters/Cargo.toml b/parameters/Cargo.toml index 300aaea000..aedee4d2ef 100644 --- a/parameters/Cargo.toml +++ b/parameters/Cargo.toml @@ -92,6 +92,9 @@ version = "0.3.63" features = [ "XmlHttpRequest" ] optional = true +[dependencies.log] +version = "0.4.14" + [target."cfg(not(target_family = \"wasm\"))".dependencies.curl] version = "0.4.43" optional = true diff --git a/parameters/examples/inclusion.rs b/parameters/examples/inclusion.rs index 66ee7f0627..6185b611ea 100644 --- a/parameters/examples/inclusion.rs +++ b/parameters/examples/inclusion.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use log::trace; use snarkvm_algorithms::crypto_hash::sha256::sha256; use snarkvm_circuit::{Aleo, Assignment}; use snarkvm_console::{ @@ -33,7 +34,7 @@ use anyhow::{anyhow, Result}; use rand::thread_rng; use serde_json::{json, Value}; use snarkvm_console::program::{Plaintext, Record}; -use snarkvm_utilities::ToBytes; +use snarkvm_utilities::{SimplerLogger, ToBytes}; use std::{ fs::File, io::{BufWriter, Write}, @@ -146,7 +147,7 @@ pub fn inclusion>() -> Result<()> { "verifier_size": verifying_key_bytes.len(), }); - println!("{}", serde_json::to_string_pretty(&metadata)?); + trace!("{}", serde_json::to_string_pretty(&metadata)?); write_metadata(&format!("{inclusion_function_name}.metadata"), &metadata)?; write_remote(&format!("{inclusion_function_name}.prover"), &proving_key_checksum, &proving_key_bytes)?; write_remote(&format!("{inclusion_function_name}.verifier"), &verifying_key_checksum, &verifying_key_bytes)?; @@ -161,13 +162,13 @@ pub fn inclusion>() -> Result<()> { )); // Print the commands. - println!("\nNow, run the following commands:\n"); - println!("snarkup remove provers"); - println!("snarkup remove verifiers\n"); + trace!("\nNow, run the following commands:\n"); + trace!("snarkup remove provers"); + trace!("snarkup remove verifiers\n"); for command in commands { - println!("{command}"); + trace!("{command}"); } - println!(); + trace!(""); Ok(()) } @@ -175,10 +176,11 @@ pub fn inclusion>() -> Result<()> { /// Run the following command to generate the inclusion circuit keys. /// `cargo run --example inclusion [network]` pub fn main() -> Result<()> { + SimplerLogger::new().init()?; let args: Vec = std::env::args().collect(); if args.len() < 2 { - println!("Invalid number of arguments. Given: {} - Required: 1", args.len() - 1); + trace!("Invalid number of arguments. Given: {} - Required: 1", args.len() - 1); return Ok(()); } diff --git a/parameters/examples/setup.rs b/parameters/examples/setup.rs index 93fce3cdbc..06da4f81f8 100644 --- a/parameters/examples/setup.rs +++ b/parameters/examples/setup.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use log::{trace, warn}; use snarkvm_algorithms::crypto_hash::sha256::sha256; use snarkvm_circuit::Aleo; use snarkvm_console::network::{Network, Testnet3}; @@ -19,7 +20,7 @@ use snarkvm_synthesizer::{Process, Program}; use anyhow::Result; use serde_json::{json, Value}; -use snarkvm_utilities::ToBytes; +use snarkvm_utilities::{SimplerLogger, ToBytes}; use std::{ fs, fs::File, @@ -101,7 +102,7 @@ pub fn credits_program>() -> Result<()> { for (function_name, _) in program.functions().iter() { // let timer = std::time::Instant::now(); // process.synthesize_key::(program_id, function_name, rng)?; - // println!("Synthesized '{}': {} ms", function_name, timer.elapsed().as_millis()); + // trace!("Synthesized '{}': {} ms", function_name, timer.elapsed().as_millis()); let proving_key = process.get_proving_key(program_id, function_name)?; let proving_key_bytes = proving_key.to_bytes_le()?; @@ -118,7 +119,7 @@ pub fn credits_program>() -> Result<()> { "verifier_size": verifying_key_bytes.len(), }); - println!("{}", serde_json::to_string_pretty(&metadata)?); + trace!("{}", serde_json::to_string_pretty(&metadata)?); write_metadata(&format!("{function_name}.metadata"), &metadata)?; write_remote(&format!("{function_name}.prover"), &proving_key_checksum, &proving_key_bytes)?; write_remote(&format!("{function_name}.verifier"), &verifying_key_checksum, &verifying_key_bytes)?; @@ -134,13 +135,13 @@ pub fn credits_program>() -> Result<()> { } // Print the commands. - println!("\nNow, run the following commands:\n"); - println!("snarkup remove provers"); - println!("snarkup remove verifiers\n"); + trace!("\nNow, run the following commands:\n"); + trace!("snarkup remove provers"); + trace!("snarkup remove verifiers\n"); for command in commands { - println!("{command}"); + trace!("{command}"); } - println!(); + trace!(""); Ok(()) } @@ -148,9 +149,10 @@ pub fn credits_program>() -> Result<()> { /// Run the following command to perform a setup. /// `cargo run --example setup [variant]` pub fn main() -> Result<()> { + SimplerLogger::new().init()?; let args: Vec = std::env::args().collect(); if args.len() < 3 { - eprintln!("Invalid number of arguments. Given: {} - Required: 2", args.len() - 1); + warn!("Invalid number of arguments. Given: {} - Required: 2", args.len() - 1); return Ok(()); } diff --git a/parameters/src/macros.rs b/parameters/src/macros.rs index 34e93a11eb..dbf30b3d73 100644 --- a/parameters/src/macros.rs +++ b/parameters/src/macros.rs @@ -34,8 +34,8 @@ macro_rules! remove_file { #[cfg(not(feature = "wasm"))] if std::path::PathBuf::from(&$filepath).exists() { match std::fs::remove_file(&$filepath) { - Ok(()) => println!("Removed {:?}. Please retry the command.", $filepath), - Err(err) => eprintln!("Failed to remove {:?}: {err}", $filepath), + Ok(()) => log::trace!("Removed {:?}. Please retry the command.", $filepath), + Err(err) => log::warn!("Failed to remove {:?}: {err}", $filepath), } } }; @@ -51,7 +51,7 @@ macro_rules! impl_store_and_remote_fetch { { use colored::*; let output = format!("{:>15} - Storing file in {:?}", "Installation", file_path); - println!("{}", output.dimmed()); + log::trace!("{}", output.dimmed()); } // Ensure the folders up to the file path all exist. @@ -62,7 +62,7 @@ macro_rules! impl_store_and_remote_fetch { // Attempt to write the parameter buffer to a file. match std::fs::File::create(file_path) { Ok(mut file) => file.write_all(&buffer)?, - Err(error) => eprintln!("{}", error), + Err(error) => log::warn!("{}", error), } Ok(()) } @@ -78,7 +78,7 @@ macro_rules! impl_store_and_remote_fetch { use colored::*; let output = format!("{:>15} - Downloading \"{}\"", "Installation", url); - println!("{}", output.dimmed()); + log::trace!("{}", output.dimmed()); easy.progress(true)?; easy.progress_function(|total_download, current_download, _, _| { @@ -178,11 +178,11 @@ macro_rules! impl_load_bytes_logic_remote { std::fs::read(&file_path)? } else { // Downloads the missing parameters and stores it in the local directory for use. - #[cfg(not(feature = "no_std_out"))] + #[cfg(not(feature = "no_std_out"))] { use colored::*; let path = format!("(in {:?})", file_path); - eprintln!( + log::warn!( "\n⚠️ \"{}\" does not exist. Downloading and storing it {}.\n", $filename, path.dimmed() ); @@ -206,7 +206,7 @@ macro_rules! impl_load_bytes_logic_remote { match Self::store_bytes(&buffer, &file_path) { Ok(()) => buffer, Err(_) => { - eprintln!( + log::warn!( "\n❗ Error - Failed to store \"{}\" locally. Please download this file manually and ensure it is stored in {:?}.\n", $filename, file_path ); diff --git a/parameters/src/testnet3/powers.rs b/parameters/src/testnet3/powers.rs index d289a74744..3949d393cd 100644 --- a/parameters/src/testnet3/powers.rs +++ b/parameters/src/testnet3/powers.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::*; +use log::trace; use snarkvm_curves::traits::PairingEngine; use snarkvm_utilities::{ CanonicalDeserialize, @@ -364,8 +365,7 @@ impl PowersOfBetaG { // Download the powers of two. for num_powers in &download_queue { - #[cfg(debug_assertions)] - println!("Loading {num_powers} powers"); + trace!("Loading {num_powers} powers"); // Download the universal SRS powers if they're not already on disk. let additional_bytes = match *num_powers { @@ -442,8 +442,7 @@ impl PowersOfBetaG { let mut final_powers = Vec::with_capacity(final_num_powers); // If the `target_degree` exceeds the current `degree`, proceed to download the new powers. for num_powers in &download_queue { - #[cfg(debug_assertions)] - println!("Loading {num_powers} shifted powers"); + trace!("Loading {num_powers} shifted powers"); // Download the universal SRS powers if they're not already on disk. let additional_bytes = match *num_powers { diff --git a/r1cs/Cargo.toml b/r1cs/Cargo.toml index c4cb18e3de..7d75e843c1 100644 --- a/r1cs/Cargo.toml +++ b/r1cs/Cargo.toml @@ -55,5 +55,8 @@ version = "0.10.3" [dependencies.thiserror] version = "1.0" +[dependencies.log] +version = "0.4.14" + [features] default = [ ] diff --git a/r1cs/src/test_constraint_system.rs b/r1cs/src/test_constraint_system.rs index 3214d7b95b..f9ac433ab3 100644 --- a/r1cs/src/test_constraint_system.rs +++ b/r1cs/src/test_constraint_system.rs @@ -13,6 +13,7 @@ // limitations under the License. use crate::{errors::SynthesisError, ConstraintSystem, Index, LinearCombination, OptionalVec, Variable}; +use log::trace; use snarkvm_fields::Field; use cfg_if::cfg_if; @@ -151,23 +152,23 @@ impl TestConstraintSystem { let self_interned_path = self_c.interned_path; let other_interned_path = other_c.interned_path; if self_c.a != other_c.a { - println!("A row {i} is different:"); - println!("self: {}", self.unintern_path(self_interned_path)); - println!("other: {}", other.unintern_path(other_interned_path)); + trace!("A row {i} is different:"); + trace!("self: {}", self.unintern_path(self_interned_path)); + trace!("other: {}", other.unintern_path(other_interned_path)); break; } if self_c.b != other_c.b { - println!("B row {i} is different:"); - println!("self: {}", self.unintern_path(self_interned_path)); - println!("other: {}", other.unintern_path(other_interned_path)); + trace!("B row {i} is different:"); + trace!("self: {}", self.unintern_path(self_interned_path)); + trace!("other: {}", other.unintern_path(other_interned_path)); break; } if self_c.c != other_c.c { - println!("C row {i} is different:"); - println!("self: {}", self.unintern_path(self_interned_path)); - println!("other: {}", other.unintern_path(other_interned_path)); + trace!("C row {i} is different:"); + trace!("self: {}", self.unintern_path(self_interned_path)); + trace!("other: {}", other.unintern_path(other_interned_path)); break; } } @@ -202,7 +203,7 @@ impl TestConstraintSystem { pub fn print_named_objects(&self) { for TestConstraint { interned_path, .. } in self.constraints.iter() { - println!("{}", self.unintern_path(*interned_path)); + trace!("{}", self.unintern_path(*interned_path)); } } diff --git a/synthesizer/snark/Cargo.toml b/synthesizer/snark/Cargo.toml index dbacfc4e51..d694372824 100644 --- a/synthesizer/snark/Cargo.toml +++ b/synthesizer/snark/Cargo.toml @@ -60,6 +60,9 @@ version = "1.17" version = "1.0" features = [ "preserve_order" ] +[dependencies.log] +version = "0.4.14" + [dev-dependencies.console] package = "snarkvm-console" path = "../../console" diff --git a/synthesizer/snark/src/certificate/mod.rs b/synthesizer/snark/src/certificate/mod.rs index 43821eae76..764754a304 100644 --- a/synthesizer/snark/src/certificate/mod.rs +++ b/synthesizer/snark/src/certificate/mod.rs @@ -17,6 +17,8 @@ use super::*; mod bytes; mod parse; mod serialize; +#[cfg(feature = "aleo-cli")] +use log::trace; #[derive(Clone, PartialEq, Eq)] pub struct Certificate { @@ -43,7 +45,7 @@ impl Certificate { let certificate = Marlin::::prove_vk(N::marlin_fs_parameters(), verifying_key, proving_key)?; #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Certified '{function_name}': {} ms", timer.elapsed().as_millis()).dimmed()); + trace!("{}", format!(" • Certified '{function_name}': {} ms", timer.elapsed().as_millis()).dimmed()); Ok(Self::new(certificate)) } @@ -64,14 +66,14 @@ impl Certificate { #[cfg(feature = "aleo-cli")] { let elapsed = timer.elapsed().as_millis(); - println!("{}", format!(" • Verified certificate for '{function_name}': {elapsed} ms").dimmed()); + trace!("{}", format!(" • Verified certificate for '{function_name}': {elapsed} ms").dimmed()); } is_valid } Err(error) => { #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Certificate verification failed: {error}").dimmed()); + trace!("{}", format!(" • Certificate verification failed: {error}").dimmed()); false } } diff --git a/synthesizer/snark/src/proving_key/mod.rs b/synthesizer/snark/src/proving_key/mod.rs index 5bffb495e6..f2a7814df5 100644 --- a/synthesizer/snark/src/proving_key/mod.rs +++ b/synthesizer/snark/src/proving_key/mod.rs @@ -17,6 +17,8 @@ use super::*; mod bytes; mod parse; mod serialize; +#[cfg(feature = "aleo-cli")] +use log::trace; use std::collections::BTreeMap; @@ -46,7 +48,7 @@ impl ProvingKey { let proof = Proof::new(Marlin::::prove(N::marlin_fs_parameters(), self, assignment, rng)?); #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Executed '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); + trace!("{}", format!(" • Executed '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); Ok(proof) } @@ -70,7 +72,7 @@ impl ProvingKey { let batch_proof = Proof::new(Marlin::::prove_batch(N::marlin_fs_parameters(), &keys_to_constraints, rng)?); #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Executed '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); + trace!("{}", format!(" • Executed '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); Ok(batch_proof) } } diff --git a/synthesizer/snark/src/universal_srs.rs b/synthesizer/snark/src/universal_srs.rs index 0f9450b32e..e7b187746b 100644 --- a/synthesizer/snark/src/universal_srs.rs +++ b/synthesizer/snark/src/universal_srs.rs @@ -13,6 +13,8 @@ // limitations under the License. use super::*; +#[cfg(feature = "aleo-cli")] +use log::trace; #[derive(Clone)] pub struct UniversalSRS { @@ -38,7 +40,7 @@ impl UniversalSRS { let (proving_key, verifying_key) = Marlin::::circuit_setup(self, assignment)?; #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Built '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); + trace!("{}", format!(" • Built '{function_name}' (in {} ms)", timer.elapsed().as_millis()).dimmed()); Ok((ProvingKey::new(Arc::new(proving_key)), VerifyingKey::new(Arc::new(verifying_key)))) } @@ -71,7 +73,7 @@ impl Deref for UniversalSRS { let universal_srs = marlin::UniversalSRS::load().expect("Failed to load the universal SRS"); #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Loaded universal setup (in {} ms)", timer.elapsed().as_millis()).dimmed()); + trace!("{}", format!(" • Loaded universal setup (in {} ms)", timer.elapsed().as_millis()).dimmed()); universal_srs }) diff --git a/synthesizer/snark/src/verifying_key/mod.rs b/synthesizer/snark/src/verifying_key/mod.rs index 6cd3421bd8..ddbc998993 100644 --- a/synthesizer/snark/src/verifying_key/mod.rs +++ b/synthesizer/snark/src/verifying_key/mod.rs @@ -13,6 +13,8 @@ // limitations under the License. use super::*; +#[cfg(feature = "aleo-cli")] +use log::trace; mod bytes; mod parse; @@ -45,14 +47,14 @@ impl VerifyingKey { #[cfg(feature = "aleo-cli")] { let elapsed = timer.elapsed().as_millis(); - println!("{}", format!(" • Verified '{function_name}' (in {elapsed} ms)").dimmed()); + trace!("{}", format!(" • Verified '{function_name}' (in {elapsed} ms)").dimmed()); } is_valid } Err(error) => { #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Verifier failed: {error}").dimmed()); + trace!("{}", format!(" • Verifier failed: {error}").dimmed()); false } } @@ -71,14 +73,14 @@ impl VerifyingKey { #[cfg(feature = "aleo-cli")] { let elapsed = timer.elapsed().as_millis(); - println!("{}", format!(" • Verified '{function_name}' (in {elapsed} ms)").dimmed()); + trace!("{}", format!(" • Verified '{function_name}' (in {elapsed} ms)").dimmed()); } is_valid } Err(error) => { #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Verifier failed: {error}").dimmed()); + trace!("{}", format!(" • Verifier failed: {error}").dimmed()); false } } diff --git a/synthesizer/src/block/transition/input/mod.rs b/synthesizer/src/block/transition/input/mod.rs index b43d1518ac..84934bbddb 100644 --- a/synthesizer/src/block/transition/input/mod.rs +++ b/synthesizer/src/block/transition/input/mod.rs @@ -168,7 +168,7 @@ impl Input { match result() { Ok(is_hash_valid) => is_hash_valid, Err(error) => { - eprintln!("{error}"); + warn!("{error}"); false } } diff --git a/synthesizer/src/block/transition/output/mod.rs b/synthesizer/src/block/transition/output/mod.rs index 7ef7cfa94f..f7f99b94d6 100644 --- a/synthesizer/src/block/transition/output/mod.rs +++ b/synthesizer/src/block/transition/output/mod.rs @@ -212,7 +212,7 @@ impl Output { match result() { Ok(is_hash_valid) => is_hash_valid, Err(error) => { - eprintln!("{error}"); + warn!("{error}"); false } } diff --git a/synthesizer/src/process/evaluate.rs b/synthesizer/src/process/evaluate.rs index 98ca375cfa..a33d6da0ba 100644 --- a/synthesizer/src/process/evaluate.rs +++ b/synthesizer/src/process/evaluate.rs @@ -24,7 +24,7 @@ impl Process { let request = authorization.peek_next()?; #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Evaluating '{}/{}'...", request.program_id(), request.function_name()).dimmed()); + trace!("{}", format!(" • Evaluating '{}/{}'...", request.program_id(), request.function_name()).dimmed()); // Evaluate the function. let response = diff --git a/synthesizer/src/process/execute.rs b/synthesizer/src/process/execute.rs index 34ad4e1ff7..f21f5d33d5 100644 --- a/synthesizer/src/process/execute.rs +++ b/synthesizer/src/process/execute.rs @@ -28,7 +28,7 @@ impl Process { let request = authorization.peek_next()?; #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Executing '{}/{}'...", request.program_id(), request.function_name()).dimmed()); + trace!("{}", format!(" • Executing '{}/{}'...", request.program_id(), request.function_name()).dimmed()); // Initialize the execution. let execution = Arc::new(RwLock::new(Execution::new())); @@ -91,8 +91,7 @@ impl Process { // Verify each transition. while let Ok(transition) = queue.pop() { - #[cfg(debug_assertions)] - println!("Verifying transition for {}/{}...", transition.program_id(), transition.function_name()); + trace!("Verifying transition for {}/{}...", transition.program_id(), transition.function_name()); // Ensure the transition ID is correct. ensure!(**transition.id() == transition.to_root()?, "The transition ID is incorrect"); @@ -204,7 +203,7 @@ impl Process { lap!(timer, "Construct the verifier inputs"); #[cfg(debug_assertions)] - println!("Transition public inputs ({} elements): {:#?}", inputs.len(), inputs); + trace!("Transition public inputs ({} elements): {:#?}", inputs.len(), inputs); // Retrieve the verifying key. let verifying_key = self.get_verifying_key(stack.program_id(), function.name())?; diff --git a/synthesizer/src/process/execute_fee.rs b/synthesizer/src/process/execute_fee.rs index 3ef153bca8..561bbc7111 100644 --- a/synthesizer/src/process/execute_fee.rs +++ b/synthesizer/src/process/execute_fee.rs @@ -54,7 +54,7 @@ impl Process { let stack = self.get_stack(request.program_id())?; #[cfg(feature = "aleo-cli")] - println!("{}", format!(" • Calling '{}/{}'...", request.program_id(), request.function_name()).dimmed()); + trace!("{}", format!(" • Calling '{}/{}'...", request.program_id(), request.function_name()).dimmed()); // Initialize the execution. let execution = Arc::new(RwLock::new(Execution::new())); @@ -88,8 +88,7 @@ impl Process { pub fn verify_fee(&self, fee: &Fee) -> Result<()> { let timer = timer!("Process::verify_fee"); - #[cfg(debug_assertions)] - println!("Verifying fee from {}/{}...", fee.program_id(), fee.function_name()); + trace!("Verifying fee from {}/{}...", fee.program_id(), fee.function_name()); // Ensure the fee has the correct program ID. let fee_program_id = ProgramID::from_str("credits.aleo")?; @@ -156,7 +155,7 @@ impl Process { } #[cfg(debug_assertions)] - println!("Fee public inputs ({} elements): {:#?}", inputs.len(), inputs); + trace!("Fee public inputs ({} elements): {:#?}", inputs.len(), inputs); // Ensure the fee contains input records. ensure!( diff --git a/synthesizer/src/process/finalize.rs b/synthesizer/src/process/finalize.rs index 2f5bc59f02..024f9e2ba0 100644 --- a/synthesizer/src/process/finalize.rs +++ b/synthesizer/src/process/finalize.rs @@ -96,8 +96,7 @@ impl Process { // Currently this loop assumes a linearly execution stack. // Finalize each transition, starting from the last one. for transition in execution.transitions() { - #[cfg(debug_assertions)] - println!("Finalizing transition for {}/{}...", transition.program_id(), transition.function_name()); + trace!("Finalizing transition for {}/{}...", transition.program_id(), transition.function_name()); // Retrieve the stack. let stack = self.get_stack(transition.program_id())?; diff --git a/synthesizer/src/process/stack/execute.rs b/synthesizer/src/process/stack/execute.rs index 64550f99e0..f6b3852d69 100644 --- a/synthesizer/src/process/stack/execute.rs +++ b/synthesizer/src/process/stack/execute.rs @@ -472,7 +472,7 @@ impl Stack { let (num_constant, num_public, num_private, num_constraints, num_nonzeros) = A::count(); // Print the log. - println!( + trace!( "{is_satisfied} {:width$} (Constant: {num_constant}, Public: {num_public}, Private: {num_private}, Constraints: {num_constraints}, NonZeros: {num_nonzeros:?})", scope.into().bold(), width = 20 diff --git a/synthesizer/src/process/stack/register_types/initialize.rs b/synthesizer/src/process/stack/register_types/initialize.rs index f8c4086385..00593a3885 100644 --- a/synthesizer/src/process/stack/register_types/initialize.rs +++ b/synthesizer/src/process/stack/register_types/initialize.rs @@ -230,11 +230,11 @@ impl RegisterTypes { match operand { // Inform the user the output operand is an input register, to ensure this is intended behavior. Operand::Register(register) if self.is_input(register) => { - eprintln!("Output {operand} in '{}' is an input register, ensure this is intended", stack.program_id()) + warn!("Output {operand} in '{}' is an input register, ensure this is intended", stack.program_id()) } // Inform the user the output operand is a literal, to ensure this is intended behavior. Operand::Literal(..) => { - eprintln!("Output {operand} in '{}' is a literal, ensure this is intended", stack.program_id()) + warn!("Output {operand} in '{}' is a literal, ensure this is intended", stack.program_id()) } // Otherwise, do nothing. _ => (), diff --git a/synthesizer/src/process/tests.rs b/synthesizer/src/process/tests.rs index 8a633e012f..02f356de29 100644 --- a/synthesizer/src/process/tests.rs +++ b/synthesizer/src/process/tests.rs @@ -687,7 +687,7 @@ function transfer: .authorize::(&caller0_private_key, program1.id(), function_name, [r0, r1, r2].iter(), rng) .unwrap(); assert_eq!(authorization.len(), 5); - println!("\nAuthorize\n{:#?}\n\n", authorization.to_vec_deque()); + trace!("\nAuthorize\n{:#?}\n\n", authorization.to_vec_deque()); let (output_a, output_b) = { // Fetch the first request. diff --git a/synthesizer/src/program/closure/bytes.rs b/synthesizer/src/program/closure/bytes.rs index 1a84abf4d7..1db62d3233 100644 --- a/synthesizer/src/program/closure/bytes.rs +++ b/synthesizer/src/program/closure/bytes.rs @@ -132,7 +132,7 @@ closure main: let expected = Closure::::from_str(closure_string)?; let expected_bytes = expected.to_bytes_le()?; - println!("String size: {:?}, Bytecode size: {:?}", closure_string.as_bytes().len(), expected_bytes.len()); + trace!("String size: {:?}, Bytecode size: {:?}", closure_string.as_bytes().len(), expected_bytes.len()); let candidate = Closure::::from_bytes_le(&expected_bytes)?; assert_eq!(expected.to_string(), candidate.to_string()); diff --git a/synthesizer/src/program/finalize/bytes.rs b/synthesizer/src/program/finalize/bytes.rs index fe836de66b..3ae94e98dd 100644 --- a/synthesizer/src/program/finalize/bytes.rs +++ b/synthesizer/src/program/finalize/bytes.rs @@ -108,7 +108,7 @@ finalize main: let expected = Finalize::::from_str(finalize_string)?; let expected_bytes = expected.to_bytes_le()?; - println!("String size: {:?}, Bytecode size: {:?}", finalize_string.as_bytes().len(), expected_bytes.len()); + trace!("String size: {:?}, Bytecode size: {:?}", finalize_string.as_bytes().len(), expected_bytes.len()); let candidate = Finalize::::from_bytes_le(&expected_bytes)?; assert_eq!(expected.to_string(), candidate.to_string()); diff --git a/synthesizer/src/program/finalize/command/finalize.rs b/synthesizer/src/program/finalize/command/finalize.rs index a675bf6f8b..8f8b383a2b 100644 --- a/synthesizer/src/program/finalize/command/finalize.rs +++ b/synthesizer/src/program/finalize/command/finalize.rs @@ -135,7 +135,7 @@ impl Display for FinalizeOperation { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is less than or equal to MAX_INPUTS. if self.operands.len() > N::MAX_INPUTS { - eprintln!("The number of operands must be <= {}, found {}", N::MAX_INPUTS, self.operands.len()); + warn!("The number of operands must be <= {}, found {}", N::MAX_INPUTS, self.operands.len()); return Err(fmt::Error); } // Print the operation. diff --git a/synthesizer/src/program/finalize/parse.rs b/synthesizer/src/program/finalize/parse.rs index 2ada8764d8..6c0bdb9883 100644 --- a/synthesizer/src/program/finalize/parse.rs +++ b/synthesizer/src/program/finalize/parse.rs @@ -40,11 +40,11 @@ impl Parser for Finalize { // Initialize a new finalize. let mut finalize = Self::new(name); if let Err(error) = inputs.iter().cloned().try_for_each(|input| finalize.add_input(input)) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } if let Err(error) = commands.iter().cloned().try_for_each(|command| finalize.add_command(command)) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } Ok::<_, Error>(finalize) diff --git a/synthesizer/src/program/function/bytes.rs b/synthesizer/src/program/function/bytes.rs index 5fd66fd964..cc84eb27f8 100644 --- a/synthesizer/src/program/function/bytes.rs +++ b/synthesizer/src/program/function/bytes.rs @@ -153,7 +153,7 @@ function main: let expected = Function::::from_str(function_string)?; let expected_bytes = expected.to_bytes_le()?; - println!("String size: {:?}, Bytecode size: {:?}", function_string.as_bytes().len(), expected_bytes.len()); + trace!("String size: {:?}, Bytecode size: {:?}", function_string.as_bytes().len(), expected_bytes.len()); let candidate = Function::::from_bytes_le(&expected_bytes)?; assert_eq!(expected.to_string(), candidate.to_string()); diff --git a/synthesizer/src/program/function/parse.rs b/synthesizer/src/program/function/parse.rs index 29922b39d5..a515ca76b0 100644 --- a/synthesizer/src/program/function/parse.rs +++ b/synthesizer/src/program/function/parse.rs @@ -55,22 +55,22 @@ impl Parser for Function { // Initialize a new function. let mut function = Self::new(name); if let Err(error) = inputs.iter().cloned().try_for_each(|input| function.add_input(input)) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } if let Err(error) = instructions.iter().cloned().try_for_each(|instruction| function.add_instruction(instruction)) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } if let Err(error) = outputs.iter().cloned().try_for_each(|output| function.add_output(output)) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } if let Some((command, finalize)) = &finalize { if let Err(error) = function.add_finalize(command.clone(), finalize.clone()) { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } } diff --git a/synthesizer/src/program/instruction/operation/assert.rs b/synthesizer/src/program/instruction/operation/assert.rs index ee34bbba5f..8342410d18 100644 --- a/synthesizer/src/program/instruction/operation/assert.rs +++ b/synthesizer/src/program/instruction/operation/assert.rs @@ -212,7 +212,7 @@ impl Display for AssertInstruction { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is 2. if self.operands.len() != 2 { - eprintln!("The number of operands must be 2, found {}", self.operands.len()); + warn!("The number of operands must be 2, found {}", self.operands.len()); return Err(fmt::Error); } // Print the operation. @@ -326,7 +326,7 @@ mod tests { mode_b: &circuit::Mode, cache: &mut HashMap, VerifyingKey)>, ) { - println!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); + trace!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); // Initialize the types. let type_a = literal_a.to_type(); diff --git a/synthesizer/src/program/instruction/operation/call.rs b/synthesizer/src/program/instruction/operation/call.rs index ffdfadc5ad..cef31bba70 100644 --- a/synthesizer/src/program/instruction/operation/call.rs +++ b/synthesizer/src/program/instruction/operation/call.rs @@ -380,7 +380,7 @@ impl Call { // Ensure the values are equal. if console_response.outputs() != response.outputs() { #[cfg(debug_assertions)] - eprintln!("\n{:#?} != {:#?}\n", console_response.outputs(), response.outputs()); + warn!("\n{:#?} != {:#?}\n", console_response.outputs(), response.outputs()); bail!("Function '{}' outputs do not match in a 'call' instruction.", function.name()) } // Return the request and response. @@ -643,12 +643,12 @@ impl Display for Call { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is within the bounds. if self.operands.len() > N::MAX_OPERANDS { - eprintln!("The number of operands must be <= {}", N::MAX_OPERANDS); + warn!("The number of operands must be <= {}", N::MAX_OPERANDS); return Err(fmt::Error); } // Ensure the number of destinations is within the bounds. if self.destinations.len() > N::MAX_OPERANDS { - eprintln!("The number of destinations must be <= {}", N::MAX_OPERANDS); + warn!("The number of destinations must be <= {}", N::MAX_OPERANDS); return Err(fmt::Error); } // Print the operation. diff --git a/synthesizer/src/program/instruction/operation/cast.rs b/synthesizer/src/program/instruction/operation/cast.rs index 53ae12d7a2..a476bba049 100644 --- a/synthesizer/src/program/instruction/operation/cast.rs +++ b/synthesizer/src/program/instruction/operation/cast.rs @@ -596,7 +596,7 @@ impl Display for Cast { RegisterType::Record(_) | RegisterType::ExternalRecord(_) => N::MAX_RECORD_ENTRIES, }; if self.operands.len().is_zero() || self.operands.len() > max_operands { - eprintln!("The number of operands must be nonzero and <= {max_operands}"); + warn!("The number of operands must be nonzero and <= {max_operands}"); return Err(fmt::Error); } // Print the operation. diff --git a/synthesizer/src/program/instruction/operation/commit.rs b/synthesizer/src/program/instruction/operation/commit.rs index bd40deb582..d8b2e6d618 100644 --- a/synthesizer/src/program/instruction/operation/commit.rs +++ b/synthesizer/src/program/instruction/operation/commit.rs @@ -260,7 +260,7 @@ impl Display for CommitInstruction { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is 2. if self.operands.len() != 2 { - eprintln!("The number of operands must be 2, found {}", self.operands.len()); + warn!("The number of operands must be 2, found {}", self.operands.len()); return Err(fmt::Error); } // Print the operation. @@ -381,7 +381,7 @@ mod tests { mode_b: &circuit::Mode, cache: &mut HashMap, VerifyingKey)>, ) { - println!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); + trace!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); // Initialize the types. let type_a = literal_a.to_type(); diff --git a/synthesizer/src/program/instruction/operation/hash.rs b/synthesizer/src/program/instruction/operation/hash.rs index c7d144bc02..7cb80ef23b 100644 --- a/synthesizer/src/program/instruction/operation/hash.rs +++ b/synthesizer/src/program/instruction/operation/hash.rs @@ -259,7 +259,7 @@ impl Display for HashInstruction { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is 1. if self.operands.len() != 1 { - eprintln!("The number of operands must be 1, found {}", self.operands.len()); + warn!("The number of operands must be 1, found {}", self.operands.len()); return Err(fmt::Error); } // Print the operation. @@ -365,7 +365,7 @@ mod tests { mode: &circuit::Mode, cache: &mut HashMap, VerifyingKey)>, ) { - println!("Checking '{opcode}' for '{literal}.{mode}'"); + trace!("Checking '{opcode}' for '{literal}.{mode}'"); // Initialize the types. let type_ = literal.to_type(); diff --git a/synthesizer/src/program/instruction/operation/is.rs b/synthesizer/src/program/instruction/operation/is.rs index 87ce936fdb..f15c2a04dd 100644 --- a/synthesizer/src/program/instruction/operation/is.rs +++ b/synthesizer/src/program/instruction/operation/is.rs @@ -228,7 +228,7 @@ impl Display for IsInstruction { fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is 2. if self.operands.len() != 2 { - eprintln!("The number of operands must be 2, found {}", self.operands.len()); + warn!("The number of operands must be 2, found {}", self.operands.len()); return Err(fmt::Error); } // Print the operation. @@ -351,7 +351,7 @@ mod tests { ) { use circuit::Eject; - println!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); + trace!("Checking '{opcode}' for '{literal_a}.{mode_a}' and '{literal_b}.{mode_b}'"); // Initialize the types. let type_a = literal_a.to_type(); diff --git a/synthesizer/src/program/instruction/operation/literals.rs b/synthesizer/src/program/instruction/operation/literals.rs index 2dbed7be03..d4a1037a31 100644 --- a/synthesizer/src/program/instruction/operation/literals.rs +++ b/synthesizer/src/program/instruction/operation/literals.rs @@ -276,12 +276,12 @@ impl, LiteralType, NUM_OPERANDS>, const N fn fmt(&self, f: &mut Formatter) -> fmt::Result { // Ensure the number of operands is within the bounds. if NUM_OPERANDS > N::MAX_OPERANDS { - eprintln!("The number of operands must be <= {}", N::MAX_OPERANDS); + warn!("The number of operands must be <= {}", N::MAX_OPERANDS); return Err(fmt::Error); } // Ensure the number of operands is correct. if self.operands.len() > NUM_OPERANDS { - eprintln!("The number of operands must be {NUM_OPERANDS}"); + warn!("The number of operands must be {NUM_OPERANDS}"); return Err(fmt::Error); } // Print the operation. diff --git a/synthesizer/src/program/mapping/bytes.rs b/synthesizer/src/program/mapping/bytes.rs index 9f105496f5..a52011a2d6 100644 --- a/synthesizer/src/program/mapping/bytes.rs +++ b/synthesizer/src/program/mapping/bytes.rs @@ -58,7 +58,7 @@ mapping main: let expected = Mapping::::from_str(mapping_string)?; let expected_bytes = expected.to_bytes_le()?; - println!("String size: {:?}, Bytecode size: {:?}", mapping_string.as_bytes().len(), expected_bytes.len()); + trace!("String size: {:?}, Bytecode size: {:?}", mapping_string.as_bytes().len(), expected_bytes.len()); let candidate = Mapping::::from_bytes_le(&expected_bytes)?; assert_eq!(expected.to_string(), candidate.to_string()); diff --git a/synthesizer/src/program/parse.rs b/synthesizer/src/program/parse.rs index 252787a76d..5a30cc35b3 100644 --- a/synthesizer/src/program/parse.rs +++ b/synthesizer/src/program/parse.rs @@ -59,7 +59,7 @@ impl Parser for Program { let mut program = match Program::::new(id) { Ok(program) => program, Err(error) => { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } }; @@ -76,7 +76,7 @@ impl Parser for Program { match result { Ok(_) => (), Err(error) => { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } } @@ -86,7 +86,7 @@ impl Parser for Program { match program.add_import(import.clone()) { Ok(_) => (), Err(error) => { - eprintln!("{error}"); + warn!("{error}"); return Err(error); } } @@ -146,35 +146,35 @@ impl Display for Program { ProgramDefinition::Mapping => match self.mappings.get(identifier) { Some(mapping) => program.push_str(&format!("{mapping}\n\n")), None => { - eprintln!("Mapping '{identifier}' is not defined."); + warn!("Mapping '{identifier}' is not defined."); return Err(fmt::Error); } }, ProgramDefinition::Struct => match self.structs.get(identifier) { Some(struct_) => program.push_str(&format!("{struct_}\n\n")), None => { - eprintln!("Struct '{identifier}' is not defined."); + warn!("Struct '{identifier}' is not defined."); return Err(fmt::Error); } }, ProgramDefinition::Record => match self.records.get(identifier) { Some(record) => program.push_str(&format!("{record}\n\n")), None => { - eprintln!("Record '{identifier}' is not defined."); + warn!("Record '{identifier}' is not defined."); return Err(fmt::Error); } }, ProgramDefinition::Closure => match self.closures.get(identifier) { Some(closure) => program.push_str(&format!("{closure}\n\n")), None => { - eprintln!("Closure '{identifier}' is not defined."); + warn!("Closure '{identifier}' is not defined."); return Err(fmt::Error); } }, ProgramDefinition::Function => match self.functions.get(identifier) { Some(function) => program.push_str(&format!("{function}\n\n")), None => { - eprintln!("Function '{identifier}' is not defined."); + warn!("Function '{identifier}' is not defined."); return Err(fmt::Error); } }, diff --git a/synthesizer/src/store/helpers/rocksdb/internal/tests.rs b/synthesizer/src/store/helpers/rocksdb/internal/tests.rs index a7bf8fd664..1c53385126 100644 --- a/synthesizer/src/store/helpers/rocksdb/internal/tests.rs +++ b/synthesizer/src/store/helpers/rocksdb/internal/tests.rs @@ -200,7 +200,7 @@ fn test_scalar_mul() { } let elapsed = timer.elapsed().as_secs(); - println!(" {ITERATIONS} Scalar Muls : {elapsed} s"); + trace!(" {ITERATIONS} Scalar Muls : {elapsed} s"); } #[test] diff --git a/synthesizer/src/store/transition/mod.rs b/synthesizer/src/store/transition/mod.rs index c8fc39b4e0..3ba1850de9 100644 --- a/synthesizer/src/store/transition/mod.rs +++ b/synthesizer/src/store/transition/mod.rs @@ -692,7 +692,7 @@ mod tests { .collect::>(); // Ensure there is at least 2 transition. - println!("\n\nNumber of transitions: {}\n", transitions.len()); + trace!("\n\nNumber of transitions: {}\n", transitions.len()); assert!(transitions.len() > 1, "\n\nNumber of transitions: {}\n", transitions.len()); // Initialize a new transition store. diff --git a/synthesizer/src/vm/finalize.rs b/synthesizer/src/vm/finalize.rs index 3b20caeea3..c2617f3ec1 100644 --- a/synthesizer/src/vm/finalize.rs +++ b/synthesizer/src/vm/finalize.rs @@ -155,7 +155,7 @@ impl> VM { Ok(confirmed_transaction) => confirmed.push(confirmed_transaction), // If the transaction failed, abort the entire batch. Err(error) => { - eprintln!("Critical bug in speculate: {error}\n\n{transaction}"); + warn!("Critical bug in speculate: {error}\n\n{transaction}"); // Note: This will abort the entire atomic batch. return Err(format!("Failed to speculate on transaction - {error}")); } @@ -299,7 +299,7 @@ impl> VM { Ok(()) => (), // If the transaction failed to finalize, abort and continue to the next transaction. Err(error) => { - eprintln!("Critical bug in finalize: {error}\n\n{transaction}"); + warn!("Critical bug in finalize: {error}\n\n{transaction}"); // Note: This will abort the entire atomic batch. return Err(format!("Failed to finalize on transaction - {error}")); } @@ -971,7 +971,7 @@ finalize compute: .finalize_store() .get_value_speculative(&program_id, &mapping_name, &Plaintext::from(Literal::Address(address))) .unwrap(); - println!("{:?}", value); + trace!("{:?}", value); assert!( !vm.finalize_store() .contains_key_confirmed(&program_id, &mapping_name, &Plaintext::from(Literal::Address(address))) diff --git a/utilities/Cargo.toml b/utilities/Cargo.toml index 75909dae70..0bae513edc 100644 --- a/utilities/Cargo.toml +++ b/utilities/Cargo.toml @@ -68,6 +68,10 @@ version = "1.0" version = "0.3" default-features = false +[dependencies.log] +version = "0.4.18" +features = ["std"] + [features] default = [ "aleo-std/cpu", "derive", "num_cpus", "std" ] derive = [ "snarkvm-utilities-derives" ] diff --git a/utilities/src/lib.rs b/utilities/src/lib.rs index af6666b105..dfed113c47 100644 --- a/utilities/src/lib.rs +++ b/utilities/src/lib.rs @@ -71,6 +71,9 @@ pub use self::rand::*; pub mod serialize; pub use serialize::*; +pub mod simpler_logger; +pub use simpler_logger::*; + #[cfg(not(feature = "std"))] pub mod io; diff --git a/utilities/src/simpler_logger.rs b/utilities/src/simpler_logger.rs new file mode 100644 index 0000000000..04ac075e14 --- /dev/null +++ b/utilities/src/simpler_logger.rs @@ -0,0 +1,69 @@ +// Copyright (C) 2019-2023 Aleo Systems Inc. +// This file is part of the snarkVM library. + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! A logger that prints to stdout and stderr. +//! +//! All records with a level of `Info` or higher are printed as-is to stdout, and all +//! records with a level of `Warn` or Lower are printed to stderr. +//! +//! # Example +//! ```rust +//! use snarkvm_utilities::simpler_logger::SimplerLogger; +//! +//! SimplerLogger::new().init().unwrap(); +//! log::trace!("trace"); // -> stdout +//! log::debug!("debug"); // -> stdout +//! log::info!("info"); // -> stdout +//! log::warn!("warn"); // -> stderr +//! log::error!("error"); // -> stderr +//! ``` +//! +use log::{Log, Metadata, Record}; + +pub struct SimplerLogger; + +impl SimplerLogger { + pub fn new() -> SimplerLogger { + SimplerLogger {} + } + + pub fn init(self) -> Result<(), log::SetLoggerError> { + log::set_boxed_logger(Box::new(self))?; + log::set_max_level(log::LevelFilter::Trace); + Ok(()) + } +} + +impl Default for SimplerLogger { + fn default() -> Self { + Self::new() + } +} + +impl Log for SimplerLogger { + fn log(&self, message: &Record) { + // Confusingly, Level::Error is `1`, and Level::Trace is `5`. + if message.level() >= log::Level::Info { + println!("{}", message.args()); + } else if message.level() < log::Level::Info { + eprintln!("{}", message.args()); + } + } + + fn enabled(&self, _metadata: &Metadata) -> bool { + true + } + + fn flush(&self) {} +} diff --git a/vm/cli/commands/run.rs b/vm/cli/commands/run.rs index b52555153e..295c1dfc8e 100644 --- a/vm/cli/commands/run.rs +++ b/vm/cli/commands/run.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use log::trace; + use super::*; pub const LOCALE: &num_format::Locale = &num_format::Locale::en; @@ -77,7 +79,7 @@ impl Run { // Log the metrics. use num_format::ToFormattedString; - println!("\n⛓ Constraints\n"); + trace!("\n⛓ Constraints\n"); for (function_constraints, counter) in program_frequency { // Log the constraints let counter_string = match counter { @@ -85,19 +87,19 @@ impl Run { counter => format!("(called {counter} times)").dimmed(), }; - println!(" • {function_constraints} {counter_string}",) + trace!(" • {function_constraints} {counter_string}",) } // Log the outputs. match response.outputs().len() { 0 => (), - 1 => println!("\n➡️ Output\n"), - _ => println!("\n➡️ Outputs\n"), + 1 => trace!("\n➡️ Output\n"), + _ => trace!("\n➡️ Outputs\n"), }; for output in response.outputs() { - println!("{}", format!(" • {output}")); + trace!("{}", format!(" • {output}")); } - println!(); + trace!(""); // Prepare the locator. let locator = Locator::::from_str(&format!("{}/{}", package.program_id(), self.function))?; diff --git a/vm/cli/main.rs b/vm/cli/main.rs index 9f1352a7a2..e630388aa0 100644 --- a/vm/cli/main.rs +++ b/vm/cli/main.rs @@ -12,17 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -use snarkvm::cli::{Updater, CLI}; - use clap::Parser; +use log::trace; +use snarkvm::{ + cli::{Updater, CLI}, + utilities::simpler_logger::SimplerLogger, +}; fn main() -> anyhow::Result<()> { + SimplerLogger::new().init()?; // Parse the given arguments. let cli = CLI::parse(); // Run the updater. - println!("{}", Updater::print_cli()); + trace!("{}", Updater::print_cli()); // Run the CLI. - println!("{}", cli.command.parse()?); + trace!("{}", cli.command.parse()?); Ok(()) } diff --git a/vm/package/deploy.rs b/vm/package/deploy.rs index 3a96238af6..d8ab4745d8 100644 --- a/vm/package/deploy.rs +++ b/vm/package/deploy.rs @@ -13,6 +13,8 @@ // limitations under the License. use crate::synthesizer::Deployment; +#[cfg(feature = "aleo-cli")] +use log::trace; use snarkvm_console::types::Address; use snarkvm_utilities::DeserializeExt; @@ -134,7 +136,7 @@ impl Package { let caller = self.manifest_file().development_address(); #[cfg(feature = "aleo-cli")] - println!("⏳ Deploying '{}'...\n", program_id.to_string().bold()); + trace!("⏳ Deploying '{}'...\n", program_id.to_string().bold()); // Construct the process. let mut process = Process::::load()?; diff --git a/vm/package/run.rs b/vm/package/run.rs index c5793a98bf..911c7e07e5 100644 --- a/vm/package/run.rs +++ b/vm/package/run.rs @@ -13,6 +13,8 @@ // limitations under the License. use super::*; +#[cfg(feature = "aleo-cli")] +use log::trace; use snarkvm_synthesizer::CallMetrics; impl Package { @@ -42,7 +44,7 @@ impl Package { let _locator = Locator::::from_str(&format!("{program_id}/{function_name}"))?; #[cfg(feature = "aleo-cli")] - println!("🚀 Executing '{}'...\n", _locator.to_string().bold()); + trace!("🚀 Executing '{}'...\n", _locator.to_string().bold()); // Construct the process. let process = self.get_process()?;