Skip to content
Open
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
2 changes: 1 addition & 1 deletion artifacts/protocol/cpu-jolt/spec-pin/PIN
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256 df8b37e6fec61ff6bb5ec8e8a9bbea842c6b99f5ca99bb1a513b7f2423a851d1 identity_kat.json
sha256 c34e43a8c813f705f8199899e4b0b0f63d6a548f39cf326a9dd7e942e03aa800 identity_kat.json
2 changes: 1 addition & 1 deletion artifacts/protocol/cpu-jolt/spec-pin/identity_kat.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"circuit_manifest(L=24,w_pc=22,P=0)": "053d2ecf655c454fc93a104a3f0e316ee48e96ee6b62a6f868d5719e5abcade0",
"M_digest(P=full(0x1fff))": "b9fd0973446005cfc6f4c5869fd8599395f79919e498edebc54a1762e6461519",
"circuit_manifest(L=24,w_pc=22,P=full(0x1fff))": "f170cff9b1093d4d20d768a388a250d4faace5101f34ca1f2a5d0994f225245b",
"parameter_set(kind 1, n=24, L=24, l=20, lp=0, l_g=6, r1=17 Round1, A=1, Akita, cm(P=full), PCS protocol/geometry/setup = 0x44/0x55/0x66 x32 placeholders)": "7694a2d565b1e316f5e63c414f572a094029c358ab8dc4ae3c3c360ee2ea10c0",
"parameter_set(kind 1, n=24, L=24, l=20, lp=0, l_g=6, r1=17 Round1, A=1, Akita, cm(P=full), PCS protocol/geometry/setup = 0x44/0x55/0x66 x32 placeholders)": "4e3b2f375dd7058baab0a6af95a7c6f712da0fbda9f1d8cdb02bdfc12dc48bcf",
"instruction_starts(one range [RAM_START, +12), J_G = 6, slots 0 2 3 5)": "823661a5e268c5babca7743129bb7e4913ff7177ee1b0cfa0781aee1a5340946",
"program_image(bytes 13000000 0100 13000000 0100 aabbccdd, text [RAM_START, +12), e_entry RAM_START)": "c939020841bdd342739d7fb2031e55bcf3ea96a9f48624e241c580cbcca5a28d",
"program_key(full: program_size 16, MemoryConfig (100, 4, 0, 8, 4096, 2^20), n_max 26, w_f 8, J_G 6, R_pool 0, n_P 0, P 0)": "f2cf3ace77223820f8982d57b68e1bec1f90e37ab4afae066ecda3edeb231dd8",
Expand Down
2 changes: 2 additions & 0 deletions crates/binary-jolt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ cargo run --release --bin e2e_bench -- --guest ../../tests/fixtures/jolt-guests/

The frontend benchmark times proof generation through Mosaic and verifier replay. The end-to-end benchmark includes the trace commitment and PCS opening. Both assemble a fresh witness per repetition. `--pcs` selects the backend. The research verifier checks the proof under the selected parameters.

CPU Spartan batches binary and packed constraints on a common row domain. A four-row univariate check binds the first two row coordinates. The prover then binds the remaining row coordinates and cycles. Set `BINARY_JOLT_TIMING=1` to see the CPU Spartan elapsed time.

Akita setup tools remain available through `e2e_bench --pins`, `--verifier-pins`, `--verifier-key`, `--prepare-shared-setup`, and `--pcs-sites`.
6 changes: 4 additions & 2 deletions crates/binary-jolt/src/subprotocols/spartan.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Virtual Spartan over the two SIMD relations (README 5.1).
//! Virtual Spartan over the two SIMD relations. Jolt CPU Spartan uses [`row_batch`].
//! The separate multiplication table uses the schedule below (README 5.1).
//!
//! 1. tau = (tau_u in K^n, tau_2 in K^f2v, tau_128 in K^5), one site of n + f2v + 5 elements
//! (f2v = ceil(log2 F2 rows) = 7 for the base protocol, so n + 12).
Expand All @@ -14,6 +15,7 @@
//!
//! In characteristic 2 the residual A B - C is A B + C.

pub(crate) mod row_batch;
mod f128_rows;
pub mod kernels;

