Conversation
…re-memory-tuple-widening # Conflicts: # vyper/codegen_venom/context.py
Gas ChangesNo changes detected. Summary
|
📊 Bytecode Size Changes (venom)No changes detected. Full bytecode sizes
|
…rkal/vyper into fix/venom/store-memory-tuple-widening
harkal
marked this pull request as ready for review
September 11, 2026 09:30
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.
What I did
Venom-only miscompile: assigning a tuple to a tuple with wider members (e.g.
x: (Bytes[10], uint256),y: (Bytes[40], uint256) = x) copiedxas a flat block, so the second member ofysits at the wrong offset and is read back wrong. Same for storage/transient/immutable tuple writes and for internal returns of tuples that have unbounded members. Legacy codegen (make_setter) is correct.Fixes the venom side of the tuple widening path that #5236 relies on.
How I did it
VenomCodegenContext.store_memory,Stmt._store_complex_typeandStmt._emit_dynamic_tuple_internal_returnchose between a flat copy and the member-wise copy (_store_memory_typed) withsrc_typ != typ.TupleT.__eq__comparesmembers, which is never populated (_equality_attrs = ("members",)), so any two tuple types compare equal and the member-wise path never fired for tuples.same_memory_layout(src_typ, dst_typ)incodegen_venom/context.py=punnable(src_typ, dst_typ) and src_typ.memory_bytes_required == dst_typ.memory_bytes_required; the three sites gate on it.punnablealone (vyper/codegen/core.py, from fix[codegen]: widen ternary arms to the result type layout #5236) is not enough: it accepts a wider top-level DynArray capacity or bytestring bound in the destination (the data present has the same layout), but a flat copy of the destination size would read past the source. The size conjunct keeps every such case on the copy path it takes today (_copy_dynarray_memory_typed/ the bytestring branch) and leaves all non-tuple codegen unchanged.ensure_memory_layoutnow falls back tomaterialize_value(store_vyper_value->store_memory) for bounded types; the comment that justified bypassing it was exactly this broken gate. The unbounded-sequence route added in feat[venom]: allow abi-dynamic elements in inf dynarrays #5240 is unchanged._emit_dynamic_tuple_internal_returnthetype_contains_unbounded_sequencechecks are evaluated beforesame_memory_layout, since unbounded members have nomemory_bytes_required._copy_dynarray_memory_typed's fast path (elements are never tuples),_lower_dynarray_append,_lower_external_return'sret_src_typ != ret_typ(can_encode_from_srcis True first for tuples),builtins/abi.py'swrapped_typ != output_typ.TupleT.__eq__itself. Fixing it in semantics touches type-checker equality; separate PR if wanted.How to verify it
Commit message
Description for the changelog
Cute Animal Picture