Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::bbapi Namespace Reference

Classes

struct  AesDecrypt
 AES-128 CBC decryption. More...
 
struct  AesEncrypt
 AES-128 CBC encryption. More...
 
struct  BBApiRequest
 
struct  Blake2s
 Compute Blake2s hash. More...
 
struct  Blake2sToField
 Compute Blake2s hash and convert to field element. More...
 
struct  Bn254FqSqrt
 Compute square root of a BN254 Fq (base field) element. More...
 
struct  Bn254FrSqrt
 Compute square root of a BN254 Fr (scalar field) element. More...
 
struct  Bn254G1FromCompressed
 Decompress a BN254 G1 point from compressed form. More...
 
struct  Bn254G1IsOnCurve
 Check if a BN254 G1 point is on the curve. More...
 
struct  Bn254G1Mul
 Multiply a BN254 G1 point by a scalar. More...
 
struct  Bn254G2Mul
 Multiply a BN254 G2 point by a scalar. More...
 
struct  ChonkAccumulate
 Accumulate the previously loaded circuit into the IVC proof. More...
 
struct  ChonkBatchVerify
 Batch-verify multiple Chonk proofs with a single IPA SRS MSM. More...
 
struct  ChonkCheckPrecomputedVk
 Verify that a precomputed verification key matches the circuit. More...
 
struct  ChonkCompressProof
 Compress a Chonk proof to a compact byte representation. More...
 
struct  ChonkComputeVk
 Compute MegaHonk verification key for a circuit to be accumulated in Chonk. More...
 
struct  ChonkDecompressProof
 Decompress a compressed Chonk proof back to field elements. More...
 
struct  ChonkLoad
 Load a circuit into the Chonk instance for accumulation. More...
 
struct  ChonkProve
 Generate a proof for all accumulated circuits. More...
 
struct  ChonkStart
 Initialize a new Chonk instance for incremental proof accumulation. More...
 
struct  ChonkStats
 Get gate counts for a circuit. More...
 
struct  ChonkVerify
 Verify a Chonk proof with its verification key. More...
 
struct  CircuitComputeVk
 
struct  CircuitInput
 A circuit to be used in either ultrahonk or Chonk proving. More...
 
struct  CircuitInputNoVK
 A circuit to be used in either ultrahonk or chonk verification key derivation. More...
 
struct  CircuitProve
 Represents a request to generate a proof. Currently, UltraHonk is the only proving system supported by BB (after plonk was deprecated and removed). This is used for one-shot proving, not our "IVC" scheme, Chonk. For that, use the Chonk* commands. More...
 
struct  CircuitStats
 Consolidated command for retrieving circuit information. Combines gate count, circuit size, and other metadata into a single command. More...
 
struct  CircuitVerify
 Verify a proof against a verification key and public inputs. More...
 
struct  CircuitWriteSolidityVerifier
 Command to generate Solidity verifier contract. More...
 
struct  EcdsaSecp256k1ComputePublicKey
 Compute ECDSA public key from private key for secp256k1. More...
 
struct  EcdsaSecp256k1ConstructSignature
 Construct an ECDSA signature for secp256k1. More...
 
struct  EcdsaSecp256k1RecoverPublicKey
 Recover public key from ECDSA signature for secp256k1. More...
 
struct  EcdsaSecp256k1VerifySignature
 Verify an ECDSA signature for secp256k1. More...
 
struct  EcdsaSecp256r1ComputePublicKey
 Compute ECDSA public key from private key for secp256r1. More...
 
struct  EcdsaSecp256r1ConstructSignature
 Construct an ECDSA signature for secp256r1. More...
 
struct  EcdsaSecp256r1RecoverPublicKey
 Recover public key from ECDSA signature for secp256r1. More...
 
struct  EcdsaSecp256r1VerifySignature
 Verify an ECDSA signature for secp256r1. More...
 
struct  ErrorResponse
 Error response returned when a command fails. More...
 
struct  GrumpkinAdd
 Add two Grumpkin points. More...
 
struct  GrumpkinBatchMul
 Multiply multiple Grumpkin points by a single scalar. More...
 
struct  GrumpkinGetRandomFr
 Get a random Grumpkin field element (BN254 Fr) More...
 
