You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(values): encode BoundedInt in its compact representation; deref boxed returns
Two remaining marshaling asymmetries:
- `Value::to_ptr` wrote a BoundedInt as the un-biased value in a 32-byte
felt slot, while the native representation (and `from_ptr`) is the
compact one: `value - lower` stored in `repr_bit_width()` bits. A
BoundedInt nested in an aggregate (top-level arguments are still gated
by the arch.rs panic, #1217) was both silently mis-decoded and
overran its slot, corrupting neighboring elements —
`Array<BoundedInt<3, 10>>` returned garbage.
- `parse_result` passed a returned `Box<T>`'s return-pointer slot
straight to `from_ptr` without dereferencing it. Any function that
uses a non-ZST builtin returns through a return pointer, so e.g.
`fn(...) -> Box<felt252>` using pedersen decoded two raw heap
addresses as the payload. Mirror the Nullable arm's deref.
Add `RangeExt::repr_encode`/`repr_decode` as the single implementation
of the compact encoding (felt-wrapping subtraction so negative lower
bounds round-trip) and use the decode side from both existing
duplicates (`Value::from_ptr` and the register path in `parse_result`).
The `to_ptr` arm now also validates against the type's range rather
than only the value's embedded one.
Fixes `test_to_ptr_bounded_int_valid`, which asserted the buggy 32-byte
encoding ([16, ...] instead of `value - lower` = [6, 0] in the 2-byte
9-bit representation), and its embedded range, which didn't match the
type's (`BoundedInt<10, 510>` parses to the range `[10, 511)`).
Adds a VM-vs-native test for a boxed return forced through the return
pointer, and round-trip unit tests for `Array<BoundedInt<3, 10>>`
(asserting the 1-byte biased element buffer) and a negative-lower
range.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
0 commit comments