Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions crates/continuations/src/verifier/common/non_leaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,38 @@ impl<C: Config> NonLeafVerifierVariables<C> {
let proof_vm_pvs = self.verify_internal_or_leaf_verifier_proof(builder, &proof);

assert_single_segment_vm_exit_successfully(builder, &proof);
builder.if_eq(i, RVar::zero()).then_or_else(
|builder| {
builder.assign(&pvs.app_commit, proof_vm_pvs.vm_verifier_pvs.app_commit);
builder.assign(
&leaf_verifier_commit,
proof_vm_pvs.extra_pvs.leaf_verifier_commit,
);
},
|builder| {
builder.assert_eq::<[_; DIGEST_SIZE]>(
pvs.app_commit,
proof_vm_pvs.vm_verifier_pvs.app_commit,
);
builder.assert_eq::<[_; DIGEST_SIZE]>(
leaf_verifier_commit,
proof_vm_pvs.extra_pvs.leaf_verifier_commit,
);
},
);

// builder.if_eq(i, RVar::zero()).then_or_else(
// |builder| {
// builder.assign(&pvs.app_commit, proof_vm_pvs.vm_verifier_pvs.app_commit);
// builder.assign(
// &leaf_verifier_commit,
// proof_vm_pvs.extra_pvs.leaf_verifier_commit,
// );
// },
// |builder| {
// builder.assert_eq::<[_; DIGEST_SIZE]>(
// pvs.app_commit,
// proof_vm_pvs.vm_verifier_pvs.app_commit,
// );
// builder.assert_eq::<[_; DIGEST_SIZE]>(
// leaf_verifier_commit,
// proof_vm_pvs.extra_pvs.leaf_verifier_commit,
// );
// },
// );
assert_or_assign_connector_pvs(
builder,
&pvs.connector,
i,
&proof_vm_pvs.vm_verifier_pvs.connector,
);
assert_or_assign_memory_pvs(
builder,
&pvs.memory,
i,
&proof_vm_pvs.vm_verifier_pvs.memory,
);
// assert_or_assign_memory_pvs(
// builder,
// &pvs.memory,
// i,
// &proof_vm_pvs.vm_verifier_pvs.memory,
// );
// This is only needed when `is_terminate` but branching here won't save much, so we
// always assign it.
builder.assign(
Expand All @@ -106,15 +107,18 @@ impl<C: Config> NonLeafVerifierVariables<C> {
let program_commit = get_program_commit(builder, proof);
let is_self_program =
eq_felt_slice(builder, &self.internal_program_commit, &program_commit);
builder.print_v(is_self_program);

builder.if_eq(is_self_program, RVar::one()).then_or_else(
|builder| {
builder.cycle_tracker_start("verify stark");
StarkVerifier::verify::<DuplexChallengerVariable<C>>(
builder,
&self.internal_pcs,
&self.internal_advice,
proof,
);
builder.cycle_tracker_end("verify stark");
assign_array_to_slice(builder, &flatten_proof_vm_pvs, &proof_vm_pvs_arr, 0);
let proof_vm_pvs: &InternalVmVerifierPvs<_> =
flatten_proof_vm_pvs.as_slice().borrow();
Expand All @@ -126,12 +130,14 @@ impl<C: Config> NonLeafVerifierVariables<C> {
);
},
|builder| {
builder.cycle_tracker_start("verify stark");
StarkVerifier::verify::<DuplexChallengerVariable<C>>(
builder,
&self.leaf_pcs,
&self.leaf_advice,
proof,
);
builder.cycle_tracker_end("verify stark");
// Leaf verifier doesn't have extra public values.
assign_array_to_slice(
builder,
Expand Down
28 changes: 23 additions & 5 deletions crates/vm/src/metrics/cycle_tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ pub struct SpanInfo {
pub start: usize,
}

#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug)]
pub struct CycleTracker {
/// Stack of span names, with most recent at the end
stack: Vec<SpanInfo>,
/// Depth of the stack.
depth: usize,
profile_depth: usize,
}

impl Default for CycleTracker {
fn default() -> Self {
Self::new()
}
}

impl CycleTracker {
pub fn new() -> Self {
Self::default()
Self {
stack: Vec::new(),
depth: 0,
profile_depth: std::env::var("CYCLE_TRACKER_PROFILE_DEPTH")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(3),
}
}

pub fn top(&self) -> Option<&String> {
Expand All @@ -40,8 +54,10 @@ impl CycleTracker {
start: cycles_count,
});
let padding = "│ ".repeat(self.depth);
tracing::info!("{}┌╴{}", padding, name);
self.depth += 1;
if self.depth < self.profile_depth {
tracing::info!("{}┌╴{}", padding, name);
}
}

/// Ends the cycle tracker span for the given name.
Expand All @@ -53,10 +69,12 @@ impl CycleTracker {
}
let SpanInfo { tag, start } = self.stack.pop().unwrap();
assert_eq!(tag, name, "Stack top does not match name");
self.depth -= 1;
let padding = "│ ".repeat(self.depth);
let span_cycles = cycles_count - start;
tracing::info!("{}└╴{} cycles", padding, span_cycles);
if self.depth < self.profile_depth {
tracing::info!("{}└╴{} cycles ({})", padding, span_cycles, name);
}
self.depth -= 1;
}

/// Ends the current cycle tracker span.
Expand Down
10 changes: 8 additions & 2 deletions crates/vm/src/system/phantom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,20 @@ where
SysPhantom::CtStart => {
let metrics = state.metrics;
if let Some(info) = metrics.debug_infos.get(pc) {
metrics.cycle_tracker.start(info.dsl_instruction.clone());
metrics.cycle_tracker.start(
info.dsl_instruction.clone(),
state.memory.timestamp as usize,
);
}
}
#[cfg(feature = "perf-metrics")]
SysPhantom::CtEnd => {
let metrics = state.metrics;
if let Some(info) = metrics.debug_infos.get(pc) {
metrics.cycle_tracker.end(info.dsl_instruction.clone());
metrics.cycle_tracker.end(
info.dsl_instruction.clone(),
state.memory.timestamp as usize,
);
}
}
_ => {}
Expand Down
Loading