Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bbapi_shared.hpp
Go to the documentation of this file.
1#pragma once
13#include <cstdint>
14#include <string>
15#include <vector>
16
17namespace bb::bbapi {
18
23enum class VkPolicy {
24 DEFAULT, // Use the provided VK as-is (default behavior)
25 CHECK, // Verify the provided VK matches the computed VK, throw error if mismatch
26 RECOMPUTE, // Always ignore the provided VK and treat it as nullptr
27 REWRITE // Check the VK and rewrite the input file with correct VK if mismatch (for check command)
28};
29
41 std::string name;
42
49 std::vector<uint8_t> bytecode;
50
52 bool operator==(const CircuitInputNoVK& other) const = default;
53};
54
66 std::string name;
67
74 std::vector<uint8_t> bytecode;
75
80 std::vector<uint8_t> verification_key;
81
83 bool operator==(const CircuitInput& other) const = default;
84};
85
91 bool ipa_accumulation = false;
92
99 std::string oracle_hash_type = "poseidon2";
100
105 bool disable_zk = false;
106
107 // TODO(md): remove this once considered stable
109
111 bool operator==(const ProofSystemSettings& other) const = default;
112};
113
118
120{
121 if (type == "keccak") {
123 }
124 if (type == "starknet") {
126 }
127 return OracleHashType::POSEIDON2; // default
128}
129
133inline VkPolicy parse_vk_policy(const std::string& policy)
134{
135 if (policy == "check") {
136 return VkPolicy::CHECK;
137 }
138 if (policy == "recompute") {
139 return VkPolicy::RECOMPUTE;
140 }
141 if (policy == "rewrite") {
142 return VkPolicy::REWRITE;
143 }
144 return VkPolicy::DEFAULT; // default
145}
146
148 // Current depth of the IVC stack for this request
149 uint32_t ivc_stack_depth = 0;
151 // Name of the last loaded circuit
153 // Store the parsed constraint system to get ahead of parsing before accumulate
155 // Store the verification key passed with the circuit
156 std::vector<uint8_t> loaded_circuit_vk;
157 // Policy for handling verification keys during accumulation
159 // Error message - empty string means no error
160 std::string error_message;
161};
162
167 static constexpr const char MSGPACK_SCHEMA_NAME[] = "ErrorResponse";
168 std::string message;
170 bool operator==(const ErrorResponse&) const = default;
171};
172
176#define BBAPI_ERROR(request, msg) \
177 do { \
178 (request).error_message = (msg); \
179 return {}; \
180 } while (0)
181
182struct Shutdown {
183 static constexpr const char MSGPACK_SCHEMA_NAME[] = "Shutdown";
184 struct Response {
185 static constexpr const char MSGPACK_SCHEMA_NAME[] = "ShutdownResponse";
186 // Empty response - success indicated by no exception
187 void msgpack(auto&& pack_fn) { pack_fn(); }
188 bool operator==(const Response&) const = default;
189 };
190 void msgpack(auto&& pack_fn) { pack_fn(); }
191 Response execute(const BBApiRequest&) && { return {}; }
192 bool operator==(const Shutdown&) const = default;
193};
194
195} // namespace bb::bbapi
OracleHashType
Convert oracle hash type string to enum for internal use.
VkPolicy
Policy for handling verification keys during IVC accumulation.
VkPolicy parse_vk_policy(const std::string &policy)
Convert VK policy string to enum for internal use.
OracleHashType parse_oracle_hash_type(const std::string &type)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::shared_ptr< IVCBase > ivc_in_progress
std::vector< uint8_t > loaded_circuit_vk
std::optional< acir_format::AcirFormat > loaded_circuit_constraints
A circuit to be used in either ultrahonk or Chonk proving.
MSGPACK_FIELDS(name, bytecode, verification_key)
bool operator==(const CircuitInput &other) const =default
std::vector< uint8_t > verification_key
Verification key of the circuit. This could be derived, but it is more efficient to have it fixed ahe...
std::string name
Human-readable name for the circuit.
std::vector< uint8_t > bytecode
Serialized bytecode representation of the circuit.
A circuit to be used in either ultrahonk or chonk verification key derivation.
MSGPACK_FIELDS(name, bytecode)
std::string name
Human-readable name for the circuit.
bool operator==(const CircuitInputNoVK &other) const =default
std::vector< uint8_t > bytecode
Serialized bytecode representation of the circuit.
Error response returned when a command fails.
bool operator==(const ErrorResponse &) const =default
static constexpr const char MSGPACK_SCHEMA_NAME[]
bool ipa_accumulation
Optional flag to indicate if the proof should be generated with IPA accumulation (i....
bool operator==(const ProofSystemSettings &other) const =default
MSGPACK_FIELDS(ipa_accumulation, oracle_hash_type, disable_zk, optimized_solidity_verifier)
std::string oracle_hash_type
The oracle hash type to be used for the proof.
bool disable_zk
Flag to disable blinding of the proof. Useful for cases that don't require privacy,...
static constexpr const char MSGPACK_SCHEMA_NAME[]
bool operator==(const Response &) const =default
void msgpack(auto &&pack_fn)
void msgpack(auto &&pack_fn)
static constexpr const char MSGPACK_SCHEMA_NAME[]
bool operator==(const Shutdown &) const =default
Response execute(const BBApiRequest &) &&