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