Skip to content

Commit

Permalink
refactor: change logger to tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Jan 11, 2024
1 parent a450b81 commit 4651c2b
Show file tree
Hide file tree
Showing 18 changed files with 181 additions and 96 deletions.
12 changes: 6 additions & 6 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ doc = false
[features]
concurrent = ["winterfell/concurrent", "std"]
default = ["std"]
std = ["hex/std", "winterfell/std", "core-utils/std", "rand-utils"]
std = ["core-utils/std", "hex/std", "rand-utils", "tracing/attributes", "winterfell/std"]

[dependencies]
winterfell = { version="0.7", path = "../winterfell", default-features = false }
blake3 = { version = "1.5", default-features = false }
core-utils = { version = "0.7", path = "../utils/core", package = "winter-utils", default-features = false }
rand-utils = { version = "0.7", path = "../utils/rand", package = "winter-rand-utils", optional = true }
hex = { version = "0.4", optional = true }
log = { version = "0.4", default-features = false }
blake3 = { version = "1.5", default-features = false }
env_logger = { version = "0.10", default-features = false }
rand-utils = { version = "0.7", path = "../utils/rand", package = "winter-rand-utils", optional = true }
structopt = { version = "0.3", default-features = false }
tracing = { version = "0.1", default-features = false, optional = true }
tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] }
winterfell = { version="0.7", path = "../winterfell", default-features = false }

[dev-dependencies]
criterion = "0.5"
Expand Down
11 changes: 7 additions & 4 deletions examples/src/fibonacci/fib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use super::utils::compute_fib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};

Check failure on line 10 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

