Skip to content

bugc: describe a storage string's encoding in its pointer - #369

Merged
gnidan merged 2 commits into
mainfrom
bugc-storage-string-pointer
Oct 7, 2026
Merged

gnidan merged 2 commits into
mainfrom
bugc-storage-string-pointer

Conversation

@gnidan

@gnidan gnidan commented Oct 7, 2026

Copy link
Copy Markdown
Member

Since #368, bugc stores a string or bytes value with Solidity's encoding, but its pointer still named only the slot. A debugger could not read the value from the pointer; it had to know the encoding itself.

The pointer now describes the encoding, in the same shape as solc's t_string_storage pointer template (and the "string storage allocation" example in ethdebug/format/pointer): a one-byte length-flag region at the slot's low byte, then a conditional on (length-flag + 1) % 2. When the flag is even, the data is a data region in the slot itself, length-flag / 2 bytes long. When it is odd, a long-length region covers the slot, and the data is a single data region from keccak256(slot), (long-length - 1) / 2 bytes long, across as many slots as it needs. This applies to top-level variables, struct members (with names qualified by the member, such as name-data), and array elements.

The new test compiles a program with a top-level string, a top-level bytes, a struct with string and bytes members, a fixed-size array of strings, and a mapping to that struct. It runs the program, then reads each pointer with @ethdebug/pointers against the resulting storage and checks the exact bytes for lengths 0, 5, 31, 32 and 70 at optimization levels 0 to 3. A mapping's pointer still names only its slot, so the test checks the entry u[7] with the pointer that the struct type gets at the entry's slot.

This changes only debug information. The create and runtime bytecode of every example, plus two string-heavy test programs, at levels 0 to 3, are byte-for-byte the same before and after.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-10-07 03:59 UTC

@gnidan
gnidan force-pushed the bugc-storage-string-pointer branch from a15c4f3 to 02da97a Compare October 7, 2026 03:37
@gnidan
gnidan merged commit 6f1cc7a into main Oct 7, 2026
7 checks passed
@gnidan
gnidan deleted the bugc-storage-string-pointer branch October 7, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant