Skip to content

refactor(codegen): migrate bb.js BB API codegen to ipc-codegen#23316

Open
charlielye wants to merge 8 commits into
cl/ipc-codegenfrom
cl/ipc-codegen-migrate-bb-wsdb
Open

refactor(codegen): migrate bb.js BB API codegen to ipc-codegen#23316
charlielye wants to merge 8 commits into
cl/ipc-codegenfrom
cl/ipc-codegen-migrate-bb-wsdb

Conversation

@charlielye
Copy link
Copy Markdown
Contributor

Summary

Stack A PR2 of the two-stack codegen migration (see `/mnt/user-data/charlie/.claude/plans/glittery-snuggling-horizon.md`).

Swaps the bb.js core BB API binding producer from `barretenberg/ts/src/cbind/generate.ts` (legacy schema-visitor) to the new `ipc-codegen/` package introduced in #23314. The output landing place (`barretenberg/ts/src/cbind/generated/`) and the exported names (`AsyncApi`, `SyncApi`, `ChonkProof`, etc.) are unchanged, so consumers in `barretenberg/ts/src/barretenberg/` and `bbapi/` compile without modification.

What this lands

  • `barretenberg/ts/package.json`: `yarn generate` now invokes `ipc-codegen/bootstrap.sh generate`
  • `ipc-codegen/bootstrap.sh`: adds the bb-schema generation invocation
  • `ipc-codegen/schemas/bb_schema.json`: refreshed from current bb binary — introduces fields like `ChonkComputeVk.use_zk_flavor` and the `AvmStat` type that bb.js consumers depend on
  • `ipc-codegen/scripts/update_schemas.sh`: path fixes after the package relocation in PR1

Out of scope (deferred)

  • WSDB codegen migration: the new wsdb codegen output triggers a `SERIALIZATION_FIELDS` macro redefinition error against `barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp`. The fix is the `#ifndef` guard in msgpack.hpp that lands in the wire/domain refactor PR (Stack B). Moving WSDB migration there bundles all the prerequisites together.
  • Deleting `cbind/`: the directory stays in-tree because the IPC stack (cl/ipc-4-avm-binary onwards) still has `aztec-cdb/generate.ts` and `aztec-avm/generate.ts` that import from it. Final deletion follows once all four service consumers (bb, wsdb, cdb, avm) migrate.

Local verification

  • `yarn workspace barretenberg/ts build:esm` → exit 0 (TS build green with new bindings)
  • `yarn generate` from `barretenberg/ts/` → produces `cbind/generated/*.ts` via ipc-codegen
  • `./bootstrap.sh test` in `ipc-codegen/` → 18/18 echo wire-compat tests still pass

Test plan

  • bb.js builds with new generated bindings
  • yarn generate works through ipc-codegen
  • echo wire-compat matrix still green
  • CI green on this PR

@charlielye charlielye force-pushed the cl/ipc-codegen-migrate-bb-wsdb branch 6 times, most recently from f8c3cd3 to f5f4f12 Compare May 15, 2026 19:58
@charlielye charlielye force-pushed the cl/ipc-codegen-migrate-bb-wsdb branch from f5f4f12 to 905a0cb Compare May 15, 2026 20:05
@charlielye charlielye force-pushed the cl/ipc-codegen-migrate-bb-wsdb branch from 905a0cb to be99316 Compare May 18, 2026 16:43
Swap the bb.js core BB API binding producer from barretenberg/ts/src/cbind/
to the new ipc-codegen package. Consumers in barretenberg/ts/src/barretenberg/
and bbapi/ continue to import from cbind/generated/ — only the producer changes.

Changes:
- barretenberg/ts/package.json: "generate" script now invokes ipc-codegen/bootstrap.sh
- ipc-codegen/bootstrap.sh: add bb-schema generation
- ipc-codegen/schemas/bb_schema.json: refresh from current bb binary (introduces
  new fields like ChonkComputeVk.use_zk_flavor and the AvmStat type that
  consumers depend on)
- ipc-codegen/scripts/update_schemas.sh: fix paths after the codegen package
  relocation from barretenberg/codegen/ to ipc-codegen/

Out of scope:
- WSDB migration: requires the SERIALIZATION_FIELDS undef guard in
  barretenberg/cpp/src/barretenberg/serialize/msgpack.hpp before the new
  wsdb codegen output can compile. That lands in the wire/domain refactor
  PR for WSDB on the IPC stack.
