Skip to main content

nautilus_lighter/signing/hash/
params.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Lighter Poseidon2 parameter set, defined verbatim from the Apache-2.0 Go
17//! reference implementation [`elliottech/poseidon_crypto`] at the pinned
18//! revision recorded in the fixture metadata. Each round constant, the
19//! diagonal of the internal MDS matrix, and the round counts must agree
20//! byte-for-byte with that reference; the fixture vectors under `test_data/`
21//! verify equivalence.
22//!
23//! - State width `t = 12`, sponge rate `r = 8` and capacity `c = 4`.
24//! - S-box exponent `D = 7`.
25//! - 8 full external rounds (split 4 + 4 around the partial rounds), 22 partial
26//!   internal rounds.
27//! - Internal MDS matrix is `M_I = diag(MATRIX_DIAG_12) + J_12` where `J_12` is
28//!   the all-ones matrix; the diagonal is taken from the Plonky3 Goldilocks
29//!   parameter set the Lighter reference adopts.
30//!
31//! [`elliottech/poseidon_crypto`]: https://github.com/elliottech/poseidon_crypto
32
33use crate::signing::field::Fp;
34
35/// Sponge state width.
36pub const WIDTH: usize = 12;
37
38/// Sponge absorption rate (elements per absorbed block).
39pub const RATE: usize = 8;
40
41/// S-box exponent: `x -> x^7`. The S-box itself is hard-coded in the
42/// permutation for performance; this constant exists to make the full
43/// parameter set explicit alongside the round counts it pairs with.
44#[allow(dead_code)]
45pub const D: u64 = 7;
46
47/// Number of full (external) rounds.
48pub const ROUNDS_F: usize = 8;
49
50/// Half the number of full rounds, applied before and after the partial rounds.
51pub const ROUNDS_F_HALF: usize = ROUNDS_F / 2;
52
53/// Number of partial (internal) rounds.
54pub const ROUNDS_P: usize = 22;
55
56/// Round constants applied at each external round (one row per round, one
57/// constant per state position).
58pub const EXTERNAL_CONSTANTS: [[Fp; WIDTH]; ROUNDS_F] = [
59    [
60        Fp::from_u64_reduce(15_492_826_721_047_263_190),
61        Fp::from_u64_reduce(11_728_330_187_201_910_315),
62        Fp::from_u64_reduce(8_836_021_247_773_420_868),
63        Fp::from_u64_reduce(16_777_404_051_263_952_451),
64        Fp::from_u64_reduce(5_510_875_212_538_051_896),
65        Fp::from_u64_reduce(6_173_089_941_271_892_285),
66        Fp::from_u64_reduce(2_927_757_366_422_211_339),
67        Fp::from_u64_reduce(10_340_958_981_325_008_808),
68        Fp::from_u64_reduce(8_541_987_352_684_552_425),
69        Fp::from_u64_reduce(9_739_599_543_776_434_497),
70        Fp::from_u64_reduce(15_073_950_188_101_532_019),
71        Fp::from_u64_reduce(12_084_856_431_752_384_512),
72    ],
73    [
74        Fp::from_u64_reduce(4_584_713_381_960_671_270),
75        Fp::from_u64_reduce(8_807_052_963_476_652_830),
76        Fp::from_u64_reduce(54_136_601_502_601_741),
77        Fp::from_u64_reduce(4_872_702_333_905_478_703),
78        Fp::from_u64_reduce(5_551_030_319_979_516_287),
79        Fp::from_u64_reduce(12_889_366_755_535_460_989),
80        Fp::from_u64_reduce(16_329_242_193_178_844_328),
81        Fp::from_u64_reduce(412_018_088_475_211_848),
82        Fp::from_u64_reduce(10_505_784_623_379_650_541),
83        Fp::from_u64_reduce(9_758_812_378_619_434_837),
84        Fp::from_u64_reduce(7_421_979_329_386_275_117),
85        Fp::from_u64_reduce(375_240_370_024_755_551),
86    ],
87    [
88        Fp::from_u64_reduce(3_331_431_125_640_721_931),
89        Fp::from_u64_reduce(15_684_937_309_956_309_981),
90        Fp::from_u64_reduce(578_521_833_432_107_983),
91        Fp::from_u64_reduce(14_379_242_000_670_861_838),
92        Fp::from_u64_reduce(17_922_409_828_154_900_976),
93        Fp::from_u64_reduce(8_153_494_278_429_192_257),
94        Fp::from_u64_reduce(15_904_673_920_630_731_971),
95        Fp::from_u64_reduce(11_217_863_998_460_634_216),
96        Fp::from_u64_reduce(3_301_540_195_510_742_136),
97        Fp::from_u64_reduce(9_937_973_023_749_922_003),
98        Fp::from_u64_reduce(3_059_102_938_155_026_419),
99        Fp::from_u64_reduce(1_895_288_289_490_976_132),
100    ],
101    [
102        Fp::from_u64_reduce(5_580_912_693_628_927_540),
103        Fp::from_u64_reduce(10_064_804_080_494_788_323),
104        Fp::from_u64_reduce(9_582_481_583_369_602_410),
105        Fp::from_u64_reduce(10_186_259_561_546_797_986),
106        Fp::from_u64_reduce(247_426_333_829_703_916),
107        Fp::from_u64_reduce(13_193_193_905_461_376_067),
108        Fp::from_u64_reduce(6_386_232_593_701_758_044),
109        Fp::from_u64_reduce(17_954_717_245_501_896_472),
110        Fp::from_u64_reduce(1_531_720_443_376_282_699),
111        Fp::from_u64_reduce(2_455_761_864_255_501_970),
112        Fp::from_u64_reduce(11_234_429_217_864_304_495),
113        Fp::from_u64_reduce(4_746_959_618_548_874_102),
114    ],
115    [
116        Fp::from_u64_reduce(13_571_697_342_473_846_203),
117        Fp::from_u64_reduce(17_477_857_865_056_504_753),
118        Fp::from_u64_reduce(15_963_032_953_523_553_760),
119        Fp::from_u64_reduce(16_033_593_225_279_635_898),
120        Fp::from_u64_reduce(14_252_634_232_868_282_405),
121        Fp::from_u64_reduce(8_219_748_254_835_277_737),
122        Fp::from_u64_reduce(7_459_165_569_491_914_711),
123        Fp::from_u64_reduce(15_855_939_513_193_752_003),
124        Fp::from_u64_reduce(16_788_866_461_340_278_896),
125        Fp::from_u64_reduce(7_102_224_659_693_946_577),
126        Fp::from_u64_reduce(3_024_718_005_636_976_471),
127        Fp::from_u64_reduce(13_695_468_978_618_890_430),
128    ],
129    [
130        Fp::from_u64_reduce(8_214_202_050_877_825_436),
131        Fp::from_u64_reduce(2_670_727_992_739_346_204),
132        Fp::from_u64_reduce(16_259_532_062_589_659_211),
133        Fp::from_u64_reduce(11_869_922_396_257_088_411),
134        Fp::from_u64_reduce(3_179_482_916_972_760_137),
135        Fp::from_u64_reduce(13_525_476_046_633_427_808),
136        Fp::from_u64_reduce(3_217_337_278_042_947_412),
137        Fp::from_u64_reduce(14_494_689_598_654_046_340),
138        Fp::from_u64_reduce(15_837_379_330_312_175_383),
139        Fp::from_u64_reduce(8_029_037_639_801_151_344),
140        Fp::from_u64_reduce(2_153_456_285_263_517_937),
141        Fp::from_u64_reduce(8_301_106_462_311_849_241),
142    ],
143    [
144        Fp::from_u64_reduce(13_294_194_396_455_217_955),
145        Fp::from_u64_reduce(17_394_768_489_610_594_315),
146        Fp::from_u64_reduce(12_847_609_130_464_867_455),
147        Fp::from_u64_reduce(14_015_739_446_356_528_640),
148        Fp::from_u64_reduce(5_879_251_655_839_607_853),
149        Fp::from_u64_reduce(9_747_000_124_977_436_185),
150        Fp::from_u64_reduce(8_950_393_546_890_284_269),
151        Fp::from_u64_reduce(10_765_765_936_405_694_368),
152        Fp::from_u64_reduce(14_695_323_910_334_139_959),
153        Fp::from_u64_reduce(16_366_254_691_123_000_864),
154        Fp::from_u64_reduce(15_292_774_414_889_043_182),
155        Fp::from_u64_reduce(10_910_394_433_429_313_384),
156    ],
157    [
158        Fp::from_u64_reduce(17_253_424_460_214_596_184),
159        Fp::from_u64_reduce(3_442_854_447_664_030_446),
160        Fp::from_u64_reduce(3_005_570_425_335_613_727),
161        Fp::from_u64_reduce(10_859_158_614_900_201_063),
162        Fp::from_u64_reduce(9_763_230_642_109_343_539),
163        Fp::from_u64_reduce(6_647_722_546_511_515_039),
164        Fp::from_u64_reduce(909_012_944_955_815_706),
165        Fp::from_u64_reduce(18_101_204_076_790_399_111),
166        Fp::from_u64_reduce(11_588_128_829_349_125_809),
167        Fp::from_u64_reduce(15_863_878_496_612_806_566),
168        Fp::from_u64_reduce(5_201_119_062_417_750_399),
169        Fp::from_u64_reduce(176_665_553_780_565_743),
170    ],
171];
172
173/// Round constants applied to `state[0]` at each partial (internal) round.
174pub const INTERNAL_CONSTANTS: [Fp; ROUNDS_P] = [
175    Fp::from_u64_reduce(11_921_381_764_981_422_944),
176    Fp::from_u64_reduce(10_318_423_381_711_320_787),
177    Fp::from_u64_reduce(8_291_411_502_347_000_766),
178    Fp::from_u64_reduce(229_948_027_109_387_563),
179    Fp::from_u64_reduce(9_152_521_390_190_983_261),
180    Fp::from_u64_reduce(7_129_306_032_690_285_515),
181    Fp::from_u64_reduce(15_395_989_607_365_232_011),
182    Fp::from_u64_reduce(8_641_397_269_074_305_925),
183    Fp::from_u64_reduce(17_256_848_792_241_043_600),
184    Fp::from_u64_reduce(6_046_475_228_902_245_682),
185    Fp::from_u64_reduce(12_041_608_676_381_094_092),
186    Fp::from_u64_reduce(12_785_542_378_683_951_657),
187    Fp::from_u64_reduce(14_546_032_085_337_914_034),
188    Fp::from_u64_reduce(3_304_199_118_235_116_851),
189    Fp::from_u64_reduce(16_499_627_707_072_547_655),
190    Fp::from_u64_reduce(10_386_478_025_625_759_321),
191    Fp::from_u64_reduce(13_475_579_315_436_919_170),
192    Fp::from_u64_reduce(16_042_710_511_297_532_028),
193    Fp::from_u64_reduce(1_411_266_850_385_657_080),
194    Fp::from_u64_reduce(9_024_840_976_168_649_958),
195    Fp::from_u64_reduce(14_047_056_970_978_379_368),
196    Fp::from_u64_reduce(838_728_605_080_212_101),
197];
198
199/// Diagonal of the internal MDS matrix (the off-diagonal entries are all 1).
200///
201/// Sourced from the Plonky3 Poseidon2 Goldilocks parameter set the Lighter
202/// reference adopts.
203pub const MATRIX_DIAG_12: [Fp; WIDTH] = [
204    Fp::from_u64_reduce(0xc3b6_c08e_23ba_9300),
205    Fp::from_u64_reduce(0xd84b_5de9_4a32_4fb6),
206    Fp::from_u64_reduce(0x0d0c_371c_5b35_b84f),
207    Fp::from_u64_reduce(0x7964_f570_e718_8037),
208    Fp::from_u64_reduce(0x5daf_18bb_d996_604b),
209    Fp::from_u64_reduce(0x6743_bc47_b959_5257),
210    Fp::from_u64_reduce(0x5528_b936_2c59_bb70),
211    Fp::from_u64_reduce(0xac45_e25b_7127_b68b),
212    Fp::from_u64_reduce(0xa207_7d7d_fbb6_06b5),
213    Fp::from_u64_reduce(0xf3fa_ac6f_aee3_78ae),
214    Fp::from_u64_reduce(0x0c63_88b5_1545_e883),
215    Fp::from_u64_reduce(0xd27d_bb69_4491_7b60),
216];