Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions barretenberg/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ cmake-build-debug
bench-out

# Generated code from msgpack schema (run `yarn generate` in ts/)
rust/barretenberg-rs/src/generated_types.rs
rust/barretenberg-rs/src/api.rs
rust/barretenberg-rs/src/generated/
ts/src/cbind/generated/

# Codegen output dirs (ipc-codegen emits into a `generated/` subdir under each consumer)
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ barretenberg_modules.dot
barretenberg_modules.png
src/barretenberg/bb/config.hpp
src/barretenberg/avm/generated/
src/barretenberg/bbapi/generated/
src/barretenberg/cdb/generated/
bench-out
*.bak
Expand Down
3 changes: 1 addition & 2 deletions barretenberg/cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ if(NOT FUZZING AND NOT WASM AND NOT BB_LITE)
add_subdirectory(barretenberg/world_state)
# NOTE: Do not conditionally base this on the AVM flag as it defines a necessary vm2_sim library.
add_subdirectory(barretenberg/vm2)
add_subdirectory(barretenberg/ipc)
add_subdirectory(barretenberg/wsdb)
add_subdirectory(barretenberg/vm2_wsdb)
add_subdirectory(barretenberg/cdb)
Expand Down Expand Up @@ -234,7 +233,7 @@ add_library(
)

