Skip to content

format: add virtual regions for computed values - #411

Merged
gnidan merged 9 commits into
mainfrom
format-virtual-regions
Nov 19, 2026
Merged

gnidan merged 9 commits into
mainfrom
format-virtual-regions

Conversation

@gnidan

@gnidan gnidan commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Implements #291.

This adds a region with "location": "virtual" for values that no EVM data location stores, e.g. a variable the optimizer removed. The pointer schema's dispatch does not change: a virtual region is just another region, and dereferencing still yields regions only.

Every region is base fields plus one addressing scheme. Virtual regions use a new third scheme, ethdebug/format/pointer/scheme/fragment: a width-bearing expression supplies the byte space (the expression's value), and optional offset (default 0) and length (default: to the end of the value) address into it. A fragment outside the value's bytes is invalid. The expression is evaluated against the same machine state as the pointer's other regions and may refer only to regions before it. Lookups follow the region's fields, so .offset and .length work and .slot does not; ~read gives the fragment's bytes.

group:
  - name: a
    location: stack
    slot: 2
  - name: x
    location: virtual
    expression:
      ~wordsized:
        ~sum:
          - ~read: a
          - 1

The reference implementation evaluates the expression while it makes the region concrete, keeps the bytes on the concrete region, and fills in the default offset and length; read returns the fragment. A new integration case reads a + 1 and the first 4 bytes of keccak256(a) from a storage variable over a solc trace.

gnidan added a commit that referenced this pull request Nov 11, 2026
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-11-19 21:31 UTC

@gnidan

gnidan commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@djolertrk @cameel would be curious what you think of this approach to solving #291

@gnidan
gnidan force-pushed the format-virtual-regions branch from be853c0 to 5aa8a7b Compare November 16, 2026 21:58
A pink badge with a dashed border, and a dashed left border in the region
output, since a virtual region's bytes are computed, not stored.
A lookup of either one threw, though the spec gives both a default.
It checked the move to templates (#399) against the compiler from before
it. That move is long done, and the test that templates read as the inline
pointers do still runs on every example.
# Conflicts:
#	CHANGELOG.md
#	packages/format/CHANGELOG.md
@gnidan
gnidan marked this pull request as ready for review November 19, 2026 21:26
@gnidan
gnidan merged commit 9cd750e into main Nov 19, 2026
9 checks passed
@gnidan
gnidan deleted the format-virtual-regions branch November 19, 2026 21:27
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