Skip to content

format: specify two-sorted (integer/bytes) expression evaluation - #286

Open
gnidan wants to merge 2 commits into
mainfrom
architect-expression-semantics
Open

format: specify two-sorted (integer/bytes) expression evaluation#286
gnidan wants to merge 2 commits into
mainfrom
architect-expression-semantics

Conversation

@gnidan

@gnidan gnidan commented Aug 6, 2026

Copy link
Copy Markdown
Member

Pointer expressions had an unstated gap: the width of a value was undefined for numeric literals, arithmetic results, and odd-digit hex, yet $concat and $keccak256 depend on operand widths — so a compiler and a debugger could legitimately disagree on the bytes produced. This specifies the evaluation model.

Expressions evaluate to a value of one of two sorts:

  • an integer — an unbounded, non-negative integer with no width;
  • bytes — a finite byte sequence with a definite width.

The forms are sorted accordingly. Integers: a JSON-number literal, $wordsize, a variable or lookup, arithmetic ($sum/$difference/$product/$quotient/$remainder), and an odd-digit hex literal (which has no whole-byte width). Bytes: an even-digit hex literal (width = bytes written), $read (width = region length), and $sizedN/$wordsized (width = N / word size).

Coercion runs one way. Where an integer is expected — arithmetic operands, a list count, a segment slot/offset/length — a bytes value is read as the non-negative integer its bytes encode (big-endian). Where bytes are expected — the operands of $concat and $keccak256, whose results depend on operand widths — the operand must be width-bearing; a bare integer there is an error and must be given a width with $sizedN/$wordsized first. The resize forms are the only bridge from an integer to bytes; there is no implicit widening.

This codifies what the mapping/string pointer examples already do (they word-size a key and slot before hashing). The keccak256 example's bare-integer operand is corrected to $wordsized: 0 to match.

Note: this is the core semantics for a future extraction of the expression language into a shared facility — the integer/bytes sorting discipline is meant to carry over. The @ethdebug/pointers evaluate implementation currently uses a single width-carrying representation and does not yet enforce the width-bearing rule; that is a tracked follow-up on the pointers side, not part of this spec change.

Schema example and validity tests pass.

gnidan added 2 commits August 5, 2026 20:17
DRAFT for writer prose pass before the PR opens.

Codifies the two-sorted semantics of pointer expressions: values are
either unbounded non-negative integers (no width) or bytes (with a
definite width). Arithmetic, JSON-number and odd-nibble-hex literals,
$wordsize, and lookups are integers; even-nibble hex, $read, and
$sizedN/$wordsized are bytes. An integer is accepted wherever an integer
is expected (a bytes value is read as its big-endian integer value), but
$concat and $keccak256 operands must be width-bearing bytes — a bare
integer there is an error and must be resized first. Fixes the keccak256
example's bare-integer operand to be word-sized, matching what the
mapping/string pointer examples already do.
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://ethdebug.github.io/format/pr-preview/pr-286/

Built to branch gh-pages at 2026-08-06 00:38 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

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