Skip to content

Commit 9ecab51

Browse files
Add tracing instrumentation for prover stages (#53)
Emit `tracing` spans for each major STARK proving stage in `System::prove_multiple_claims`: stage 1 commit, lookup construction, stage 2 commit, quotient, and FRI opening. Lookup trace construction itself is broken into `lookup_messages`, `batch_inverse`, and `lookup_traces` sub-spans. The whole call is wrapped in `stark/prove` via `#[tracing::instrument]`. No subscriber is installed here — downstream consumers wire up a subscriber (e.g. `tracing-texray`) to consume the spans.
1 parent 65387a2 commit 9ecab51

4 files changed

Lines changed: 23 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rust-version = "1.88"
99
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1010

1111
[dependencies]
12+
tracing = "0.1"
1213
serde = { version = "1", features = ["derive"] }
1314
bincode = { version = "2", features = ["serde"] }
1415
p3-air = { git = "https://github.com/Plonky3/Plonky3", rev = "e9d75614dd6816f9b5dbb4413c69be63536efd64" }

src/lookup.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,20 @@ impl Lookup<Val> {
126126
// Flatten the references serially first so the parallel map operates
127127
// on an indexed slice and `collect` can write straight into the
128128
// output Vec without tree-reducing worker buffers.
129+
let _g = tracing::info_span!("stark/lookup_messages").entered();
129130
let flat: Vec<&Self> = lookups.iter().flatten().flatten().collect();
130131
let messages: Vec<ExtVal> = flat
131132
.par_iter()
132133
.map(|lookup| lookup.compute_message(lookup_challenge, fingerprint_challenge))
133134
.collect();
135+
drop(_g);
134136

135137
// Compute the inverses of all messages in batch.
136-
let messages_inverses = batch_multiplicative_inverse(&messages);
138+
let messages_inverses = tracing::info_span!("stark/batch_inverse")
139+
.in_scope(|| batch_multiplicative_inverse(&messages));
137140

138141
// Compute and collect intermediate accumulators and traces.
142+
let _g = tracing::info_span!("stark/lookup_traces").entered();
139143
let mut intermediate_accumulators = Vec::with_capacity(lookups.len());
140144
let mut traces = Vec::with_capacity(lookups.len());
141145
let mut offset = 0;
@@ -174,6 +178,7 @@ impl Lookup<Val> {
174178
intermediate_accumulators.push(accumulator);
175179
traces.push(trace);
176180
}
181+
drop(_g);
177182
(traces, intermediate_accumulators)
178183
}
179184

src/prover.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
240240
///
241241
/// Each claim is a slice of field elements that is observed by the challenger
242242
/// before lookup challenges are sampled, binding the proof to the claimed values.
243+
#[tracing::instrument(level = "info", skip_all, name = "stark/prove")]
243244
pub fn prove_multiple_claims(
244245
&self,
245246
fri_parameters: FriParameters,
@@ -254,6 +255,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
254255

255256
// Cost: "Stage 1 commit" — coset LDE (FFT) of each trace from n_i to
256257
// n_i·B rows, then Merkle tree. FFT work: Σ w_i · n_i · B · log₂(n_i·B).
258+
let _g = tracing::info_span!("stark/stage1_commit").entered();
257259
let mut log_degrees = vec![];
258260
let evaluations = witness.traces.into_iter().map(|trace| {
259261
let degree = trace.height();
@@ -265,6 +267,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
265267
});
266268
let (stage_1_trace_commit, stage_1_trace_data) =
267269
<Pcs as PcsTrait<ExtVal, Challenger>>::commit(pcs, evaluations);
270+
drop(_g);
268271

269272
if let Some(commit) = &self.preprocessed_commit {
270273
challenger.observe(commit);
@@ -299,14 +302,18 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
299302

300303
// Cost: "Lookup trace construction" — fingerprint (Horner), batch
301304
// inversion, and accumulator update. Total: Σ n_i·L_i extension field ops.
305+
let _g = tracing::info_span!("stark/lookup_construction").entered();
302306
let (stage_2_traces, intermediate_accumulators) = Lookup::stage_2_traces(
303307
&witness.lookups,
304308
lookup_argument_challenge,
305309
&fingerprint_challenge,
306310
acc,
307311
);
312+
drop(_g);
313+
308314
// Cost: "Stage 2 commit" — LDE + Merkle for flattened extension traces.
309315
// FFT work: Σ w2_i · D · n_i · B · log₂(n_i·B).
316+
let _g = tracing::info_span!("stark/stage2_commit").entered();
310317
let evaluations = stage_2_traces.into_iter().map(|trace| {
311318
let degree = trace.height();
312319
let trace_domain =
@@ -315,6 +322,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
315322
});
316323
let (stage_2_trace_commit, stage_2_trace_data) =
317324
<Pcs as PcsTrait<ExtVal, Challenger>>::commit(pcs, evaluations);
325+
drop(_g);
318326
challenger.observe(stage_2_trace_commit.clone());
319327

320328
// generate constraint challenge
@@ -323,6 +331,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
323331
// Cost: "Quotient computation and commit" — constraint evaluation on the
324332
// quotient domain (Σ n_i·q_i·eval_cost(k_i)) plus LDE + Merkle of the
325333
// quotient sub-polynomials (Σ q_i·D·n_i·B·log₂(n_i·B)).
334+
let _g = tracing::info_span!("stark/quotient").entered();
326335
debug_assert_eq!(intermediate_accumulators.len(), self.circuits.len());
327336
debug_assert_eq!(log_degrees.len(), self.circuits.len());
328337
let mut quotient_degrees = vec![];
@@ -407,6 +416,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
407416
let (quotient_commit, quotient_data) =
408417
<Pcs as PcsTrait<ExtVal, Challenger>>::commit(pcs, quotient_evaluations);
409418
challenger.observe(quotient_commit.clone());
419+
drop(_g);
410420

411421
// save the commitments
412422
let commitments = Commitments {
@@ -417,6 +427,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
417427

418428
// Cost: "FRI opening" — barycentric interpolation (Σ n_i·B·W_i),
419429
// FRI folding (≈ H), and FRI queries (Q·R·log₂ H hash ops).
430+
let _g = tracing::info_span!("stark/fri_open").entered();
420431
let zeta: ExtVal = challenger.sample_algebra_element();
421432
let mut round0_openings = vec![];
422433
let mut round1_openings = vec![];
@@ -446,6 +457,7 @@ impl<A: BaseAir<Val> + for<'a> Air<ProverConstraintFolder<'a>>> System<A> {
446457
rounds.push((key.preprocessed_data.as_ref().unwrap(), round0_openings));
447458
}
448459
let (opened_values, opening_proof) = pcs.open(rounds, &mut challenger);
460+
drop(_g);
449461
let mut opened_values_iter = opened_values.into_iter();
450462
let stage_1_opened_values = opened_values_iter.next().unwrap();
451463
let stage_2_opened_values = opened_values_iter.next().unwrap();

0 commit comments

Comments
 (0)