Skip to content

[PeerDAS] Expose compute_cells (cells without proofs) through the C ABI and constantine-go - #626

Merged
mratsim merged 3 commits into
mratsim:masterfrom
syjn99:feat/cells-only-api
Aug 4, 2026
Merged

[PeerDAS] Expose compute_cells (cells without proofs) through the C ABI and constantine-go#626
mratsim merged 3 commits into
mratsim:masterfrom
syjn99:feat/cells-only-api

Conversation

@syjn99

@syjn99 syjn99 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

On the PeerDAS/Fulu block proposal hot path, consensus clients receive cell proofs from the execution layer for free (BlobsBundleV2 / engine_getBlobsV2) and only need the erasure-extended cells.

I'm assessing Constantine for Prysm's KZG operations (OffchainLabs/prysm#16850); in our benchmarks of constantine-go against c-kzg-4844 Constantine wins every measured operation, but this API gap is currently the main blocker to adoption: Prysm calls a cells-only ComputeCells at

  • beacon-chain/blockchain/kzg/validation.go (proof verification path), and
  • beacon-chain/core/peerdas/reconstruction.go (data-column reconstruction)

c-kzg-4844, go-eth-kzg and rust-eth-kzg all expose the equivalent entry point, matching the consensus-spec function compute_cells. With this change, migrating to constantine from other kzg libraries would be much easier.

Summary by CodeRabbit

  • New Features

    • Added support for computing all 128 EIP-7594 cells from an extended blob without generating KZG proofs.
    • Exposed cell computation through the C and Go APIs, including error handling for invalid inputs.
  • Tests

    • Added Go test-vector coverage for cells-only computation.
    • Updated PeerDAS benchmarks and tests for the new cell-computation interface.

syjn99 and others added 2 commits July 29, 2026 16:44
compute_cells already existed as a Nim-only API. Consensus clients on the
PeerDAS hot path receive cell proofs from the execution layer
(engine_getBlobsV2 / BlobsBundleV2) and only need the erasure-extended
cells: one size-4096 IFFT + one size-4096 FFT (~1.5 ms/blob) instead of
the 128 FK20 MSMs of compute_cells_and_kzg_proofs (~80-140 ms/blob),
a ~50x difference.

Align its signature with the other PeerDAS exports
(ptr UncheckedArray[Cell] + FFI nil-pointer validation of ctx and cells)
and export it as ctt_eth_kzg_compute_cells, declared in
ethereum_eip7594_peerdas.h. As with the sibling exports, the blob
parameter is passed by reference and must be non-NULL from C.

Matches the compute_cells function of the consensus spec:
https://github.com/ethereum/consensus-specs/blob/dev/specs/fulu/polynomial-commitments-sampling.md

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cells-only Go binding over ctt_eth_kzg_compute_cells, mirroring
ComputeCellsAndKzgProofs, with a test over the consensus-spec-tests
compute_cells vectors.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The EIP-7594 cells-only computation API now supports FFI-compatible output buffers, exposes a C declaration, and adds a Go binding with test-vector validation. Nim benchmarks and tests pass unchecked cell buffers while preserving existing assertions and recovery logic.

Changes

EIP-7594 compute-cells API

Layer / File(s) Summary
FFI and public API contract
include/constantine/protocols/..., constantine/eth_eip7594_peerdas.nim
The public C API and Nim implementation now accept caller-provided unchecked cell buffers, validate nil inputs, and bridge the buffer to internal computation.
Go binding and vector validation
constantine-go/constantine.go, constantine-go/eth_kzg7594_peerdas_test.go
EthKzgContext.ComputeCells calls the C API, converts failures to Go errors, and is validated against cells-only EIP-7594 vectors.
Nim callers and benchmark validation
benchmarks/..., tests/...
Benchmarks and PeerDAS tests pass buffers through asUnchecked() while retaining existing status, recovery, and output checks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestComputeCells
  participant EthKzgContext
  participant CApi
  participant NimComputeCells
  TestComputeCells->>EthKzgContext: ComputeCells(blob)
  EthKzgContext->>CApi: ctt_eth_kzg_compute_cells(ctx, cells, blob)
  CApi->>NimComputeCells: forward output buffer and blob
  NimComputeCells-->>CApi: return status and populated cells
  CApi-->>EthKzgContext: return status
  EthKzgContext-->>TestComputeCells: cells or error
Loading

Possibly related PRs

Suggested reviewers: mratsim

Poem

A rabbit hops through cells so bright,
Unchecked buffers fit just right.
Go gathers one-twenty-eight,
Tests compare each cell’s fate.
Nim benchmarks cheer: “Compute straight!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes exposing PeerDAS compute_cells through the C ABI and constantine-go, matching the main changes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment on lines 207 to +210
func compute_cells*(
ctx: ptr EthereumKZGContext,
cells: var array[CELLS_PER_EXT_BLOB, Cell],
blob: Blob): cttEthKzgStatus =
cells: ptr UncheckedArray[Cell],
blob: Blob): cttEthKzgStatus {.libPrefix: prefix_eth_kzg, raises: [].} =

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 Public Nim API signature breaks

When an existing Nim consumer calls compute_cells(ctx, cells, blob) with a fixed array[CELLS_PER_EXT_BLOB, Cell], the new pointer-only signature rejects the argument, causing downstream compilation to fail. Retain a typed compatibility overload or separate the C export wrapper from the existing Nim API.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

Adds cells-only PeerDAS computation across the existing implementation and language bindings.

  • Exports compute_cells through the C ABI with null-pointer validation.
  • Adds a Go ComputeCells wrapper returning 128 cells.
  • Adds consensus-vector tests and updates Nim tests and benchmarks for the pointer-based interface.

Confidence Score: 4/5

The PR is not yet safe to merge because the previously reported public Nim API compatibility break remains unfixed.

The current public compute_cells declaration still accepts only ptr UncheckedArray[Cell]; no exported fixed-array overload preserves the former call form, so existing Nim consumers passing array[CELLS_PER_EXT_BLOB, Cell] fail to compile.

Files Needing Attention: constantine/eth_eip7594_peerdas.nim

Important Files Changed

Filename Overview
constantine/eth_eip7594_peerdas.nim Exports cells-only computation through the C ABI and adds pointer validation, but the pointer-only public signature leaves the previously reported Nim source-compatibility break outstanding.
include/constantine/protocols/ethereum_eip7594_peerdas.h Declares the new C ABI function and its caller-allocated 128-cell output contract.
constantine-go/constantine.go Adds a nil-safe Go wrapper whose cell and blob layouts match the C ABI types.
constantine-go/eth_kzg7594_peerdas_test.go Adds consensus-vector coverage for successful and invalid cells-only inputs.

Sequence Diagram

sequenceDiagram
    participant Client as Go/C client
    participant ABI as ctt_eth_kzg_compute_cells
    participant KZG as Constantine PeerDAS
    Client->>ABI: context, 128-cell output buffer, blob
    ABI->>KZG: compute_cells
    KZG->>KZG: deserialize and extend blob
    KZG-->>ABI: 128 cells and status
    ABI-->>Client: cells or error
Loading

Reviews (2): Last reviewed commit: "[PeerDAS] constantine-go: add EthKzgCont..." | Re-trigger Greptile

syjn99 added a commit to syjn99/kzg-bench-constantine that referenced this pull request Jul 29, 2026
Rename RESULTS_DRAFT.md to RESULTS.md, drop the draft banner, link the
upstream cells-only PR (mratsim/constantine#626), and cross-link the
report and README.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mratsim
mratsim enabled auto-merge (squash) August 4, 2026 08:58
@mratsim

mratsim commented Aug 4, 2026

Copy link
Copy Markdown
Owner

SGTM, will create a separate issue to expose the same in Rust as well as this is go only.

Seems like there are unrelated CI stuff to fix though. Will have a look

@mratsim

mratsim commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Hopefully CI is unblocked by #627

@syjn99

syjn99 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@mratsim thanks, will wait until #627 got merged.

@mratsim mratsim closed this Aug 4, 2026
auto-merge was automatically disabled August 4, 2026 11:02

Pull request was closed

@mratsim mratsim reopened this Aug 4, 2026
@mratsim

mratsim commented Aug 4, 2026

Copy link
Copy Markdown
Owner

The go tests are done first and are passing. The issue left seems to be a regression in an unreleased Nim v2.2.x that affects unit tests but not integration tests or building the static library so merging. Regression tracked in #628.

@mratsim
mratsim merged commit de33a00 into mratsim:master Aug 4, 2026
1 of 9 checks passed
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