Skip to main content

cheap_matmul

Function cheap_matmul 

Source
pub fn cheap_matmul<F: Field, A: Algebra<F>, const WIDTH: usize>(
    state: &mut [A; WIDTH],
    first_row: &[F; WIDTH],
    v: &[F; WIDTH],
)
Expand description

Sparse matrix-vector multiplication in O(WIDTH) operations.

Replaces the full O(t^2) MDS multiply in each partial round. Computes state <- S * state where S has the structure:

  S = ┌─────────┬──────┐
      │ mds_0_0 │  ŵ   │    state'[0] = mds_0_0 * s[0] + Σ ŵ[j] * s[j+1]
      ├─────────┼──────┤
      │    v    │   I  │    state'[i] = s[i] + v[i-1] * s[0],  for i ≥ 1
      └─────────┴──────┘

first_row contains the pre-assembled full first row [mds_0_0, ŵ[0], ..., ŵ[WIDTH-2]], enabling a branch-free dot product for the new state[0].

v contains the first-column vector (excluding [0,0]): [v[0], ..., v[WIDTH-2], 0].

The identity block means state[1..] is updated by a simple rank-1 correction (add a multiple of the old state[0]), and state[0] is a dot product.