arnaucube
arnaucube/miden-cryptoPublic Self-hosted repository
miden-crypto/src/hash/rpo/mod.rs
src/hash/rpo/mod.rsRaw
  1use super::{Digest, ElementHasher, Felt, FieldElement, Hasher, StarkField, ONE, ZERO};
  2use core::{convert::TryInto, ops::Range};
  3
  4mod digest;
  5pub use digest::RpoDigest;
  6
  7mod mds_freq;
  8use mds_freq::mds_multiply_freq;
  9
 10#[cfg(test)]
 11mod tests;
 12
 13// CONSTANTS
 14// ================================================================================================
 15
 16/// Sponge state is set to 12 field elements or 96 bytes; 8 elements are reserved for rate and
 17/// the remaining 4 elements are reserved for capacity.
 18const STATE_WIDTH: usize = 12;
 19
 20/// The rate portion of the state is located in elements 4 through 11.
 21const RATE_RANGE: Range<usize> = 4..12;
 22const RATE_WIDTH: usize = RATE_RANGE.end - RATE_RANGE.start;
 23
 24const INPUT1_RANGE: Range<usize> = 4..8;
 25const INPUT2_RANGE: Range<usize> = 8..12;
 26
 27/// The capacity portion of the state is located in elements 0, 1, 2, and 3.
 28const CAPACITY_RANGE: Range<usize> = 0..4;
 29
 30/// The output of the hash function is a digest which consists of 4 field elements or 32 bytes.
 31///
 32/// The digest is returned from state elements 4, 5, 6, and 7 (the first four elements of the
 33/// rate portion).
 34const DIGEST_RANGE: Range<usize> = 4..8;
 35const DIGEST_SIZE: usize = DIGEST_RANGE.end - DIGEST_RANGE.start;
 36
 37/// The number of rounds is set to 7 to target 128-bit security level
 38const NUM_ROUNDS: usize = 7;
 39
 40/// The number of byte chunks defining a field element when hashing a sequence of bytes
 41const BINARY_CHUNK_SIZE: usize = 7;
 42
 43/// S-Box and Inverse S-Box powers;
 44///
 45/// The constants are defined for tests only because the exponentiations in the code are unrolled
 46/// for efficiency reasons.
 47#[cfg(test)]
 48const ALPHA: u64 = 7;
 49#[cfg(test)]
 50const INV_ALPHA: u64 = 10540996611094048183;
 51
 52// HASHER IMPLEMENTATION
 53// ================================================================================================
 54
 55/// Implementation of the Rescue Prime Optimized hash function with 256-bit output.
 56///
 57/// The hash function is implemented according to the Rescue Prime Optimized
 58/// [specifications](https://github.com/ASDiscreteMathematics/rpo)
 59///
 60/// The parameters used to instantiate the function are:
 61/// * Field: 64-bit prime field with modulus 2^64 - 2^32 + 1.
 62/// * State width: 12 field elements.
 63/// * Capacity size: 4 field elements.
 64/// * Number of founds: 7.
 65/// * S-Box degree: 7.
 66///
 67/// The above parameters target 128-bit security level. The digest consists of four field elements
 68/// and it can be serialized into 32 bytes (256 bits).
 69///
 70/// ## Hash output consistency
 71/// Functions [hash_elements()](Rpo256::hash_elements), [merge()](Rpo256::merge), and
 72/// [merge_with_int()](Rpo256::merge_with_int) are internally consistent. That is, computing
 73/// a hash for the same set of elements using these functions will always produce the same
 74/// result. For example, merging two digests using [merge()](Rpo256::merge) will produce the
 75/// same result as hashing 8 elements which make up these digests using
 76/// [hash_elements()](Rpo256::hash_elements) function.
 77///
 78/// However, [hash()](Rpo256::hash) function is not consistent with functions mentioned above.
 79/// For example, if we take two field elements, serialize them to bytes and hash them using
 80/// [hash()](Rpo256::hash), the result will differ from the result obtained by hashing these
 81/// elements directly using [hash_elements()](Rpo256::hash_elements) function. The reason for
 82/// this difference is that [hash()](Rpo256::hash) function needs to be able to handle
 83/// arbitrary binary strings, which may or may not encode valid field elements - and thus,
 84/// deserialization procedure used by this function is different from the procedure used to
 85/// deserialize valid field elements.
 86///
 87/// Thus, if the underlying data consists of valid field elements, it might make more sense
 88/// to deserialize them into field elements and then hash them using
 89/// [hash_elements()](Rpo256::hash_elements) function rather then hashing the serialized bytes
 90/// using [hash()](Rpo256::hash) function.
 91pub struct Rpo256();
 92
 93impl Hasher for Rpo256 {
 94    type Digest = RpoDigest;
 95
 96    fn hash(bytes: &[u8]) -> Self::Digest {
 97        // compute the number of elements required to represent the string; we will be processing
 98        // the string in BINARY_CHUNK_SIZE-byte chunks, thus the number of elements will be equal
 99        // to the number of such chunks (including a potential partial chunk at the end).
100        let num_elements = if bytes.len() % BINARY_CHUNK_SIZE == 0 {
101            bytes.len() / BINARY_CHUNK_SIZE
102        } else {
103            bytes.len() / BINARY_CHUNK_SIZE + 1
104        };
105
106        // initialize state to all zeros, except for the first element of the capacity part, which
107        // is set to the number of elements to be hashed. this is done so that adding zero elements
108        // at the end of the list always results in a different hash.
109        let mut state = [ZERO; STATE_WIDTH];
110        state[CAPACITY_RANGE.start] = Felt::new(num_elements as u64);
111
112        // break the string into BINARY_CHUNK_SIZE-byte chunks, convert each chunk into a field
113        // element, and absorb the element into the rate portion of the state. we use
114        // BINARY_CHUNK_SIZE-byte chunks because every BINARY_CHUNK_SIZE-byte chunk is guaranteed
115        // to map to some field element.
116        let mut i = 0;
117        let mut buf = [0_u8; 8];
118        for chunk in bytes.chunks(BINARY_CHUNK_SIZE) {
119            if i < num_elements - 1 {
120                buf[..BINARY_CHUNK_SIZE].copy_from_slice(chunk);
121            } else {
122                // if we are dealing with the last chunk, it may be smaller than BINARY_CHUNK_SIZE
123                // bytes long, so we need to handle it slightly differently. We also append a byte
124                // with value 1 to the end of the string; this pads the string in such a way that
125                // adding trailing zeros results in different hash
126                let chunk_len = chunk.len();
127                buf = [0_u8; 8];
128                buf[..chunk_len].copy_from_slice(chunk);
129                buf[chunk_len] = 1;
130            }
131
132            // convert the bytes into a field element and absorb it into the rate portion of the
133            // state; if the rate is filled up, apply the Rescue permutation and start absorbing
134            // again from zero index.
135            state[RATE_RANGE.start + i] = Felt::new(u64::from_le_bytes(buf));
136            i += 1;
137            if i % RATE_WIDTH == 0 {
138                Self::apply_permutation(&mut state);
139                i = 0;
140            }
141        }
142
143        // if we absorbed some elements but didn't apply a permutation to them (would happen when
144        // the number of elements is not a multiple of RATE_WIDTH), apply the RPO permutation.
145        // we don't need to apply any extra padding because we injected total number of elements
146        // in the input list into the capacity portion of the state during initialization.
147        if i > 0 {
148            Self::apply_permutation(&mut state);
149        }
150
151        // return the first 4 elements of the state as hash result
152        RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
153    }
154
155    fn merge(values: &[Self::Digest; 2]) -> Self::Digest {
156        // initialize the state by copying the digest elements into the rate portion of the state
157        // (8 total elements), and set the capacity elements to 0.
158        let mut state = [ZERO; STATE_WIDTH];
159        let it = Self::Digest::digests_as_elements(values.iter());
160        for (i, v) in it.enumerate() {
161            state[RATE_RANGE.start + i] = *v;
162        }
163
164        // apply the RPO permutation and return the first four elements of the state
165        Self::apply_permutation(&mut state);
166        RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
167    }
168
169    fn merge_with_int(seed: Self::Digest, value: u64) -> Self::Digest {
170        // initialize the state as follows:
171        // - seed is copied into the first 4 elements of the rate portion of the state.
172        // - if the value fits into a single field element, copy it into the fifth rate element
173        //   and set the sixth rate element to 1.
174        // - if the value doesn't fit into a single field element, split it into two field
175        //   elements, copy them into rate elements 5 and 6, and set the seventh rate element
176        //   to 1.
177        // - set the first capacity element to 1
178        let mut state = [ZERO; STATE_WIDTH];
179        state[INPUT1_RANGE].copy_from_slice(seed.as_elements());
180        state[INPUT2_RANGE.start] = Felt::new(value);
181        if value < Felt::MODULUS {
182            state[INPUT2_RANGE.start + 1] = ONE;
183        } else {
184            state[INPUT2_RANGE.start + 1] = Felt::new(value / Felt::MODULUS);
185            state[INPUT2_RANGE.start + 2] = ONE;
186        }
187
188        // common padding for both cases
189        state[CAPACITY_RANGE.start] = ONE;
190
191        // apply the RPO permutation and return the first four elements of the state
192        Self::apply_permutation(&mut state);
193        RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
194    }
195}
196
197impl ElementHasher for Rpo256 {
198    type BaseField = Felt;
199
200    fn hash_elements<E: FieldElement<BaseField = Self::BaseField>>(elements: &[E]) -> Self::Digest {
201        // convert the elements into a list of base field elements
202        let elements = E::as_base_elements(elements);
203
204        // initialize state to all zeros, except for the first element of the capacity part, which
205        // is set to 1 if the number of elements is not a multiple of RATE_WIDTH.
206        let mut state = [ZERO; STATE_WIDTH];
207        if elements.len() % RATE_WIDTH != 0 {
208            state[CAPACITY_RANGE.start] = ONE;
209        }
210
211        // absorb elements into the state one by one until the rate portion of the state is filled
212        // up; then apply the Rescue permutation and start absorbing again; repeat until all
213        // elements have been absorbed
214        let mut i = 0;
215        for &element in elements.iter() {
216            state[RATE_RANGE.start + i] = element;
217            i += 1;
218            if i % RATE_WIDTH == 0 {
219                Self::apply_permutation(&mut state);
220                i = 0;
221            }
222        }
223
224        // if we absorbed some elements but didn't apply a permutation to them (would happen when
225        // the number of elements is not a multiple of RATE_WIDTH), apply the RPO permutation after
226        // padding by appending a 1 followed by as many 0 as necessary to make the input length a
227        // multiple of the RATE_WIDTH.
228        if i > 0 {
229            state[RATE_RANGE.start + i] = ONE;
230            i += 1;
231            while i != RATE_WIDTH {
232                state[RATE_RANGE.start + i] = ZERO;
233                i += 1;
234            }
235            Self::apply_permutation(&mut state);
236        }
237
238        // return the first 4 elements of the state as hash result
239        RpoDigest::new(state[DIGEST_RANGE].try_into().unwrap())
240    }
241}
242
243// HASH FUNCTION IMPLEMENTATION
244// ================================================================================================
245
246impl Rpo256 {
247    // CONSTANTS
248    // --------------------------------------------------------------------------------------------
249
250    /// The number of rounds is set to 7 to target 128-bit security level.
251    pub const NUM_ROUNDS: usize = NUM_ROUNDS;
252
253    /// Sponge state is set to 12 field elements or 768 bytes; 8 elements are reserved for rate and
254    /// the remaining 4 elements are reserved for capacity.
255    pub const STATE_WIDTH: usize = STATE_WIDTH;
256
257    /// The rate portion of the state is located in elements 4 through 11 (inclusive).
258    pub const RATE_RANGE: Range<usize> = RATE_RANGE;
259
260    /// The capacity portion of the state is located in elements 0, 1, 2, and 3.
261    pub const CAPACITY_RANGE: Range<usize> = CAPACITY_RANGE;
262
263    /// The output of the hash function can be read from state elements 4, 5, 6, and 7.
264    pub const DIGEST_RANGE: Range<usize> = DIGEST_RANGE;
265
266    /// MDS matrix used for computing the linear layer in a RPO round.
267    pub const MDS: [[Felt; STATE_WIDTH]; STATE_WIDTH] = MDS;
268
269    /// Round constants added to the hasher state in the first half of the RPO round.
270    pub const ARK1: [[Felt; STATE_WIDTH]; NUM_ROUNDS] = ARK1;
271
272    /// Round constants added to the hasher state in the second half of the RPO round.
273    pub const ARK2: [[Felt; STATE_WIDTH]; NUM_ROUNDS] = ARK2;
274
275    // TRAIT PASS-THROUGH FUNCTIONS
276    // --------------------------------------------------------------------------------------------
277
278    /// Returns a hash of the provided sequence of bytes.
279    #[inline(always)]
280    pub fn hash(bytes: &[u8]) -> RpoDigest {
281        <Self as Hasher>::hash(bytes)
282    }
283
284    /// Returns a hash of two digests. This method is intended for use in construction of
285    /// Merkle trees and verification of Merkle paths.
286    #[inline(always)]
287    pub fn merge(values: &[RpoDigest; 2]) -> RpoDigest {
288        <Self as Hasher>::merge(values)
289    }
290
291    /// Returns a hash of the provided field elements.
292    #[inline(always)]
293    pub fn hash_elements<E: FieldElement<BaseField = Felt>>(elements: &[E]) -> RpoDigest {
294        <Self as ElementHasher>::hash_elements(elements)
295    }
296
297    // RESCUE PERMUTATION
298    // --------------------------------------------------------------------------------------------
299
300    /// Applies RPO permutation to the provided state.
301    #[inline(always)]
302    pub fn apply_permutation(state: &mut [Felt; STATE_WIDTH]) {
303        for i in 0..NUM_ROUNDS {
304            Self::apply_round(state, i);
305        }
306    }
307
308    /// RPO round function.
309    #[inline(always)]
310    pub fn apply_round(state: &mut [Felt; STATE_WIDTH], round: usize) {
311        // apply first half of RPO round
312        Self::apply_mds(state);
313        Self::add_constants(state, &ARK1[round]);
314        Self::apply_sbox(state);
315
316        // apply second half of RPO round
317        Self::apply_mds(state);
318        Self::add_constants(state, &ARK2[round]);
319        Self::apply_inv_sbox(state);
320    }
321
322    // HELPER FUNCTIONS
323    // --------------------------------------------------------------------------------------------
324
325    #[inline(always)]
326    fn apply_mds(state: &mut [Felt; STATE_WIDTH]) {
327        let mut result = [ZERO; STATE_WIDTH];
328
329        // Using the linearity of the operations we can split the state into a low||high decomposition
330        // and operate on each with no overflow and then combine/reduce the result to a field element.
331        // The no overflow is guaranteed by the fact that the MDS matrix is a small powers of two in
332        // frequency domain.
333        let mut state_l = [0u64; STATE_WIDTH];
334        let mut state_h = [0u64; STATE_WIDTH];
335
336        for r in 0..STATE_WIDTH {
337            let s = state[r].inner();
338            state_h[r] = s >> 32;
339            state_l[r] = (s as u32) as u64;
340        }
341
342        let state_h = mds_multiply_freq(state_h);
343        let state_l = mds_multiply_freq(state_l);
344
345        for r in 0..STATE_WIDTH {
346            let s = state_l[r] as u128 + ((state_h[r] as u128) << 32);
347            let s_hi = (s >> 64) as u64;
348            let s_lo = s as u64;
349            let z = (s_hi << 32) - s_hi;
350            let (res, over) = s_lo.overflowing_add(z);
351
352            result[r] = Felt::from_mont(res.wrapping_add(0u32.wrapping_sub(over as u32) as u64));
353        }
354        *state = result;
355    }
356
357    #[inline(always)]
358    fn add_constants(state: &mut [Felt; STATE_WIDTH], ark: &[Felt; STATE_WIDTH]) {
359        state.iter_mut().zip(ark).for_each(|(s, &k)| *s += k);
360    }
361
362    #[inline(always)]
363    fn apply_sbox(state: &mut [Felt; STATE_WIDTH]) {
364        state[0] = state[0].exp7();
365        state[1] = state[1].exp7();
366        state[2] = state[2].exp7();
367        state[3] = state[3].exp7();
368        state[4] = state[4].exp7();
369        state[5] = state[5].exp7();
370        state[6] = state[6].exp7();
371        state[7] = state[7].exp7();
372        state[8] = state[8].exp7();
373        state[9] = state[9].exp7();
374        state[10] = state[10].exp7();
375        state[11] = state[11].exp7();
376    }
377
378    #[inline(always)]
379    fn apply_inv_sbox(state: &mut [Felt; STATE_WIDTH]) {
380        // compute base^10540996611094048183 using 72 multiplications per array element
381        // 10540996611094048183 = b1001001001001001001001001001000110110110110110110110110110110111
382
383        // compute base^10
384        let mut t1 = *state;
385        t1.iter_mut().for_each(|t| *t = t.square());
386
387        // compute base^100
388        let mut t2 = t1;
389        t2.iter_mut().for_each(|t| *t = t.square());
390
391        // compute base^100100
392        let t3 = Self::exp_acc::<Felt, STATE_WIDTH, 3>(t2, t2);
393
394        // compute base^100100100100
395        let t4 = Self::exp_acc::<Felt, STATE_WIDTH, 6>(t3, t3);
396
397        // compute base^100100100100100100100100
398        let t5 = Self::exp_acc::<Felt, STATE_WIDTH, 12>(t4, t4);
399
400        // compute base^100100100100100100100100100100
401        let t6 = Self::exp_acc::<Felt, STATE_WIDTH, 6>(t5, t3);
402
403        // compute base^1001001001001001001001001001000100100100100100100100100100100
404        let t7 = Self::exp_acc::<Felt, STATE_WIDTH, 31>(t6, t6);
405
406        // compute base^1001001001001001001001001001000110110110110110110110110110110111
407        for (i, s) in state.iter_mut().enumerate() {
408            let a = (t7[i].square() * t6[i]).square().square();
409            let b = t1[i] * t2[i] * *s;
410            *s = a * b;
411        }
412    }
413
414    #[inline(always)]
415    fn exp_acc<B: StarkField, const N: usize, const M: usize>(
416        base: [B; N],
417        tail: [B; N],
418    ) -> [B; N] {
419        let mut result = base;
420        for _ in 0..M {
421            result.iter_mut().for_each(|r| *r = r.square());
422        }
423        result.iter_mut().zip(tail).for_each(|(r, t)| *r *= t);
424        result
425    }
426}
427
428// MDS
429// ================================================================================================
430/// RPO MDS matrix
431const MDS: [[Felt; STATE_WIDTH]; STATE_WIDTH] = [
432    [
433        Felt::new(7),
434        Felt::new(23),
435        Felt::new(8),
436        Felt::new(26),
437        Felt::new(13),
438        Felt::new(10),
439        Felt::new(9),
440        Felt::new(7),
441        Felt::new(6),
442        Felt::new(22),
443        Felt::new(21),
444        Felt::new(8),
445    ],
446    [
447        Felt::new(8),
448        Felt::new(7),
449        Felt::new(23),
450        Felt::new(8),
451        Felt::new(26),
452        Felt::new(13),
453        Felt::new(10),
454        Felt::new(9),
455        Felt::new(7),
456        Felt::new(6),
457        Felt::new(22),
458        Felt::new(21),
459    ],
460    [
461        Felt::new(21),
462        Felt::new(8),
463        Felt::new(7),
464        Felt::new(23),
465        Felt::new(8),
466        Felt::new(26),
467        Felt::new(13),
468        Felt::new(10),
469        Felt::new(9),
470        Felt::new(7),
471        Felt::new(6),
472        Felt::new(22),
473    ],
474    [
475        Felt::new(22),
476        Felt::new(21),
477        Felt::new(8),
478        Felt::new(7),
479        Felt::new(23),
480        Felt::new(8),
481        Felt::new(26),
482        Felt::new(13),
483        Felt::new(10),
484        Felt::new(9),
485        Felt::new(7),
486        Felt::new(6),
487    ],
488    [
489        Felt::new(6),
490        Felt::new(22),
491        Felt::new(21),
492        Felt::new(8),
493        Felt::new(7),
494        Felt::new(23),
495        Felt::new(8),
496        Felt::new(26),
497        Felt::new(13),
498        Felt::new(10),
499        Felt::new(9),
500        Felt::new(7),
501    ],
502    [
503        Felt::new(7),
504        Felt::new(6),
505        Felt::new(22),
506        Felt::new(21),
507        Felt::new(8),
508        Felt::new(7),
509        Felt::new(23),
510        Felt::new(8),
511        Felt::new(26),
512        Felt::new(13),
513        Felt::new(10),
514        Felt::new(9),
515    ],
516    [
517        Felt::new(9),
518        Felt::new(7),
519        Felt::new(6),
520        Felt::new(22),
521        Felt::new(21),
522        Felt::new(8),
523        Felt::new(7),
524        Felt::new(23),
525        Felt::new(8),
526        Felt::new(26),
527        Felt::new(13),
528        Felt::new(10),
529    ],
530    [
531        Felt::new(10),
532        Felt::new(9),
533        Felt::new(7),
534        Felt::new(6),
535        Felt::new(22),
536        Felt::new(21),
537        Felt::new(8),
538        Felt::new(7),
539        Felt::new(23),
540        Felt::new(8),
541        Felt::new(26),
542        Felt::new(13),
543    ],
544    [
545        Felt::new(13),
546        Felt::new(10),
547        Felt::new(9),
548        Felt::new(7),
549        Felt::new(6),
550        Felt::new(22),
551        Felt::new(21),
552        Felt::new(8),
553        Felt::new(7),
554        Felt::new(23),
555        Felt::new(8),
556        Felt::new(26),
557    ],
558    [
559        Felt::new(26),
560        Felt::new(13),
561        Felt::new(10),
562        Felt::new(9),
563        Felt::new(7),
564        Felt::new(6),
565        Felt::new(22),
566        Felt::new(21),
567        Felt::new(8),
568        Felt::new(7),
569        Felt::new(23),
570        Felt::new(8),
571    ],
572    [
573        Felt::new(8),
574        Felt::new(26),
575        Felt::new(13),
576        Felt::new(10),
577        Felt::new(9),
578        Felt::new(7),
579        Felt::new(6),
580        Felt::new(22),
581        Felt::new(21),
582        Felt::new(8),
583        Felt::new(7),
584        Felt::new(23),
585    ],
586    [
587        Felt::new(23),
588        Felt::new(8),
589        Felt::new(26),
590        Felt::new(13),
591        Felt::new(10),
592        Felt::new(9),
593        Felt::new(7),
594        Felt::new(6),
595        Felt::new(22),
596        Felt::new(21),
597        Felt::new(8),
598        Felt::new(7),
599    ],
600];
601
602// ROUND CONSTANTS
603// ================================================================================================
604
605/// Rescue round constants;
606/// computed as in [specifications](https://github.com/ASDiscreteMathematics/rpo)
607///
608/// The constants are broken up into two arrays ARK1 and ARK2; ARK1 contains the constants for the
609/// first half of RPO round, and ARK2 contains constants for the second half of RPO round.
610const ARK1: [[Felt; STATE_WIDTH]; NUM_ROUNDS] = [
611    [
612        Felt::new(5789762306288267392),
613        Felt::new(6522564764413701783),
614        Felt::new(17809893479458208203),
615        Felt::new(107145243989736508),
616        Felt::new(6388978042437517382),
617        Felt::new(15844067734406016715),
618        Felt::new(9975000513555218239),
619        Felt::new(3344984123768313364),
620        Felt::new(9959189626657347191),
621        Felt::new(12960773468763563665),
622        Felt::new(9602914297752488475),
623        Felt::new(16657542370200465908),
624    ],
625    [
626        Felt::new(12987190162843096997),
627        Felt::new(653957632802705281),
628        Felt::new(4441654670647621225),
629        Felt::new(4038207883745915761),
630        Felt::new(5613464648874830118),
631        Felt::new(13222989726778338773),
632        Felt::new(3037761201230264149),
633        Felt::new(16683759727265180203),
634        Felt::new(8337364536491240715),
635        Felt::new(3227397518293416448),
636        Felt::new(8110510111539674682),
637        Felt::new(2872078294163232137),
638    ],
639    [
640        Felt::new(18072785500942327487),
641        Felt::new(6200974112677013481),
642        Felt::new(17682092219085884187),
643        Felt::new(10599526828986756440),
644        Felt::new(975003873302957338),
645        Felt::new(8264241093196931281),
646        Felt::new(10065763900435475170),
647        Felt::new(2181131744534710197),
648        Felt::new(6317303992309418647),
649        Felt::new(1401440938888741532),
650        Felt::new(8884468225181997494),
651        Felt::new(13066900325715521532),
652    ],
653    [
654        Felt::new(5674685213610121970),
655        Felt::new(5759084860419474071),
656        Felt::new(13943282657648897737),
657        Felt::new(1352748651966375394),
658        Felt::new(17110913224029905221),
659        Felt::new(1003883795902368422),
660        Felt::new(4141870621881018291),
661        Felt::new(8121410972417424656),
662        Felt::new(14300518605864919529),
663        Felt::new(13712227150607670181),
664        Felt::new(17021852944633065291),
665        Felt::new(6252096473787587650),
666    ],
667    [
668        Felt::new(4887609836208846458),
669        Felt::new(3027115137917284492),
670        Felt::new(9595098600469470675),
671        Felt::new(10528569829048484079),
672        Felt::new(7864689113198939815),
673        Felt::new(17533723827845969040),
674        Felt::new(5781638039037710951),
675        Felt::new(17024078752430719006),
676        Felt::new(109659393484013511),
677        Felt::new(7158933660534805869),
678        Felt::new(2955076958026921730),
679        Felt::new(7433723648458773977),
680    ],
681    [
682        Felt::new(16308865189192447297),
683        Felt::new(11977192855656444890),
684        Felt::new(12532242556065780287),
685        Felt::new(14594890931430968898),
686        Felt::new(7291784239689209784),
687        Felt::new(5514718540551361949),
688        Felt::new(10025733853830934803),
689        Felt::new(7293794580341021693),
690        Felt::new(6728552937464861756),
691        Felt::new(6332385040983343262),
692        Felt::new(13277683694236792804),
693        Felt::new(2600778905124452676),
694    ],
695    [
696        Felt::new(7123075680859040534),
697        Felt::new(1034205548717903090),
698        Felt::new(7717824418247931797),
699        Felt::new(3019070937878604058),
700        Felt::new(11403792746066867460),
701        Felt::new(10280580802233112374),
702        Felt::new(337153209462421218),
703        Felt::new(13333398568519923717),
704        Felt::new(3596153696935337464),
705        Felt::new(8104208463525993784),
706        Felt::new(14345062289456085693),
707        Felt::new(17036731477169661256),
708    ],
709];
710
711const ARK2: [[Felt; STATE_WIDTH]; NUM_ROUNDS] = [
712    [
713        Felt::new(6077062762357204287),
714        Felt::new(15277620170502011191),
715        Felt::new(5358738125714196705),
716        Felt::new(14233283787297595718),
717        Felt::new(13792579614346651365),
718        Felt::new(11614812331536767105),
719        Felt::new(14871063686742261166),
720        Felt::new(10148237148793043499),
721        Felt::new(4457428952329675767),
722        Felt::new(15590786458219172475),
723        Felt::new(10063319113072092615),
724        Felt::new(14200078843431360086),
725    ],
726    [
727        Felt::new(6202948458916099932),
728        Felt::new(17690140365333231091),
729        Felt::new(3595001575307484651),
730        Felt::new(373995945117666487),
731        Felt::new(1235734395091296013),
732        Felt::new(14172757457833931602),
733        Felt::new(707573103686350224),
734        Felt::new(15453217512188187135),
735        Felt::new(219777875004506018),
736        Felt::new(17876696346199469008),
737        Felt::new(17731621626449383378),
738        Felt::new(2897136237748376248),
739    ],
740    [
741        Felt::new(8023374565629191455),
742        Felt::new(15013690343205953430),
743        Felt::new(4485500052507912973),
744        Felt::new(12489737547229155153),
745        Felt::new(9500452585969030576),
746        Felt::new(2054001340201038870),
747        Felt::new(12420704059284934186),
748        Felt::new(355990932618543755),
749        Felt::new(9071225051243523860),
750        Felt::new(12766199826003448536),
751        Felt::new(9045979173463556963),
752        Felt::new(12934431667190679898),
753    ],
754    [
755        Felt::new(18389244934624494276),
756        Felt::new(16731736864863925227),
757        Felt::new(4440209734760478192),
758        Felt::new(17208448209698888938),
759        Felt::new(8739495587021565984),
760        Felt::new(17000774922218161967),
761        Felt::new(13533282547195532087),
762        Felt::new(525402848358706231),
763        Felt::new(16987541523062161972),
764        Felt::new(5466806524462797102),
765        Felt::new(14512769585918244983),
766        Felt::new(10973956031244051118),
767    ],
768    [
769        Felt::new(6982293561042362913),
770        Felt::new(14065426295947720331),
771        Felt::new(16451845770444974180),
772        Felt::new(7139138592091306727),
773        Felt::new(9012006439959783127),
774        Felt::new(14619614108529063361),
775        Felt::new(1394813199588124371),
776        Felt::new(4635111139507788575),
777        Felt::new(16217473952264203365),
778        Felt::new(10782018226466330683),
779        Felt::new(6844229992533662050),
780        Felt::new(7446486531695178711),
781    ],
782    [
783        Felt::new(3736792340494631448),
784        Felt::new(577852220195055341),
785        Felt::new(6689998335515779805),
786        Felt::new(13886063479078013492),
787        Felt::new(14358505101923202168),
788        Felt::new(7744142531772274164),
789        Felt::new(16135070735728404443),
790        Felt::new(12290902521256031137),
791        Felt::new(12059913662657709804),
792        Felt::new(16456018495793751911),
793        Felt::new(4571485474751953524),
794        Felt::new(17200392109565783176),
795    ],
796    [
797        Felt::new(17130398059294018733),
798        Felt::new(519782857322261988),
799        Felt::new(9625384390925085478),
800        Felt::new(1664893052631119222),
801        Felt::new(7629576092524553570),
802        Felt::new(3485239601103661425),
803        Felt::new(9755891797164033838),
804        Felt::new(15218148195153269027),
805        Felt::new(16460604813734957368),
806        Felt::new(9643968136937729763),
807        Felt::new(3611348709641382851),
808        Felt::new(18256379591337759196),
809    ],
810];