Skip to content

Commit

Permalink
feat: enable tracing_forest as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Jan 30, 2024
1 parent 9ef238f commit 5a00b61
Show file tree
Hide file tree
Showing 16 changed files with 281 additions and 245 deletions.
3 changes: 2 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ doc = false
[features]
concurrent = ["winterfell/concurrent", "std"]
default = ["std"]
tree = ["std", "tracing-forest"]
std = ["core-utils/std", "hex/std", "rand-utils", "winterfell/std"]

[dependencies]
Expand All @@ -33,7 +34,7 @@ rand-utils = { version = "0.7", path = "../utils/rand", package = "winter-rand-u
structopt = { version = "0.3", default-features = false }
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", features = ["std", "env-filter"] }
tracing-forest = { version = "0.1", features = ["ansi", "smallvec"] }
tracing-forest = { version = "0.1", features = ["ansi", "smallvec"], optional = true }
winterfell = { version="0.7", path = "../winterfell", default-features = false }

[dev-dependencies]
Expand Down
37 changes: 27 additions & 10 deletions examples/src/fibonacci/fib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::utils::compute_fib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -97,19 +97,36 @@ where
let prover = FibProver::<H>::new(self.options.clone());

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(self.sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace_width,
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

// let span = info_span!("Generating execution trace", registers_num = field::Empty, steps = field::Empty);
// let trace = prover.build_trace(self.sequence_length);
// span.record("registers_num", &format!("{}", trace.width()));
// span.record("steps", &format!("2^{} steps", trace.length().ilog2()));

// let trace = info_span!("Generating execution trace").in_scope(|| {
// let trace = prover.build_trace(self.sequence_length);
// let trace_width = trace.width();
// let trace_length = trace.length();
// event!(
// Level::DEBUG,
// "Generated execution trace of {} registers and 2^{} steps",
// trace_width,
// trace_length.ilog2(),
// );
// trace
// });

// generate the proof
prover.prove(trace).unwrap()
}
Expand Down
19 changes: 9 additions & 10 deletions examples/src/fibonacci/fib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::utils::compute_fib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -97,16 +97,15 @@ where
let prover = Fib8Prover::<H>::new(self.options.clone());

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(self.sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace_width,
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
19 changes: 9 additions & 10 deletions examples/src/fibonacci/fib_small/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::utils::compute_fib_term;
use crate::{Example, ExampleOptions, HashFunction};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f64::BaseElement, FieldElement},
Expand Down Expand Up @@ -112,16 +112,15 @@ where
let prover = FibSmallProver::<H>::new(self.options.clone());

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(self.sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace_width,
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
19 changes: 9 additions & 10 deletions examples/src/fibonacci/mulfib2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::utils::compute_mulfib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -92,16 +92,15 @@ where
let prover = MulFib2Prover::<H>::new(self.options.clone());

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace_width,
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
19 changes: 9 additions & 10 deletions examples/src/fibonacci/mulfib8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::utils::compute_mulfib_term;
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -93,16 +93,15 @@ where
let prover = MulFib8Prover::<H>::new(self.options.clone());

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(sequence_length);
let trace_width = trace.width();
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace_width,
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
19 changes: 10 additions & 9 deletions examples/src/lamport/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
use crate::{Blake3_192, Blake3_256, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField},
Expand Down Expand Up @@ -122,15 +122,16 @@ where
let prover =
LamportAggregateProver::<H>::new(&self.pub_keys, &self.messages, self.options.clone());

let trace = info_span!("Generating execution trace").in_scope(|| {
// generate execution trace
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(&self.messages, &self.signatures);
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace.width(),
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
18 changes: 9 additions & 9 deletions examples/src/lamport/threshold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
use crate::{Blake3_192, Blake3_256, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, get_power_series, FieldElement, StarkField},
Expand Down Expand Up @@ -129,15 +129,15 @@ where
);

// generate execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(&self.pub_key, self.message, &self.signatures);
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace.width(),
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
25 changes: 21 additions & 4 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
use std::time::Instant;
use structopt::StructOpt;
use tracing::info_span;
#[cfg(feature = "tree")]
use tracing_forest::ForestLayer;
#[cfg(not(feature = "tree"))]
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};
use winterfell::StarkProof;

Expand All @@ -22,11 +25,25 @@ fn main() {
if std::env::var("WINTER_LOG").is_err() {
std::env::set_var("WINTER_LOG", "info");
}
let registry =
tracing_subscriber::registry::Registry::default().with(EnvFilter::from_env("WINTER_LOG"));

tracing_subscriber::registry::Registry::default()
.with(EnvFilter::from_env("WINTER_LOG"))
.with(ForestLayer::default())
.init();
#[cfg(feature = "tree")]
registry.with(ForestLayer::default()).init();

#[cfg(not(feature = "tree"))]
{
let format = tracing_subscriber::fmt::layer()
.with_level(false)
.with_target(false)
.with_thread_names(false)
.with_span_events(FmtSpan::CLOSE)
.with_ansi(false)
.with_timer(tracing_subscriber::fmt::time::SystemTime::default())

Check failure on line 42 in examples/src/main.rs

View workflow job for this annotation

GitHub Actions / Clippy

use of `default` to create a unit struct
.compact();

registry.with(format).init();
}

// read command-line args
let options = ExampleOptions::from_args();
Expand Down
20 changes: 10 additions & 10 deletions examples/src/merkle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
use core::marker::PhantomData;
use rand_utils::{rand_value, rand_vector};
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, Digest, ElementHasher, MerkleTree},
math::{fields::f128::BaseElement, FieldElement, StarkField},
Expand Down Expand Up @@ -116,16 +116,16 @@ where
// create the prover
let prover = MerkleProver::<H>::new(self.options.clone());

// generate the execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
// generate execution trace
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(self.value, &self.path, self.index);
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace.width(),
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
20 changes: 10 additions & 10 deletions examples/src/rescue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use crate::{Blake3_192, Blake3_256, Example, ExampleOptions, HashFunction, Sha3_256};
use core::marker::PhantomData;
use std::time::Instant;
use tracing::{event, info_span, Level};
use tracing::{field, info_span};
use winterfell::{
crypto::{DefaultRandomCoin, ElementHasher},
math::{fields::f128::BaseElement, FieldElement},
Expand Down Expand Up @@ -101,16 +101,16 @@ where
// create a prover
let prover = RescueProver::<H>::new(self.options.clone());

// generate the execution trace
let trace = info_span!("Generating execution trace").in_scope(|| {
// generate execution trace
let trace = info_span!(
"Generated execution trace",
registers_num = field::Empty,
steps = field::Empty
)
.in_scope(|| {
let trace = prover.build_trace(self.seed, self.chain_length);
let trace_length = trace.length();
event!(
Level::DEBUG,
"Generated execution trace of {} registers and 2^{} steps",
trace.width(),
trace_length.ilog2(),
);
tracing::Span::current().record("registers_num", &format!("{}", trace.width()));
tracing::Span::current().record("steps", &format!("2^{}", trace.length().ilog2()));
trace
});

Expand Down
Loading

0 comments on commit 5a00b61

Please sign in to comment.