22 request.ivc_stack_depth = 0;
29 if (!request.ivc_in_progress) {
33 request.loaded_circuit_name = circuit.name;
35 request.loaded_circuit_vk = circuit.verification_key;
37 info(
"ChonkLoad - loaded circuit '", request.loaded_circuit_name,
"'");
45 if (!request.ivc_in_progress) {
49 if (!request.loaded_circuit_constraints.has_value()) {
57 auto circuit = acir_format::create_circuit<IVCBase::ClientCircuit>(program, metadata);
62 precomputed_vk =
nullptr;
64 if (!request.loaded_circuit_vk.empty()) {
65 validate_vk_size<Chonk::MegaVerificationKey>(request.loaded_circuit_vk);
66 precomputed_vk = from_buffer<std::shared_ptr<Chonk::MegaVerificationKey>>(request.loaded_circuit_vk);
73 if (*precomputed_vk != *computed_vk) {
74 throw_or_abort(
"VK check failed for circuit '" + request.loaded_circuit_name +
75 "': provided VK does not match computed VK");
80 throw_or_abort(
"Invalid VK policy. Valid options: default, check, recompute");
83 info(
"ChonkAccumulate - accumulating circuit '", request.loaded_circuit_name,
"'");
84 request.ivc_in_progress->accumulate(circuit, precomputed_vk);
85 request.ivc_stack_depth++;
87 request.loaded_circuit_constraints.reset();
88 request.loaded_circuit_vk.clear();
96 if (!request.ivc_in_progress) {
100 if (request.ivc_stack_depth == 0) {
101 throw_or_abort(
"No circuits accumulated. Call ChonkAccumulate first.");
104 info(
"ChonkProve - generating proof for ", request.ivc_stack_depth,
" accumulated circuits");
108 bool verification_passed =
false;
110 info(
"ChonkProve - using Chonk");
112 auto proof = chonk->prove();
113 auto vk_and_hash = chonk->get_hiding_kernel_vk_and_hash();
117 info(
"ChonkProve - verifying the generated proof as a sanity check");
119 verification_passed = verifier.
verify(proof);
121 if (!verification_passed) {
127 request.ivc_in_progress.reset();
128 request.ivc_stack_depth = 0;
138 validate_vk_size<VerificationKey>(
vk);
144 const size_t expected_proof_size =
146 if (proof.size() != expected_proof_size) {
154 const bool verified = verifier.
verify(proof);
156 return { .valid = verified };
170 info(
"ChonkComputeVk - deriving MegaVerificationKey for circuit '", circuit.name,
"'");
178 info(
"ChonkComputeVk - VK derived, size: ",
to_buffer(*verification_key).size(),
" bytes");
180 return { .bytes =
to_buffer(*verification_key), .fields = verification_key->to_field_elements() };
192 if (circuit.verification_key.empty()) {
193 info(
"FAIL: Expected precomputed vk for function ", circuit.name);
197 validate_vk_size<Chonk::MegaVerificationKey>(circuit.verification_key);
200 auto precomputed_vk = from_buffer<std::shared_ptr<Chonk::MegaVerificationKey>>(circuit.verification_key);
203 response.
valid =
true;
204 if (*computed_vk != *precomputed_vk) {
205 response.valid =
false;
206 response.actual_vk =
to_buffer(computed_vk);
220 const auto& ivc_constraints = constraint_system.hn_recursion_constraints;
225 .collect_gates_per_opcode = include_gates_per_opcode
229 auto builder = acir_format::create_circuit<MegaCircuitBuilder>(program, metadata);
230 builder.finalize_circuit(
true);
233 response.
acir_opcodes = program.constraints.num_acir_opcodes;
237 if (include_gates_per_opcode) {
238 response.
gates_per_opcode = std::vector<uint32_t>(program.constraints.gates_per_opcode.begin(),
239 program.constraints.gates_per_opcode.end());
243 info(
"ChonkStats - circuit: ",
#define BB_BENCH_NAME(name)
Chonk-specific command definitions for the Barretenberg RPC API.
Flavor::VerificationKey MegaVerificationKey
Verifier for Chonk IVC proofs (both native and recursive).
Output verify(const Proof &proof)
Verify a Chonk proof.
Base Native verification key class.
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
std::vector< uint8_t > to_buffer(T const &value)
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
The size of a Chonk proof without backend-added public inputs.
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 verification key in multiple formats.
Response execute(const BBApiRequest &request={}) &&
Empty response indicating successful circuit loading.
Response execute(BBApiRequest &request) &&
Contains the generated IVC proof.
ChonkProof 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)