Expand Down Expand Up @@ -131,7 +133,7 @@ fn prove_live<P: ProverTr>(tr: &mut P, circ: &Circuit, planes: &Planes, n: usize
let mut g = GruenClaim { claim: zero(), pi: one() };
let mut r_128 = Vec::with_capacity(f128v);
for k in 1..=f128v {
let (q0, qi) = f128_round_msg(&mm, &ll, tau_128, &r_128, k);
let (q0, qi) = f128_round_msg(&mm, &ll, &tau_128[k..], &r_128);
r_128.push(g.round(tr, tau_128[k - 1], q0, &[qi], G_ROW)?);
}
let (claim_128, e_128) = (g.claim, g.pi);
Expand Down
40 changes: 16 additions & 24 deletions crates/binary-jolt/src/subprotocols/spartan/f128_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,12 @@ pub(super) fn f128_moments(rows: &F128Rows, planes: &Planes, tau_u: &[K], tail:
let chunks = 1usize << (task - 6);
let plan = planes.plan(&rows.columns());
let hole = hole_blocks(hi.len(), chunks, tail);
let (mut m, mut l) = hi
let mut m = hi
.par_iter()
.enumerate()
.filter(|(h, _)| !hole.contains(h))
.map(|(h, &eh)| {
let mut buckets = Buckets::new(r);
let mut lacc = vec![WordAcc::default(); r];
let (mut words, mut g) = (vec![[0u64; 64]; rows.slots.len()], [0u64; 64]);
let mut buf = planes.buf();
for c in 0..chunks {
Expand All @@ -258,12 +257,6 @@ pub(super) fn f128_moments(rows: &F128Rows, planes: &Planes, tau_u: &[K], tail:
}
}
}
for &(j, lane) in &rows.c {
let w = lane.get(&words, t);
if w != 0 {
lacc[j].fmadd_word(e, w);
}
}
}
}
let mut m = vec![zero(); r * r];
Expand All @@ -275,18 +268,15 @@ pub(super) fn f128_moments(rows: &F128Rows, planes: &Planes, tau_u: &[K], tail:
}
}
}
(m, lacc.iter().map(|&a| eh * a.reduce()).collect::<Vec<K>>())
m
})
.reduce(
|| (vec![zero(); r * r], vec![zero(); r]),
|(mut m, mut l), (m2, l2)| {
|| vec![zero(); r * r],
|mut m, m2| {
for (x, y) in m.iter_mut().zip(m2) {
*x += y;
}
for (x, y) in l.iter_mut().zip(l2) {
*x += y;
}
(m, l)
m
},
);
if !hole.is_empty() {
Expand All @@ -299,20 +289,19 @@ pub(super) fn f128_moments(rows: &F128Rows, planes: &Planes, tau_u: &[K], tail:
*x += mass * word(lane);
}
}
for &(j, lane) in &rows.c {
l[j] += mass * word(&lane);
}
}
((0..r).map(|i| m[i * r..(i + 1) * r].to_vec()).collect(), l)
// An honest row has C_i = A_i B_i, including the constant tail. The
// terminal C evaluation still reads the actual constraint matrix.
let linear = (0..r).map(|i| m[i * r + i]).collect();
((0..r).map(|i| m[i * r..(i + 1) * r].to_vec()).collect(), linear)
}

