Skip to content

feat: ssz engine API transport#8994

Merged
nazarhussain merged 4 commits into
ChainSafe:nh/ssz-engine-apifrom
Giulio2002:eip-8161-ssz-rest
May 19, 2026
Merged

feat: ssz engine API transport#8994
nazarhussain merged 4 commits into
ChainSafe:nh/ssz-engine-apifrom
Giulio2002:eip-8161-ssz-rest

Conversation

@Giulio2002
Copy link
Copy Markdown

@Giulio2002 Giulio2002 commented Mar 5, 2026

Summary

Implements SSZ-REST Engine API transport on the consensus layer (client side), as specified in ethereum/execution-apis#764.

  • New CLI flag --execution.sszRestUrl to configure SSZ-REST endpoint
  • SSZ-encoded request/response bodies for all Engine API methods
  • Automatic fallback to JSON-RPC on network errors
  • Supports: new_payload (v1-v5), forkchoice_updated (v1-v3), get_payload (v1-v5), exchange_capabilities
  • Proper fork-based version selection for Deneb/Electra/Fulu

Implement SSZ-REST transport for all Engine API methods:
- new_payload (v3/v4/v5)
- forkchoice_updated (v3)
- get_payload (v3/v4/v5)
- exchange_capabilities (v1)

New CLI flag --execution.sszRestUrl enables SSZ-REST with automatic
fallback to JSON-RPC on network errors.

Includes proper fork-based version selection for Fulu (v5).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant upgrade to the execution layer communication by integrating the EIP-8161 SSZ-REST Engine API transport. This change allows for more efficient, binary-encoded interactions with the execution layer, enhancing performance and aligning with new Ethereum standards. The implementation includes a resilient fallback mechanism to JSON-RPC in case of network issues, ensuring continuous operation. It also provides a new configuration option for users to enable and specify the SSZ-REST endpoint.

Highlights

  • EIP-8161 SSZ-REST Engine API Transport: Implemented support for the EIP-8161 SSZ-REST Engine API transport on the consensus layer (client side), enabling a new binary-encoded communication method with the execution layer.
  • Automatic Fallback to JSON-RPC: The system is configured to automatically attempt SSZ-REST requests first and fall back to the traditional JSON-RPC transport if network errors occur, ensuring robustness and compatibility.
  • New CLI Flag for Configuration: A new CLI flag, --execution.sszRestUrl, has been introduced to allow users to configure the SSZ-REST endpoint, making the feature optional and configurable.
  • Comprehensive Engine API Method Support: The SSZ-REST transport now supports key Engine API methods including new_payload (v1-v5), forkchoice_updated (v1-v3), get_payload (v1-v5), and exchange_capabilities, with proper fork-based version selection.
  • SSZ Encoding and Decoding: Dedicated logic for SSZ-encoding request bodies and SSZ-decoding response bodies for all supported Engine API methods has been added, ensuring efficient binary data transfer.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • packages/beacon-node/src/execution/engine/http.ts
    • Updated imports to include SSZ codecs and new SSZ-REST client/encoding utilities.
    • Extended ExecutionEngineHttpOpts to include an optional sszRestUrl.
    • Added sszRestClient property to ExecutionEngineHttp and initialized it in the constructor if sszRestUrl is provided.
    • Modified executePayload, forkchoiceUpdated, getPayload, and getBlobs methods to prioritize SSZ-REST requests and implement automatic fallback to JSON-RPC on network errors.
    • Introduced helper functions deserializeExecutionPayloadSsz, deserializeBlobsBundleSsz, and deserializeExecutionRequestsSsz for decoding SSZ responses.
  • packages/beacon-node/src/execution/engine/sszRestClient.ts
    • Added a new file defining the SszRestClient for handling EIP-8161 SSZ-REST HTTP requests.
    • Implemented SszRestError for specific SSZ-REST related errors.
    • Provided isSszRestNetworkError to identify network-level errors for fallback logic.
    • Included JWT authentication support for SSZ-REST requests.
    • Added utility functions for hex-to-bytes conversion.
  • packages/beacon-node/src/execution/engine/sszRestEncoding.ts
    • Added a new file containing comprehensive encoding and decoding functions for SSZ-REST Engine API messages.
    • Implemented little-endian (LE) integer read/write helpers for various byte lengths (Uint32, Uint64, Uint256).
    • Provided specific encoding functions for ForkchoiceUpdated, NewPayload, GetPayload, GetBlobs, and ExchangeCapabilities requests.
    • Provided specific decoding functions for PayloadStatus, ForkchoiceUpdatedResponse, GetPayloadResponse, ExchangeCapabilities, and GetBlobsResponse.
    • Integrated @lodestar/types SSZ codecs for serializing ExecutionPayload and ExecutionRequests based on the active fork.
  • packages/cli/src/options/beaconNodeOptions/execution.ts
    • Extended ExecutionEngineArgs interface to include execution.sszRestUrl.
    • Mapped the new CLI argument to the execution options.
    • Added a new CLI option --execution.sszRestUrl with a description for configuring the SSZ-REST endpoint.
