Commit d2bd178
refactor(poseidon1): inline circulant MDS helper and tighten permutation docs (leanEthereum#780)
* refactor(poseidon1): inline circulant MDS helper and tighten permutation docs
Inline the single-use _build_circulant_mds helper into Poseidon1.__init__
with the circulant invariant kept as a comment. Restructure the JIT
permutation body around Phase 1/2/3 labels so each block carries its own
rationale (boundary non-linearity, Hades partial-round optimization,
algebraic-attack defense). Move the int64-overflow argument next to the
S-box line where it lives, and add line-by-line documentation to the
MDS matrix-vector loop explaining the per-product modular reduction.
Drop "from __future__ import annotations" since the file defines a
Pydantic model and project rules forbid lazy annotations there.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(poseidon1): cover field validators, field-boundary inputs, and add rounds_f even-check
Add a Pydantic field validator that rejects odd values for the full-round
count, with rationale: the permutation splits full rounds into equal halves
around the partial middle, so an odd count silently drops one full round
and orphans a width-sized block of round constants.
Extend the test suite from 8 to 18 cases:
- Each Field constraint on Poseidon1Params now has its own pytest.raises
check (width > 0, rounds_f > 0, rounds_p >= 0, mds_first_row non-empty,
round_constants non-empty).
- New test pins the rounds_f even-check.
- Output-in-field invariant is asserted for both widths.
- All-zero and field-boundary inputs (Fp(P - 1) across all lanes) verify
the int64 path stays in-field on degenerate and maximum-value states.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* test(poseidon1): assert on full error messages, not substrings
Each pytest.raises match pattern now spells out the complete authored
sentence. The two engine ValueError checks use anchored regexes so the
match cannot accidentally pass on a longer message that happens to
contain the expected fragment.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* docs(poseidon1): document paper deviations and the unenforced RF lower bound
Annotate the parameter and constant tables with the cryptanalytic context
that justifies the chosen instances:
- Poseidon1Params records the paper's 6-round (or 10 in some regimes) lower
bound on the full-round count and disclaims enforcement; callers remain
responsible for choosing secure parameters.
- Both MDS first-row constants flag the circulant-vs-Cauchy deviation
from the paper, link the upstream Plonky3 source, and note the GRS21
invariant-subspace requirement.
- PARAMS_16 and PARAMS_24 pin the round-count derivation to Plonky3's
koala-bear instance and the paper's Eq. 2-4 bounds, and call out the
ABM23 attack's inapplicability (explicit for width 24).
The module header and permutation docstring also note that this is the
original Hades-based Poseidon1, distinguishing it from the Poseidon2
successor.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 82f7c92 commit d2bd178
2 files changed
Lines changed: 186 additions & 43 deletions
File tree
- src/lean_spec/subspecs/poseidon1
- tests/lean_spec/subspecs/poseidon1
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | | - | |
11 | | - | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 27 | | |
40 | 28 | | |
41 | 29 | | |
| |||
46 | 34 | | |
47 | 35 | | |
48 | 36 | | |
| 37 | + | |
49 | 38 | | |
| 39 | + | |
| 40 | + | |
50 | 41 | | |
| 42 | + | |
| 43 | + | |
51 | 44 | | |
| 45 | + | |
52 | 46 | | |
| 47 | + | |
53 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
54 | 52 | | |
| 53 | + | |
| 54 | + | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
76 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
80 | | - | |
| 82 | + | |
81 | 83 | | |
82 | | - | |
83 | | - | |
84 | | - | |
| 84 | + | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
91 | 95 | | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
96 | | - | |
| 100 | + | |
97 | 101 | | |
98 | | - | |
99 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
105 | 111 | | |
106 | | - | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
112 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
113 | 121 | | |
114 | 122 | | |
115 | 123 | | |
| |||
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
126 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
127 | 140 | | |
128 | 141 | | |
129 | 142 | | |
| |||
137 | 150 | | |
138 | 151 | | |
139 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
140 | 166 | | |
141 | 167 | | |
142 | 168 | | |
| |||
151 | 177 | | |
152 | 178 | | |
153 | 179 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
| 180 | + | |
160 | 181 | | |
161 | 182 | | |
162 | 183 | | |
| |||
186 | 207 | | |
187 | 208 | | |
188 | 209 | | |
189 | | - | |
190 | | - | |
191 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
192 | 218 | | |
193 | 219 | | |
194 | 220 | | |
| |||
228 | 254 | | |
229 | 255 | | |
230 | 256 | | |
231 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
232 | 263 | | |
233 | 264 | | |
234 | 265 | | |
| |||
256 | 287 | | |
257 | 288 | | |
258 | 289 | | |
259 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
260 | 296 | | |
261 | 297 | | |
262 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | | - | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
129 | 202 | | |
130 | 203 | | |
131 | 204 | | |
132 | 205 | | |
133 | 206 | | |
134 | 207 | | |
135 | 208 | | |
136 | | - | |
| 209 | + | |
137 | 210 | | |
138 | 211 | | |
139 | 212 | | |
140 | 213 | | |
141 | 214 | | |
142 | | - | |
| 215 | + | |
143 | 216 | | |
144 | 217 | | |
145 | 218 | | |
| |||
160 | 233 | | |
161 | 234 | | |
162 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
0 commit comments