struct  GrumpkinMul
 Multiply a Grumpkin point by a scalar. More...
 
struct  GrumpkinReduce512
 Reduce a 512-bit value modulo Grumpkin scalar field (BN254 Fr) More...
 
struct  MegaVkAsFields
 Convert a MegaFlavor verification key to field elements representation. Used for private function verification keys which use MegaFlavor (127 fields). More...
 
struct  PedersenCommit
 Compute Pedersen commitment to field elements. More...
 
struct  PedersenHash
 Compute Pedersen hash of field elements. More...
 
struct  PedersenHashBuffer
 Compute Pedersen hash of raw buffer. More...
 
struct  Poseidon2Hash
 Compute Poseidon2 hash of input field elements. More...
 
struct  Poseidon2Permutation
 Compute Poseidon2 permutation on state (4 field elements) More...
 
struct  ProofSystemSettings
 
struct  SchnorrComputePublicKey
 Compute Schnorr public key from private key. More...
 
struct  SchnorrConstructSignature
 Construct a Schnorr signature. More...
 
struct  SchnorrVerifySignature
 Verify a Schnorr signature. More...
 
struct  Secp256k1GetRandomFr
 Get a random Secp256k1 field element. More...
 
struct  Secp256k1Mul
 Multiply a Secp256k1 point by a scalar. More...
 
struct  Secp256k1Reduce512
 Reduce a 512-bit value modulo Secp256k1 scalar field. More...
 
struct  Shutdown
 
struct  SrsInitGrumpkinSrs
 Initialize Grumpkin SRS with Grumpkin points. More...
 
struct  SrsInitSrs
 Initialize BN254 SRS with G1 and G2 points. More...
 
struct  VkAsFields
 Convert a verification key to field elements representation. WORKTODO(bbapi): this should become mostly obsolete with having the verification keys always reported as field elements as well, and having a simpler serialization method. More...
 

Typedefs

using Command = NamedUnion< CircuitProve, CircuitComputeVk, CircuitStats, CircuitVerify, ChonkComputeVk, ChonkStart, ChonkLoad, ChonkAccumulate, ChonkProve, ChonkVerify, ChonkBatchVerify, VkAsFields, MegaVkAsFields, CircuitWriteSolidityVerifier, ChonkCheckPrecomputedVk, ChonkStats, ChonkCompressProof, ChonkDecompressProof, Poseidon2Hash, Poseidon2Permutation, PedersenCommit, PedersenHash, PedersenHashBuffer, Blake2s, Blake2sToField, AesEncrypt, AesDecrypt, GrumpkinMul, GrumpkinAdd, GrumpkinBatchMul, GrumpkinGetRandomFr, GrumpkinReduce512, Secp256k1Mul, Secp256k1GetRandomFr, Secp256k1Reduce512, Bn254FrSqrt, Bn254FqSqrt, Bn254G1Mul, Bn254G2Mul, Bn254G1IsOnCurve, Bn254G1FromCompressed, SchnorrComputePublicKey, SchnorrConstructSignature, SchnorrVerifySignature, EcdsaSecp256k1ComputePublicKey, EcdsaSecp256r1ComputePublicKey, EcdsaSecp256k1ConstructSignature, EcdsaSecp256r1ConstructSignature, EcdsaSecp256k1RecoverPublicKey, EcdsaSecp256r1RecoverPublicKey, EcdsaSecp256k1VerifySignature, EcdsaSecp256r1VerifySignature, SrsInitSrs, SrsInitGrumpkinSrs, Shutdown >
 