# bb-external: static library for external consumers (e.g. barretenberg-rs).
# Uses the core object list without lmdb/world_state — FFI consumers only need bbapi().
# Uses the core object list without lmdb/world_state — FFI consumers only need ipc_ffi_entry().
# Built with -fvisibility=hidden; only WASM_EXPORT symbols remain visible.
if(NOT WASM)
add_library(
Expand Down
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ if(AVM_TRANSPILER_LIB)
endif()

if(NOT WASM AND NOT BB_LITE)
target_link_libraries(api_objects PRIVATE ipc)
target_link_libraries(api_objects PRIVATE ipc_runtime)
endif()
324 changes: 55 additions & 269 deletions barretenberg/cpp/src/barretenberg/api/api_msgpack.cpp

Large diffs are not rendered by default.

55 changes: 19 additions & 36 deletions barretenberg/cpp/src/barretenberg/api/api_msgpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,40 @@

#include <cstddef>
#include <iosfwd>
#include <memory>
#include <string>

#ifndef __wasm__
#include "barretenberg/ipc/ipc_server.hpp"
#endif

namespace bb {

/**
* @brief Process msgpack API commands from an input stream
*
* This function reads length-encoded msgpack buffers from the provided input stream,
* deserializes them into Command objects, executes them via the bbapi interface,
* and writes length-encoded responses back to stdout.
* @brief Process msgpack API commands from an input stream (offline replay / wasm).
*
* The format for each message is:
* - 4-byte length prefix (little-endian)
* - msgpack buffer of the specified length
* Reads bare length-prefixed msgpack buffers ([4-byte LE length][payload]) from
* the stream, executes them via the generated bbapi dispatch, and writes
* length-prefixed responses to stdout. This is the offline-file format; live
* transports (stdio pipe, socket, shared memory) run over ipc-runtime with its
* request-id envelope framing instead.
*
* @param input_stream The input stream to read msgpack commands from (stdin or file)
* @param input_stream The input stream to read msgpack commands from
* @return int Status code: 0 for success, non-zero for errors
*/
int process_msgpack_commands(std::istream& input_stream);

#ifndef __wasm__
/**
* @brief Execute msgpack commands over IPC
* @brief Execute the `bb msgpack run` subcommand.
*
* Runs an IPC server that accepts concurrent clients.
* Clients can send msgpack commands independently, and responses are automatically
* routed back to the correct client.
*
* @param server IPC server instance (socket or shared memory)
* @return int Status code: 0 for success, non-zero for errors
*/
int execute_msgpack_ipc_server(std::unique_ptr<ipc::IpcServer> server);
#endif

/**
* @brief Execute msgpack run command
* Input selection:
* - "" or "-" → serve the process's own stdin/stdout (ipc-runtime pipe transport)
* - "*.sock" → serve a Unix domain socket
* - "*.shm" → serve MPSC shared memory
* - existing file → offline replay of bare length-prefixed commands
*
* This function handles the msgpack run subcommand, reading commands from either
* stdin, a specified file, a Unix domain socket (if path ends in .sock), or
* shared memory IPC (if path ends in .shm).
* All live transports use the shared ipc-runtime server (request-id envelope
* framing, completion-order responses via run_reactor).
*
* @param msgpack_input_file Path to input file (empty string means use stdin,
* .sock suffix means Unix socket, .shm suffix means shared memory)
* @param max_clients Maximum number of concurrent clients for IPC servers (default: 1)
* @param request_ring_size Request ring buffer size for shared memory (default: 1MB)
* @param response_ring_size Response ring buffer size for shared memory (default: 1MB)
* @param msgpack_input_file Input path as above
* @param max_clients Maximum concurrent clients for IPC servers
* @param request_ring_size Request ring size for shared memory
* @param response_ring_size Response ring size for shared memory
* @return int Status code: 0 for success, non-zero for errors
*/
int execute_msgpack_run(const std::string& msgpack_input_file,
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/bb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (NOT(FUZZING))
target_link_libraries(bb PRIVATE avm_transpiler)
endif()
if(NOT WASM AND NOT BB_LITE)
target_link_libraries(bb PRIVATE ipc)
target_link_libraries(bb PRIVATE ipc_runtime)
endif()
if(ENABLE_STACKTRACES)
target_link_libraries(
Expand Down Expand Up @@ -63,7 +63,7 @@ if (NOT(FUZZING))
target_link_libraries(bb-avm PRIVATE avm_transpiler)
endif()
if(NOT WASM AND NOT BB_LITE)
target_link_libraries(bb-avm PRIVATE ipc)
target_link_libraries(bb-avm PRIVATE ipc_runtime)
endif()
if(ENABLE_STACKTRACES)
target_link_libraries(
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/bb/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "barretenberg/bb/cli11_formatter.hpp"
#include "barretenberg/bb/curve_constants.hpp"
#include "barretenberg/bbapi/bbapi.hpp"
#include "barretenberg/bbapi/bbapi_schema.hpp"
#include "barretenberg/bbapi/bbapi_ultra_honk.hpp"
#include "barretenberg/bbapi/c_bind.hpp"
#include "barretenberg/common/bb_bench.hpp"
Expand Down Expand Up @@ -913,7 +914,7 @@ int parse_and_run_cli_command(int argc, char* argv[])

// MSGPACK
if (msgpack_schema_command->parsed()) {
std::cout << bbapi::get_msgpack_schema_as_json() << std::endl;
std::cout << bbapi::get_bb_schema_as_json() << std::endl;
return 0;
}
if (msgpack_curve_constants_command->parsed()) {
Expand Down
50 changes: 50 additions & 0 deletions barretenberg/cpp/src/barretenberg/bbapi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,55 @@
# Generate BB IPC wire types and server dispatch from bb_schema.json (the
# checked-in wire contract). bb is the server; the clients are bb.js and
# barretenberg-rs, generated from the same file, so no C++ client is emitted.
# WASM builds consume the generated dispatch header, so codegen must run
# outside native-only blocks.
set(BB_SCHEMA ${CMAKE_CURRENT_SOURCE_DIR}/bb_schema.json)
set(BB_GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/generated)

if(NOT FUZZING)
set(BB_GEN_OUTPUTS
${BB_GEN_DIR}/bb_dispatch.hpp
${BB_GEN_DIR}/bb_ipc_server.hpp
${BB_GEN_DIR}/bb_types.hpp
${BB_GEN_DIR}/ipc_codegen/msgpack_adaptor.hpp
${BB_GEN_DIR}/ipc_codegen/msgpack_include.hpp
${BB_GEN_DIR}/ipc_codegen/throw.hpp
)
set(IPC_CODEGEN_DIR ${CMAKE_SOURCE_DIR}/../../ipc-codegen)
file(GLOB_RECURSE IPC_CODEGEN_SRC
${IPC_CODEGEN_DIR}/src/*.ts
${IPC_CODEGEN_DIR}/templates/cpp/*.hpp
)
add_custom_command(
OUTPUT ${BB_GEN_OUTPUTS}
COMMAND node --experimental-strip-types --experimental-transform-types --no-warnings
${IPC_CODEGEN_DIR}/src/generate.ts
--schema ${BB_SCHEMA}
--lang cpp
--out ${BB_GEN_DIR}
--server
--cpp-namespace bb::bbapi
--cpp-include-dir barretenberg/bbapi/generated
--strip-method-prefix
DEPENDS ${BB_SCHEMA} ${IPC_CODEGEN_SRC}
COMMENT "Generating BB IPC wire types + server dispatch from bb_schema.json"
VERBATIM
)
add_custom_target(bb_ipc_generated DEPENDS ${BB_GEN_OUTPUTS})
endif()

# Embed the schema so `bb msgpack schema` reports the exact contract this
# binary was built against. Configure-time: re-runs when the schema changes.
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${BB_SCHEMA})
file(READ ${BB_SCHEMA} BB_SCHEMA_CONTENT)
configure_file(bb_schema_embed.hpp.in ${BB_GEN_DIR}/bb_schema_embed.hpp @ONLY)

barretenberg_module(bbapi common chonk dsl crypto_poseidon2 crypto_pedersen_commitment crypto_pedersen_hash crypto_blake2s crypto_aes128 crypto_schnorr crypto_ecdsa ecc srs)

if(NOT FUZZING)
add_dependencies(bbapi_objects bb_ipc_generated)
endif()

# bbapi_tests needs vm2_stub to resolve dsl's AVM recursion constraint references
if(NOT WASM AND NOT FUZZING)
target_link_libraries(bbapi_tests PRIVATE vm2_stub)
Expand Down
36 changes: 36 additions & 0 deletions barretenberg/cpp/src/barretenberg/bbapi/bb_curve_constants.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"bn254_fr_modulus": "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001",
"bn254_fq_modulus": "30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47",
"bn254_g1_generator": {
"x": "0000000000000000000000000000000000000000000000000000000000000001",
"y": "0000000000000000000000000000000000000000000000000000000000000002"
},
"bn254_g2_generator": {
"x": [
"1800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed",
"198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c2"
],
"y": [
"12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa",
"090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b"
]
},
"grumpkin_fr_modulus": "30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47",
"grumpkin_fq_modulus": "30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001",
"grumpkin_g1_generator": {
"x": "0000000000000000000000000000000000000000000000000000000000000001",
"y": "0000000000000002cf135e7506a45d632d270d45f1181294833fc48d823f272c"
},
"secp256k1_fr_modulus": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
"secp256k1_fq_modulus": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"secp256k1_g1_generator": {
"x": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
"y": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
},
"secp256r1_fr_modulus": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
"secp256r1_fq_modulus": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
"secp256r1_g1_generator": {
"x": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
"y": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
}
}
Loading
Loading