Skip to content

Commit

Permalink
refactor: get data before span
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Jan 31, 2024
1 parent a8b4696 commit abca6b6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 81 deletions.
113 changes: 50 additions & 63 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use air::{
DeepCompositionCoefficients, EvaluationFrame, FieldExtension, ProofOptions, TraceInfo,
TraceLayout, TransitionConstraintDegree,
};
use tracing::{field, info_span};
use tracing::{event, field, info_span, Level};
pub use utils::{
iterators, ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable,
SliceReader,
Expand Down Expand Up @@ -253,11 +253,11 @@ pub trait Prover {
// 1 ----- Commit to the execution trace --------------------------------------------------

// build computation domain; this is used later for polynomial evaluations
let domain = info_span!(
"Built domain",
elements_number = format!("2^{}", air.lde_domain_size().ilog2())
)
.in_scope(|| StarkDomain::new(&air));
let lde_domain_size = air.lde_domain_size();
let domain =
info_span!("build_domain", domain_size = format!("2^{}", lde_domain_size.ilog2()))
.in_scope(|| StarkDomain::new(&air));
assert_eq!(domain.lde_domain_size(), lde_domain_size);

// extend the main execution trace and build a Merkle tree from the extended trace
let (mut trace_lde, mut trace_polys): (Self::TraceLde<E>, TracePolyTable<E>) =
Expand All @@ -275,10 +275,12 @@ pub trait Prover {
let mut aux_trace_segments = Vec::new();
let mut aux_trace_rand_elements = AuxTraceRandElements::new();
for i in 0..trace.layout().num_aux_segments() {
let num_columns = trace.layout().get_aux_segment_width(i);
let num_rows = air.trace_length();
let (aux_segment, rand_elements) = info_span!(
"Built auxiliary trace segment",
columns_number = field::Empty,
steps = field::Empty
"build_aux_trace_segment",
num_columns,
num_rows = format!("2^{}", num_rows.ilog2()),
)
.in_scope(|| {
// draw a set of random elements required to build an auxiliary trace segment
Expand All @@ -288,11 +290,10 @@ pub trait Prover {
let aux_segment = trace
.build_aux_segment(&aux_trace_segments, &rand_elements)
.expect("failed build auxiliary trace segment");
tracing::Span::current().record("columns_number", aux_segment.num_cols());
tracing::Span::current()
.record("steps", &format!("2^{}", aux_segment.num_rows().ilog2()));
(aux_segment, rand_elements)
});
assert_eq!(aux_segment.num_cols(), num_columns);
assert_eq!(aux_segment.num_rows(), num_rows);

// extend the auxiliary trace segment and build a Merkle tree from the extended trace
let (aux_segment_polys, aux_segment_root) =
Expand Down Expand Up @@ -321,16 +322,13 @@ pub trait Prover {
// evaluate constraints specified by the AIR over the constraint evaluation domain, and
// compute random linear combinations of these evaluations using coefficients drawn from
// the channel
let ce_domain_size = air.ce_domain_size();
let composition_poly_trace =
info_span!("Evaluated constraints", domain_size = field::Empty).in_scope(|| {
info_span!("evaluate_constraints", ce_domain_size).in_scope(|| {
let constraint_coeffs = channel.get_constraint_composition_coeffs();
let evaluator =
self.new_evaluator(&air, aux_trace_rand_elements, constraint_coeffs);
let composition_poly_trace = evaluator.evaluate(&trace_lde, &domain);
tracing::Span::current().record(
"domain_size",
&format!("2^{} elements", composition_poly_trace.num_rows().ilog2()),
);
composition_poly_trace

Check failure on line 332 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

returning the result of a `let` binding from a block
});

Expand All @@ -350,7 +348,7 @@ pub trait Prover {

// 4 ----- build DEEP composition polynomial ----------------------------------------------
let deep_composition_poly =
info_span!("Built DEEP composition polynomial", degree = field::Empty).in_scope(|| {
info_span!("build_deep_composition_poly", degree = field::Empty).in_scope(|| {
// draw an out-of-domain point z. Depending on the type of E, the point is drawn either
// from the base field or from an extension field defined by E.
//
Expand Down Expand Up @@ -392,8 +390,8 @@ pub trait Prover {

// 5 ----- evaluate DEEP composition polynomial over LDE domain ---------------------------
let deep_evaluations = info_span!(
"Evaluated DEEP composition polynomial over LDE domain",
domain_size = format!("2^{}", domain.lde_domain_size().ilog2())
"evaluate_deep_composition_poly",
domain_size = format!("2^{}", lde_domain_size.ilog2())
)
.in_scope(|| {
let deep_evaluations = deep_composition_poly.evaluate(&domain);
Expand All @@ -408,36 +406,26 @@ pub trait Prover {
});

// 6 ----- compute FRI layers for the composition polynomial ------------------------------
let mut fri_prover = info_span!(
"Computed FRI layers from composition polynomial evaluations",
layers_number = field::Empty
)
.in_scope(|| {
let mut fri_prover = FriProver::new(air.options().to_fri_options());
let mut fri_prover = FriProver::new(air.options().to_fri_options());
info_span!("compute_fri_layers", num_layers = fri_prover.num_layers()).in_scope(|| {
fri_prover.build_layers(&mut channel, deep_evaluations);

tracing::Span::current().record("layers_number", fri_prover.num_layers());

fri_prover
});

// 7 ----- determine query positions ------------------------------------------------------
let num_positions = air.options().num_queries();
let query_positions =
info_span!("Determined unique query positions", positions_number = field::Empty)
.in_scope(|| {
// apply proof-of-work to the query seed
channel.grind_query_seed();

// generate pseudo-random query positions
let query_positions = channel.get_query_positions();

tracing::Span::current().record("positions_number", query_positions.len());

query_positions
});
info_span!("determine_query_positions", num_positions).in_scope(|| {
// apply proof-of-work to the query seed
channel.grind_query_seed();

// generate pseudo-random query positions
let query_positions = channel.get_query_positions();
event!(Level::DEBUG, "query_positions_len: {}", query_positions.len());
query_positions
});

// 8 ----- build proof object -------------------------------------------------------------
let proof = info_span!("Built proof object").in_scope(|| {
let proof = info_span!("build_proof_object").in_scope(|| {
// generate FRI proof
let fri_proof = fri_prover.build_proof(&query_positions);

Expand Down Expand Up @@ -470,7 +458,7 @@ pub trait Prover {
fn build_constraint_commitment<E>(
&self,
composition_poly_trace: CompositionPolyTrace<E>,
num_trace_poly_columns: usize,
num_constraint_composition_columns: usize,
domain: &StarkDomain<Self::BaseField>,
) -> (ConstraintCommitment<E, Self::HashFn>, CompositionPoly<E>)
where
Expand All @@ -481,52 +469,51 @@ pub trait Prover {
// - "break" the polynomial into a set of column polynomials each of degree equal to
// trace_length - 1
let composition_poly = info_span!(
"Converted constraint evaluations into composition polynomial columns",
columns_number = field::Empty,
degree = field::Empty
"build_composition_poly_columns",
num_columns = num_constraint_composition_columns,
degree = domain.trace_length() - 1
)
.in_scope(|| {
let composition_poly =
CompositionPoly::new(composition_poly_trace, domain, num_trace_poly_columns);

tracing::Span::current().record("columns_number", composition_poly.num_columns());
tracing::Span::current().record("degree", composition_poly.column_degree());
let composition_poly = CompositionPoly::new(
composition_poly_trace,
domain,
num_constraint_composition_columns,
);

composition_poly

Check failure on line 483 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

returning the result of a `let` binding from a block
});
assert_eq!(composition_poly.num_columns(), num_constraint_composition_columns);
assert_eq!(composition_poly.column_degree(), domain.trace_length() - 1);

// then, evaluate composition polynomial columns over the LDE domain
let composed_evaluations = info_span!(
"Evaluated composition polynomial columns over LDE domain",
columns_number = field::Empty,
domain_size = field::Empty
"evaluate_composition_poly_columns",
num_columns = num_constraint_composition_columns,
domain_size = format!("2^{}", domain.lde_domain_size().ilog2())
)
.in_scope(|| {
let composed_evaluations = RowMatrix::evaluate_polys_over::<DEFAULT_SEGMENT_WIDTH>(
composition_poly.data(),
domain,
);

tracing::Span::current().record("columns_number", composed_evaluations.num_cols());
tracing::Span::current().record("domain_size", composed_evaluations.num_rows().ilog2());

composed_evaluations
});
assert_eq!(composed_evaluations.num_cols(), num_constraint_composition_columns);
assert_eq!(composed_evaluations.num_rows(), domain.lde_domain_size());

// finally, build constraint evaluation commitment
let constraint_commitment = info_span!(
"Computed constraint evaluation commitment",
merkle_tree_depth = field::Empty
"compute_constraint_evaluation_commitment",
tree_depth = domain.lde_domain_size().ilog2()
)
.in_scope(|| {
let commitment = composed_evaluations.commit_to_rows();
let constraint_commitment = ConstraintCommitment::new(composed_evaluations, commitment);

tracing::Span::current()
.record("merkle_tree_depth", constraint_commitment.tree_depth());

constraint_commitment

Check failure on line 514 in prover/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

returning the result of a `let` binding from a block
});
assert_eq!(constraint_commitment.tree_depth(), domain.lde_domain_size().ilog2() as usize);

(constraint_commitment, composition_poly)
}
Expand Down
30 changes: 12 additions & 18 deletions prover/src/trace/trace_lde/default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};
use crate::{RowMatrix, DEFAULT_SEGMENT_WIDTH};
use crypto::MerkleTree;
use tracing::{field, info_span};
use tracing::info_span;

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -231,34 +231,28 @@ where
{
// extend the execution trace
let (trace_lde, trace_polys) = info_span!(
"Extended execution trace",
columns_number = field::Empty,
from = field::Empty,
to = field::Empty,
blowup = field::Empty
"extend_execution_trace",
num_cols = trace.num_cols(),
from_domain_size = format!("2^{}", trace.num_rows()),
to_domain_size = format!("2^{}", domain.lde_domain_size()),
blowup = format!("{}x", domain.trace_to_lde_blowup())
)
.in_scope(|| {
let trace_polys = trace.interpolate_columns();
let trace_lde =
RowMatrix::evaluate_polys_over::<DEFAULT_SEGMENT_WIDTH>(&trace_polys, domain);

tracing::Span::current().record("columns_number", &format!("{}", trace_lde.num_cols()));
tracing::Span::current().record("from", &format!("2^{}", trace_polys.num_rows().ilog2()));
tracing::Span::current().record("to", &format!("2^{}", trace_lde.num_rows().ilog2()));
tracing::Span::current().record("blowup", &format!("{}x", domain.trace_to_lde_blowup()));

(trace_lde, trace_polys)
});
assert_eq!(trace_lde.num_cols(), trace.num_cols());
assert_eq!(trace_polys.num_rows(), trace.num_rows());
assert_eq!(trace_lde.num_rows(), domain.lde_domain_size());

// build trace commitment
let trace_tree =
info_span!("Computed execution trace commitment", merkle_tree_depth = field::Empty)
.in_scope(|| {
let trace_tree = trace_lde.commit_to_rows();
tracing::Span::current()
.record("merkle_tree_depth", &format!("{}", trace_tree.depth()));
trace_tree
});
info_span!("compute_execution_trace_commitment", depth = trace_lde.num_rows().ilog2())
.in_scope(|| trace_lde.commit_to_rows());
assert_eq!(trace_tree.depth(), trace_lde.num_rows().ilog2() as usize);

(trace_lde, trace_tree, trace_polys)
}
Expand Down

0 comments on commit abca6b6

Please sign in to comment.