/// Row-phase message (q0, q_inf) for the F2^128 relation from the moments, at round k (1-based)
/// with prefix challenges `r` (len k-1).
pub(super) fn f128_round_msg(m: &[Vec<K>], l: &[K], tau: &[K], r: &[K], k: usize) -> (K, K) {
/// Row-phase message (q0, q_inf) for the F2^128 relation from the moments, after prefix `r`, with equality weights for the remaining unbound coordinates.
pub(super) fn f128_round_msg(m: &[Vec<K>], l: &[K], rest: &[K], r: &[K]) -> (K, K) {
let rows = m.len();
let g = 1usize << (k - 1);
let g = 1usize << r.len();
let e = eq_table(r);
let eq_rest = eq_table(&tau[k..]);
let eq_rest = eq_table(rest);
let get_m = |i: usize, j: usize| if i < rows && j < rows { m[i][j] } else { zero() };
let get_l = |j: usize| if j < rows { l[j] } else { zero() };
let (mut q0, mut qi) = (zero(), zero());
Expand Down Expand Up @@ -641,3 +630,6 @@ impl F128Cycle {
[self.t[0][0], self.t[1][0], self.t[2][0]]
}
}

mod shared_rows;
pub(super) use shared_rows::{cycle_cache_fill, row_moments};
268 changes: 268 additions & 0 deletions crates/binary-jolt/src/subprotocols/spartan/f128_rows/shared_rows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
//! Witness passes for the joint binary and packed row sumcheck.
use super::*;
use crate::field::simd::V;
use crate::subprotocols::spartan::kernels;
pub(in crate::subprotocols::spartan) fn cycle_cache_fill<'a>(
c: &'a Circuit,
rows: &'a F128Rows,
planes: &'a Planes,
weights: &'a [K],
lambda: K,
) -> impl Fn(usize, &mut [u128]) + Sync + 'a {
let tabs = ByteTables::new(&weights[..c.f2.len()]);
let mixed: Vec<_> = weights[..c.f2.len()].iter().map(|&w| lambda * w).collect();
let mixed = ByteTables::new(&mixed);
assert!(rows.rows() <= 32);
let mut cols = rows.columns();
cols.extend(c.f2.iter().flat_map(|r| r[..2].iter().flatten().copied()));
let plan = planes.plan(&cols);
move |mut pos, mut dst| {
assert_eq!(pos % 4, 0);
assert_eq!(dst.len() % 17, 0);
let mut buf = planes.buf();
let mut words = vec![[0; 64]; rows.slots.len()];
while !dst.is_empty() {
let cw = planes.chunk_plan(pos / 64, plan.as_ref(), &mut buf);
let mut gu = [0; 64];
rows.chunk(cw, &mut words, &mut gu);
let bits = [0, 1].map(|side| {
let mut w = [0; kernels::MAX_ROWS];
kernels::row_words(&c.f2, side, cw, &mut w);
kernels::row_vectors(&w, c.f2.len())
});
let offset = pos % 64;
let len = (dst.len() / 17 * 4).min(64 - offset);
let (part, rest) = dst.split_at_mut(17 * (len / 4));
for (group, raw) in part.chunks_exact_mut(17).enumerate() {
let mut guard_word = 0u128;
for (j, out) in raw[..16].chunks_exact_mut(4).enumerate() {
let t = offset + 4 * group + j;
guard_word |= (gu[t] as u128) << (32 * j);
let mut pb = WordAcc::default();
let mut pc = WordAcc::default();
for (lane, &w) in rows.b.iter().zip(weights) {
let v = lane.get(&words, t);
if v != 0 {
pb.fmadd_word(w, v);
}
}
for &(i, lane) in &rows.c {
let v = lane.get(&words, t);
if v != 0 {
pc.fmadd_word(weights[i], v);
}
}
let [a, b] = [bits[0][t], bits[1][t]];
// Honest binary rows satisfy C_i = A_i & B_i at Boolean cycles.
let binary_c = [a[0] & b[0], a[1] & b[1]];
out.copy_from_slice(&[
tabs.sum_bits(&a).to_raw(),
mixed.sum_bits(&b).to_raw(),
pb.reduce().to_raw(),
(pc.reduce() + mixed.sum_bits(&binary_c)).to_raw(),
]);
}
raw[16] = guard_word;
}
pos += len;
dst = rest;
}
}
}

/// A ternary grid for one tile of consecutive binary rows. Padding rows are zero.
struct TileGrid {
live: usize,
steps: Vec<(usize, usize, usize)>,
aliases: Vec<(usize, usize)>,
}

impl TileGrid {
fn new(grid: &kernels::Grid, live: usize) -> Self {
let mut source = vec![None; grid.points()];
for &i in &grid.binary[..live] {
source[i] = Some(i);
}
let mut steps = Vec::new();
let mut aliases = Vec::new();
for &(dst, lo, hi) in &grid.steps {
source[dst] = match (source[lo], source[hi]) {
(Some(a), Some(b)) => {
steps.push((dst, a, b));
Some(dst)
}
(Some(i), None) | (None, Some(i)) => {
// At infinity the operand is the XOR of its endpoints.
// One zero endpoint leaves the other endpoint's product.
aliases.push((dst, i));
Some(i)
}
(None, None) => None,
};
}
Self {
live,
steps,
aliases,
}
}
}

