format: count segment offsets from the most significant byte - #309
Merged
Merged
Conversation
Contributor
|
gnidan
force-pushed
the
architect-segment-offset-direction
branch
from
September 30, 2026 17:39
43622f3 to
3e9ead8
Compare
gnidan
force-pushed
the
architect-segment-offset-direction
branch
from
September 30, 2026 17:47
3e9ead8 to
6520af2
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.
The segment schema said
offset: 0is "the start of the specified slot" without saying which end of the word that is. It is the most significant byte: a slot's value is its$wordsize-byte big-endian word, and byte0is the first byte of that word. The reference implementation (packages/evmstorage reads,packages/pointerssegment resolution, including the carry) and bugc's packed storage access already work this way, so this changes no behavior.The
offsetdescription now says this plainly and gives the conversion for layouts that count from the low-order end, such as Solidity's packed storage: a value ofnbytes that sitsobytes from the low-order end is atoffset$wordsize - o - n. An emitter can write that as a literal number, which is simplest to read and resolve, or as an expression such as{ "$difference": ["$wordsize", { "$sum": [o, { ".length": "$this" }] }] }, which can takenfrom the region's ownlength, keeps the layout's own numbers visible, needs no arithmetic in the emitter, and does not depend on a fixed word size.The segment schema gains packed examples that model Solidity's
address owner; uint32 count;sharing one slot: a 20-byteaddressat the low-order end of slot 2 ("offset": 12) and a four-byteuint32just above it ("offset": 8), each written once with literal offsets and once with the$differenceform, takingnfrom the region's ownlength.segment.examples.test.tsin@ethdebug/pointersresolves each of them against a slot with a known word and checks the literal forms yield the address and theuint32, and that each expression form yields the same bytes as its literal twin. The pointer concepts page gets a one-sentence note, and the spec CHANGELOG has an entry.Fixes #307