Skip to content

Commit 3d2c773

Browse files
committed
fix: rebase PR #505 onto current main
Adapt the inline-PC work to two intervening main commits: 1. #514 replaced the old `TransitionEvaluationContext` Prover/Verifier split with a single generic `evaluate<F,E>(&self, step: &TableView<F,E>) -> FieldElement<F>`. Rewrite the two new constraints (`PcDoubleReadRs1Constraint`, `PcDoubleReadBorrowConstraint`) to this shape and use `.boxed()` for the `TransitionConstraintEvaluator` adapter instead of `Box::new(...)`. The evaluate<F,E> body is field-parametric, so the old to_extension / explicit GoldilocksExtension paths collapse into a single generic implementation. 2. The later commit `perf: eliminate REGISTER table by computing bus contributions in verifier` removed the `register` field from the `Traces` struct but left a dangling `register` pattern in two destructurings plus a `register.num_rows() * (REGISTER_COLS - ...)` expression. Drop the pattern, the unused `REGISTER_COLS` / `REGISTER_PREPROCESSED` imports, the `let n_register = ...` binding, and the contribution line. Add a short NOTE comment explaining the REGISTER table is now verifier-computed. Also run `cargo fmt --all` over the tree to clear the remaining CI fmt diffs introduced during the rebase (prover/src/lib.rs:257,452,528 and a few others). Verified: - cargo check --workspace - cargo clippy --workspace (default features + debug-checks) -- -D warnings - cargo fmt --check --all - cargo test -p stark --release --lib: 121/121 pass
1 parent 18f435b commit 3d2c773

4 files changed

Lines changed: 65 additions & 72 deletions

File tree

prover/src/constraints/cpu.rs

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,19 @@ impl PcDoubleReadRs1Constraint {
10331033
pub fn new(idx: usize) -> Self {
10341034
Self { idx }
10351035
}
1036+
1037+
fn compute<F, E>(&self, step: &TableView<F, E>) -> FieldElement<F>
1038+
where
1039+
F: IsSubFieldOf<E>,
1040+
E: IsField,
1041+
{
1042+
let pc_double_read = step
1043+
.get_main_evaluation_element(0, cols::PC_DOUBLE_READ)
1044+
.clone();
1045+
let rs1 = step.get_main_evaluation_element(0, cols::RS1).clone();
1046+
let val_255 = FieldElement::<F>::from(255u64);
1047+
pc_double_read * (rs1 - val_255)
1048+
}
10361049
}
10371050

10381051
impl TransitionConstraint<GoldilocksField, GoldilocksExtension> for PcDoubleReadRs1Constraint {
@@ -1044,28 +1057,12 @@ impl TransitionConstraint<GoldilocksField, GoldilocksExtension> for PcDoubleRead
10441057
self.idx
10451058
}
10461059

1047-
fn evaluate(
1048-
&self,
1049-
evaluation_context: &TransitionEvaluationContext<GoldilocksField, GoldilocksExtension>,
1050-
transition_evaluations: &mut [FieldElement<GoldilocksExtension>],
1051-
) {
1052-
match evaluation_context {
1053-
TransitionEvaluationContext::Prover { frame, .. } => {
1054-
let step = frame.get_evaluation_step(0);
1055-
let pc_double_read = *step.get_main_evaluation_element(0, cols::PC_DOUBLE_READ);
1056-
let rs1 = *step.get_main_evaluation_element(0, cols::RS1);
1057-
let val_255 = FieldElement::<GoldilocksField>::from(255u64);
1058-
transition_evaluations[self.idx] =
1059-
(pc_double_read * (rs1 - val_255)).to_extension();
1060-
}
1061-
TransitionEvaluationContext::Verifier { frame, .. } => {
1062-
let step = frame.get_evaluation_step(0);
1063-
let pc_double_read = *step.get_main_evaluation_element(0, cols::PC_DOUBLE_READ);
1064-
let rs1 = *step.get_main_evaluation_element(0, cols::RS1);
1065-
let val_255 = FieldElement::<GoldilocksExtension>::from(255u64);
1066-
transition_evaluations[self.idx] = pc_double_read * (rs1 - val_255);
1067-
}
1068-
}
1060+
fn evaluate<F, E>(&self, step: &TableView<F, E>) -> FieldElement<F>
1061+
where
1062+
F: IsSubFieldOf<E>,
1063+
E: IsField,
1064+
{
1065+
self.compute(step)
10691066
}
10701067
}
10711068

@@ -1079,6 +1076,20 @@ impl PcDoubleReadBorrowConstraint {
10791076
pub fn new(idx: usize) -> Self {
10801077
Self { idx }
10811078
}
1079+
1080+
fn compute<F, E>(&self, step: &TableView<F, E>) -> FieldElement<F>
1081+
where
1082+
F: IsSubFieldOf<E>,
1083+
E: IsField,
1084+
{
1085+
let pc_double_read = step
1086+
.get_main_evaluation_element(0, cols::PC_DOUBLE_READ)
1087+
.clone();
1088+
let borrow = step
1089+
.get_main_evaluation_element(0, cols::PREV_PC_TIMESTAMP_BORROW)
1090+
.clone();
1091+
pc_double_read * borrow
1092+
}
10821093
}
10831094

