31void write_standalone_vk(std::vector<uint8_t>
bytecode,
const std::filesystem::path& output_path)
37 bool is_stdout = output_path ==
"-";
41 write_file(output_path /
"vk", response.bytes);
44void write_chonk_vk(std::vector<uint8_t>
bytecode,
const std::filesystem::path& output_dir)
47 info(
"Chonk: computing IVC vk for hiding kernel circuit");
49 const bool output_to_stdout = output_dir ==
"-";
50 if (output_to_stdout) {
59 const std::filesystem::path& input_path,
60 const std::filesystem::path& output_dir)
68 info(
"Chonk: starting with ", raw_steps.size(),
" circuits");
69 for (
const auto& step : raw_steps) {
71 .
circuit = { .
name = step.function_name, .bytecode = step.bytecode, .verification_key = step.vk }
75 info(
"Chonk: accumulating " + step.function_name);
83 const bool output_to_stdout = output_dir ==
"-";
85 const auto write_proof = [&]() {
87 if (output_to_stdout) {
88 vinfo(
"writing Chonk proof to stdout");
91 vinfo(
"writing Chonk proof in directory ", output_dir);
99 vinfo(
"writing Chonk vk in directory ", output_dir);
101 write_chonk_vk(raw_steps[raw_steps.size() - 1].bytecode, output_dir);
106 [[maybe_unused]]
const std::filesystem::path& public_inputs_path,
107 const std::filesystem::path& proof_path,
108 const std::filesystem::path& vk_path)
111 auto proof_fields = many_from_buffer<fr>(
read_file(proof_path));
117 return response.valid;
129 auto proof = ivc->prove();
141 [[maybe_unused]]
const std::filesystem::path& output_path,
142 [[maybe_unused]]
const std::filesystem::path& vk_path)
155 bool check_failed =
false;
156 for (
auto& step : raw_steps) {
157 if (step.vk.empty()) {
158 info(
"FAIL: Expected precomputed vk for function ", step.function_name);
162 .
circuit = { .
name = step.function_name, .bytecode = step.bytecode, .verification_key = step.vk }
165 if (!response.valid) {
166 info(
"VK mismatch detected for function ", step.function_name);
168 info(
"Computed VK differs from precomputed VK in ivc-inputs.msgpack");
171 info(
"Updating VK in ivc-inputs.msgpack with computed value");
172 step.vk = response.actual_vk;
184 const std::filesystem::path& bytecode_path,
185 const std::filesystem::path& output_path)
190 write_chonk_vk(
bytecode, output_path);
192 write_standalone_vk(
bytecode, output_path);
195 write_standalone_vk(
bytecode, output_path);
197 const std::string msg = std::string(
"Can't write vk for verifier type ") + flags.
verifier_type;
203 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
204 [[maybe_unused]]
const std::filesystem::path& witness_path)
214 std::string functions_string =
"{\"functions\": [\n ";
220 .include_gates_per_opcode = include_gates_per_opcode }
225 std::string gates_per_opcode_str;
226 if (include_gates_per_opcode && !response.gates_per_opcode.empty()) {
227 for (
size_t j = 0; j < response.gates_per_opcode.size(); j++) {
228 gates_per_opcode_str +=
std::to_string(response.gates_per_opcode[j]);
229 if (j != response.gates_per_opcode.size() - 1) {
230 gates_per_opcode_str +=
",";
234 auto result_string =
format(
235 "{\n \"acir_opcodes\": ",
236 response.acir_opcodes,
237 ",\n \"circuit_size\": ",
238 response.circuit_size,
239 (include_gates_per_opcode ?
format(
",\n \"gates_per_opcode\": [", gates_per_opcode_str,
"]") :
""),
241 functions_string =
format(functions_string, result_string);
void write_bytes_to_stdout(const std::vector< uint8_t > &data)
Writes raw bytes of the vector to stdout.
std::shared_ptr< Napi::ThreadSafeFunction > bytecode
#define BB_BENCH_NAME(name)
bool prove_and_verify(const std::filesystem::path &input_path)
bool verify(const Flags &flags, const std::filesystem::path &public_inputs_path, const std::filesystem::path &proof_path, const std::filesystem::path &vk_path) override
void write_vk(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path) override
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
bool check(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path) override
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
void write_solidity_verifier(const Flags &flags, const std::filesystem::path &output_path, const std::filesystem::path &vk_path) override
static bool verify(const Proof &proof, const VerificationKey &vk)
std::string format(Args... args)
std::vector< uint8_t > get_bytecode(const std::string &bytecodePath)
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.
Entry point for Barretenberg command-line interface.
void chonk_gate_count(const std::string &bytecode_path, bool include_gates_per_opcode)
std::vector< uint8_t > read_file(const std::string &filename, size_t bytes=0)
void write_file(const std::string &filename, std::vector< uint8_t > const &data)
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)
bool include_gates_per_opcode
std::string verifier_type
static Proof from_field_elements(const std::vector< Chonk::FF > &fields)
static void compress_and_save(std::vector< PrivateExecutionStepRaw > &&steps, const std::filesystem::path &output_path)
static std::vector< PrivateExecutionStepRaw > load_and_decompress(const std::filesystem::path &input_path)
std::shared_ptr< Chonk > accumulate()
void parse(std::vector< PrivateExecutionStepRaw > &&steps)
Accumulate the previously loaded circuit into the IVC proof.
std::vector< uint8_t > witness
Serialized witness data for the last loaded circuit.
Verify that a precomputed verification key matches the circuit.
CircuitInput circuit
Circuit with its precomputed verification key.
Compute IVC verification key for the complete proof.
Compute standalone verification key for a circuit.
Load a circuit into the Chonk instance for accumulation.
CircuitInput circuit
Circuit to be loaded with its bytecode and verification key.
Chonk::Proof proof
Complete IVC proof for all accumulated circuits.
Generate a proof for all accumulated circuits.
Response execute(BBApiRequest &request) &&
Initialize a new Chonk instance for incremental proof accumulation.
Get gate counts for a circuit.
CircuitInputNoVK circuit
The circuit to analyze.
Verify a Chonk proof with its verification key.
Chonk::Proof proof
The Chonk proof to verify.
void throw_or_abort(std::string const &err)