Skip to content

Commit

Permalink
fix: Remove proving key buf len estimation (#26)
Browse files Browse the repository at this point in the history
remove proving key buf len estimation, generalize like init_verification_key in standard_example
  • Loading branch information
vezenovm authored Mar 13, 2023
1 parent c222e48 commit dbd5443
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(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)
Expand Down

0 comments on commit dbd5443

Please sign in to comment.