Repository navigation
bugc: copy structs and strings between storage and memory - #377
Merged
Merged
Conversation
gnidan
force-pushed
the
bugc-struct-copies
branch
from
October 9, 2026 05:09
95607a5 to
5043a0f
Compare
Contributor
|
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.
This lets a BUG program copy a struct from storage, change it in memory, and write it back, as Arcade does with
let player: Player = players[msg.sender];...players[msg.sender] = player;, and gives a struct local a pointer to its fields.It fixes two silent miscompiles:
let m: string = motd;loaded the slot's word and used it as a memory address. Astringorbytesread from storage as a whole is now copied to memory: the length, then the data, from either the short (in-slot) or long (fromkeccak256(slot)) encoding.players[msg.sender] = player;wrote the struct's memory address into one slot. A struct in memory assigned to storage is now written field by field, each packed into its bytes in its slot, and astringorbytesfield is copied as Solidity encodes it, with the old value's unused data words cleared (as in bugc: clear unused data words when a storage string shrinks #370).Also:
stringandbytesfields (each field's word holds the address of its own copy). Nested structs copy recursively in both directions.group: the local's word, then each field's region in its word in memory (player-score, a scalar right-aligned), and for astringfield its word plus nestedplayer-name-lengthandplayer-name-dataregions, the length read from memory. The locals soundness test resolves it with@ethdebug/pointersat every step of a real trace, at every optimization level.