using CommandResponse = NamedUnion< ErrorResponse, CircuitProve::Response, CircuitComputeVk::Response, CircuitStats::Response, CircuitVerify::Response, ChonkComputeVk::Response, ChonkStart::Response, ChonkLoad::Response, ChonkAccumulate::Response, ChonkProve::Response, ChonkVerify::Response, ChonkBatchVerify::Response, VkAsFields::Response, MegaVkAsFields::Response, CircuitWriteSolidityVerifier::Response, ChonkCheckPrecomputedVk::Response, ChonkStats::Response, ChonkCompressProof::Response, ChonkDecompressProof::Response, Poseidon2Hash::Response, Poseidon2Permutation::Response, PedersenCommit::Response, PedersenHash::Response, PedersenHashBuffer::Response, Blake2s::Response, Blake2sToField::Response, AesEncrypt::Response, AesDecrypt::Response, GrumpkinMul::Response, GrumpkinAdd::Response, GrumpkinBatchMul::Response, GrumpkinGetRandomFr::Response, GrumpkinReduce512::Response, Secp256k1Mul::Response, Secp256k1GetRandomFr::Response, Secp256k1Reduce512::Response, Bn254FrSqrt::Response, Bn254FqSqrt::Response, Bn254G1Mul::Response, Bn254G2Mul::Response, Bn254G1IsOnCurve::Response, Bn254G1FromCompressed::Response, SchnorrComputePublicKey::Response, SchnorrConstructSignature::Response, SchnorrVerifySignature::Response, EcdsaSecp256k1ComputePublicKey::Response, EcdsaSecp256r1ComputePublicKey::Response, EcdsaSecp256k1ConstructSignature::Response, EcdsaSecp256r1ConstructSignature::Response, EcdsaSecp256k1RecoverPublicKey::Response, EcdsaSecp256r1RecoverPublicKey::Response, EcdsaSecp256k1VerifySignature::Response, EcdsaSecp256r1VerifySignature::Response, SrsInitSrs::Response, SrsInitGrumpkinSrs::Response, Shutdown::Response >
 

Enumerations

enum class  VkPolicy { DEFAULT , CHECK , RECOMPUTE , REWRITE }
 Policy for handling verification keys during IVC accumulation. More...
 
enum class  OracleHashType { POSEIDON2 , KECCAK , STARKNET }
 Convert oracle hash type string to enum for internal use. More...
 

Functions

std::string get_msgpack_schema_as_json ()
 
CommandResponse execute (BBApiRequest &request, Command &&command)
 Executes a command by visiting a variant of all possible commands.
 
template<typename VK >
void validate_vk_size (const std::vector< uint8_t > &vk_bytes)
 Validate verification key size before deserialization.
 
OracleHashType parse_oracle_hash_type (const std::string &type)
 
VkPolicy parse_vk_policy (const std::string &policy)
 Convert VK policy string to enum for internal use.
 
template<typename Flavor >
Flavor::Transcript::Proof concatenate_proof (const std::vector< uint256_t > &public_inputs, const std::vector< uint256_t > &proof)
 Concatenate public inputs and proof into a complete proof for verification.
 
template<typename VK >
std::vector< uint256_tvk_to_uint256_fields (const VK &vk)
 Convert VK to uint256 field elements, handling flavor-specific return types.
 
void validate_rollup_settings (const ProofSystemSettings &settings)
 Validate rollup circuit settings.
 
template<typename Operation >
auto dispatch_by_settings (const ProofSystemSettings &settings, Operation &&operation)
 Dispatch to the correct Flavor and IO type based on proof system settings.
 
template<typename IO >
acir_format::ProgramMetadata _create_program_metadata ()
 
template<typename Flavor , typename IO , typename Circuit = typename Flavor::CircuitBuilder>
Circuit _compute_circuit (std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness)
 
template<typename Flavor , typename IO >
std::shared_ptr< ProverInstance_< Flavor > > _compute_prover_instance (std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness)
 
template<typename Flavor , typename IO >
CircuitProve::Response _prove (std::vector< uint8_t > &&bytecode, std::vector< uint8_t > &&witness, std::vector< uint8_t > &&vk_bytes)
 
template<typename Flavor , typename IO >
bool _verify (const std::vector< uint8_t > &vk_bytes, const std::vector< uint256_t > &public_inputs, const std::vector< uint256_t > &proof)
 
template<typename Flavor , typename IO >
CircuitStats::Response _stats (std::vector< uint8_t > &&bytecode, bool include_gates_per_opcode)
 
CommandResponse bbapi (Command &&command)
 Main API function that processes commands and returns responses.
 

Typedef Documentation

◆ Command

◆ CommandResponse

