Skip to content

Commit

Permalink
feat: logging
Browse files Browse the repository at this point in the history
  • Loading branch information
joske committed Jun 5, 2023
1 parent 576c1b2 commit 27db284
Show file tree
Hide file tree
Showing 81 changed files with 384 additions and 190 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
29 changes: 13 additions & 16 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 @@ -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;

Expand Down Expand Up @@ -151,22 +150,20 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
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);
}

Expand Down
17 changes: 7 additions & 10 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 @@ -78,14 +77,12 @@ impl<F: PrimeField, MM: MarlinMode> AHPForR1CS<F, MM> {
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)
Expand Down
12 changes: 5 additions & 7 deletions algorithms/src/snark/marlin/marlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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},
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand All @@ -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()
);
Expand Down Expand Up @@ -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: {}",
Expand Down
4 changes: 2 additions & 2 deletions algorithms/src/snark/marlin/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(),
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.11.7"
path = "../types"
version = "=0.11.7"

[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.11.7"
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
Loading

0 comments on commit 27db284

Please sign in to comment.