Skip to content

feat: SSZ-REST Engine API transport#8994

Draft
Giulio2002 wants to merge 4 commits intoChainSafe:unstablefrom
Giulio2002:eip-8161-ssz-rest
Draft

feat: SSZ-REST Engine API transport#8994
Giulio2002 wants to merge 4 commits intoChainSafe:unstablefrom
Giulio2002:eip-8161-ssz-rest

Conversation

@Giulio2002
Copy link

@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
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
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
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
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
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
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
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
Author

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

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.

2 participants