8std::vector<uint8_t>
compress(
const std::vector<uint8_t>& input)
11 std::unique_ptr<libdeflate_compressor, void (*)(libdeflate_compressor*)>{ libdeflate_alloc_compressor(6),
12 libdeflate_free_compressor };
15 size_t max_compressed_size = libdeflate_gzip_compress_bound(compressor.get(), input.size());
16 std::vector<uint8_t> compressed(max_compressed_size);
18 size_t actual_compressed_size =
19 libdeflate_gzip_compress(compressor.get(), input.data(), input.size(), compressed.data(), compressed.size());
21 if (actual_compressed_size == 0) {
22 THROW std::runtime_error(
"Failed to compress data");
25 compressed.resize(actual_compressed_size);
29std::vector<uint8_t>
decompress(
const void* bytes,
size_t size)
31 std::vector<uint8_t> content;
33 content.resize(1024ULL * 128ULL);
35 auto decompressor = std::unique_ptr<libdeflate_decompressor, void (*)(libdeflate_decompressor*)>{
36 libdeflate_alloc_decompressor(), libdeflate_free_decompressor
38 size_t actual_size = 0;
39 libdeflate_result decompress_result =
40 libdeflate_gzip_decompress(decompressor.get(), bytes, size, content.data(), content.size(), &actual_size);
41 if (decompress_result == LIBDEFLATE_INSUFFICIENT_SPACE) {
43 content.resize(content.size() * 2);
46 if (decompress_result == LIBDEFLATE_BAD_DATA) {
47 THROW std::invalid_argument(
"bad gzip data in bb main");
49 content.resize(actual_size);
58 fin.open(filename, std::ios::ate | std::ios::binary);
60 THROW std::invalid_argument(
"file not found");
62 if (fin.tellg() == -1) {
63 THROW std::invalid_argument(
"something went wrong");
66 size_t fsize =
static_cast<size_t>(fin.tellg());
67 fin.seekg(0, std::ios_base::beg);
70 std::string encoded_data(fsize,
'\0');
72 msgpack::unpack(encoded_data.data(), fsize).get().convert(result);
80 return unpack_from_file<std::vector<PrivateExecutionStepRaw>>(input_path);
92 const std::filesystem::path& input_path)
95 auto raw_steps =
load(input_path);
97 step.bytecode =
decompress(step.bytecode.data(), step.bytecode.size());
98 step.witness =
decompress(step.witness.data(), step.witness.size());
107 msgpack::unpack(
reinterpret_cast<const char*
>(
buf.data()),
buf.size()).get().convert(raw_steps);
122 for (
size_t i = 0; i < steps.size(); i++) {
131 if (step.
vk.empty()) {
135 auto vk = 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);
177 step.function_name = step.function_name;
181 std::stringstream ss;
182 msgpack::pack(ss, steps);
183 std::string packed_data = ss.str();
186 std::ofstream file(output_path, std::ios::binary);
188 THROW std::runtime_error(
"Failed to open file for writing: " + output_path.string());
190 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