Skip to content

feat(zkevm): fill public_keys execution witness field - #2825

Merged
jsign merged 8 commits into
ethereum:projects/zkevmfrom
jsign:jsign-execution-witness-pubkeys
May 11, 2026
Merged

jsign merged 8 commits into
ethereum:projects/zkevmfrom
jsign:jsign-execution-witness-pubkeys

Conversation

@jsign

@jsign jsign commented May 7, 2026

Copy link
Copy Markdown
Contributor

🗒️ Description

Adds transaction public keys to Amsterdam stateless validation input and threads them through payload/block execution.

  • Populate StatelessInput.public_keys with one 65-byte uncompressed SEC1 public key per payload transaction.
  • Validate public-key count and SSZ public-key length before stateless execution.
  • Allow Amsterdam execution to verify sender derivation from supplied transaction public keys.
  • Extend the blockchain filler with public-key verification/mutation hooks for stateless input tests.
  • Add coverage for valid public-key construction, invalid public-key rejection, SSZ length checks, and public-key count mismatches.

So, although I added some test cases to check tha valid construction works fine, and basic invalid public key are rejected by the guest program, I believe we need to add some extra tests here. Mainly regarding potential wrong public keys reg ECDSA parity checks, and probably other cases. We will do that in other upcoming PRs.

🔗 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
original_stateless_input_bytes: Bytes,
execution_witness: ExecutionWitness,
execution_witness: ExecutionWitness | None = None,
public_keys: Tuple[Bytes, ...] | None = None,

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.

Mainly adding public_keys as a new field in the execution witness that can be modified by tests to check if the guest program is correctly validating its correctness. (The execution_witness change is a simplification to make both potentially modified execution_witness and public_keys feel symmetrical at this method API design).

return public_keys, payload_transactions


def verify_stateless_input_public_keys(

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.

Whenever a test is filled, we always check the public_keys generated by t8n matches an explicit list of public keys recovered with ecrecover.

This happens automatically for all tests and do not need an explicit signal from the test creator. This might be a bit harshish on the filler to check this always, but it feels way safer since it is an invariant that must always hold.

I filled locally and didn't notice any observable slowdown because of ecrecovers, so looks should be okay. Eventually if we conclude otherwise, we can avoid doing it always and expect the test writer to provide explicit signal to do this check for partiular cases. NBD.

new_payload_request: NewPayloadRequest,
pre_state: PreState,
chain_context: ChainContext,
transaction_public_keys: Optional[Tuple[Bytes, ...]] = None,

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.

execute_new_paylaod_request can receive an optional list of transaction_public_keys.

The call of this method from the guest program perspective always provide the values. But remember this method is also called from the "Engine API" context which is stateful, in that case it isn't passed.

Comment on lines +572 to +577
if sender_public_key is None:
sender_address = recover_sender(block_env.chain_id, tx)
else:
sender_address = recover_sender_from_public_key(
block_env.chain_id, tx, sender_public_key
)

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.

Key point: if the public key ways provided, we use a recover_sender_from_public_key which will check if the sender_public_key provided is correct or not (and theoretically leverage it to make the signature check faster -- "theoretically" because of a comment I'll do later).

if len(rlp.encode(block)) > MAX_RLP_BLOCK_SIZE:
raise InvalidBlock("Block rlp size exceeds MAX_RLP_BLOCK_SIZE")

if transaction_public_keys is not None and len(

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.

Here in execute_block we do an early check of length matching between public_keys and txs count. Later when processing tx, each concrete pubkey will be verified against the tx signature.

Comment on lines +700 to +718
def recover_sender_from_public_key(
chain_id: U64, tx: Transaction, public_key: Bytes
) -> Address:
"""
Verify that ``public_key`` is the transaction sender's canonical
uncompressed SEC1 public key.

This reference implementation verifies the supplied key by recovering the
canonical public key from the transaction signature and comparing the two.
Optimized implementations may avoid full public-key recovery, but must
still verify that the supplied key validates the signature and is
consistent with the transaction's recovery id / y-parity bit. Otherwise,
another valid recovery candidate could derive a different sender address.

Returns the sender address derived from the verified public key.
"""
if public_key != recover_transaction_public_key(chain_id, tx):
raise InvalidSignatureError
return _sender_address_from_public_key(public_key)

@jsign jsign May 7, 2026 •

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.

This is the "theoretically" comment I made before.

This is the method now called when processing transactions to get the address from the tx plus provided public key. Note the method comment.

For the spec, I want things to be simple, so I simply do ecrecover on the tx signature and check it against the provided public key in the witness. This is the simplest way to comply with the spec of verifying pubkey correctness.

As mentioned in this method comment, a real EL should leverage the public key to verify the ECDSA signature against it since that's faster than a full ecrecover. But I also add an important reminder point that that's not enough and it should also check the provided public key matches the parity bit from the tx signature. This is relevant since our case here is not really a normal ECDSA-verification that we trust the public key being correct, but should match what the yParity says in the signature to not have the symmetric EC point of r-X-coordinate.

TL;DR: in the spec, I'm doing the easiest non-optimized thing. But leaving the comment for EL authors reading this since might not be obvious.

I'm also planning to add a test to trigger this border case since it is far from obvious, and could lead to an incorrect address derivation of the sender.

cc @kevaundray

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.

The two simple tests for valid and invalid cases to do minimal coverage that things are working as expected.

@codecov

codecov Bot commented May 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.09524% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.36%. Comparing base (258c3c1) to head (ef07b7e).
⚠️ Report is 166 commits behind head on projects/zkevm.

Files with missing lines Patch % Lines
src/ethereum/forks/amsterdam/fork.py 75.00% 1 Missing and 1 partial ⚠️
src/ethereum/forks/amsterdam/stateless_ssz.py 50.00% 1 Missing and 1 partial ⚠️
src/ethereum/forks/amsterdam/transactions.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           projects/zkevm    #2825      +/-   ##
==================================================
+ Coverage           85.72%   86.36%   +0.63%     
==================================================
  Files                 612      613       +1     
  Lines               37853    38157     +304     
  Branches             3932     3980      +48     
==================================================
+ Hits                32451    32954     +503     
+ Misses               4652     4556      -96     
+ Partials              750      647     -103     
Flag Coverage Δ
unittests 86.36% <88.09%> (+0.63%) ⬆️

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.

@jsign
jsign marked this pull request as ready for review May 7, 2026 20:42
@jsign
jsign merged commit 85fc20c into ethereum:projects/zkevm May 11, 2026
25 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.

2 participants