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): make Value::to_ptr always return the inline representation (#1655)
For memory-allocated types (>=2-variant enums and aggregates containing
one), `Value::to_ptr` returned a *wrapper* pointer (a slot holding the
data pointer) while `Value::from_ptr` always reads the inline
representation. Every recursive consumer had to un-box the wrapper, and
four of six forgot:
- the Array arm copied `elem_layout.size()` bytes out of the 8-byte
wrapper, so even `Array<bool>` was corrupted (the 16-byte-aligned enum
body keeps the tag bit clear, decoding every element as variant 0);
- the Felt252Dict arm had the same omission (`Felt252Dict<bool>`);
- the `AbiArgument` Box and Nullable arms memcpy'd the wrapper bytes
into the heap block (`Box<SomeEnum>`).
Enumerating all callers shows nothing consumes the wrapper — every call
site either stripped it immediately or was one of these bugs — so invert
the contract instead of patching each site: `to_ptr` now always returns
a pointer to the inline representation per `TypeBuilder::layout()`,
exactly what `from_ptr` reads, and the by-pointer ABI decision lives
only in `crate::arch`'s `AbiArgument` impl.
Also make the Felt252Dict arm follow the same convention: it returned
the `FeltDict*` itself instead of a slot holding it, so a dict nested in
an aggregate copied 8 bytes of HashMap internals instead of the dict
pointer. The arch.rs dict arm now dereferences the slot once. The
Nullable arm also now passes the payload type id like the Box arm does.
Only reachable via the `invoke_dynamic(&[Value])` API; the Starknet
contract path marshals felts directly and is unaffected.
Adds a VM-vs-native regression test for `Array<bool>` and
`to_ptr`->`from_ptr` round-trip unit tests (bool array, struct with
bool, nested enum, bool dict) that the new symmetric contract enables.
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
0 commit comments