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
7 changes: 3 additions & 4 deletions crypto/stark/src/constraint_ir/interp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn eval_program<F, E>(
E: IsField,
{
let TransitionEvaluationContext::Prover {
frame,
rows,
rap_challenges,
logup_alpha_powers,
logup_table_offset,
Expand All @@ -188,12 +188,11 @@ pub fn eval_program<F, E>(
let values = run(
prog,
|main, offset, row, col| {
let step: &TableView<F, E> = frame.get_evaluation_step(offset as usize);
debug_assert_eq!(row, 0, "tables read row 0 of each frame step");
if main {
Value::Base(step.get_main_evaluation_element(0, col as usize).clone())
Value::Base(rows.main(offset as usize, col as usize).clone())
} else {
Value::Ext(step.get_aux_evaluation_element(0, col as usize).clone())
Value::Ext(rows.aux(offset as usize, col as usize).clone())
}
},
|idx| rap_challenges[idx as usize].clone(),
Expand Down
49 changes: 42 additions & 7 deletions crypto/stark/src/constraint_ir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ fn frame_offset_reads_next_step() {
let alpha: Vec<ExtE> = vec![];
let offset = ExtE::zero();
let shifts = PackingShifts::<Fp>::new();
let ctx = TransitionEvaluationContext::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);

let mut base_evals = vec![FpE::zero()];
let mut ext_evals: Vec<ExtE> = vec![];
Expand Down Expand Up @@ -234,7 +240,13 @@ fn mixed_base_ext_auto_embeds() {
let alpha: Vec<ExtE> = vec![];
let offset = ExtE::zero();
let shifts = PackingShifts::<Fp>::new();
let ctx = TransitionEvaluationContext::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);

let mut base_evals: Vec<FpE> = vec![];
let mut ext_evals = vec![ExtE::zero(), ExtE::zero()];
Expand Down Expand Up @@ -267,7 +279,13 @@ fn explicit_embed_and_ext_neg() {
let alpha: Vec<ExtE> = vec![];
let offset = ExtE::zero();
let shifts = PackingShifts::<Fp>::new();
let ctx = TransitionEvaluationContext::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);

let mut base_evals: Vec<FpE> = vec![];
let mut ext_evals = vec![ExtE::zero()];
Expand Down Expand Up @@ -317,7 +335,13 @@ fn all_leaf_kinds_logup_shaped() {
let step = TableView::<Fp, Ext>::new(vec![main_row], vec![aux_row]);
let frame = Frame::<Fp, Ext>::new(vec![step]);
let shifts = PackingShifts::<Fp>::new();
let ctx = TransitionEvaluationContext::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);

let mut base_evals: Vec<FpE> = vec![];
let mut ext_evals = vec![ExtE::zero()];
Expand Down Expand Up @@ -354,7 +378,13 @@ fn prover_entry_point_splits_base_and_ext() {
let alpha = vec![ext3(3, 3, 3)];
let offset = ExtE::zero();
let shifts = PackingShifts::<Fp>::new();
let ctx = TransitionEvaluationContext::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);

let mut base_evals = vec![FpE::zero()];
let mut ext_evals = vec![ExtE::zero(), ExtE::zero()];
Expand Down Expand Up @@ -485,8 +515,13 @@ fn non_goldilocks_reflexive_tower_builds_and_interprets() {
let alpha: Vec<GE> = vec![];
let offset = g(0);
let shifts = PackingShifts::<G>::new();
let ctx =
TransitionEvaluationContext::<G, G>::new_prover(&frame, &rap, &alpha, &offset, &shifts);
let ctx = TransitionEvaluationContext::<G, G>::new_prover(
frame.as_row_frame(),
&rap,
&alpha,
&offset,
&shifts,
);
let mut base_evals = vec![GE::zero()];
let mut ext_evals = vec![GE::zero(), GE::zero()];
eval_program(&prog, &ctx, &mut base_evals, &mut ext_evals);
Expand Down
18 changes: 6 additions & 12 deletions crypto/stark/src/constraints/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use math::field::element::FieldElement;
use math::field::traits::{IsField, IsSubFieldOf};

use crate::constraint_ir::{ConstraintProgram, Dim, IrBuilder};
use crate::frame::Frame;
use crate::frame::{Frame, RowFrame};
use crate::traits::TransitionEvaluationContext;

// =============================================================================
Expand Down Expand Up @@ -381,7 +381,7 @@ where
F: IsSubFieldOf<E>,
E: IsField,
{
frame: &'a Frame<F, E>,
rows: RowFrame<'a, F, E>,
challenges: &'a [FieldElement<E>],
alphas: &'a [FieldElement<E>],
logup_table_offset: &'a FieldElement<E>,
Expand All @@ -406,7 +406,7 @@ where
ext_out: &'a mut [FieldElement<E>],
) -> Self {
let TransitionEvaluationContext::Prover {
frame,
rows,
rap_challenges,
logup_alpha_powers,
logup_table_offset,
Expand All @@ -417,7 +417,7 @@ where
};
let num_constraints = base_out.len().max(ext_out.len());
Self {
frame,
rows: *rows,
challenges: rap_challenges,
alphas: logup_alpha_powers,
logup_table_offset,
Expand All @@ -443,16 +443,10 @@ where
type ExprE = FieldElement<E>;

fn main(&self, offset: usize, col: usize) -> FieldElement<F> {
self.frame
.get_evaluation_step(offset)
.get_main_evaluation_element(0, col)
.clone()
self.rows.main(offset, col).clone()
}
fn aux(&self, offset: usize, col: usize) -> FieldElement<E> {
self.frame
.get_evaluation_step(offset)
.get_aux_evaluation_element(0, col)
.clone()
self.rows.aux(offset, col).clone()
}
fn challenge(&self, idx: usize) -> FieldElement<E> {
self.challenges[idx].clone()
Expand Down
31 changes: 23 additions & 8 deletions crypto/stark/src/constraints/builder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fn prover_folder_matches_direct_arithmetic() {
let challenges = vec![t.challenge0];
let alphas = vec![t.alpha0];
let ctx = TransitionEvaluationContext::new_prover(
&frame,
frame.as_row_frame(),
&challenges,
&alphas,
&t.offset,
Expand Down Expand Up @@ -226,7 +226,7 @@ fn prover_folder_matches_interpreted_capture() {
let challenges = vec![t.challenge0];
let alphas = vec![t.alpha0];
let ctx = TransitionEvaluationContext::new_prover(
&frame,
frame.as_row_frame(),
&challenges,
&alphas,
&t.offset,
Expand Down Expand Up @@ -360,8 +360,13 @@ fn prover_folder_missing_emit_asserts() {
let challenges: Vec<ExtE> = vec![];
let alphas: Vec<ExtE> = vec![];
let offset = ExtE::zero();
let ctx =
TransitionEvaluationContext::new_prover(&frame, &challenges, &alphas, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&challenges,
&alphas,
&offset,
&shifts,
);

let mut base_out = vec![FpE::zero(); 2];
let mut ext_out = vec![ExtE::zero(); 2];
Expand All @@ -381,8 +386,13 @@ fn prover_folder_double_emit_asserts() {
let challenges: Vec<ExtE> = vec![];
let alphas: Vec<ExtE> = vec![];
let offset = ExtE::zero();
let ctx =
TransitionEvaluationContext::new_prover(&frame, &challenges, &alphas, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&challenges,
&alphas,
&offset,
&shifts,
);

let mut base_out = vec![FpE::zero(); 2];
let mut ext_out = vec![ExtE::zero(); 2];
Expand Down Expand Up @@ -594,8 +604,13 @@ fn next_row_aux_and_multi_alpha_folder_matches_capture() {
.map(|s| TableView::new(vec![rows[s].clone()], vec![auxs[s].clone()]))
.collect();
let frame = Frame::<Fp, Ext>::new(steps);
let ctx =
TransitionEvaluationContext::new_prover(&frame, &challenges, &alphas, &offset, &shifts);
let ctx = TransitionEvaluationContext::new_prover(
frame.as_row_frame(),
&challenges,
&alphas,
&offset,
&shifts,
);

let mut folder_base = vec![FpE::zero(); num_base];
let mut folder_ext = vec![ExtE::zero(); meta.len()];
Expand Down
42 changes: 12 additions & 30 deletions crypto/stark/src/constraints/evaluator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::boundary::BoundaryConstraints;
use crate::domain::Domain;
use crate::frame::Frame;
use crate::frame::RowFrame;
use crate::lookup::{BusPublicInputs, LOGUP_CHALLENGE_ALPHA, PackingShifts, compute_alpha_powers};
use crate::trace::LDETraceTable;
use crate::traits::{AIR, TransitionEvaluationContext, ZerofierEvaluations};
Expand Down Expand Up @@ -61,29 +61,21 @@ where
// Precompute packing shift constants once for all LDE domain points.
let packing_shifts = PackingShifts::<Field>::new();

// Per-thread buffers via map_init: each Rayon worker allocates once,
// then reuses for all iterations assigned to that thread.
// The Frame is pre-allocated and filled in-place to avoid Vec allocations
// on every LDE point (a significant fraction of total CPU time).
let blowup_factor = lde_trace.blowup_factor;
let lde_step_size = lde_trace.lde_step_size;
let rows_per_step = lde_step_size / blowup_factor;
let num_main_cols = lde_trace.num_main_cols();
let num_aux_cols = lde_trace.num_aux_cols();
let num_offsets = offsets.len();

// Per-thread output buffers via map_init: each Rayon worker allocates
// once, then reuses for all iterations assigned to that thread. The
// trace rows themselves are BORROWED in place per LDE point (the LDE
// buffers are row-major) — no per-row gather copy.
// Per-row evaluation, shared by the parallel and sequential paths below:
// fill the frame, evaluate transition constraints, accumulate with zerofiers.
// borrow the rows, evaluate transition constraints, accumulate with zerofiers.
let eval_row = |i: usize,
boundary: FieldElement<FieldExtension>,
transition_buf: &mut [FieldElement<FieldExtension>],
base_buf: &mut [FieldElement<Field>],
frame: &mut Frame<Field, FieldExtension>|
base_buf: &mut [FieldElement<Field>]|
-> FieldElement<FieldExtension> {
frame.fill_from_lde(lde_trace, i, offsets);
let rows = RowFrame::from_lde(lde_trace, i, offsets);

let ctx = TransitionEvaluationContext::new_prover(
frame,
rows,
rap_challenges,
&logup_alpha_powers,
logup_table_offset,
Expand Down Expand Up @@ -145,16 +137,10 @@ where
(
vec![FieldElement::<FieldExtension>::zero(); num_transition],
vec![FieldElement::<Field>::zero(); num_base],
Frame::preallocate(
num_offsets,
rows_per_step,
num_main_cols,
num_aux_cols,
),
)
},
|(transition_buf, base_buf, frame), (i, boundary)| {
eval_row(i, boundary, transition_buf, base_buf, frame)
|(transition_buf, base_buf), (i, boundary)| {
eval_row(i, boundary, transition_buf, base_buf)
},
)
.collect()
Expand All @@ -164,15 +150,11 @@ where
{
let mut transition_buf = vec![FieldElement::<FieldExtension>::zero(); num_transition];
let mut base_buf = vec![FieldElement::<Field>::zero(); num_base];
let mut frame =
Frame::preallocate(num_offsets, rows_per_step, num_main_cols, num_aux_cols);

boundary_evaluation
.into_iter()
.enumerate()
.map(|(i, boundary)| {
eval_row(i, boundary, &mut transition_buf, &mut base_buf, &mut frame)
})
.map(|(i, boundary)| eval_row(i, boundary, &mut transition_buf, &mut base_buf))
.collect()
}
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/stark/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn validate_trace<
for step in 0..lde_trace.num_steps() {
let frame = Frame::read_step_from_lde(&lde_trace, step, &air.context().transition_offsets);
let transition_evaluation_context = TransitionEvaluationContext::new_prover(
&frame,
frame.as_row_frame(),
rap_challenges,
&logup_alpha_powers,
&logup_table_offset,
Expand Down
Loading
Loading