31void write_standalone_vk(
const std::string& output_format,
32 const std::filesystem::path& bytecode_path,
33 const std::filesystem::path& output_path)
40 bool wrote_file =
false;
41 bool is_stdout = output_path ==
"-";
42 auto write_fn = [&](
const std::filesystem::path& path,
const auto&
data) {
49 if (output_format ==
"bytes_and_fields" && is_stdout) {
50 throw_or_abort(
"Cannot write to stdout in bytes_and_fields format.");
52 if (output_format ==
"bytes" || output_format ==
"bytes_and_fields") {
53 write_fn(output_path /
"vk", response.bytes);
56 if (output_format ==
"fields" || output_format ==
"bytes_and_fields") {
58 write_fn(output_path /
"vk_fields.json", std::vector<uint8_t>(json.begin(), json.end()));
62 throw_or_abort(
"Unsupported output format for standalone vk: " + output_format);
66std::vector<uint8_t> write_civc_vk(
const std::string& output_format,
67 std::vector<uint8_t> bytecode,
68 const std::filesystem::path& output_dir)
70 if (output_format !=
"bytes") {
71 throw_or_abort(
"Unsupported output format for ClientIVC vk: " + output_format);
74 info(
"ClientIVC: computing IVC vk for hiding kernel circuit");
77 }.execute({ .trace_settings = {} });
78 auto civc_vk_bytes = response.bytes;
79 const bool output_to_stdout = output_dir ==
"-";
80 if (output_to_stdout) {
91 const std::filesystem::path& input_path,
92 const std::filesystem::path& output_dir)
99 info(
"ClientIVC: starting with ", raw_steps.size(),
" circuits");
100 for (
const auto& step : raw_steps) {
102 .
circuit = { .
name = step.function_name, .bytecode = step.bytecode, .verification_key = step.vk }
106 info(
"ClientIVC: accumulating " + step.function_name);
114 const bool output_to_stdout = output_dir ==
"-";
116 const auto write_proof = [&]() {
118 if (output_to_stdout) {
119 vinfo(
"writing ClientIVC proof to stdout");
122 vinfo(
"writing ClientIVC proof in directory ", output_dir);
123 proof.to_file_msgpack(output_dir /
"proof");
130 vinfo(
"writing ClientIVC vk in directory ", output_dir);
132 auto vk_buf = write_civc_vk(
"bytes", raw_steps[raw_steps.size() - 1].bytecode, output_dir);
133 auto vk = from_buffer<ClientIVC::VerificationKey>(vk_buf);
138 [[maybe_unused]]
const std::filesystem::path& public_inputs_path,
139 const std::filesystem::path& proof_path,
140 const std::filesystem::path& vk_path)
145 return response.valid;
157 const bool verified = ivc->prove_and_verify();
167 [[maybe_unused]]
const std::filesystem::path& output_path,
168 [[maybe_unused]]
const std::filesystem::path& vk_path)
178 bool check_failed =
false;
179 for (
auto& step : raw_steps) {
180 if (step.vk.empty()) {
181 info(
"FAIL: Expected precomputed vk for function ", step.function_name);
185 .
circuit = { .
name = step.function_name, .bytecode = step.bytecode, .verification_key = step.vk }
188 if (!response.valid) {
192 step.vk = response.actual_vk;
204 const std::filesystem::path& bytecode_path,
205 const std::filesystem::path& output_path)
212 write_standalone_vk(flags.
output_format, bytecode_path, output_path);
214 const std::string msg = std::string(
"Can't write vk for verifier type ") + flags.
verifier_type;
220 [[maybe_unused]]
const std::filesystem::path& bytecode_path,
221 [[maybe_unused]]
const std::filesystem::path& witness_path)
230 std::string functions_string =
"{\"functions\": [\n ";
236 .include_gates_per_opcode = include_gates_per_opcode }
241 std::string gates_per_opcode_str;
242 if (include_gates_per_opcode && !response.gates_per_opcode.empty()) {
243 for (
size_t j = 0; j < response.gates_per_opcode.size(); j++) {
244 gates_per_opcode_str +=
std::to_string(response.gates_per_opcode[j]);
245 if (j != response.gates_per_opcode.size() - 1) {
246 gates_per_opcode_str +=
",";
250 auto result_string =
format(
251 "{\n \"acir_opcodes\": ",
252 response.acir_opcodes,
253 ",\n \"circuit_size\": ",
254 response.circuit_size,
255 (include_gates_per_opcode ?
format(
",\n \"gates_per_opcode\": [", gates_per_opcode_str,
"]") :
""),
257 functions_string =
format(functions_string, result_string);
264 PrivateFunctionExecutionMockCircuitProducer circuit_producer{ 1 };
265 const size_t NUM_CIRCUITS = circuit_producer.total_num_circuits;
266 ClientIVC ivc{ NUM_CIRCUITS, { AZTEC_TRACE_STRUCTURE } };
269 for (
size_t idx = 0; idx < NUM_CIRCUITS; ++idx) {
270 circuit_producer.construct_and_accumulate_next_circuit(ivc);
276 vinfo(
"writing ClientIVC proof and vk...");
void write_bytes_to_stdout(const std::vector< uint8_t > &data)
Writes raw bytes of the vector to stdout.
void gates(const Flags &flags, const std::filesystem::path &bytecode_path) override
bool check(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &witness_path) override
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
bool check_precomputed_vks(const Flags &flags, const std::filesystem::path &input_path)
bool prove_and_verify(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
void prove(const Flags &flags, const std::filesystem::path &input_path, const std::filesystem::path &output_dir)
void write_vk(const Flags &flags, const std::filesystem::path &bytecode_path, const std::filesystem::path &output_path) override
The IVC scheme used by the aztec client for private function execution.
std::string format(Args... args)
const std::vector< FF > data
std::vector< uint8_t > get_bytecode(const std::string &bytecodePath)
Entry point for Barretenberg command-line interface.
void write_arbitrary_valid_client_ivc_proof_and_vk_to_file(const std::filesystem::path &output_dir)
void gate_count_for_ivc(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)
std::string field_elements_to_json(const std::vector< Fr > &fields)
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)
bool include_gates_per_opcode
std::string verifier_type
std::string output_format
A full proof for the IVC scheme containing a Mega proof showing correctness of the hiding circuit (wh...
void to_file_msgpack(const std::string &filename) const
static Proof from_file_msgpack(const std::string &filename)
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< ClientIVC > accumulate()
void parse(std::vector< PrivateExecutionStepRaw > &&steps)
TraceSettings trace_settings
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 ClientIVC instance for accumulation.
CircuitInput circuit
Circuit to be loaded with its bytecode and verification key.
ClientIVC::Proof proof
Complete IVC proof for all accumulated circuits.
Generate a proof for all accumulated circuits.
Response execute(BBApiRequest &request) &&
Initialize a new ClientIVC instance for incremental proof accumulation.
Get gate counts for a circuit.
CircuitInputNoVK circuit
The circuit to analyze.
Verify a ClientIVC proof with its verification key.
ClientIVC::Proof proof
The ClientIVC proof to verify.
void throw_or_abort(std::string const &err)