Skip to content

feat(zkevm): add schema-id prefix to stateless guest program input bytes - #2826

Merged
jsign merged 5 commits into
ethereum:projects/zkevmfrom
jsign:jsign-stateless-input-schema-id
May 9, 2026
Merged

jsign merged 5 commits into
ethereum:projects/zkevmfrom
jsign:jsign-stateless-input-schema-id

Conversation

@jsign

@jsign jsign commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

🗒️ Description

This PR adds a schema-id two-byte big-int prefix to the guest program input bytes.

Before this PR, the guest input was SSZ-bytes corresponding to StatelessInput. SSZ encoded bytes does not describe which is the target struct to deserialize to. As a concrete example, different forks would have different ExecutionPayload thus indirectly different StatelessInput definitions.

Guest programs are meant to support multiple forks so they are useful between fork boundaries, thus they need some clear way to distinguish which target StatelessInput should be used to deserialize the received input bytes. While this can be done by using some assumptions about SSZ field ordering to read timestamp against the ChainConfig, this might feel a bit hacky.

Note that schema-id isn't really a signal of a target fork -- it can even mean that the rest of bytes after schema-id byte have other encoding formats, so should be interpreted as [schema-id-byte][rest input bytes...] instead of [schema-id-byte][ssz-encoded-stateless-input-for-fork-XXX...] (although for a while this might be the right interpretation in practice).

Other notes:

  • schema-id is a two-byte prefix. This should provide enough capacity for the near future. Thought about LEB128, but feels like overkill.
  • Decided that schema-id == 0 is not a valid value, mainly to avoid being used by error since it is the default value of a byte.
  • Amstedram being 0x01 is mainly the most obvious value, although in the near future, if we end up supporting historical forks, we might want to redefine this if another ordering feels more natural.

🔗 Related Issues or PRs

N/A.

✅ Checklist

  • All: Ran fast static checks to avoid unnecessary CI fails, see also Code Standards and Enabling Pre-commit Checks:
    just static
  • All: PR title adheres to the repo standard - it will be used as the squash commit message and should start type(scope):.
  • All: Considered updating the online docs in the ./docs/ directory.
  • All: Set appropriate labels for the changes (only maintainers can apply labels).
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.
  • Tests: For PRs implementing a missed test case, update the post-mortem document to add an entry the list.
  • Ported Tests: All converted JSON/YML tests from ethereum/tests or tests/static have been assigned @ported_from marker.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@jsign jsign added the zkEVM zkEVM project related issues/PRs label May 7, 2026
@@ -25,8 +26,15 @@ def serialize_stateless_output(


def deserialize_stateless_input(data: Bytes) -> StatelessInput:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Crux of the PR.

Comment on lines +33 to +36
if schema_id != STATELESS_INPUT_SCHEMA_ID:
raise ValueError(
f"Unsupported stateless input schema id: 0x{schema_id:02x}"
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the spec, we don't have a single guest program entry point that supports multiple-forks. This is mainly related on how execution-specs is architected having full specs per fork in different folders.

In real EL guest programs which support multiple forks, they will probably have a switch here to act accordingly.

@jsign
jsign marked this pull request as ready for review May 7, 2026 21:45
@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.37%. Comparing base (258c3c1) to head (4d63eb6).
⚠️ Report is 147 commits behind head on projects/zkevm.

Files with missing lines Patch % Lines
src/ethereum/forks/amsterdam/stateless_guest.py 33.33% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           projects/zkevm    #2826      +/-   ##
==================================================
+ Coverage           85.72%   86.37%   +0.64%     
==================================================
  Files                 612      613       +1     
  Lines               37853    38019     +166     
  Branches             3932     3964      +32     
==================================================
+ Hits                32451    32839     +388     
+ Misses               4652     4543     -109     
+ Partials              750      637     -113     
Flag Coverage Δ
unittests 86.37% <60.00%> (+0.64%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@marioevz marioevz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the single comment is a suggestion that could be addressed later.

jsign added 2 commits May 8, 2026 19:35
@jsign
jsign force-pushed the jsign-stateless-input-schema-id branch from c2d368f to 0951b85 Compare May 8, 2026 22:45

@rubo rubo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is the schema-id size being a single byte. I'm leaning more toward 2-byte or varint.

@jsign

jsign commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

My only concern is the schema-id size being a single byte. I'm leaning more toward 2-byte or varint.

Yep, sounds good. I think I'll switch to a fixed-two-byte value, mostly because something like LEB128 might be an overkill of fiddling with bits inside zkVM (although compared to the big picture shouldn't be a big deal either). Two-bytes would give us >65k values which should be enough.

@jsign

jsign commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

@rubo, made the change in e1eb780 if you want to take a final look (two-byte big-endian encoding).

@jsign
jsign merged commit 4efa59d into ethereum:projects/zkevm May 9, 2026
24 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

zkEVM zkEVM project related issues/PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants