Skip to content

Commit 358e47b

Browse files
jotabulaciosdiegokingstonMauroToscano
authored
Feat/shrink cpu byte alu (#644)
* Add shrink-cpu buses, decode layout, EQ chip * Add BYTEWISE ALU chip * Add BYTEWISE, STORE and CPU32 chips * Add CPU32 buses; fix EQ ALU output width * Register EQ/BYTEWISE/STORE/CPU32 as empty tables * Migrate CPU + ALU/memory chips to unified ALU bus * Delegate word instructions to the CPU32 table * Re-enable and rewrite CPU/decode/constraint tests for the shrink-cpu layout, and document the deviations * remove unnecesary files * Unify LT/MUL/memw/dvrm onto the ALU bus * Pin JALR rvd to pc+len * Align SHIFT shift-amount layout with the spec * reconcile prover with shrink-cpu spec * Add spec assumption range checks * Add explicit IS_BYTE[shift[0]] range check * Sync CPU with merged shrink-cpu spec * remove old comments * use constants * Propagate carry in branch rvd constraint * prevent register side effects in CPU32 padding * Use unreachable for validated carry arms * Force signed to zero on CPU32 padding rows * Force res_sign to zero on CPU32 padding rows * Gate CPU32 sign lookups by signed * close LT/SHIFT/LOAD underconstrained gaps * Remove dead LT carry helper and fix stale comments * Remove legacy byte-op buses --------- Co-authored-by: Diego K <43053772+diegokingston@users.noreply.github.com> Co-authored-by: MauroFab <maurotoscano2@gmail.com> Co-authored-by: Mauro Toscano <12560266+MauroToscano@users.noreply.github.com>
1 parent 55e8c7b commit 358e47b

45 files changed

Lines changed: 6363 additions & 5229 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

prover/src/constraints/cpu.rs

Lines changed: 339 additions & 789 deletions
Large diffs are not rendered by default.

prover/src/constraints/templates.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl AddConstraint {
449449
let carry = match self.carry_idx {
450450
0 => self.compute_carry_0(step),
451451
1 => self.compute_carry_1(step),
452-
_ => panic!("Invalid carry index"),
452+
_ => unreachable!("carry_idx validated <= 1 at construction"),
453453
};
454454

455455
if self.cond_cols.is_empty() {

prover/src/lib.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ use crate::tables::trace_builder::Traces;
4848
use crate::tables::trace_builder::count_table_lengths;
4949
use crate::tables::types::BusId;
5050
use crate::test_utils::{
51-
E, F, VmAir, create_bitwise_air, create_branch_air, create_commit_air, create_cpu_air,
52-
create_decode_air, create_dvrm_air, create_halt_air, create_keccak_air, create_keccak_rc_air,
53-
create_keccak_rnd_air, create_load_air, create_lt_air, create_memw_air,
54-
create_memw_aligned_air, create_memw_register_air, create_mul_air, create_page_air,
55-
create_register_air, create_shift_air,
51+
E, F, VmAir, create_bitwise_air, create_branch_air, create_bytewise_air, create_commit_air,
52+
create_cpu_air, create_cpu32_air, create_decode_air, create_dvrm_air, create_eq_air,
53+
create_halt_air, create_keccak_air, create_keccak_rc_air, create_keccak_rnd_air,
54+
create_load_air, create_lt_air, create_memw_air, create_memw_aligned_air,
55+
create_memw_register_air, create_mul_air, create_page_air, create_register_air,
56+
create_shift_air, create_store_air,
5657
};
5758

5859
use stark::proof::options::{GoldilocksCubicProofOptions, ProofOptions};
@@ -84,6 +85,11 @@ pub struct TableCounts {
8485
pub shift: usize,
8586
pub branch: usize,
8687
pub memw_register: usize,
88+
// Auxiliary ALU / memory / CPU32 dispatch chips
89+
pub eq: usize,
90+
pub bytewise: usize,
91+
pub store: usize,
92+
pub cpu32: usize,
8793
}
8894

8995
impl TableCounts {
@@ -99,6 +105,10 @@ impl TableCounts {
99105
+ self.shift
100106
+ self.branch
101107
+ self.memw_register
108+
+ self.eq
109+
+ self.bytewise
110+
+ self.store
111+
+ self.cpu32
102112
}
103113

104114
/// Validate that all required tables have at least one chunk.
@@ -117,6 +127,10 @@ impl TableCounts {
117127
("shift", self.shift),
118128
("branch", self.branch),
119129
("memw_register", self.memw_register),
130+
("eq", self.eq),
131+
("bytewise", self.bytewise),
132+
("store", self.store),
133+
("cpu32", self.cpu32),
120134
];
121135
for (name, count) in checks {
122136
if count == 0 {
@@ -212,6 +226,11 @@ pub(crate) struct VmAirs {
212226
pub register: VmAir,
213227
pub pages: Vec<VmAir>,
214228
pub memw_registers: Vec<VmAir>,
229+
// Auxiliary ALU / memory / CPU32 dispatch chips
230+
pub eqs: Vec<VmAir>,
231+
pub bytewises: Vec<VmAir>,
232+
pub stores: Vec<VmAir>,
233+
pub cpu32s: Vec<VmAir>,
215234
}
216235

217236
impl VmAirs {
@@ -269,6 +288,18 @@ impl VmAirs {
269288
{
270289
pairs.push((air, trace, &()));
271290
}
291+
for (air, trace) in self.eqs.iter().zip(traces.eqs.iter_mut()) {
292+
pairs.push((air, trace, &()));
293+
}
294+
for (air, trace) in self.bytewises.iter().zip(traces.bytewises.iter_mut()) {
295+
pairs.push((air, trace, &()));
296+
}
297+
for (air, trace) in self.stores.iter().zip(traces.stores.iter_mut()) {
298+
pairs.push((air, trace, &()));
299+
}
300+
for (air, trace) in self.cpu32s.iter().zip(traces.cpu32s.iter_mut()) {
301+
pairs.push((air, trace, &()));
302+
}
272303

273304
pairs
274305
}
@@ -319,6 +350,18 @@ impl VmAirs {
319350
for air in &self.memw_registers {
320351
refs.push(air);
321352
}
353+
for air in &self.eqs {
354+
refs.push(air);
355+
}
356+
for air in &self.bytewises {
357+
refs.push(air);
358+
}
359+
for air in &self.stores {
360+
refs.push(air);
361+
}
362+
for air in &self.cpu32s {
363+
refs.push(air);
364+
}
322365

323366
refs
324367
}
@@ -454,6 +497,18 @@ impl VmAirs {
454497
let memw_registers: Vec<_> = (0..table_counts.memw_register)
455498
.map(|i| create_memw_register_air(proof_options).with_name(&format!("MEMW_R[{}]", i)))
456499
.collect();
500+
let eqs: Vec<_> = (0..table_counts.eq)
501+
.map(|i| create_eq_air(proof_options).with_name(&format!("EQ[{}]", i)))
502+
.collect();
503+
let bytewises: Vec<_> = (0..table_counts.bytewise)
504+
.map(|i| create_bytewise_air(proof_options).with_name(&format!("BYTEWISE[{}]", i)))
505+
.collect();
506+
let stores: Vec<_> = (0..table_counts.store)
507+
.map(|i| create_store_air(proof_options).with_name(&format!("STORE[{}]", i)))
508+
.collect();
509+
let cpu32s: Vec<_> = (0..table_counts.cpu32)
510+
.map(|i| create_cpu32_air(proof_options).with_name(&format!("CPU32[{}]", i)))
511+
.collect();
457512

458513
#[cfg(feature = "debug-checks")]
459514
debug_report::print_bus_legend();
@@ -478,6 +533,10 @@ impl VmAirs {
478533
register,
479534
pages,
480535
memw_registers,
536+
eqs,
537+
bytewises,
538+
stores,
539+
cpu32s,
481540
}
482541
}
483542
}

prover/src/statement.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::test_utils::E;
1616
use crate::{RuntimePageRange, TableCounts};
1717

1818
/// Domain-separation tag. Bump the suffix (`_V2`, ...) on any encoding change.
19-
const DOMAIN_TAG: &[u8] = b"LAMBDAVM_STARK_STATEMENT_V1";
19+
const DOMAIN_TAG: &[u8] = b"LAMBDAVM_STARK_STATEMENT_V2";
2020

2121
fn elf_digest(elf: &[u8]) -> [u8; 32] {
2222
let mut h = Keccak256::new();
@@ -55,6 +55,10 @@ pub(crate) fn absorb_statement(
5555
shift,
5656
branch,
5757
memw_register,
58+
eq,
59+
bytewise,
60+
store,
61+
cpu32,
5862
} = table_counts;
5963
for count in [
6064
cpu,
@@ -67,6 +71,10 @@ pub(crate) fn absorb_statement(
6771
shift,
6872
branch,
6973
memw_register,
74+
eq,
75+
bytewise,
76+
store,
77+
cpu32,
7078
] {
7179
t.append_bytes(&(count as u64).to_le_bytes());
7280
}

0 commit comments

Comments
 (0)