Commit 5e2c8b6
refactor(cast): unify downcast felt252 canonicalization branches (#1653)
Both arms of the felt252 canonicalization in build_downcast reduce to
"subtract PRIME when the felt exceeds a threshold": 0 for a
non-positive destination range, HALF_PRIME for one that straddles zero.
This also fixes a VM divergence: the non-positive branch subtracted
PRIME unconditionally, interpreting felt 0 as -PRIME. For a destination
whose lower bound is exactly 1 - PRIME no lower-bound check is emitted,
so downcast<felt252, BoundedInt<1-P, U<=0>>(0) returned Some where the
VM returns None (and under-charged the range check builtin, 2 vs 3).
With the 0 threshold, felt 0 stays 0 and is rejected by the upper-bound
check, matching the VM on both the value and the builtin counter.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 0aaf5bf commit 5e2c8b6
1 file changed
Lines changed: 21 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
161 | 164 | | |
162 | | - | |
163 | | - | |
164 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
165 | 168 | | |
166 | | - | |
167 | | - | |
| 169 | + | |
168 | 170 | | |
169 | 171 | | |
170 | 172 | | |
| |||
0 commit comments