From dbd544318819cf710dede8ffb7b7eafa112f5aed Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Mon, 13 Mar 2023 14:43:25 -0400 Subject: [PATCH] fix: Remove proving key buf len estimation (#26) remove proving key buf len estimation, generalize like init_verification_key in standard_example --- .../standard_example/standard_example.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/barretenberg/src/aztec/rollup/proofs/standard_example/standard_example.cpp b/barretenberg/src/aztec/rollup/proofs/standard_example/standard_example.cpp index 51de2530a..af02ef878 100644 --- a/barretenberg/src/aztec/rollup/proofs/standard_example/standard_example.cpp +++ b/barretenberg/src/aztec/rollup/proofs/standard_example/standard_example.cpp @@ -178,20 +178,12 @@ size_t c_init_proving_key(uint8_t const* constraint_system_buf, uint8_t const** auto composer = create_circuit(constraint_system, std::move(crs_factory)); auto proving_key = composer.compute_proving_key(); - // Computing the size of the serialized key is non trivial. We know it's ~331mb. - // Allocate a buffer large enough to hold it, and abort if we overflow. - // This is to keep memory usage down. - size_t total_buf_len = 350 * 1024 * 1024; - auto raw_buf = (uint8_t*)malloc(total_buf_len); - auto raw_buf_end = raw_buf; - write(raw_buf_end, *proving_key); + auto buffer = to_buffer(*proving_key); + auto raw_buf = (uint8_t*)malloc(buffer.size()); + memcpy(raw_buf, (void*)buffer.data(), buffer.size()); *pk_buf = raw_buf; - auto len = static_cast(raw_buf_end - raw_buf); - if (len > total_buf_len) { - info("Buffer overflow serializing proving key."); - std::abort(); - } - return len; + + return buffer.size(); } size_t c_init_verification_key(void* pippenger, uint8_t const* g2x, uint8_t const* pk_buf, uint8_t const** vk_buf)