10841095
impl TransitionConstraint<GoldilocksField, GoldilocksExtension> for PcDoubleReadBorrowConstraint {
@@ -1090,25 +1101,12 @@ impl TransitionConstraint<GoldilocksField, GoldilocksExtension> for PcDoubleRead
10901101
self.idx
10911102
}
10921103

1093-
fn evaluate(
1094-
&self,
1095-
evaluation_context: &TransitionEvaluationContext<GoldilocksField, GoldilocksExtension>,
1096-
transition_evaluations: &mut [FieldElement<GoldilocksExtension>],
1097-
) {
1098-
match evaluation_context {
1099-
TransitionEvaluationContext::Prover { frame, .. } => {
1100-
let step = frame.get_evaluation_step(0);
1101-
let pc_double_read = *step.get_main_evaluation_element(0, cols::PC_DOUBLE_READ);
1102-
let borrow = *step.get_main_evaluation_element(0, cols::PREV_PC_TIMESTAMP_BORROW);
1103-
transition_evaluations[self.idx] = (pc_double_read * borrow).to_extension();
1104-
}
1105-
TransitionEvaluationContext::Verifier { frame, .. } => {
1106-
let step = frame.get_evaluation_step(0);
1107-
let pc_double_read = *step.get_main_evaluation_element(0, cols::PC_DOUBLE_READ);
1108-
let borrow = *step.get_main_evaluation_element(0, cols::PREV_PC_TIMESTAMP_BORROW);
1109-
transition_evaluations[self.idx] = pc_double_read * borrow;
1110-
}
1111-
}
1104+
fn evaluate<F, E>(&self, step: &TableView<F, E>) -> FieldElement<F>
1105+
where
1106+
F: IsSubFieldOf<E>,
1107+
E: IsField,
1108+
{
1109+
self.compute(step)
11121110
}
11131111
}
11141112

