Skip to content

Add real EIP-4844 KZG support (vendored blst + c-kzg-4844)#99

Merged
koko1123 merged 2 commits into
mainfrom
feat/kzg-4844
Jun 11, 2026
Merged

Add real EIP-4844 KZG support (vendored blst + c-kzg-4844)#99
koko1123 merged 2 commits into
mainfrom
feat/kzg-4844

Conversation

@koko1123

@koko1123 koko1123 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Why

Closes the one genuine client-library feature gap vs Voltaire: building a blob-transaction sidecar from raw blob data. We had blob types + versioned-hash computation but no KZG commitment/proof crypto. This is real, vector-verified KZG -- no stubs.

What

  • Vendored blst v0.3.14 (portable no-asm C) and c-kzg-4844 v2.1.1 under src/crypto/blst/src/crypto/c-kzg, matching the existing secp256k1/XKCP vendoring (zero external deps). build.zig gains addKzg; .paths updated.
    • Build hurdle solved honestly: blst's pure-C backend only defines llimb_t for 32-bit limbs, but vect.h selects 64-bit on aarch64 before the no-asm branch. A small, commented vect.h patch hoists the __BLST_NO_ASM__ branch above the arch branch, so -D__BLST_NO_ASM__ yields the pure-C backend on every target -- no per-arch assembly to vendor.
  • src/kzg.zig (eth.kzg): init/deinit load the embedded mainnet trusted setup via fmemopen over @embedFile (no disk access, idempotent once-guard); blobToKzgCommitment, computeBlobKzgProof, verifyBlobKzgProof, verifyBlobKzgProofBatch. blob.buildSidecar(raw_blob) -> commitment + proof + versioned hash.

Correctness (vector-verified)

The official c-kzg-4844 v2.1.1 test vectors are embedded and asserted byte-for-byte: blob_to_kzg_commitment and compute_blob_kzg_proof reproduce the official output exactly, and verify_blob_kzg_proof returns true/false for the correct/incorrect vectors. Plus round-trip, batch, versioned-hash, and lifecycle tests.

Verification

839/839 tests pass on 0.16.0 with a clean build compiling blst + c-kzg from scratch; fmt clean; docs build (new kzg.mdx). Note: the first clean build now compiles blst (~2 min), then caches.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • kzg module: EIP-4844 KZG support — initialize/deinitialize trusted setup, compute/verify commitments & proofs, batch verification, build blob sidecars, and derive versioned hashes; validated against official test vectors.
    • abigen module: compile-time Solidity ABI bindings with typed call/event decoding helpers.
  • Documentation

    • Added detailed KZG docs and updated README to mark EIP-4844 KZG as Complete.
  • Tests

    • Added vector-based and lifecycle tests covering init/deinit, round-trip, tamper detection, and batch verification.

@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
eth-zig Ready Ready Preview, Comment Jun 11, 2026 5:40pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f8b0698b-4a3d-43bc-9c7d-5e01fa073168

📥 Commits

Reviewing files that changed from the base of the PR and between 0d452a1 and 67b79ea.