unresolved import `tracing`
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -65,7 +65,8 @@ impl<H: ElementHasher> FibExample<H> {
// compute Fibonacci sequence
let now = Instant::now();
let result = compute_fib_term(sequence_length);
debug!(
event!(

Check failure on line 68 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

cannot determine resolution for the macro `event`

Check failure on line 68 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

cannot determine resolution for the macro `event`

Check failure on line 68 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

cannot determine resolution for the macro `event`
Level::DEBUG,
"Computed Fibonacci sequence up to {}th term in {} ms",
sequence_length,
now.elapsed().as_millis()
Expand All @@ -88,7 +89,8 @@ where
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
event!(

Check failure on line 92 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

cannot determine resolution for the macro `event`

Check failure on line 92 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

cannot determine resolution for the macro `event`

Check failure on line 92 in examples/src/fibonacci/fib2/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

cannot determine resolution for the macro `event`
Level::DEBUG,
"Generating proof for computing Fibonacci sequence (2 terms per step) up to {}th term\n\
---------------------",
self.sequence_length
Expand All @@ -103,7 +105,8 @@ where

let trace_width = trace.width();
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace_width,
trace_length.ilog2(),
Expand Down
11 changes: 7 additions & 4 deletions examples/src/fibonacci/fib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use super::utils::compute_fib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};

Check failure on line 10 in examples/src/fibonacci/fib8/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib8/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib8/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

unresolved import `tracing`
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -65,7 +65,8 @@ impl<H: ElementHasher> Fib8Example<H> {
// compute Fibonacci sequence
let now = Instant::now();
let result = compute_fib_term(sequence_length);
debug!(
event!(
Level::DEBUG,
"Computed Fibonacci sequence up to {}th term in {} ms",
sequence_length,
now.elapsed().as_millis()
Expand All @@ -88,7 +89,8 @@ where
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
event!(
Level::DEBUG,
"Generating proof for computing Fibonacci sequence (8 terms per step) up to {}th term\n\
---------------------",
self.sequence_length
Expand All @@ -102,7 +104,8 @@ where
let trace = prover.build_trace(self.sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace_width,
trace_length.ilog2(),
Expand Down
11 changes: 7 additions & 4 deletions examples/src/fibonacci/fib_small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use super::utils::compute_fib_term;
use crate::{Example, ExampleOptions, HashFunction};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};

Check failure on line 10 in examples/src/fibonacci/fib_small/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib_small/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/fib_small/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

unresolved import `tracing`
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f64::BaseElement, FieldElement},
Expand Down Expand Up @@ -80,7 +80,8 @@ impl<H: ElementHasher> FibExample<H> {
// compute Fibonacci sequence
let now = Instant::now();
let result = compute_fib_term::<BaseElement>(sequence_length);
debug!(
event!(
Level::DEBUG,
"Computed Fibonacci sequence up to {}th term in {} ms",
sequence_length,
now.elapsed().as_millis()
Expand All @@ -103,7 +104,8 @@ where
H: ElementHasher<BaseField = BaseElement>,
{
fn prove(&self) -> StarkProof {
debug!(
event!(
Level::DEBUG,
"Generating proof for computing Fibonacci sequence (2 terms per step) up to {}th term\n\
---------------------",
self.sequence_length
Expand All @@ -118,7 +120,8 @@ where

let trace_width = trace.width();
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace_width,
trace_length.ilog2(),
Expand Down
11 changes: 7 additions & 4 deletions examples/src/fibonacci/mulfib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use super::utils::compute_mulfib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};

Check failure on line 10 in examples/src/fibonacci/mulfib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/mulfib2/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/mulfib2/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

unresolved import `tracing`
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -59,7 +59,8 @@ impl<H: ElementHasher> MulFib2Example<H> {
// compute Fibonacci sequence
let now = Instant::now();
let result = compute_mulfib_term(sequence_length);
debug!(
event!(
Level::DEBUG,
"Computed multiplicative Fibonacci sequence up to {}th term in {} ms",
sequence_length,
now.elapsed().as_millis()
Expand All @@ -83,7 +84,8 @@ where
{
fn prove(&self) -> StarkProof {
let sequence_length = self.sequence_length;
debug!(
event!(
Level::DEBUG,
"Generating proof for computing multiplicative Fibonacci sequence (8 terms per step) up to {}th term\n\
---------------------",
sequence_length
Expand All @@ -97,7 +99,8 @@ where
let trace = prover.build_trace(sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace_width,
trace_length.ilog2(),
Expand Down
11 changes: 7 additions & 4 deletions examples/src/fibonacci/mulfib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use super::utils::compute_mulfib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};

Check failure on line 10 in examples/src/fibonacci/mulfib8/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (stable, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/mulfib8/mod.rs

View workflow job for this annotation

GitHub Actions / no-std (nightly, wasm32-unknown-unknown)

unresolved import `tracing`

Check failure on line 10 in examples/src/fibonacci/mulfib8/mod.rs

View workflow job for this annotation

GitHub Actions / Check with --no-default-features

unresolved import `tracing`
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -60,7 +60,8 @@ impl<H: ElementHasher> MulFib8Example<H> {
// compute Fibonacci sequence
let now = Instant::now();
let result = compute_mulfib_term(sequence_length);
debug!(
event!(
Level::DEBUG,
"Computed multiplicative Fibonacci sequence up to {}th term in {} ms",
sequence_length,
now.elapsed().as_millis()
Expand All @@ -84,7 +85,8 @@ where
{
fn prove(&self) -> StarkProof {
let sequence_length = self.sequence_length;
debug!(
event!(
Level::DEBUG,
"Generating proof for computing multiplicative Fibonacci sequence (2 terms per step) up to {}th term\n\
---------------------",
sequence_length
Expand All @@ -98,7 +100,8 @@ where
let trace = prover.build_trace(sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace_width,
trace_length.ilog2(),
Expand Down
25 changes: 19 additions & 6 deletions examples/src/lamport/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use super::{
};
use crate::{Blake3_192, Blake3_256, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField},
Expand Down Expand Up @@ -69,7 +69,8 @@ impl<H: ElementHasher> LamportAggregateExample<H> {
private_keys.push(PrivateKey::from_seed([i as u8; 32]));
public_keys.push(private_keys[i].pub_key().to_elements());
}
debug!(
event!(
Level::DEBUG,
"Generated {} private-public key pairs in {} ms",
num_signatures,
now.elapsed().as_millis()
Expand All @@ -84,7 +85,12 @@ impl<H: ElementHasher> LamportAggregateExample<H> {
signatures.push(private_key.sign(msg.as_bytes()));
messages.push(message_to_elements(msg.as_bytes()));
}
debug!("Signed {} messages in {} ms", num_signatures, now.elapsed().as_millis());
event!(
Level::DEBUG,
"Signed {} messages in {} ms",
num_signatures,
now.elapsed().as_millis()
);

// verify signature
let now = Instant::now();
Expand All @@ -95,7 +101,12 @@ impl<H: ElementHasher> LamportAggregateExample<H> {
let msg = format!("test message {i}");
assert!(pk.verify(msg.as_bytes(), signature));
}
debug!("Verified {} signature in {} ms", num_signatures, now.elapsed().as_millis());
event!(
Level::DEBUG,
"Verified {} signature in {} ms",
num_signatures,
now.elapsed().as_millis()
);

LamportAggregateExample {
options,
Expand All @@ -116,7 +127,8 @@ where
{
fn prove(&self) -> StarkProof {
// generate the execution trace
debug!(
event!(
Level::DEBUG,
"Generating proof for verifying {} Lamport+ signatures \n\
---------------------",
self.signatures.len(),
Expand All @@ -129,7 +141,8 @@ where
let now = Instant::now();
let trace = prover.build_trace(&self.messages, &self.signatures);
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace.width(),
trace_length.ilog2(),
Expand Down
13 changes: 8 additions & 5 deletions examples/src/lamport/threshold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use super::{
};
use crate::{Blake3_192, Blake3_256, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use log::debug;
use std::time::Instant;
use tracing::{event, Level};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField},
Expand Down Expand Up @@ -72,7 +72,8 @@ impl<H: ElementHasher> LamportThresholdExample<H> {
// generate private/public key pairs for the specified number of signatures
let now = Instant::now();
let private_keys = build_keys(num_signers);
debug!(
event!(
Level::DEBUG,
"Generated {} private-public key pairs in {} ms",
num_signers,
now.elapsed().as_millis()
Expand All @@ -91,7 +92,7 @@ impl<H: ElementHasher> LamportThresholdExample<H> {
// build the aggregated public key
let now = Instant::now();
let pub_key = AggPublicKey::new(public_keys);
debug!("Built aggregated public key in {} ms", now.elapsed().as_millis());
event!(Level::DEBUG, "Built aggregated public key in {} ms", now.elapsed().as_millis());

let (options, _) = options.to_proof_options(28, 8);

Expand All @@ -114,7 +115,8 @@ where
{
fn prove(&self) -> StarkProof {
// generate the execution trace
debug!(
event!(
Level::DEBUG,
"Generating proof for verifying {}-of-{} signature \n\
---------------------",
self.signatures.len(),
Expand All @@ -133,7 +135,8 @@ where
let now = Instant::now();
let trace = prover.build_trace(&self.pub_key, self.message, &self.signatures);
let trace_length = trace.length();
debug!(
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps in {} ms",
trace.width(),
trace_length.ilog2(),
Expand Down
Loading

0 comments on commit 4651c2b

Please sign in to comment.