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