📒 Files selected for processing (91)
  • CHANGELOG.md
  • README.md
  • build.zig
  • build.zig.zon
  • docs/content/docs/kzg.mdx
  • docs/content/docs/meta.json
  • src/blob.zig
  • src/crypto/blst/LICENSE
  • src/crypto/blst/bindings/blst.h
  • src/crypto/blst/bindings/blst_aux.h
  • src/crypto/blst/src/aggregate.c
  • src/crypto/blst/src/bulk_addition.c
  • src/crypto/blst/src/bytes.h
  • src/crypto/blst/src/client_min_pk.c
  • src/crypto/blst/src/client_min_sig.c
  • src/crypto/blst/src/consts.c
  • src/crypto/blst/src/consts.h
  • src/crypto/blst/src/cpuid.c
  • src/crypto/blst/src/e1.c
  • src/crypto/blst/src/e2.c
  • src/crypto/blst/src/ec_mult.h
  • src/crypto/blst/src/ec_ops.h
  • src/crypto/blst/src/errors.h
  • src/crypto/blst/src/exp.c
  • src/crypto/blst/src/exports.c
  • src/crypto/blst/src/fields.h
  • src/crypto/blst/src/fp12_tower.c
  • src/crypto/blst/src/hash_to_field.c
  • src/crypto/blst/src/keygen.c
  • src/crypto/blst/src/map_to_g1.c
  • src/crypto/blst/src/map_to_g2.c
  • src/crypto/blst/src/multi_scalar.c
  • src/crypto/blst/src/no_asm.h
  • src/crypto/blst/src/pairing.c
  • src/crypto/blst/src/pentaroot-addchain.h
  • src/crypto/blst/src/pentaroot.c
  • src/crypto/blst/src/point.h
  • src/crypto/blst/src/rb_tree.c
  • src/crypto/blst/src/recip-addchain.h
  • src/crypto/blst/src/recip.c
  • src/crypto/blst/src/server.c
  • src/crypto/blst/src/sha256.h
  • src/crypto/blst/src/sqrt-addchain.h
  • src/crypto/blst/src/sqrt.c
  • src/crypto/blst/src/vect.c
  • src/crypto/blst/src/vect.h
  • src/crypto/c-kzg/LICENSE
  • src/crypto/c-kzg/VENDOR.md
  • src/crypto/c-kzg/src/ckzg.c
  • src/crypto/c-kzg/src/ckzg.h
  • src/crypto/c-kzg/src/common/alloc.c
  • src/crypto/c-kzg/src/common/alloc.h
  • src/crypto/c-kzg/src/common/bytes.c
  • src/crypto/c-kzg/src/common/bytes.h
  • src/crypto/c-kzg/src/common/ec.c
  • src/crypto/c-kzg/src/common/ec.h
  • src/crypto/c-kzg/src/common/fr.c
  • src/crypto/c-kzg/src/common/fr.h
  • src/crypto/c-kzg/src/common/lincomb.c
  • src/crypto/c-kzg/src/common/lincomb.h
  • src/crypto/c-kzg/src/common/ret.h
  • src/crypto/c-kzg/src/common/utils.c
  • src/crypto/c-kzg/src/common/utils.h
  • src/crypto/c-kzg/src/eip4844/blob.c
  • src/crypto/c-kzg/src/eip4844/blob.h
  • src/crypto/c-kzg/src/eip4844/eip4844.c
  • src/crypto/c-kzg/src/eip4844/eip4844.h
  • src/crypto/c-kzg/src/eip7594/cell.c
  • src/crypto/c-kzg/src/eip7594/cell.h
  • src/crypto/c-kzg/src/eip7594/eip7594.c
  • src/crypto/c-kzg/src/eip7594/eip7594.h
  • src/crypto/c-kzg/src/eip7594/fft.c
  • src/crypto/c-kzg/src/eip7594/fft.h
  • src/crypto/c-kzg/src/eip7594/fk20.c
  • src/crypto/c-kzg/src/eip7594/fk20.h
  • src/crypto/c-kzg/src/eip7594/poly.c
  • src/crypto/c-kzg/src/eip7594/poly.h
  • src/crypto/c-kzg/src/eip7594/recovery.c
  • src/crypto/c-kzg/src/eip7594/recovery.h
  • src/crypto/c-kzg/src/setup/settings.h
  • src/crypto/c-kzg/src/setup/setup.c
  • src/crypto/c-kzg/src/setup/setup.h
  • src/crypto/c-kzg/src/trusted_setup.txt
  • src/crypto/c-kzg/test_vectors/ATTRIBUTION.md
  • src/crypto/c-kzg/test_vectors/blob_to_kzg_commitment_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/compute_blob_kzg_proof_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/verify_blob_kzg_proof_correct_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/verify_blob_kzg_proof_incorrect_19b3f3f8c98ea31e.yaml
  • src/kzg.zig
  • src/kzg_vectors_test.zig
  • src/root.zig
✅ Files skipped from review due to trivial changes (6)
  • src/crypto/blst/LICENSE
  • docs/content/docs/meta.json
  • src/crypto/c-kzg/test_vectors/ATTRIBUTION.md
  • src/crypto/c-kzg/LICENSE
  • docs/content/docs/kzg.mdx
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (62)
  • README.md
  • build.zig.zon
  • src/crypto/c-kzg/src/eip7594/poly.h
  • src/crypto/c-kzg/src/eip7594/fk20.h
  • src/crypto/c-kzg/src/eip7594/cell.c
  • src/crypto/c-kzg/src/eip7594/fft.h
  • src/crypto/blst/src/errors.h
  • src/root.zig
  • src/crypto/c-kzg/src/common/ret.h
  • src/crypto/blst/src/server.c
  • src/crypto/c-kzg/src/common/utils.h
  • src/crypto/blst/src/client_min_sig.c
  • src/crypto/c-kzg/src/setup/settings.h
  • src/crypto/c-kzg/src/eip4844/blob.h
  • src/crypto/blst/src/pentaroot-addchain.h
  • src/crypto/c-kzg/src/ckzg.h
  • src/crypto/c-kzg/src/eip7594/eip7594.h
  • src/crypto/c-kzg/src/eip7594/recovery.h
  • src/crypto/c-kzg/src/eip4844/eip4844.h
  • src/crypto/c-kzg/src/setup/setup.h
  • src/blob.zig
  • src/crypto/blst/src/recip-addchain.h
  • src/crypto/blst/src/client_min_pk.c
  • src/crypto/c-kzg/src/common/ec.c
  • src/crypto/c-kzg/src/eip7594/fk20.c
  • src/crypto/blst/src/rb_tree.c
  • build.zig
  • src/crypto/c-kzg/src/eip7594/cell.h
  • src/crypto/c-kzg/src/common/lincomb.c
  • src/crypto/c-kzg/src/common/bytes.h
  • src/crypto/blst/src/point.h
  • src/crypto/blst/src/recip.c
  • src/crypto/c-kzg/src/common/alloc.h
  • src/crypto/blst/src/consts.h
  • src/crypto/blst/src/hash_to_field.c
  • src/crypto/c-kzg/src/common/lincomb.h
  • src/crypto/c-kzg/src/common/utils.c
  • src/crypto/c-kzg/src/common/fr.c
  • src/crypto/c-kzg/src/common/alloc.c
  • src/crypto/c-kzg/src/common/bytes.c
  • src/crypto/blst/src/consts.c
  • src/crypto/c-kzg/src/eip4844/blob.c
  • src/kzg_vectors_test.zig
  • src/crypto/c-kzg/src/common/fr.h
  • src/crypto/blst/src/cpuid.c
  • src/crypto/c-kzg/src/eip7594/poly.c
  • src/crypto/blst/src/pentaroot.c
  • src/crypto/blst/src/fields.h
  • src/crypto/blst/src/exp.c
  • src/crypto/blst/src/sqrt-addchain.h
  • src/crypto/blst/src/sqrt.c
  • src/crypto/c-kzg/src/eip7594/fft.c
  • src/crypto/c-kzg/src/eip7594/recovery.c
  • src/crypto/blst/src/sha256.h
  • src/kzg.zig
  • src/crypto/c-kzg/src/common/ec.h
  • src/crypto/c-kzg/src/eip7594/eip7594.c
  • src/crypto/blst/bindings/blst.h
  • src/crypto/blst/src/ec_ops.h
  • src/crypto/blst/src/fp12_tower.c
  • src/crypto/blst/src/vect.h
  • src/crypto/c-kzg/src/setup/setup.c

📝 Walkthrough

Walkthrough

