Skip to content

Commit

Permalink
chore: Upstream changes to fix proving key serialization in turbo_pro…
Browse files Browse the repository at this point in the history
…ofs (#204)
  • Loading branch information
vezenovm authored and phated committed Mar 7, 2023
1 parent 49afe08 commit 9c67dfe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
13 changes: 12 additions & 1 deletion cpp/src/aztec/dsl/acir_format/ecdsa_secp256k1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ void create_ecdsa_verify_constraints(plonk::TurboComposer& composer, const Ecdsa
stdlib::ecdsa::signature<plonk::TurboComposer> sig{ stdlib::byte_array<plonk::TurboComposer>(&composer, rr),
stdlib::byte_array<plonk::TurboComposer>(&composer, ss) };

auto pub_key = secp256k1_ct::g1_ct(pub_key_x_fq, pub_key_y_fq);
pub_key_x_fq.assert_is_in_field();
pub_key_y_fq.assert_is_in_field();

// TODO: crypto-dev to fix calculation and constraining of the signature result is correct
// the above line is currently a placeholder as unused variabels are not allowed in the build
// auto pub_key = secp256k1_ct::g1_ct(pub_key_x_fq, pub_key_y_fq);
// bool_ct signature_result = stdlib::ecdsa::
// verify_signature<plonk::TurboComposer, secp256k1_ct::fq_ct, secp256k1_ct::bigfr_ct,
// secp256k1_ct::g1_bigfr_ct>(
// message, pub_key, sig);

// auto result_bool = composer.add_variable(signature_result.get_value() == true);

composer.assert_equal(false, input.result);
}
Expand Down
20 changes: 6 additions & 14 deletions cpp/src/aztec/dsl/turbo_proofs/turbo_proofs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,13 @@ size_t turbo_init_proving_key(uint8_t const* constraint_system_buf, uint8_t cons
auto crs_factory = std::make_unique<ReferenceStringFactory>();
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 turbo_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 9c67dfe

Please sign in to comment.