9std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input)
12 std::unique_ptr<libdeflate_compressor, void (*)(libdeflate_compressor*)>{ libdeflate_alloc_compressor(6),
13 libdeflate_free_compressor };
16 size_t max_compressed_size = libdeflate_gzip_compress_bound(compressor.get(), input.size());
17 std::vector<uint8_t> compressed(max_compressed_size);
19 size_t actual_compressed_size =
20 libdeflate_gzip_compress(compressor.get(), input.data(), input.size(), compressed.data(), compressed.size());
22 if (actual_compressed_size == 0) {
23 THROW std::runtime_error(
"Failed to compress data");
26 compressed.resize(actual_compressed_size);
30std::vector<uint8_t>
decompress(
const void* bytes,
size_t size)
32 std::vector<uint8_t> content;
34 content.resize(1024ULL * 128ULL);
36 auto decompressor = std::unique_ptr<libdeflate_decompressor, void (*)(libdeflate_decompressor*)>{
37 libdeflate_alloc_decompressor(), libdeflate_free_decompressor
39 size_t actual_size = 0;
40 libdeflate_result decompress_result =
41 libdeflate_gzip_decompress(decompressor.get(), bytes, size, content.data(), content.size(), &actual_size);
42 if (decompress_result == LIBDEFLATE_INSUFFICIENT_SPACE) {
44 content.resize(content.size() * 2);
47 if (decompress_result == LIBDEFLATE_BAD_DATA) {
48 THROW std::invalid_argument(
"bad gzip data in bb main");
50 content.resize(actual_size);
59 fin.open(filename, std::ios::ate | std::ios::binary);
61 THROW std::invalid_argument(
"file not found");
63 if (fin.tellg() == -1) {
64 THROW std::invalid_argument(
"something went wrong");
67 size_t fsize =
static_cast<size_t>(fin.tellg());
68 fin.seekg(0, std::ios_base::beg);
71 std::string encoded_data(fsize,
'\0');
73 msgpack::unpack(encoded_data.data(), fsize).get().convert(result);
81 return unpack_from_file<std::vector<PrivateExecutionStepRaw>>(input_path);
93 const std::filesystem::path& input_path)
96 auto raw_steps =
load(input_path);
98 step.bytecode =
decompress(step.bytecode.data(), step.bytecode.size());
99 step.witness =
decompress(step.witness.data(), step.witness.size());
108 msgpack::unpack(
reinterpret_cast<const char*
>(
buf.data()),
buf.size()).get().convert(raw_steps);
123 for (
size_t i = 0; i < steps.size(); i++) {
132 if (step.
vk.empty()) {
136 precomputed_vks[i] = from_buffer<std::shared_ptr<ClientIVC::MegaVerificationKey>>(step.
vk);
151 info(
"DEPRECATED: Precomputed VKs expected for the given circuits.");
158 auto circuit = acir_format::create_circuit<MegaCircuitBuilder>(program, metadata);
160 info(
"ClientIVC: accumulating " + function_name);
163 ivc->accumulate(circuit, precomputed_vk);
170 const std::filesystem::path& output_path)
174 step.bytecode =
compress(step.bytecode);
175 step.witness =
compress(step.witness);
179 std::stringstream ss;
180 msgpack::pack(ss, steps);
181 std::string packed_data = ss.str();
184 std::ofstream file(output_path, std::ios::binary);
186 THROW std::runtime_error(
"Failed to open file for writing: " + output_path.string());
188 file.write(packed_data.data(),
static_cast<std::streamsize>(packed_data.size()));
Entry point for Barretenberg command-line interface.
std::vector< uint8_t > compress(const std::vector< uint8_t > &input)
std::vector< uint8_t > decompress(const void *bytes, size_t size)
T unpack_from_file(const std::filesystem::path &filename)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
This is the msgpack encoding of the objects returned by the following typescript: const stepToStruct ...
std::vector< uint8_t > vk
std::vector< uint8_t > bytecode
static void compress_and_save(std::vector< PrivateExecutionStepRaw > &&steps, const std::filesystem::path &output_path)
std::string function_name
static std::vector< PrivateExecutionStepRaw > load_and_decompress(const std::filesystem::path &input_path)
std::vector< uint8_t > witness
static std::vector< PrivateExecutionStepRaw > parse_uncompressed(const std::vector< uint8_t > &buf)
static std::vector< PrivateExecutionStepRaw > load(const std::filesystem::path &input_path)
std::vector< std::shared_ptr< ClientIVC::MegaVerificationKey > > precomputed_vks
std::shared_ptr< ClientIVC > accumulate()
void parse(std::vector< PrivateExecutionStepRaw > &&steps)
std::vector< acir_format::AcirProgram > folding_stack
std::vector< std::string > function_names