Adds vendored BLST and c-kzg sources, wires them into the build, and exposes KZG/EIP-4844 and EIP-7594 APIs through C and Zig wrappers. It also adds docs, tests, vendor/license files, and a Blob sidecar builder.

Changes

Vendored KZG and BLST stack

Layer / File(s) Summary
Public docs and build wiring
CHANGELOG.md, README.md, build.zig, build.zig.zon, docs/content/docs/kzg.mdx, docs/content/docs/meta.json, src/crypto/c-kzg/LICENSE, src/crypto/c-kzg/VENDOR.md, src/crypto/blst/LICENSE, src/crypto/c-kzg/test_vectors/ATTRIBUTION.md, src/root.zig
kzg is added to build metadata, docs, and top-level module exports, and the vendored source paths and licenses are included.
BLST public headers and types
src/crypto/blst/bindings/blst.h, src/crypto/blst/bindings/blst_aux.h, src/crypto/blst/src/point.h, src/crypto/blst/src/vect.h, src/crypto/blst/src/fields.h, src/crypto/blst/src/errors.h, src/crypto/blst/src/consts.h, src/crypto/blst/src/sha256.h, src/crypto/blst/src/bytes.h, src/crypto/blst/src/ec_mult.h, src/crypto/blst/src/ec_ops.h
The BLST headers define exported scalar, field, point, pairing, and helper APIs plus the macro-generated point and arithmetic contracts used by the sources.
BLST core arithmetic and pairing
src/crypto/blst/src/exports.c, src/crypto/blst/src/e1.c, src/crypto/blst/src/e2.c, src/crypto/blst/src/map_to_g1.c, src/crypto/blst/src/map_to_g2.c, src/crypto/blst/src/hash_to_field.c, src/crypto/blst/src/keygen.c, src/crypto/blst/src/pairing.c, src/crypto/blst/src/fp12_tower.c, src/crypto/blst/src/recip.c, src/crypto/blst/src/sqrt.c, src/crypto/blst/src/pentaroot.c, src/crypto/blst/src/pentaroot-addchain.h, src/crypto/blst/src/recip-addchain.h, src/crypto/blst/src/sqrt-addchain.h, src/crypto/blst/src/exp.c
The vendored BLST implementation adds field arithmetic, curve operations, hash-to-curve, key generation, pairings, inverses, roots, and Fp12 tower operations.
BLST binaries and wrappers
src/crypto/blst/src/client_min_pk.c, src/crypto/blst/src/client_min_sig.c, src/crypto/blst/src/server.c, src/crypto/blst/src/consts.c, src/crypto/blst/src/cpuid.c, src/crypto/blst/src/no_asm.h, src/crypto/blst/src/vect.c
Wrapper translation units, constants, CPU detection, and portable no-ASM helpers are added for the vendored BLST build.
c-kzg common, EIP-4844, and setup
src/crypto/c-kzg/src/ckzg.c, src/crypto/c-kzg/src/ckzg.h, src/crypto/c-kzg/src/common/*, src/crypto/c-kzg/src/eip4844/*, src/crypto/c-kzg/src/setup/*
The vendored c-kzg code adds common allocation, byte, field, utility, EIP-4844, and setup code for blob commitments and proofs.
EIP-7594 proof and recovery flow
src/crypto/c-kzg/src/eip7594/*
The EIP-7594 code adds FFT, FK20 proof generation, polynomial transforms, cell recovery, and batch verification.
Zig wrapper and vector tests
src/kzg.zig, src/kzg_vectors_test.zig, src/blob.zig
The Zig wrapper initializes trusted setup state, exposes KZG APIs, adds buildSidecar, and includes vector-based interop tests against official c-kzg vectors.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~90+ minutes

Poem

🐰 I hop through hashes, fields, and proofs,
Past roots of unity and trusted roofs.
A carrot bright, a sidecar neat,
KZG twirls on little bunny feet.
Hop hop—commit, verify, repeat!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/kzg-4844

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/kzg.zig (1)

342-348: 💤 Low value

Comment mentions restoration but no code follows.

The comment at line 347-348 says "Restore for any subsequent ordering-independent tests" but there's no actual restoration code. While other tests call init() at their start anyway, consider either removing the misleading comment or adding the restoration:

💡 Option: Remove misleading comment
 test "kzg verify rejects when not initialized" {
     // Ensure clean state for this test.
     deinit();
     var blob: Blob = `@splat`(0);
     try testing.expectError(error.NotInitialized, blobToKzgCommitment(&blob));
-    // Restore for any subsequent ordering-independent tests.
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/kzg.zig` around lines 342 - 348, The trailing comment "Restore for any
subsequent ordering-independent tests" in the test "kzg verify rejects when not
initialized" is misleading because no restoration occurs; fix by either removing
that comment or actually restoring the global state by calling init() at the end
of this test (after the testing.expectError call) so subsequent tests have the
expected initialized state; locate the test block around the deinit() and
blobToKzgCommitment(&blob) usage and apply one of those two changes.
src/crypto/blst/src/e2.c (1)

260-260: src/crypto/blst/src/e2.c: Line 260 BLS12_381_Rx.p is effectively equivalent to BLS12_381_Rx.p2 for POINTonE2::Z

POINTonE2::Z is vec384x (FP2: vec384x[2]), and vec_is_equal compares bytes over sizeof(in->Z). BLS12_381_Rx is a union where .p and .p2 share the same underlying storage, with the FP2 “one” laid out as (ONE_MONT_P, 0), so comparing against BLS12_381_Rx.p over vec384x bytes matches what BLS12_381_Rx.p2 would provide. Consider using .p2 here purely for consistency/readability.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/crypto/blst/src/e2.c` at line 260, The comparison uses BLS12_381_Rx.p
which is backend-equivalent to p2 but confusing for the FP2 field: update the
vec_is_equal call that compares POINTonE2::Z (a vec384x[2] FP2) to use
BLS12_381_Rx.p2 instead of BLS12_381_Rx.p for clarity/readability while keeping
the same byte-length (sizeof(in->Z)) and the same vec_is_equal usage; locate the
check around the vec_is_equal(in->Z, BLS12_381_Rx.p, sizeof(in->Z)) and replace
the right-hand operand with BLS12_381_Rx.p2.
src/crypto/blst/src/vect.h (1)

35-40: 💤 Low value

Dead code: unreachable preprocessor branch.

This #elif branch is unreachable because lines 18-24 already handle the __BLST_NO_ASM__ and __wasm64__ cases. The condition at line 35 can never be true.

This is harmless and likely an artifact of the patch described in lines 11-17. Could be removed for clarity, but not required.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/crypto/blst/src/vect.h` around lines 35 - 40, The preprocessor branch
that typedefs limb_t and defines LIMB_T_BITS and __BLST_NO_ASM__ is unreachable
because __BLST_NO_ASM__ and __wasm64__ are already handled earlier; remove the
redundant `#elif` block (the typedef unsigned int limb_t, # define LIMB_T_BITS 32
and the # define __BLST_NO_ASM__ inside it) to eliminate dead code and avoid
confusing duplicated definitions, ensuring any remaining references to limb_t
and LIMB_T_BITS come from the intended earlier branch.
src/crypto/blst/src/pairing.c (1)

427-429: 💤 Low value

Potential undefined behavior with NULL pointer arithmetic (vendored code).

If the first element of Qs or Ps arrays is NULL, this performs NULL+1 since Qptr/Pptr are initialized to NULL on lines 423-424. Per the C standard, pointer arithmetic on NULL is undefined behavior.

This appears to be intentional API design where NULL means "contiguous from previous," implying the caller must ensure the first element is non-NULL. Given this is vendored blst code with established usage patterns, no change is recommended, but worth noting if issues arise during integration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/crypto/blst/src/pairing.c` around lines 427 - 429, The loop using Qptr
and Pptr risks NULL pointer arithmetic when the first element of Qs or Ps is
NULL; update the initialization and loop in pairing.c so Qptr and Pptr are
initialized from the first array element (e.g., set Qptr = *Qs ? *Qs : NULL and
similarly for Pptr) and then within the for-loop use conditional logic that
advances via pointer arithmetic only when the previous pointer is non-NULL
(i.e., if (*Qs) use *Qs++ else if (Qptr) Qptr = Qptr+1; same for Ps), or
alternatively require and assert the first element is non-NULL before entering
the loop to avoid NULL+1 undefined behavior; reference Qptr, Pptr, Qs, Ps and
the for (i = 0, j = 0; j < n; j++) loop when making changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/crypto/c-kzg/src/eip7594/fft.c`:
- Around line 267-277: Both coset_fft and poly_lagrange_to_monomial allocate
buffers (e.g., call new_fr_array to create in_shifted) before validating the
input length; move the length validation to the top of each function so invalid
n (or related length parameters) are checked and return an error code before any
heap allocation. Specifically, in functions coset_fft and
poly_lagrange_to_monomial, validate the polynomial length arguments (n and any
dependent sizes) and return C_KZG_BAD_ARGS (or the function's error) immediately
if invalid, then proceed to call new_fr_array and other allocation/processing
(e.g., creating in_shifted, calling shift_poly and fr_fft) only after the checks
pass. Ensure all early-return paths consistently free nothing (since nothing
allocated) and maintain existing error codes.

In `@src/kzg.zig`:
- Around line 197-201: The deinit() function has a TOCTOU race: replace the
plain load-check with an atomic compare-and-exchange on init_state so only one
caller transitions the state (e.g., STATE_READY -> STATE_DEINITIALIZING or
STATE_UNINIT) and performs free_trusted_setup(&settings); use `@atomicCmpxchg`
(cmpxchgStrong semantics) against init_state and only call free_trusted_setup
when your cmpxchg succeeded; ensure you store the final STATE_UNINIT (with
.release) after the free, and leave other callers returning early when their
cmpxchg fails.

---

Nitpick comments:
In `@src/crypto/blst/src/e2.c`:
- Line 260: The comparison uses BLS12_381_Rx.p which is backend-equivalent to p2
but confusing for the FP2 field: update the vec_is_equal call that compares
POINTonE2::Z (a vec384x[2] FP2) to use BLS12_381_Rx.p2 instead of BLS12_381_Rx.p
for clarity/readability while keeping the same byte-length (sizeof(in->Z)) and
the same vec_is_equal usage; locate the check around the vec_is_equal(in->Z,
BLS12_381_Rx.p, sizeof(in->Z)) and replace the right-hand operand with
BLS12_381_Rx.p2.

In `@src/crypto/blst/src/pairing.c`:
- Around line 427-429: The loop using Qptr and Pptr risks NULL pointer
arithmetic when the first element of Qs or Ps is NULL; update the initialization
and loop in pairing.c so Qptr and Pptr are initialized from the first array
element (e.g., set Qptr = *Qs ? *Qs : NULL and similarly for Pptr) and then
within the for-loop use conditional logic that advances via pointer arithmetic
only when the previous pointer is non-NULL (i.e., if (*Qs) use *Qs++ else if
(Qptr) Qptr = Qptr+1; same for Ps), or alternatively require and assert the
first element is non-NULL before entering the loop to avoid NULL+1 undefined
behavior; reference Qptr, Pptr, Qs, Ps and the for (i = 0, j = 0; j < n; j++)
loop when making changes.

In `@src/crypto/blst/src/vect.h`:
- Around line 35-40: The preprocessor branch that typedefs limb_t and defines
LIMB_T_BITS and __BLST_NO_ASM__ is unreachable because __BLST_NO_ASM__ and
__wasm64__ are already handled earlier; remove the redundant `#elif` block (the
typedef unsigned int limb_t, # define LIMB_T_BITS 32 and the # define
__BLST_NO_ASM__ inside it) to eliminate dead code and avoid confusing duplicated
definitions, ensuring any remaining references to limb_t and LIMB_T_BITS come
from the intended earlier branch.

In `@src/kzg.zig`:
- Around line 342-348: The trailing comment "Restore for any subsequent
ordering-independent tests" in the test "kzg verify rejects when not
initialized" is misleading because no restoration occurs; fix by either removing
that comment or actually restoring the global state by calling init() at the end
of this test (after the testing.expectError call) so subsequent tests have the
expected initialized state; locate the test block around the deinit() and
blobToKzgCommitment(&blob) usage and apply one of those two changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f946411-13c3-468a-9915-2e196324c93d

📥 Commits

Reviewing files that changed from the base of the PR and between b735c86 and 3c76906.

📒 Files selected for processing (91)
  • CHANGELOG.md
  • README.md
  • build.zig
  • build.zig.zon
  • docs/content/docs/kzg.mdx
  • docs/content/docs/meta.json
  • src/blob.zig
  • src/crypto/blst/LICENSE
  • src/crypto/blst/bindings/blst.h
  • src/crypto/blst/bindings/blst_aux.h
  • src/crypto/blst/src/aggregate.c
  • src/crypto/blst/src/bulk_addition.c
  • src/crypto/blst/src/bytes.h
  • src/crypto/blst/src/client_min_pk.c
  • src/crypto/blst/src/client_min_sig.c
  • src/crypto/blst/src/consts.c
  • src/crypto/blst/src/consts.h
  • src/crypto/blst/src/cpuid.c
  • src/crypto/blst/src/e1.c
  • src/crypto/blst/src/e2.c
  • src/crypto/blst/src/ec_mult.h
  • src/crypto/blst/src/ec_ops.h
  • src/crypto/blst/src/errors.h
  • src/crypto/blst/src/exp.c
  • src/crypto/blst/src/exports.c
  • src/crypto/blst/src/fields.h
  • src/crypto/blst/src/fp12_tower.c
  • src/crypto/blst/src/hash_to_field.c
  • src/crypto/blst/src/keygen.c
  • src/crypto/blst/src/map_to_g1.c
  • src/crypto/blst/src/map_to_g2.c
  • src/crypto/blst/src/multi_scalar.c
  • src/crypto/blst/src/no_asm.h
  • src/crypto/blst/src/pairing.c
  • src/crypto/blst/src/pentaroot-addchain.h
  • src/crypto/blst/src/pentaroot.c
  • src/crypto/blst/src/point.h
  • src/crypto/blst/src/rb_tree.c
  • src/crypto/blst/src/recip-addchain.h
  • src/crypto/blst/src/recip.c
  • src/crypto/blst/src/server.c
  • src/crypto/blst/src/sha256.h
  • src/crypto/blst/src/sqrt-addchain.h
  • src/crypto/blst/src/sqrt.c
  • src/crypto/blst/src/vect.c
  • src/crypto/blst/src/vect.h
  • src/crypto/c-kzg/LICENSE
  • src/crypto/c-kzg/VENDOR.md
  • src/crypto/c-kzg/src/ckzg.c
  • src/crypto/c-kzg/src/ckzg.h
  • src/crypto/c-kzg/src/common/alloc.c
  • src/crypto/c-kzg/src/common/alloc.h
  • src/crypto/c-kzg/src/common/bytes.c
  • src/crypto/c-kzg/src/common/bytes.h
  • src/crypto/c-kzg/src/common/ec.c
  • src/crypto/c-kzg/src/common/ec.h
  • src/crypto/c-kzg/src/common/fr.c
  • src/crypto/c-kzg/src/common/fr.h
  • src/crypto/c-kzg/src/common/lincomb.c
  • src/crypto/c-kzg/src/common/lincomb.h
  • src/crypto/c-kzg/src/common/ret.h
  • src/crypto/c-kzg/src/common/utils.c
  • src/crypto/c-kzg/src/common/utils.h
  • src/crypto/c-kzg/src/eip4844/blob.c
  • src/crypto/c-kzg/src/eip4844/blob.h
  • src/crypto/c-kzg/src/eip4844/eip4844.c
  • src/crypto/c-kzg/src/eip4844/eip4844.h
  • src/crypto/c-kzg/src/eip7594/cell.c
  • src/crypto/c-kzg/src/eip7594/cell.h
  • src/crypto/c-kzg/src/eip7594/eip7594.c
  • src/crypto/c-kzg/src/eip7594/eip7594.h
  • src/crypto/c-kzg/src/eip7594/fft.c
  • src/crypto/c-kzg/src/eip7594/fft.h
  • src/crypto/c-kzg/src/eip7594/fk20.c
  • src/crypto/c-kzg/src/eip7594/fk20.h
  • src/crypto/c-kzg/src/eip7594/poly.c
  • src/crypto/c-kzg/src/eip7594/poly.h
  • src/crypto/c-kzg/src/eip7594/recovery.c
  • src/crypto/c-kzg/src/eip7594/recovery.h
  • src/crypto/c-kzg/src/setup/settings.h
  • src/crypto/c-kzg/src/setup/setup.c
  • src/crypto/c-kzg/src/setup/setup.h
  • src/crypto/c-kzg/src/trusted_setup.txt
  • src/crypto/c-kzg/test_vectors/ATTRIBUTION.md
  • src/crypto/c-kzg/test_vectors/blob_to_kzg_commitment_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/compute_blob_kzg_proof_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/verify_blob_kzg_proof_correct_19b3f3f8c98ea31e.yaml
  • src/crypto/c-kzg/test_vectors/verify_blob_kzg_proof_incorrect_19b3f3f8c98ea31e.yaml
  • src/kzg.zig
  • src/kzg_vectors_test.zig
  • src/root.zig

Comment thread src/crypto/c-kzg/src/eip7594/fft.c
Comment thread src/kzg.zig
koko1123 added 2 commits June 11, 2026 13:37
Closes the one client-library feature gap vs Voltaire: building a blob
transaction sidecar from raw blob data. Real, vector-verified crypto --
no stubs.

- Vendored blst v0.3.14 (portable no-asm C) and c-kzg-4844 v2.1.1 under
  src/crypto/blst and src/crypto/c-kzg, matching the existing
  secp256k1/XKCP vendoring pattern. blst built with -D__BLST_NO_ASM__
  via a small documented vect.h patch that hoists the no-asm branch
  above the arch branch (the pure-C backend only defines llimb_t for
  32-bit limbs). build.zig gains addKzg; build.zig.zon .paths updated.
- src/kzg.zig (eth.kzg): init/deinit load the embedded mainnet trusted
  setup via fmemopen over @embedfile (no disk access, idempotent once-
  guard); blobToKzgCommitment, computeBlobKzgProof, verifyBlobKzgProof,
  verifyBlobKzgProofBatch over the c-kzg FFI. blob.buildSidecar wires
  raw blob -> commitment + proof + versioned hash.
- Official c-kzg-4844 v2.1.1 test vectors asserted byte-for-byte
  (blob_to_kzg_commitment / compute_blob_kzg_proof / verify both
  correct and incorrect), plus round-trip, batch, versioned-hash, and
  lifecycle tests.

839/839 tests pass on 0.16.0 (clean build compiles the C from scratch);
fmt clean; docs build (new kzg.mdx). Note: a clean build now compiles
blst (~2 min) the first time, then caches.
Two concurrent deinit() calls could both observe STATE_READY and both
call free_trusted_setup. Claim the teardown with a single
cmpxchg(READY -> UNINIT) so only the winning thread frees.
@koko1123
koko1123 merged commit 554e174 into main Jun 11, 2026
12 checks passed
@koko1123
koko1123 deleted the feat/kzg-4844 branch June 11, 2026 18:31
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.

1 participant