@@ -1240,9 +1238,9 @@ pub fn create_all_cpu_constraints() -> (
12401238
next_idx += 2;
12411239

12421240
// Inline PC constraints
1243-
other.push(Box::new(PcDoubleReadRs1Constraint::new(next_idx)));
1241+
other.push(PcDoubleReadRs1Constraint::new(next_idx).boxed());
12441242
next_idx += 1;
1245-
other.push(Box::new(PcDoubleReadBorrowConstraint::new(next_idx)));
1243+
other.push(PcDoubleReadBorrowConstraint::new(next_idx).boxed());
12461244
next_idx += 1;
12471245

12481246
(is_bit, add_constraints, other, next_idx)

prover/src/lib.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,8 @@ impl VmAirs {
257257

258258
/// Collect AIR references for [`Verifier::multi_verify`].
259259
pub fn air_refs(&self) -> Vec<&dyn AIR<Field = F, FieldExtension = E, PublicInputs = ()>> {
260-
let mut refs: Vec<&dyn AIR<Field = F, FieldExtension = E, PublicInputs = ()>> = vec![
261-
&self.bitwise,
262-
&self.decode,
263-
&self.halt,
264-
&self.commit,
265-
];
260+
let mut refs: Vec<&dyn AIR<Field = F, FieldExtension = E, PublicInputs = ()>> =
261+
vec![&self.bitwise, &self.decode, &self.halt, &self.commit];
266262

267263
for air in &self.cpus {
268264
refs.push(air);
@@ -452,7 +448,11 @@ pub(crate) fn compute_commit_bus_offset(
452448
.collect();
453449

454450
FieldElement::inplace_batch_inverse(&mut fingerprints).ok()?;
455-
Some(fingerprints.iter().fold(FieldElement::zero(), |acc, inv| acc + inv))
451+
Some(
452+
fingerprints
453+
.iter()
454+
.fold(FieldElement::zero(), |acc, inv| acc + inv),
455+
)
456456
}
457457

458458
/// Compute the bus balance offset for the REGISTER table on the Memory bus.
@@ -528,16 +528,12 @@ pub(crate) fn compute_register_bus_offset(
528528

529529
FieldElement::inplace_batch_inverse(&mut fingerprints).ok()?;
530530

531-
let total = fingerprints
532-
.iter()
533-
.zip(signs.iter())
534-
.fold(FieldElement::<E>::zero(), |acc, (inv, &sign)| {
535-
if sign > 0 {
536-
acc + inv
537-
} else {
538-
acc - inv
539-
}
540-
});
531+
let total = fingerprints.iter().zip(signs.iter()).fold(
532+
FieldElement::<E>::zero(),
533+
|acc, (inv, &sign)| {
534+
if sign > 0 { acc + inv } else { acc - inv }
535+
},
536+
);
541537

542538
Some(total)
543539
}

prover/src/tables/trace_builder.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,8 @@ fn collect_halt_ops(register_state: &mut RegisterState) -> Vec<MemwOperation> {
723723
let (old_val, old_ts) = register_state.read(0);
724724
let old_value = pack_register_value(old_val);
725725
let old_timestamps = [old_ts, old_ts, 0, 0, 0, 0, 0, 0];
726-
let memw_op = MemwOperation::new(true, 0, [0; 8], ts, 2, false)
727-
.with_old(old_value, old_timestamps);
726+
let memw_op =
727+
MemwOperation::new(true, 0, [0; 8], ts, 2, false).with_old(old_value, old_timestamps);
728728
ops.push(memw_op);
729729
// x0 value stays 0, but update timestamp directly (write() guards x0).
730730
register_state.regs[0] = (0, ts);
@@ -772,8 +772,8 @@ fn collect_halt_ops(register_state: &mut RegisterState) -> Vec<MemwOperation> {
772772
let (old_index, old_ts) = register_state.read_index();
773773
let old_value = [old_index as u64, 0, 0, 0, 0, 0, 0, 0];
774774
let old_timestamps = [old_ts, 0, 0, 0, 0, 0, 0, 0];
775-
let memw_op = MemwOperation::new(true, 508, [0; 8], ts, 1, false)
776-
.with_old(old_value, old_timestamps);
775+
let memw_op =
776+
MemwOperation::new(true, 508, [0; 8], ts, 1, false).with_old(old_value, old_timestamps);
777777
ops.push(memw_op);
778778
register_state.write_index(0, ts);
779779
}
@@ -1985,10 +1985,11 @@ impl Traces {
19851985
use super::mul::cols::NUM_COLUMNS as MUL_COLS;
19861986
use super::page::NUM_PREPROCESSED_COLS as PAGE_PREPROCESSED;
19871987
use super::page::cols::NUM_COLUMNS as PAGE_COLS;
1988-
use super::register::NUM_PREPROCESSED_COLS as REGISTER_PREPROCESSED;
1989-
use super::register::cols::NUM_COLUMNS as REGISTER_COLS;
19901988
use super::shift::cols::NUM_COLUMNS as SHIFT_COLS;
19911989

1990+
// NOTE: REGISTER table is no longer materialized in `Traces` — its bus
1991+
// contributions are computed verifier-side in `compute_register_bus_offset`.
1992+
19921993
let Traces {
19931994
cpus,
19941995
bitwise,
@@ -2001,7 +2002,6 @@ impl Traces {
20012002
muls,
20022003
dvrms,
20032004
pages,
2004-
register,
20052005
branches,
20062006
halt,
20072007
commit,
@@ -2042,7 +2042,6 @@ impl Traces {
20422042
}
20432043
total += (halt.num_rows() * HALT_COLS) as u64;
20442044
total += (commit.num_rows() * COMMIT_COLS) as u64;
2045-
total += (register.num_rows() * (REGISTER_COLS - REGISTER_PREPROCESSED)) as u64;
20462045
for t in pages {
20472046
total += (t.num_rows() * (PAGE_COLS - PAGE_PREPROCESSED)) as u64;
20482047
}
@@ -2077,7 +2076,6 @@ impl Traces {
20772076
let n_branch = aux_cols(super::branch::bus_interactions().len());
20782077
let n_halt = aux_cols(super::halt::bus_interactions().len());
20792078
let n_commit = aux_cols(super::commit::bus_interactions().len());
2080-
let n_register = aux_cols(super::register::bus_interactions().len());
20812079
// page::bus_interactions count is constant regardless of page_base.
20822080
let n_page = aux_cols(super::page::bus_interactions(0).len());
20832081
let n_memw_r = aux_cols(super::memw_register::bus_interactions().len());
@@ -2094,7 +2092,6 @@ impl Traces {
20942092
muls,
20952093
dvrms,
20962094
pages,
2097-
register,
20982095
branches,
20992096
halt,
21002097
commit,
@@ -2135,7 +2132,6 @@ impl Traces {
21352132
}
21362133
total += (halt.num_rows() * n_halt) as u64;
21372134
total += (commit.num_rows() * n_commit) as u64;
2138-
total += (register.num_rows() * n_register) as u64;
21392135
for t in pages {
21402136
total += (t.num_rows() * n_page) as u64;
21412137
}

prover/src/tests/prove_elfs_tests.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,10 @@ fn test_debug_memory_bus_tokens() {
10421042
println!("After MEMW: total_sum = {}", total_sum);
10431043

10441044
// REGISTER tokens are now verifier-computed (not in trace).
1045-
println!("After MEMW (REGISTER eliminated): total_sum = {}", total_sum);
1045+
println!(
1046+
"After MEMW (REGISTER eliminated): total_sum = {}",
1047+
total_sum
1048+
);
10461049
println!(
10471050
"Bus {} (should be ~0 if balanced)",
10481051
if total_sum.abs() < 1e-10 {

0 commit comments

Comments
 (0)