Activity
  • The pull request author has successfully tested the SSZ-REST transport in a multi-client devnet with Erigon EL, achieving finality.
  • Unit tests for SSZ encoding/decoding are planned.
  • Benchmarks comparing SSZ-REST vs JSON-RPC are planned.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements EIP-8161, adding SSZ-REST transport for the Engine API. The changes are well-structured, introducing a new SszRestClient, SSZ encoding/decoding logic, and integrating it into the existing ExecutionEngineHttp with a fallback to JSON-RPC. My review includes a few suggestions to improve code reuse and maintainability by replacing custom utility functions with existing ones from @lodestar/utils and refactoring duplicated logic.

Comment on lines +255 to +256
const version =
ForkSeq[fork] >= ForkSeq.fulu ? 5 : ForkSeq[fork] >= ForkSeq.electra ? 4 : ForkSeq[fork] >= ForkSeq.deneb ? 3 : ForkSeq[fork] >= ForkSeq.capella ? 2 : 1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This version selection logic is duplicated in the getPayload method (lines 554-555). To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, consider extracting this logic into a dedicated helper function. For example:

function getPayloadApiVersion(fork: ForkName): number {
  const forkSeq = ForkSeq[fork];
  if (forkSeq >= ForkSeq.fulu) return 5;
  if (forkSeq >= ForkSeq.electra) return 4;
  if (forkSeq >= ForkSeq.deneb) return 3;
  if (forkSeq >= ForkSeq.capella) return 2;
  return 1;
}

You can then call this function here and in getPayload.