- Deletion of barretenberg/ts/src/cbind/: the directory's generator sources
  remain in-tree because the IPC stack (cl/ipc-4-avm-binary onwards) still
  has aztec-cdb/generate.ts and aztec-avm/generate.ts that import from it.
  Final deletion follows once all four service consumers migrate.

Verify:
- yarn workspace barretenberg/ts build:esm  # bb.js TS build green
- yarn generate                              # produces cbind/generated/*.ts via ipc-codegen
@charlielye charlielye force-pushed the cl/ipc-codegen-migrate-bb-wsdb branch from be99316 to 96184d9 Compare May 18, 2026 17:14
…t output

The previous PR2 commit replaced `yarn generate` with just the ipc-codegen
build + aztec-wsdb generation. That dropped the Rust bindings cbind/generate.ts
emits to barretenberg/rust/barretenberg-rs/src/{api,generated_types}.rs,
which barretenberg-rs/src/lib.rs declares as `pub mod api;` and
`pub mod generated_types;`. cargo build then failed with E0583
"file not found for module" in CI.

Run cbind/generate.ts first (produces Rust + an initial TS pass), then
ipc-codegen (overwrites cbind/generated/* with the ipc-codegen output),
then aztec-wsdb/generate.ts. Order matters: ipc-codegen runs AFTER cbind
so its TS output wins; the Rust files are only written by cbind so they
survive. A follow-up PR can migrate the Rust side and finally remove
cbind/generate.ts.
…e.ts

PR2's stated goal was to replace cbind/generate.ts with ipc-codegen for
the BB API. The previous version of this PR only migrated the TS side
and kept cbind/generate.ts in `yarn generate` to produce the Rust
bindings. This commit finishes the job:

- ipc-codegen/bootstrap.sh: add `gen --lang rust --uds --prefix Bb` for
  bb_schema.json, writing to barretenberg-rs/src/generated/. The --uds
  flag is what pulls in the Backend trait and IpcError templates the
  generated client imports.
- barretenberg-rs/src/lib.rs: declare `pub mod generated { ... }` and
  re-export under the existing public-API names (BarretenbergApi,
  BarretenbergError, Backend, Fr, Command, Response, etc.) so the 230+
  external references don't move.
- Delete the now-redundant hand-written src/{backend,error,types}.rs:
  - backend.rs is byte-identical to the ipc-codegen template (modulo
    `crate::error::Result` vs `super::error::Result`).
  - error.rs is the same enum, just under a different name (IpcError vs
    BarretenbergError) — re-exported with `as BarretenbergError`.
  - types.rs's `Fr` is now produced by the codegen; its extension
    methods (from_u64, from_be_bytes, from_buffer, to_buffer, ...) move
    to a new src/fr_ext.rs as an extra `impl Fr` block. `Point` is no
    longer exported anywhere; existing curve points (GrumpkinPoint,
    Secp256k1Point, etc.) come from the generated bb_types.
- backends/{pipe,ffi}.rs: update imports from the old `crate::error::*`
  / `crate::backend::*` / `crate::api::*` paths to the lib-root
  re-exports.
- ts/package.json: drop `ts-node src/cbind/generate.ts` from `yarn
  generate`. The remaining pipeline is ipc-codegen (TS + Rust) then
  aztec-wsdb/generate.ts (still on cbind libs; that's a separate
  follow-up).
- barretenberg/.gitignore: drop the now-obsolete legacy paths
  (`src/generated_types.rs`, `src/api.rs`); the `**/generated/` rule
  covers the new layout.

Verify:
- yarn workspace bb.js build:esm
- (cd barretenberg/rust && BB_LIB_DIR=<...> cargo build --release)
@charlielye charlielye force-pushed the cl/ipc-codegen-migrate-bb-wsdb branch from 1211029 to a048306 Compare May 18, 2026 20:41
…egen's

barretenberg-rs/src/backends/ffi.rs and ipc-codegen/templates/rust/ffi_backend.rs
were already 163 lines of nearly-byte-identical code — same extern "C" fn
bbapi signature, same FfiBackend struct, same trait impl, same test block.
Add --ffi to the ipc-codegen call so the template lands at
barretenberg-rs/src/generated/ffi_backend.rs, declare it as a feature-gated
module under crate::generated, and re-export it from `pub mod backends`
to preserve the existing `barretenberg_rs::backends::FfiBackend` path.

External users (incl. iOS apps consuming FfiBackend via FFI into
libbarretenberg.a) see the same public API.

The pipe backend stays hand-written — there's no `pipe_backend` template,
and spawning a subprocess is barretenberg-rs-specific anyway.
…ration

The earlier "migrate to ipc-codegen" commit moved the generated Rust
sources from barretenberg-rs/src/{api,generated_types}.rs into
barretenberg-rs/src/generated/{bb_client,bb_types}.rs (alongside the
template-copied backend.rs/error.rs/ffi_backend.rs/uds_backend.rs).

barretenberg/rust/bootstrap.sh still referenced the old single-file
paths in two places:
- cache_upload listed the obsolete files, so tar exited 1 with
  "Cannot stat: barretenberg-rs/src/generated_types.rs" after the
  successful cargo build, failing the bb-rs bootstrap.
- release() checked for the old paths to decide whether to re-run
  `yarn generate`.

Switch both to the new directory layout: `barretenberg-rs/src/generated`
(for cache_upload) and `bb_client.rs` / `bb_types.rs` (for the existence
check). cargo build itself was already passing; this is purely the
cache-upload glue.
The ipc-codegen Rust bindings expose ECDSA/Schnorr signature components
and BN254 G2 coordinates as typed Fr (32-byte newtype) where the legacy
cbind-generated api.rs used Vec<u8> / [u8; 32] directly. The lib itself
compiled, but barretenberg-tests' FFI tests failed because they were:

- Calling .len() on Fr (now needs .0.len() to access the inner [u8; 32]).
- Passing &Fr where the generated verify methods take Fr by value.
- Building Bn254G2Point from raw vec![...] literals (now needs
  Fr::from_be_bytes([...])).

Mechanical adaptation only — no behavioral change. Tests link and
the unittest binaries build under cargo test --features ffi.
ipc-codegen now generates wsdb's C++ and TS clients from the committed
wsdb_schema.json. The aztec-wsdb server binary is unchanged on next — its
hand-written SERIALIZATION_FIELDS still define the canonical wire format,
and the schema was extracted from it, so both producers emit byte-compatible
clients and the server keeps speaking the same protocol.

C++ client:
- Lift wsdb_ipc_merkle_db.cpp from cl/more_ipc_v2: adds inline wire<->domain
  conversion helpers (fr_to_wire, fr_from_wire, fr_vec_from_wire,
  revision_to_wire, tree_id_to_wire) and threads them through every call
  site. Public interface unchanged.
- wsdb/CMakeLists.txt now compiles generated/wsdb_ipc_client.cpp (from
  ipc-codegen) instead of the legacy hand-emitted wsdb_ipc_client_generated.cpp.

TS:
- ipc-codegen emits aztec-wsdb's TS client to barretenberg/ts/src/aztec-wsdb/generated/
  (same path the previous cbind-based pipeline used).
- aztec-wsdb/index.ts re-exports of AsyncApi + api_types continue to resolve.

Deletions:
- barretenberg/ts/src/cbind/ (legacy multi-language codegen — superseded by
  ipc-codegen for every remaining consumer).
- barretenberg/ts/src/aztec-wsdb/generate.ts (driver for the deleted cbind/).
- yarn-project/world-state/src/native/ipc_world_state_instance.ts (dead code
  on next; the IPC stack re-adds it against the new generated shape during
  its cutover).
generate.ts wrote the cpp templates (msgpack_struct_map_impl.hpp,
ipc_client.hpp, ipc_server.hpp) verbatim via copyTemplate without pushing
them through formatCpp. When ipc-codegen's output landed under
barretenberg/cpp/src/.../generated/, the project-wide format-check
caught the LLVM-default formatting of those templates and failed.

Add the copied template paths to cppFiles so formatCpp picks them up
alongside the generated client/server source. clang-format walks up from
each file path, so the destination's .clang-format gets applied
correctly for each consumer.
@AztecBot
Copy link
Copy Markdown
Collaborator

Flakey Tests

🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/f41a8ccb6fdf4a0d�f41a8ccb6fdf4a0d8;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_epochs/epochs_high_tps_block_building.test.ts (306s) (code: 0) group:e2e-p2p-epoch-flakes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants