fix[venom]: type state variable reads with the declared type - #5239
Conversation
Gas ChangesNo changes detected. Summary
|
📊 Bytecode Size Changes (venom)No changes detected. Full bytecode sizes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a23d740576
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
charles-cooper
left a comment
There was a problem hiding this comment.
hmm it's a bit surprising that this changes behavior. @Sporarum can you take a look?
Sporarum
left a comment
There was a problem hiding this comment.
LGTM
The one question I have, is why only those specific cases ?
I'm also having issues with ternary ifs, and I think the root cause is the same
What I did
Fix a venom-only miscompile when a storage, transient or immutable variable is
read into a wider type, e.g.
ys: DynArray[Bytes[512], 5] = self.storedwithstored: DynArray[Bytes[10], 5]. Same bug family as #5236.The semantic pass stamps the
self.x/lib.Xnode with the expected(widened) type.
codegen_venomused that type to describe the borrowed pointerto the state variable, but the data has the declared type's layout. Two things
went wrong:
load_storage_to_memorysized the copy loop from the widetype (86 slots for
DynArray[Bytes[512], 5]vs the declared 11), readingslots that belong to neighbouring variables;
(544 bytes vs 64), so every element after the first was garbage.
For
[b'a', b'0123456789', b'']this returned[b'a', b'', b'']; other shapeshalted out of gas. Immutables had the same defect via
load_immutable_to_memory. Legacy codegen is unaffecthese IRnodes with
varinfo.typ.How I did it
Type the pointer returned by
lower_Attribute(state variable reads) andlower_Name(immutable reads) with the variable's denode._metadata["type"]. The existing typed copies on the consumer side(
store_memory(..., src_typ=...), `_store_complex_tyreturn encoding, call args) then widen element-wise. No new copy machinery.
Not covered here:
for x: <wide> in self.storedcopies each element linearlyin
_lower_iter_loopand has the same class of bug fwidenings. That is a separate code path and will be a separate PR.
How to verify it
Commit message
Description for the changelog
Cute Animal Picture