constructor(opts: SszRestClientOpts) {
// Strip trailing slash for consistent path joining
this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
this.jwtSecret = opts.jwtSecretHex ? hexToBytes(opts.jwtSecretHex) : undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency and to leverage a more robust utility, please use the fromHex function from @lodestar/utils instead of the custom hexToBytes implementation. You'll need to add fromHex to your imports and can then remove the hexToBytes function (lines 139-146).

Suggested change
this.jwtSecret = opts.jwtSecretHex ? hexToBytes(opts.jwtSecretHex) : undefined;
this.jwtSecret = opts.jwtSecretHex ? fromHex(opts.jwtSecretHex) : undefined;

Comment on lines +606 to +616
function hexToBytes20(hex: string): Uint8Array {
const stripped = hex.startsWith("0x") ? hex.slice(2) : hex;
if (stripped.length !== 40) {
throw Error(`Expected 20-byte hex address, got ${stripped.length / 2} bytes`);
}
const bytes = new Uint8Array(20);
for (let i = 0; i < 20; i++) {
bytes[i] = parseInt(stripped.substring(i * 2, i * 2 + 2), 16);
}
return bytes;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of a custom hexToBytes20 implementation, you can use the existing fromHex utility from @lodestar/utils and add a length check. This promotes code reuse and consistency.

You will need to add import {fromHex} from "@lodestar/utils";.

function hexToBytes20(hex: string): Uint8Array {
  const bytes = fromHex(hex);
  if (bytes.length !== 20) {
    throw Error(`Expected 20-byte hex address, got ${bytes.length} bytes`);
  }
  return bytes;
}

Giulio2002 and others added 2 commits March 6, 2026 00:01
…-REST

- new_payload → POST /engine/v{N}/payloads
- forkchoice_updated → POST /engine/v{N}/forkchoice
- get_payload → GET /engine/v{N}/payloads/{payload_id}
- get_blobs → POST /engine/v{N}/blobs
- Error responses now text/plain instead of JSON
- Added doGetRequest for GET support, Fulu version selection fix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per execution-apis PR ChainSafe#764 spec:
- PayloadStatus.latest_valid_hash: List[Hash32, 1]
- ForkchoiceUpdatedResponse.payload_id: List[Bytes8, 1]
- ForkchoiceUpdatedRequest.payload_attributes: List[PayloadAttributes, 1]

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nflaig
Copy link
Copy Markdown
Member

nflaig commented Mar 6, 2026

is this different from #8993 which is based on @barnabasbusa ssz engine api spec?

SSZ-REST URL is now derived from the first engine URL (same host:port).
The EL serves SSZ-REST on the engine port under /engine/* paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Giulio2002
Copy link
Copy Markdown
Author

Giulio2002 commented Mar 8, 2026

effectively the same

@Giulio2002 Giulio2002 changed the title feat: EIP-8161 SSZ-REST Engine API transport feat: SSZ-REST Engine API transport Mar 8, 2026
@Giulio2002
Copy link
Copy Markdown
Author

Implements the SSZ-REST Engine API transport spec: ethereum/execution-apis#764

@lodekeeper
Copy link
Copy Markdown
Contributor

Both this PR and #8993 implement the same spec (execution-apis PR #764) — SSZ-first Engine API transport with JSON-RPC fallback. As Giulio confirmed, effectively the same goal.

Key differences in approach:

Happy to consolidate if there is a preferred direction.

@nazarhussain nazarhussain changed the base branch from unstable to nh/ssz-engine-api May 19, 2026 10:50
@nazarhussain nazarhussain changed the title feat: SSZ-REST Engine API transport feat: ssz engine API transport May 19, 2026
@nazarhussain nazarhussain marked this pull request as ready for review May 19, 2026 10:57
@nazarhussain nazarhussain requested a review from a team as a code owner May 19, 2026 10:57
@nazarhussain nazarhussain merged commit 2d17bb9 into ChainSafe:nh/ssz-engine-api May 19, 2026
1 of 4 checks passed
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66b6604dc2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +338 to +346
const latestValidHashOffset = readUint32LE(data, 1);
const validationErrorOffset = readUint32LE(data, 5);

// Decode latestValidHash: List[Hash32, 1] — 0 bytes = absent, 32 bytes = present
let latestValidHash: string | null = null;
const hashLen = validationErrorOffset - latestValidHashOffset;
if (hashLen === 32) {
const hashBytes = data.subarray(latestValidHashOffset, validationErrorOffset);
latestValidHash = "0x" + bytesToHex(hashBytes);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Decode PayloadStatus using its fixed SSZ layout

EIP-8178 defines PayloadStatusV1 as status: uint8, fixed latest_valid_hash: Bytes32, then a variable validation_error; there are not two offsets after the status byte. When an SSZ-REST newPayload or forkchoice response is decoded here, bytes from the hash are interpreted as offsets, so latestValidHash and validationError are dropped or decoded as garbage for normal INVALID/SYNCING/ACCEPTED responses instead of reflecting the EL result.

Useful? React with 👍 / 👎.

Comment on lines +670 to +672
return decoded.map((item) => ({
blob: item.blob,
proof: item.kzgProof,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve Fulu blob cell proofs

When fork is Fulu this path selects /engine/v2/blobs, whose response items are BlobAndProofV2 values with a proofs list, not a single Deneb-style proof. Returning {blob, proof} means callers of the Fulu overload receive objects where proofs is undefined, so SSZ-REST blob retrieval cannot be verified/used once this path succeeds.

Useful? React with 👍 / 👎.

Comment on lines +430 to +433
const executionPayloadOffset = readUint32LE(data, 0);
const blockValue = readUint256LE(data, 4);
const blobsBundleOffset = readUint32LE(data, 36);
const shouldOverrideBuilder = data[40] !== 0;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle version-specific getPayload responses

This decoder assumes every getPayload response has a blobs-bundle offset and shouldOverrideBuilder byte, but SSZ v1 returns a raw ExecutionPayload and v2 only has execution_payload plus block_value before the payload bytes. For Bellatrix/Capella SSZ-REST responses, bytes 36/40 are part of the payload rather than header fields, so the payload is sliced with bogus offsets and deserialization fails instead of returning the built block.

Useful? React with 👍 / 👎.

nazarhussain pushed a commit that referenced this pull request May 19, 2026
## Summary

Implements SSZ-REST Engine API transport on the consensus layer (client
side), as specified in
[ethereum/execution-apis#764](ethereum/execution-apis#764).

- New CLI flag `--execution.sszRestUrl` to configure SSZ-REST endpoint
- SSZ-encoded request/response bodies for all Engine API methods
- Automatic fallback to JSON-RPC on network errors
- Supports: `new_payload` (v1-v5), `forkchoice_updated` (v1-v3),
`get_payload` (v1-v5), `exchange_capabilities`
- Proper fork-based version selection for Deneb/Electra/Fulu

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 19, 2026
Replace the hand-rolled byte-level encoders/decoders in sszRestEncoding.ts
with @chainsafe/ssz ContainerType definitions for every Engine API request
and response. This fixes a number of wire-format defects from #8994:

- NewPayloadV1/V2 now carry the required Container offset prefix.
- PayloadAttributes encoding matches the per-fork shape (V1 lacks
  withdrawals, V2 lacks parentBeaconBlockRoot, etc.) instead of always
  writing the V3 layout.
- execution_requests is encoded as the spec's flat List[ByteList, 256]
  with proper SSZ list framing, not a flat concatenation of typed blobs.
- GetPayloadResponse V2 (Shanghai) and the V5/V6 Osaka/Amsterdam shapes
  are now decodable.
- GetBlobs V2 cell proofs (List[Bytes48, CELLS_PER_EXT_BLOB]) decode
  correctly; the previous fixed-stride scan only worked for V1.
- Fork → version mapping is centralized in newPayloadVersion,
  getPayloadVersion, forkchoiceUpdatedVersion, and getBlobsVersion,
  fixing the prior fulu→v5 mismapping for newPayload and the v4 gap for
  forkchoiceUpdated.

PayloadAttributes containers are redefined locally because
ssz.{fork}.PayloadAttributes from @lodestar/types declares
suggestedFeeRecipient with a JSON-only stringType that throws on SSZ
serialize.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 19, 2026
…sszRest

The SSZ-REST Engine API transport from #8994 was constructed unconditionally
and probed on every Engine call, then silently fell back to JSON-RPC on
network errors. Until ethereum/execution-apis#764 stabilises and the ELs we
test against advertise support consistently, this probing is wasted traffic
against vanilla EL deployments and can mask transient infra issues.

Add a `sszRest` flag to ExecutionEngineHttpOpts and a hidden
`--execution.sszRest` CLI flag. The SszRestClient is only constructed when
the flag is set; otherwise the JSON-RPC path is used exclusively.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 19, 2026
Drop the local hexToBytes helper in favour of fromHex from @lodestar/utils,
matching the convention used elsewhere in the package. Addresses
gemini-code-assist feedback on #8994.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nazarhussain pushed a commit that referenced this pull request May 20, 2026
## Summary

Implements SSZ-REST Engine API transport on the consensus layer (client
side), as specified in
[ethereum/execution-apis#764](ethereum/execution-apis#764).

- New CLI flag `--execution.sszRestUrl` to configure SSZ-REST endpoint
- SSZ-encoded request/response bodies for all Engine API methods
- Automatic fallback to JSON-RPC on network errors
- Supports: `new_payload` (v1-v5), `forkchoice_updated` (v1-v3),
`get_payload` (v1-v5), `exchange_capabilities`
- Proper fork-based version selection for Deneb/Electra/Fulu

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 20, 2026
Replace the hand-rolled byte-level encoders/decoders in sszRestEncoding.ts
with @chainsafe/ssz ContainerType definitions for every Engine API request
and response. This fixes a number of wire-format defects from #8994:

- NewPayloadV1/V2 now carry the required Container offset prefix.
- PayloadAttributes encoding matches the per-fork shape (V1 lacks
  withdrawals, V2 lacks parentBeaconBlockRoot, etc.) instead of always
  writing the V3 layout.
- execution_requests is encoded as the spec's flat List[ByteList, 256]
  with proper SSZ list framing, not a flat concatenation of typed blobs.
- GetPayloadResponse V2 (Shanghai) and the V5/V6 Osaka/Amsterdam shapes
  are now decodable.
- GetBlobs V2 cell proofs (List[Bytes48, CELLS_PER_EXT_BLOB]) decode
  correctly; the previous fixed-stride scan only worked for V1.
- Fork → version mapping is centralized in newPayloadVersion,
  getPayloadVersion, forkchoiceUpdatedVersion, and getBlobsVersion,
  fixing the prior fulu→v5 mismapping for newPayload and the v4 gap for
  forkchoiceUpdated.

PayloadAttributes containers are redefined locally because
ssz.{fork}.PayloadAttributes from @lodestar/types declares
suggestedFeeRecipient with a JSON-only stringType that throws on SSZ
serialize.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 20, 2026
…sszRest

The SSZ-REST Engine API transport from #8994 was constructed unconditionally
and probed on every Engine call, then silently fell back to JSON-RPC on
network errors. Until ethereum/execution-apis#764 stabilises and the ELs we
test against advertise support consistently, this probing is wasted traffic
against vanilla EL deployments and can mask transient infra issues.

Add a `sszRest` flag to ExecutionEngineHttpOpts and a hidden
`--execution.sszRest` CLI flag. The SszRestClient is only constructed when
the flag is set; otherwise the JSON-RPC path is used exclusively.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
nazarhussain added a commit that referenced this pull request May 20, 2026
Drop the local hexToBytes helper in favour of fromHex from @lodestar/utils,
matching the convention used elsewhere in the package. Addresses
gemini-code-assist feedback on #8994.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

4 participants