using bb::bbapi::CommandResponse = typedef NamedUnion<ErrorResponse, CircuitProve::Response, CircuitComputeVk::Response, CircuitStats::Response, CircuitVerify::Response, ChonkComputeVk::Response, ChonkStart::Response, ChonkLoad::Response, ChonkAccumulate::Response, ChonkProve::Response, ChonkVerify::Response, ChonkBatchVerify::Response, VkAsFields::Response, MegaVkAsFields::Response, CircuitWriteSolidityVerifier::Response, ChonkCheckPrecomputedVk::Response, ChonkStats::Response, ChonkCompressProof::Response, ChonkDecompressProof::Response, Poseidon2Hash::Response, Poseidon2Permutation::Response, PedersenCommit::Response, PedersenHash::Response, PedersenHashBuffer::Response, Blake2s::Response, Blake2sToField::Response, AesEncrypt::Response, AesDecrypt::Response, GrumpkinMul::Response, GrumpkinAdd::Response, GrumpkinBatchMul::Response, GrumpkinGetRandomFr::Response, GrumpkinReduce512::Response, Secp256k1Mul::Response, Secp256k1GetRandomFr::Response, Secp256k1Reduce512::Response, Bn254FrSqrt::Response, Bn254FqSqrt::Response, Bn254G1Mul::Response, Bn254G2Mul::Response, Bn254G1IsOnCurve::Response, Bn254G1FromCompressed::Response, SchnorrComputePublicKey::Response, SchnorrConstructSignature::Response, SchnorrVerifySignature::Response, EcdsaSecp256k1ComputePublicKey::Response, EcdsaSecp256r1ComputePublicKey::Response, EcdsaSecp256k1ConstructSignature::Response, EcdsaSecp256r1ConstructSignature::Response, EcdsaSecp256k1RecoverPublicKey::Response, EcdsaSecp256r1RecoverPublicKey::Response, EcdsaSecp256k1VerifySignature::Response, EcdsaSecp256r1VerifySignature::Response, SrsInitSrs::Response, SrsInitGrumpkinSrs::Response, Shutdown::Response>

Definition at line 72 of file bbapi_execute.hpp.

Enumeration Type Documentation

◆ OracleHashType

enum class bb::bbapi::OracleHashType
strong

Convert oracle hash type string to enum for internal use.

Enumerator
POSEIDON2 
KECCAK 
STARKNET 

Definition at line 143 of file bbapi_shared.hpp.

◆ VkPolicy

enum class bb::bbapi::VkPolicy
strong

Policy for handling verification keys during IVC accumulation.

Enumerator
DEFAULT 
CHECK 
RECOMPUTE 
REWRITE 

Definition at line 49 of file bbapi_shared.hpp.

Function Documentation

◆ _compute_circuit()

template<typename Flavor , typename IO , typename Circuit = typename Flavor::CircuitBuilder>
Circuit bb::bbapi::_compute_circuit ( std::vector< uint8_t > &&  bytecode,
std::vector< uint8_t > &&  witness 
)

Definition at line 21 of file bbapi_ultra_honk.cpp.

◆ _compute_prover_instance()

template<typename Flavor , typename IO >
std::shared_ptr< ProverInstance_< Flavor > > bb::bbapi::_compute_prover_instance ( std::vector< uint8_t > &&  bytecode,
std::vector< uint8_t > &&  witness 
)

Definition at line 33 of file bbapi_ultra_honk.cpp.

◆ _create_program_metadata()

template<typename IO >
acir_format::ProgramMetadata bb::bbapi::_create_program_metadata ( )

Definition at line 15 of file bbapi_ultra_honk.cpp.

◆ _prove()

template<typename Flavor , typename IO >
CircuitProve::Response bb::bbapi::_prove ( std::vector< uint8_t > &&  bytecode,
std::vector< uint8_t > &&  witness,
std::vector< uint8_t > &&  vk_bytes 
)

Definition at line 60 of file bbapi_ultra_honk.cpp.

◆ _stats()

template<typename Flavor , typename IO >
CircuitStats::Response bb::bbapi::_stats ( std::vector< uint8_t > &&  bytecode,
bool  include_gates_per_opcode 
)

Definition at line 164 of file bbapi_ultra_honk.cpp.

◆ _verify()

template<typename Flavor , typename IO >
bool bb::bbapi::_verify ( const std::vector< uint8_t > &  vk_bytes,
const std::vector< uint256_t > &  public_inputs,
const std::vector< uint256_t > &  proof 
)

Definition at line 103 of file bbapi_ultra_honk.cpp.

