Skip to content

Commit

Permalink
feat: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
joske committed Jun 14, 2023
1 parent f56a474 commit 8ccf194
Show file tree
Hide file tree
Showing 78 changed files with 377 additions and 173 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ optional = true
version = "2.6"
features = [ "json" ]

[dependencies.log]
version = "0.4.14"

[dev-dependencies.bincode]
version = "1.3"

Expand Down
3 changes: 3 additions & 0 deletions algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
27 changes: 13 additions & 14 deletions algorithms/src/snark/marlin/ahp/indexer/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,8 +38,6 @@ use std::collections::BTreeMap;

#[cfg(not(feature = "serial"))]
use rayon::prelude::*;
#[cfg(not(feature = "std"))]
use snarkvm_utilities::println;

use super::Matrix;

Expand Down Expand Up @@ -153,21 +152,21 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
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);
}

Expand Down
15 changes: 7 additions & 8 deletions algorithms/src/snark/marlin/ahp/prover/round_functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -79,12 +78,12 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
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
Expand Down
8 changes: 4 additions & 4 deletions algorithms/src/snark/marlin/marlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use std::{borrow::Borrow, collections::BTreeMap, ops::Deref, sync::Arc};

use crate::srs::UniversalProver;
#[cfg(not(feature = "std"))]
use snarkvm_utilities::println;
use log::{trace, warn};

/// The Marlin proof system.
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -629,7 +629,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)
Expand All @@ -653,7 +653,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()
);
Expand Down Expand Up @@ -837,7 +837,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: {}",
Expand Down
3 changes: 3 additions & 0 deletions circuit/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ version = "=0.12.0"
path = "../types"
version = "=0.12.0"

[dependencies.log]
version = "0.4.14"

[dev-dependencies.snarkvm-utilities]
path = "../../utilities"

Expand Down
3 changes: 3 additions & 0 deletions circuit/algorithms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ path = "../../fields"
version = "=0.12.0"
default-features = false

[dependencies.log]
version = "0.4.14"

[dev-dependencies.snarkvm-curves]
path = "../../curves"
default-features = false
Expand Down
6 changes: 4 additions & 2 deletions circuit/algorithms/src/bhp/hasher/hash_uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> 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
}
}
});
Expand All @@ -157,7 +158,8 @@ impl<E: Environment, const NUM_WINDOWS: u8, const WINDOW_SIZE: u8> 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"),
}
Expand Down
2 changes: 1 addition & 1 deletion circuit/algorithms/src/pedersen/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion circuit/algorithms/src/pedersen/commit_uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions circuit/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ version = "=0.12.0"
path = "../types"
version = "=0.12.0"

[dependencies.log]
version = "0.4.14"

[dev-dependencies.snarkvm-circuit-network]
path = "../network"

Expand Down
3 changes: 3 additions & 0 deletions circuit/environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ version = "0.2"
[dependencies.once_cell]
version = "1.18.0"

[dependencies.log]
version = "0.4.14"

[dev-dependencies.snarkvm-algorithms]
path = "../../algorithms"
features = [ "polycommit_full", "snark" ]
Expand Down
Loading

0 comments on commit 8ccf194

Please sign in to comment.