poseidon_mersenne61_state
stdlib/mersenne61/poseidon/poseidon_mersenne61_state.nbv only in the mersenne61 field
poseidon_mersenne61_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,pow17- Precompiles
assert_eq!,chunks_flat_map!,clone!,div_floor!,len!,split_at!,wtns!- Used by
mersenne61/poseidon/poseidon_mersenne61,mersenne61/poseidon/poseidon_mersenne61_state_16_8
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 = pow17(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] = pow17(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 = pow17(state + c)
state = mat_vec_mul((clone! MDS_MATRIX), state)
1
}
state