Index Mathematics Conjectures nbv lettuce Widgets

poseidon_milli_state

stdlib/milli/poseidon/poseidon_milli_state.nbv only in the milli field

poseidon_milli_state(mut state, INPUT_LEN, OUTPUT_LEN, ALPHA, N_ROUNDS_F, N_ROUNDS_P, MDS_MATRIX, ROUND_CONSTANTS)

make sure our input is non-constant witness variables

Calls
mat_vec_mul, pow11
Precompiles
assert_eq!, chunks_flat_map!, clone!, div_floor!, len!, split_at!, wtns!
Used by
milli/poseidon/poseidon_milli, milli/poseidon/poseidon_milli_state_32_16, oraccle/oraccle_sample_uniform_vec

Source

(
  mut state,
  INPUT_LEN,
  OUTPUT_LEN,
  ALPHA,
  N_ROUNDS_F,
  N_ROUNDS_P,
  MDS_MATRIX,
  ROUND_CONSTANTS
)

# make sure our input is non-constant
# witness variables
state = wtns! state

assert_eq! OUTPUT_LEN + INPUT_LEN, len! state

static T = INPUT_LEN + OUTPUT_LEN
static N_ROUNDS_F_HALF = div_floor! N_ROUNDS_F, 2

# number of round constants
static TOTAL_ROUNDS = N_ROUNDS_F + N_ROUNDS_P
assert_eq! TOTAL_ROUNDS * T, len! ROUND_CONSTANTS

# MDS matrix is TxT
assert_eq! T * T, len! MDS_MATRIX

# split up the round constants for use
(static ROUND_CONSTANTS_FIRST, static ROUND_CONSTANTS_REM) = split_at! ROUND_CONSTANTS, T * N_ROUNDS_F_HALF
(static ROUND_CONSTANTS_SECOND, static ROUND_CONSTANTS_THIRD) = split_at! ROUND_CONSTANTS_REM, T * N_ROUNDS_P

# first set of full rounds
static _ = chunks_flat_map! ROUND_CONSTANTS_FIRST, T, c {
  state = pow11(state + c)
  state = mat_vec_mul((clone! MDS_MATRIX), state)
  1
}

# partial rounds
static _ = chunks_flat_map! ROUND_CONSTANTS_SECOND, T, c {
  state = state + c
  state[0] = pow11(state[0])
  state = mat_vec_mul((clone! MDS_MATRIX), state)
  1
}

# final set of full rounds
static _ = chunks_flat_map! ROUND_CONSTANTS_THIRD, T, c {
  state = pow11(state + c)
  state = mat_vec_mul((clone! MDS_MATRIX), state)
  1
}

state