// Accumulate the bit-sliced binary interpolation grid and the packed moments
// while the same 64-cycle block of witness columns is in cache.
pub(in crate::subprotocols::spartan) fn row_moments(
c: &Circuit,
packed: &F128Rows,
planes: &Planes,
tu: &[K],
grid: &kernels::Grid,
local: usize,
tail: &Range<usize>,
) -> (Vec<K>, Vec<Vec<K>>, Vec<K>) {
let mut cols = packed.columns();
cols.extend(c.f2.iter().flat_map(|r| r[..2].iter().flatten().copied()));
let plan = planes.plan(&cols);
let little = kernels::Grid::new(local);
let width = 1 << local;
let tiles = c.f2.len().div_ceil(width);
let size = little.points();
let tile_grids: Vec<_> = c
.f2
.chunks(width)
.map(|rows| TileGrid::new(&little, rows.len()))
.collect();
let split = tu.len().min(12);
let lo = eq_table(&tu[..split]);
let hi = eq_table_par(&tu[split..]);
let tabs = ByteTables::new(&eq_table(&tu[..6]));
let chunk_weights = eq_table(&tu[6..split]);
let per = chunk_weights.len();
let hole = hole_blocks(hi.len(), per, tail);
let rows = packed.rows();
let block = |start: usize, len: usize, eh: K, constant: bool| {
let mut buf = planes.buf();
let mut words = vec![[0; 64]; packed.slots.len()];
let mut buckets = Buckets::new(rows);
let mut acc = vec![Wide::zero(); tiles * size];
let mut a = vec![0u64; size];
let mut b = vec![0u64; size];
for i in 0..len {
let cw = planes.chunk_plan(start + i, plan.as_ref(), &mut buf);
let mut guards = [0; 64];
packed.chunk(cw, &mut words, &mut guards);
for t in 0..if constant { 1 } else { 64 } {
if guards[t] == 0 {
continue;
}
let e = if constant { one() } else { lo[i * 64 + t] };
for (dst, lane) in buckets.get(guards[t]).iter_mut().zip(&packed.b) {
let word = lane.get(&words, t);
if word != 0 {
dst.fmadd_word(e, word);
}
}
}
let mut aw = [0u64; kernels::MAX_ROWS];
let mut bw = [0u64; kernels::MAX_ROWS];
kernels::row_words(&c.f2, 0, cw, &mut aw);
kernels::row_words(&c.f2, 1, cw, &mut bw);
let ew = Mul::new(if constant { one() } else { chunk_weights[i] });
for (tile, part) in acc.chunks_mut(size).enumerate() {
let tile_grid = &tile_grids[tile];
for (j, &idx) in little.binary[..tile_grid.live].iter().enumerate() {
a[idx] = aw[tile * width + j];
b[idx] = bw[tile * width + j];
let xy = a[idx] & b[idx];
if xy != 0 {
part[idx].madd(&ew, V::of(tabs.sum_bits(&[xy])));
}
}
for &(d, x, y) in &tile_grid.steps {
a[d] = a[x] ^ a[y];
b[d] = b[x] ^ b[y];
let xy = a[d] & b[d];
if xy != 0 {
part[d].madd(&ew, V::of(tabs.sum_bits(&[xy])));
}
}
}
}
let mut sums = vec![zero(); rows * rows + tiles * size];
for (s, &g) in buckets.patterns.iter().enumerate() {
let v: Vec<_> = buckets.acc[s * rows..(s + 1) * rows]
.iter()
.map(|&a| eh * a.reduce())
.collect();
for i in (0..rows).filter(|&i| g >> i & 1 != 0) {
for (dst, &x) in sums[i * rows..(i + 1) * rows].iter_mut().zip(&v) {
*dst += x;
}
}
}
for (dst, a) in sums[rows * rows..].iter_mut().zip(acc) {
*dst = eh * a.get();
}
sums
};
let add = |mut a: Vec<K>, b: Vec<K>| {
for (x, y) in a.iter_mut().zip(b) {
*x += y;
}
a
};
let mut sums = hi
.par_iter()
.enumerate()
.filter(|(h, _)| !hole.contains(h))
.map(|(h, &eh)| block(h * per, per, eh, false))
.reduce(|| vec![zero(); rows * rows + tiles * size], add);
if !hole.is_empty() {
sums = add(sums, block(tail.start, 1, hole_mass(&hi, hole), true));
}
let mut q = vec![zero(); grid.points()];
for (t, v) in sums[rows * rows..].chunks(size).enumerate() {
let base = grid.binary[t * width];
let values = &mut q[base..base + size];
values.copy_from_slice(v);
for &(dst, src) in &tile_grids[t].aliases {
values[dst] = values[src];
}
}
let m = sums[..rows * rows]
.chunks(rows)
.map(|r| r.to_vec())
.collect();
// For honest packed rows the C moments are the diagonal of M.
let l = (0..rows).map(|i| sums[i * rows + i]).collect();
(q, m, l)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn padded_tiles_preserve_all_grid_products() {
let grid = kernels::Grid::new(5);
for live in 1..=grid.binary.len() {
let tile = TileGrid::new(&grid, live);
// Each set bit identifies one independent row. The operand at an
// infinity coordinate is the XOR of its two endpoint masks.
let mut dense = vec![0u32; grid.points()];
for (row, &index) in grid.binary[..live].iter().enumerate() {
dense[index] = 1 << row;
}
let mut pruned = dense.clone();
for &(dst, a, b) in &grid.steps {
dense[dst] = dense[a] ^ dense[b];
}
for &(dst, a, b) in &tile.steps {
pruned[dst] = pruned[a] ^ pruned[b];
}
for &(dst, src) in &tile.aliases {
pruned[dst] = pruned[src];
}
assert_eq!(pruned, dense, "live rows: {live}");
}
}
}
Loading
Loading