21 request.ivc_stack_depth = 0;
28 if (!request.ivc_in_progress) {
32 request.loaded_circuit_name = circuit.name;
34 request.loaded_circuit_vk = circuit.verification_key;
36 info(
"ChonkLoad - loaded circuit '", request.loaded_circuit_name,
"'");
44 if (!request.ivc_in_progress) {
48 if (!request.loaded_circuit_constraints.has_value()) {
56 auto circuit = acir_format::create_circuit<IVCBase::ClientCircuit>(program, metadata);
61 precomputed_vk =
nullptr;
63 if (!request.loaded_circuit_vk.empty()) {
64 precomputed_vk = from_buffer<std::shared_ptr<Chonk::MegaVerificationKey>>(request.loaded_circuit_vk);
71 if (*precomputed_vk != *computed_vk) {
72 throw_or_abort(
"VK check failed for circuit '" + request.loaded_circuit_name +
73 "': provided VK does not match computed VK");
78 throw_or_abort(
"Invalid VK policy. Valid options: default, check, recompute");
81 info(
"ChonkAccumulate - accumulating circuit '", request.loaded_circuit_name,
"'");
82 request.ivc_in_progress->accumulate(circuit, precomputed_vk);
83 request.ivc_stack_depth++;
85 request.loaded_circuit_constraints.reset();
86 request.loaded_circuit_vk.clear();
94 if (!request.ivc_in_progress) {
98 if (request.ivc_stack_depth == 0) {
99 throw_or_abort(
"No circuits accumulated. Call ChonkAccumulate first.");
102 info(
"ChonkProve - generating proof for ", request.ivc_stack_depth,
" accumulated circuits");
106 bool verification_passed =
false;
108 info(
"ChonkProve - using Chonk");
110 auto proof = sumcheck_ivc->prove();
111 auto vk = sumcheck_ivc->get_vk();
115 info(
"ChonkProve - verifying the generated proof as a sanity check");
118 if (!verification_passed) {
125 request.ivc_in_progress.reset();
126 request.ivc_stack_depth = 0;
138 const bool verified =
Chonk::verify(proof, verification_key);
140 return { .valid = verified };
154 info(
"ChonkComputeStandaloneVk - deriving VK for circuit '", circuit.name,
"'");
162 return { .bytes =
to_buffer(*verification_key), .fields = verification_key->to_field_elements() };
168 info(
"ChonkComputeIvcVk - deriving IVC VK for circuit '", circuit.name,
"'");
174 auto mega_vk = from_buffer<Chonk::MegaVerificationKey>(standalone_vk_response.bytes);
181 info(
"ChonkComputeIvcVk - IVC VK derived, size: ", response.
bytes.size(),
" bytes");
195 if (circuit.verification_key.empty()) {
196 info(
"FAIL: Expected precomputed vk for function ", circuit.name);
201 auto precomputed_vk = from_buffer<std::shared_ptr<Chonk::MegaVerificationKey>>(circuit.verification_key);
204 response.
valid =
true;
205 if (*computed_vk != *precomputed_vk) {
206 response.valid =
false;
207 response.actual_vk =
to_buffer(computed_vk);
221 const auto& ivc_constraints = constraint_system.hn_recursion_constraints;
226 .collect_gates_per_opcode = include_gates_per_opcode
230 auto builder = acir_format::create_circuit<MegaCircuitBuilder>(program, metadata);
231 builder.finalize_circuit(
true);
234 response.
acir_opcodes = program.constraints.num_acir_opcodes;
238 if (include_gates_per_opcode) {
239 response.
gates_per_opcode = std::vector<uint32_t>(program.constraints.gates_per_opcode.begin(),
240 program.constraints.gates_per_opcode.end());
244 info(
"ChonkStats - circuit: ",
#define BB_BENCH_NAME(name)
Chonk-specific command definitions for the Barretenberg RPC API.
static bool verify(const Proof &proof, const VerificationKey &vk)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< uint8_t > to_buffer(T const &value)
A full proof for the IVC scheme containing a Mega proof showing correctness of the Hiding kernel (whi...
std::shared_ptr< MegaVerificationKey > mega
Empty response indicating successful circuit accumulation.
Response execute(BBApiRequest &request) &&
Contains the validation result.
bool valid
True if the precomputed VK matches the circuit.
Response execute(const BBApiRequest &request={}) &&
Contains the computed IVC verification key.
std::vector< uint8_t > bytes
Serialized IVC verification key in binary format.
Response execute(const BBApiRequest &request={}) &&
Contains the computed verification key in multiple formats.
Compute standalone verification key for a circuit.
Response execute(const BBApiRequest &request={}) &&
Empty response indicating successful circuit loading.
Response execute(BBApiRequest &request) &&
Contains the generated IVC proof.
Chonk::Proof proof
Complete IVC proof for all accumulated circuits.
Response execute(BBApiRequest &request) &&
Empty response indicating successful initialization.
Response execute(BBApiRequest &request) &&
Contains gate count information.
uint32_t circuit_size
Circuit size (total number of gates)
uint32_t acir_opcodes
Number of ACIR opcodes.
std::vector< uint32_t > gates_per_opcode
Optional: gate counts per opcode.
Response execute(BBApiRequest &request) &&
Contains the verification result.
Response execute(const BBApiRequest &request={}) &&
void throw_or_abort(std::string const &err)