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