fix(soroban): support scalar-array returns and unsigned enum tag - #1983
Open
salaheldinsoliman wants to merge 2 commits into
Open
fix(soroban): support scalar-array returns and unsigned enum tag#1983salaheldinsoliman wants to merge 2 commits into
salaheldinsoliman wants to merge 2 commits into
Conversation
Codegen lowers array allocation to vector_new with an element count and a separate element size, but the Soroban branch dropped the element size and soroban_alloc_init treated the count as a byte size. Multi-byte-element dynamic arrays were under-allocated: a uint64[3] got a 3-byte payload, so element stores overflowed into adjacent heap allocations and the elements' high bytes were never zero-initialized. Thread elem_size through soroban_alloc_init and size the payload as members * elem_size, keeping len/size in element units. Regression tests land with the scalar-array return support stacked on top of this change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: salaheldinsoliman <salaheldin_sameh@aucegypt.edu>
encode_vector blitted the array's raw memory as if it already contained encoded Vals, which is only correct for SorobanHandle elements (decoded arguments passed straight through). A freshly built scalar array returned garbage once past the return-type gate. Encode each element through soroban_encode_arg into a Val buffer inside a counted loop, registering the loop counter for phi insertion so it is not folded to a constant. Lift the return-type gate for scalar-element arrays only; string, bytes/ bytesN, and struct element types stay rejected pending verified encodings (the unsupported_parameters testcase now uses bytes[] for that assertion). Enum discriminants were encoded with the signed I32 Val tag but decoded as Uint(32), so enum returns failed with ConversionError; encode with U32. Tests: array_return (fresh uint64[] return + arg/return round trip) and other_custom_types (enum and struct-with-enum-field ABI round trips). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: salaheldinsoliman <salaheldin_sameh@aucegypt.edu>
This was referenced Jul 26, 2026
1 task
Islam-Imad
force-pushed
the
fix/soroban-alloc-elem-size
branch
from
July 29, 2026 12:22
f01f23c to
d6184f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stacked on #1982 (requires the allocator element-size fix to be correct at runtime).
Two ABI fixes:
Scalar-array returns.
encode_vectorblitted the array's raw memory as if it already contained encodedVals — only correct forSorobanHandleelements (decoded arguments passed straight through). A freshly built scalar array (uint64[]) returned garbage. It now encodes each element throughsoroban_encode_arginto aValbuffer inside a counted loop, registering the loop counter for phi insertion (new_dirty_tracker/set_phis) so it is not constant-folded into an infinite loop. The return-type gate is lifted only for scalar-element arrays;string/bytes/bytesN/struct element types stay rejected pending verified encodings (theunsupported_parameterstestcase now asserts onbytes[]).Enum returns. Enum discriminants were encoded with the signed
I32Valtag but decoded asUint(32), failing withConversionError. Encode withU32.Tests
array_return: returning a freshuint64[]; array-arg → array-return round trip.other_custom_types: enum and struct-with-enum-field ABI round trips (toward the upstreamother_custom_typesexample).🤖 Generated with Claude Code