◆ bbapi()

CommandResponse bb::bbapi::bbapi ( Command &&  command)

Main API function that processes commands and returns responses.

Parameters
commandThe command to execute
Returns
CommandResponse The response from executing the command

Definition at line 24 of file c_bind.cpp.

◆ concatenate_proof()

template<typename Flavor >
Flavor::Transcript::Proof bb::bbapi::concatenate_proof ( const std::vector< uint256_t > &  public_inputs,
const std::vector< uint256_t > &  proof 
)
inline

Concatenate public inputs and proof into a complete proof for verification.

Joins the separated public_inputs and proof portions back together. Handles implicit conversion from uint256_t to the flavor's DataType.

The proof structure after concatenation is: [public_inputs | honk_proof (| ipa_proof)] For rollup circuits (RollupIO), the proof portion includes the IPA proof appended at the end. This must match the split done in _prove() and the verification in _verify().

Parameters
public_inputsThe ACIR public inputs (user inputs, not including IO-specific data)
proofThe proof data (Honk proof, plus IPA proof for rollup circuits)

Definition at line 234 of file bbapi_shared.hpp.

◆ dispatch_by_settings()

template<typename Operation >
auto bb::bbapi::dispatch_by_settings ( const ProofSystemSettings settings,
Operation &&  operation 
)

Dispatch to the correct Flavor and IO type based on proof system settings.

Maps settings (ipa_accumulation, oracle_hash_type, disable_zk) to the appropriate Flavor and IO template parameters.

Rollup Path:

  • When ipa_accumulation=true, uses UltraFlavor with RollupIO (includes IPA claim for ECCVM)
  • Validates that rollup settings are compatible (poseidon2, disable_zk=true)

Non-Rollup Paths:

  • Routes to appropriate Flavor based on oracle_hash_type and disable_zk
  • Uses DefaultIO (includes only pairing points, no IPA)
Parameters
settingsThe proof system settings determining which flavor/IO to use
operationA callable object that will be invoked with <Flavor, IO> template parameters
Returns
The result of calling operation.template operator()<Flavor, IO>()

Definition at line 295 of file bbapi_shared.hpp.

◆ execute()

CommandResponse bb::bbapi::execute ( BBApiRequest request,
Command &&  command 
)
inline

Executes a command by visiting a variant of all possible commands.

Parameters
commandThe command to execute, consumed by this function.
requestThe circuit registry (acting as the request context).
Returns
A variant of all possible command responses.

Definition at line 136 of file bbapi_execute.hpp.

◆ get_msgpack_schema_as_json()

std::string bb::bbapi::get_msgpack_schema_as_json ( )

Definition at line 11 of file bbapi_execute.cpp.

◆ parse_oracle_hash_type()

OracleHashType bb::bbapi::parse_oracle_hash_type ( const std::string &  type)
inline

Definition at line 145 of file bbapi_shared.hpp.

◆ parse_vk_policy()

VkPolicy bb::bbapi::parse_vk_policy ( const std::string &  policy)
inline

Convert VK policy string to enum for internal use.

Definition at line 159 of file bbapi_shared.hpp.

◆ validate_rollup_settings()

void bb::bbapi::validate_rollup_settings ( const ProofSystemSettings settings)
inline

Validate rollup circuit settings.

Rollup circuits require poseidon2 oracle hash for efficient recursion. The disable_zk flag is ignored - rollup always uses UltraFlavor (non-ZK).

Exceptions
Iforacle_hash_type is not poseidon2

Definition at line 264 of file bbapi_shared.hpp.

◆ validate_vk_size()

template<typename VK >
void bb::bbapi::validate_vk_size ( const std::vector< uint8_t > &  vk_bytes)
inline

Validate verification key size before deserialization.

Template Parameters
VKThe verification key type
Parameters
vk_bytesThe serialized verification key bytes
Exceptions
Ifthe size doesn't match the expected size for the VK type

Definition at line 36 of file bbapi_shared.hpp.

◆ vk_to_uint256_fields()

template<typename VK >
std::vector< uint256_t > bb::bbapi::vk_to_uint256_fields ( const VK &  vk)

Convert VK to uint256 field elements, handling flavor-specific return types.

Definition at line 247 of file bbapi_shared.hpp.