diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 81c4a2bfb49..dfcd63d8d3c 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -53,11 +53,11 @@ acir_format::acir_format get_constraint_system(std::string const& bytecode_path) */ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessPath, bool recursive) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); - auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); - auto verified = acir_composer->verify_proof(proof, recursive); + auto proof = acir_composer.create_proof(constraint_system, witness, recursive); + auto verified = acir_composer.verify_proof(proof, recursive); vinfo("verified: ", verified); return verified; @@ -80,10 +80,10 @@ void prove(const std::string& bytecodePath, bool recursive, const std::string& outputPath) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); - auto proof = acir_composer->create_proof(srs::get_crs_factory(), constraint_system, witness, recursive); + auto proof = acir_composer.create_proof(constraint_system, witness, recursive); if (outputPath == "-") { writeRawBytesToStdout(proof); @@ -104,10 +104,10 @@ void prove(const std::string& bytecodePath, */ void gateCount(const std::string& bytecodePath) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto constraint_system = get_constraint_system(bytecodePath); - acir_composer->create_circuit(constraint_system); - auto gate_count = acir_composer->get_total_circuit_size(); + acir_composer.create_circuit(constraint_system); + auto gate_count = acir_composer.get_total_circuit_size(); writeUint64AsRawBytesToStdout(static_cast(gate_count)); vinfo("gate count: ", gate_count); @@ -131,10 +131,10 @@ void gateCount(const std::string& bytecodePath) */ bool verify(const std::string& proof_path, bool recursive, const std::string& vk_path) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto vk_data = from_buffer(read_file(vk_path)); - acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); - auto verified = acir_composer->verify_proof(read_file(proof_path), recursive); + acir_composer.load_verification_key(std::move(vk_data)); + auto verified = acir_composer.verify_proof(read_file(proof_path), recursive); vinfo("verified: ", verified); @@ -153,10 +153,10 @@ bool verify(const std::string& proof_path, bool recursive, const std::string& vk */ void writeVk(const std::string& bytecodePath, const std::string& outputPath) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto constraint_system = get_constraint_system(bytecodePath); - acir_composer->init_proving_key(srs::get_crs_factory(), constraint_system); - auto vk = acir_composer->init_verification_key(); + acir_composer.init_proving_key(constraint_system); + auto vk = acir_composer.init_verification_key(); auto serialized_vk = to_buffer(*vk); if (outputPath == "-") { writeRawBytesToStdout(serialized_vk); @@ -182,10 +182,10 @@ void writeVk(const std::string& bytecodePath, const std::string& outputPath) */ void contract(const std::string& output_path, const std::string& vk_path) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto vk_data = from_buffer(read_file(vk_path)); - acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); - auto contract = acir_composer->get_solidity_verifier(); + acir_composer.load_verification_key(std::move(vk_data)); + auto contract = acir_composer.get_solidity_verifier(); if (output_path == "-") { writeStringToStdout(contract); @@ -223,9 +223,9 @@ void contract(const std::string& output_path, const std::string& vk_path) */ void proofAsFields(const std::string& proof_path, std::string const& vk_path, const std::string& output_path) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto vk_data = from_buffer(read_file(vk_path)); - auto data = acir_composer->serialize_proof_into_fields(read_file(proof_path), vk_data.num_public_inputs); + auto data = acir_composer.serialize_proof_into_fields(read_file(proof_path), vk_data.num_public_inputs); auto json = format("[", join(map(data, [](auto fr) { return format("\"", fr, "\""); })), "]"); if (output_path == "-") { @@ -252,10 +252,10 @@ void proofAsFields(const std::string& proof_path, std::string const& vk_path, co */ void vkAsFields(const std::string& vk_path, const std::string& output_path) { - auto acir_composer = new acir_proofs::AcirComposer(MAX_CIRCUIT_SIZE, verbose); + acir_proofs::AcirComposer acir_composer(MAX_CIRCUIT_SIZE, verbose); auto vk_data = from_buffer(read_file(vk_path)); - acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); - auto data = acir_composer->serialize_verification_key_into_fields(); + acir_composer.load_verification_key(std::move(vk_data)); + auto data = acir_composer.serialize_verification_key_into_fields(); // We need to move vk_hash to the front... std::rotate(data.begin(), data.end() - 1, data.end()); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp index 29463a06db7..da774efecd3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -31,9 +31,7 @@ void AcirComposer::create_circuit(acir_format::acir_format& constraint_system) size_hint_ = circuit_subgroup_size_; } -void AcirComposer::init_proving_key( - std::shared_ptr> const& crs_factory, - acir_format::acir_format& constraint_system) +void AcirComposer::init_proving_key(acir_format::acir_format& constraint_system) { vinfo("building circuit... ", size_hint_); builder_ = acir_format::Builder(size_hint_); @@ -47,16 +45,14 @@ void AcirComposer::init_proving_key( total_circuit_size_ = builder_.get_total_circuit_size(); circuit_subgroup_size_ = builder_.get_circuit_subgroup_size(total_circuit_size_); - composer_ = acir_format::Composer(crs_factory); + composer_ = acir_format::Composer(); vinfo("computing proving key..."); proving_key_ = composer_.compute_proving_key(builder_); } -std::vector AcirComposer::create_proof( - std::shared_ptr> const& crs_factory, - acir_format::acir_format& constraint_system, - acir_format::WitnessVector& witness, - bool is_recursive) +std::vector AcirComposer::create_proof(acir_format::acir_format& constraint_system, + acir_format::WitnessVector& witness, + bool is_recursive) { // Release prior memory first. composer_ = acir_format::Composer(/*p_key=*/0, /*v_key=*/0); @@ -67,12 +63,10 @@ std::vector AcirComposer::create_proof( composer_ = [&]() { if (proving_key_) { - auto composer = acir_format::Composer(proving_key_, verification_key_); - // You can't produce the verification key unless you manually set the crs. Which seems like a bug. - composer_.crs_factory_ = crs_factory; + auto composer = acir_format::Composer(proving_key_, nullptr); return composer; } else { - return acir_format::Composer(crs_factory); + return acir_format::Composer(); } }(); if (!proving_key_) { @@ -108,12 +102,10 @@ std::shared_ptr AcirComposer::init_verifi return verification_key_; } -void AcirComposer::load_verification_key( - std::shared_ptr> const& crs_factory, - proof_system::plonk::verification_key_data&& data) +void AcirComposer::load_verification_key(proof_system::plonk::verification_key_data&& data) { - verification_key_ = - std::make_shared(std::move(data), crs_factory->get_verifier_crs()); + verification_key_ = std::make_shared( + std::move(data), srs::get_crs_factory()->get_verifier_crs()); composer_ = acir_format::Composer(proving_key_, verification_key_); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp index 25814e78d91..f4e125478ba 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp @@ -14,18 +14,13 @@ class AcirComposer { void create_circuit(acir_format::acir_format& constraint_system); - void init_proving_key(std::shared_ptr> const& crs_factory, - acir_format::acir_format& constraint_system); - - std::vector create_proof( - std::shared_ptr> const& crs_factory, - acir_format::acir_format& constraint_system, - acir_format::WitnessVector& witness, - bool is_recursive); - - void load_verification_key( - std::shared_ptr> const& crs_factory, - proof_system::plonk::verification_key_data&& data); + void init_proving_key(acir_format::acir_format& constraint_system); + + std::vector create_proof(acir_format::acir_format& constraint_system, + acir_format::WitnessVector& witness, + bool is_recursive); + + void load_verification_key(proof_system::plonk::verification_key_data&& data); std::shared_ptr init_verification_key(); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp index 1af145e2978..0bdfbb519d2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -35,7 +35,7 @@ WASM_EXPORT void acir_init_proving_key(in_ptr acir_composer_ptr, uint8_t const* auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec)); - acir_composer->init_proving_key(barretenberg::srs::get_crs_factory(), constraint_system); + acir_composer->init_proving_key(constraint_system); } WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr, @@ -48,8 +48,7 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr, auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec)); auto witness = acir_format::witness_buf_to_witness_data(from_buffer>(witness_vec)); - auto proof_data = - acir_composer->create_proof(barretenberg::srs::get_crs_factory(), constraint_system, witness, *is_recursive); + auto proof_data = acir_composer->create_proof(constraint_system, witness, *is_recursive); *out = to_heap_buffer(proof_data); } @@ -57,7 +56,7 @@ WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t co { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto vk_data = from_buffer(vk_buf); - acir_composer->load_verification_key(barretenberg::srs::get_crs_factory(), std::move(vk_data)); + acir_composer->load_verification_key(std::move(vk_data)); } WASM_EXPORT void acir_init_verification_key(in_ptr acir_composer_ptr) diff --git a/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp b/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp index 23129857262..53f373658fe 100644 --- a/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp @@ -6,7 +6,7 @@ using namespace proof_system::plonk::stdlib::types; WASM_EXPORT void examples_simple_create_and_verify_proof(bool* valid) { - auto ptrs = examples::simple::create_builder_and_composer(barretenberg::srs::get_crs_factory()); + auto ptrs = examples::simple::create_builder_and_composer(); auto proof = examples::simple::create_proof(ptrs); *valid = examples::simple::verify_proof(ptrs, proof); examples::simple::delete_builder_and_composer(ptrs); diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp index 19af6aa0d69..ad35fa0ee95 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp @@ -19,8 +19,7 @@ void build_circuit(Builder& builder) } } -BuilderComposerPtrs create_builder_and_composer( - std::shared_ptr> const& crs_factory) +BuilderComposerPtrs create_builder_and_composer() { // WARNING: Size hint is essential to perform 512k circuits! auto builder = std::make_unique(CIRCUIT_SIZE); @@ -36,7 +35,7 @@ BuilderComposerPtrs create_builder_and_composer( info("composer gates: ", builder->get_num_gates()); info("computing proving key..."); - auto composer = std::make_unique(crs_factory); + auto composer = std::make_unique(); auto pk = composer->compute_proving_key(*builder); return { builder.release(), composer.release() }; diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp index 0932708bf21..264d328d2d2 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp @@ -12,8 +12,7 @@ struct BuilderComposerPtrs { Composer* composer; }; -BuilderComposerPtrs create_builder_and_composer( - std::shared_ptr> const& crs_factory); +BuilderComposerPtrs create_builder_and_composer(); proof create_proof(BuilderComposerPtrs pair); diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp index a43c3de4503..17689497a75 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp @@ -8,8 +8,8 @@ namespace examples::simple { TEST(examples_simple, create_proof) { auto srs_path = std::filesystem::absolute("../srs_db/ignition"); - auto crs_factory = std::make_shared>(srs_path); - auto ptrs = create_builder_and_composer(crs_factory); + srs::init_crs_factory(srs_path); + auto ptrs = create_builder_and_composer(); auto proof = create_proof(ptrs); bool valid = verify_proof(ptrs, proof); delete_builder_and_composer(ptrs); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp index 40f39d24e4e..cdf0dbeb171 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp @@ -56,9 +56,9 @@ circuit_data get_circuit_data(std::string const& name, circuit_data data; data.srs = srs; data.mock = mock; - Composer composer(srs); + Composer composer; Builder builder; - Composer mock_proof_composer(srs); + Composer mock_proof_composer; Builder mock_builder; BenchmarkInfoCollator benchmark_collator; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp deleted file mode 100644 index fcddcbfdb94..00000000000 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include - -#include "../mock/mock_circuit.hpp" -#include "barretenberg/common/container.hpp" -#include "barretenberg/common/mem.hpp" -#include "barretenberg/common/streams.hpp" -#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#include "barretenberg/join_split_example/types.hpp" -#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" -#include "barretenberg/srs/global_crs.hpp" -#include "c_bind.h" -#include "compute_signing_data.hpp" -#include "join_split.hpp" - -using namespace barretenberg; -using namespace join_split_example::proofs::join_split; - -WASM_EXPORT void join_split__init_proving_key(bool mock) -{ - init_proving_key(barretenberg::srs::get_crs_factory(), mock); -} - -// WASM_EXPORT void join_split__init_proving_key_from_buffer(uint8_t const* pk_buf) -// { -// std::shared_ptr crs; -// plonk::proving_key_data pk_data; -// read(pk_buf, pk_data); -// init_proving_key(crs, std::move(pk_data)); -// } - -WASM_EXPORT void join_split__release_key() -{ - release_proving_key(); -} - -WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output) -{ - // 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. - - auto proving_key = get_proving_key(); - auto buffer = to_buffer(*proving_key); - auto raw_buf = (uint8_t*)malloc(buffer.size()); - memcpy(raw_buf, (void*)buffer.data(), buffer.size()); - *output = raw_buf; - - return static_cast(buffer.size()); -} - -WASM_EXPORT void join_split__init_verification_key(void* /*unused*/, uint8_t const* /*unused*/) -{ - init_verification_key(barretenberg::srs::get_crs_factory()); -} - -// WASM_EXPORT void join_split__init_verification_key_from_buffer(uint8_t const* vk_buf, uint8_t const* g2x) -// { -// auto crs = std::make_shared(g2x); -// plonk::verification_key_data vk_data; -// read(vk_buf, vk_data); -// init_verification_key(crs, std::move(vk_data)); -// } - -WASM_EXPORT uint32_t join_split__get_new_verification_key_data(uint8_t** output) -{ - auto buffer = to_buffer(*get_verification_key()); - auto raw_buf = (uint8_t*)malloc(buffer.size()); - memcpy(raw_buf, (void*)buffer.data(), buffer.size()); - *output = raw_buf; - return static_cast(buffer.size()); -} - -WASM_EXPORT void join_split__compute_signing_data(uint8_t const* join_split_tx_buf, uint8_t* output) -{ - auto tx = from_buffer(join_split_tx_buf); - auto signing_data = compute_signing_data(tx); - barretenberg::fr::serialize_to_buffer(signing_data, output); -} - -WASM_EXPORT void* join_split__new_prover(uint8_t const* join_split_buf, bool mock) -{ - auto tx = from_buffer(join_split_buf); - auto prover = new_join_split_prover(tx, mock); - auto heapProver = new join_split_example::Prover(std::move(prover)); - return heapProver; -} - -WASM_EXPORT void join_split__delete_prover(void* prover) -{ - delete reinterpret_cast(prover); -} - -WASM_EXPORT bool join_split__verify_proof(uint8_t* proof, uint32_t length) -{ - plonk::proof pp = { std::vector(proof, proof + length) }; - return verify_proof(pp); -} diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h deleted file mode 100644 index cd7390b1dad..00000000000 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/c_bind.h +++ /dev/null @@ -1,3 +0,0 @@ -#include - -WASM_EXPORT uint32_t join_split__get_new_proving_key_data(uint8_t** output); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp index 1da1caee45f..c4c52a1be38 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp @@ -14,8 +14,7 @@ using namespace proof_system::plonk::stdlib::merkle_tree; static std::shared_ptr proving_key; static std::shared_ptr verification_key; -void init_proving_key(std::shared_ptr> const& crs_factory, - bool mock) +void init_proving_key(bool mock) { if (proving_key) { return; @@ -27,12 +26,12 @@ void init_proving_key(std::shared_ptr> const& crs_factory) +void init_verification_key() { if (!proving_key) { std::abort(); } - // Patch the 'nothing' reference string fed to init_proving_key. - proving_key->reference_string = crs_factory->get_prover_crs(proving_key->circuit_size + 1); verification_key = - proof_system::plonk::compute_verification_key_common(proving_key, crs_factory->get_verifier_crs()); + proof_system::plonk::compute_verification_key_common(proving_key, srs::get_crs_factory()->get_verifier_crs()); } Prover new_join_split_prover(join_split_tx const& tx, bool mock) diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp index 1d4a1dd5fa7..a436d99f884 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.hpp @@ -7,12 +7,11 @@ namespace join_split_example { namespace proofs { namespace join_split { -void init_proving_key(std::shared_ptr> const& crs_factory, - bool mock); +void init_proving_key(bool mock); void release_proving_key(); -void init_verification_key(std::shared_ptr> const& crs_factory); +void init_verification_key(); Prover new_join_split_prover(join_split_tx const& tx, bool mock); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp index 8b86c4d1641..ef41bcfbf67 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp @@ -44,11 +44,10 @@ class join_split_tests : public ::testing::Test { static void SetUpTestCase() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); - auto null_crs_factory = std::make_shared>(); - init_proving_key(null_crs_factory, false); + init_proving_key(false); auto crs_factory = std::make_unique>("../srs_db/ignition"); - init_verification_key(std::move(crs_factory)); + init_verification_key(); info("vk hash: ", get_verification_key()->sha256_hash()); } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp index f23bceef85f..ba601d93447 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_js_parity.test.cpp @@ -25,11 +25,9 @@ class join_split_js_parity_tests : public ::testing::Test { protected: static void SetUpTestCase() { - auto null_crs_factory = std::make_shared>(); - init_proving_key(null_crs_factory, false); - auto crs_factory = - std::make_unique>("../srs_db/ignition"); - init_verification_key(std::move(crs_factory)); + srs::init_crs_factory("../srs_db/ignition"); + init_proving_key(false); + init_verification_key(); info("vk hash: ", get_verification_key()->sha256_hash()); } diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp index 7b0ded945c8..1026193bdf7 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp @@ -375,10 +375,11 @@ std::shared_ptr UltraComposer::compute_proving_key(CircuitBuilder& const size_t minimum_circuit_size = tables_size + lookups_size; const size_t num_randomized_gates = NUM_RESERVED_GATES; + auto crs_factory = srs::get_crs_factory(); // Initialize circuit_proving_key // TODO(#392)(Kesha): replace composer types. circuit_proving_key = initialize_proving_key( - circuit_constructor, crs_factory_.get(), minimum_circuit_size, num_randomized_gates, CircuitType::ULTRA); + circuit_constructor, crs_factory.get(), minimum_circuit_size, num_randomized_gates, CircuitType::ULTRA); construct_selector_polynomials(circuit_constructor, circuit_proving_key.get()); @@ -491,10 +492,12 @@ std::shared_ptr UltraComposer::compute_verification_key return circuit_verification_key; } + auto crs_factory = srs::get_crs_factory(); + if (!circuit_proving_key) { compute_proving_key(circuit_constructor); } - circuit_verification_key = compute_verification_key_common(circuit_proving_key, crs_factory_->get_verifier_crs()); + circuit_verification_key = compute_verification_key_common(circuit_proving_key, crs_factory->get_verifier_crs()); circuit_verification_key->circuit_type = CircuitType::ULTRA; diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp index fcea9028d83..0d365a6c0c4 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp @@ -27,7 +27,6 @@ class UltraComposer { std::shared_ptr circuit_verification_key; // The crs_factory holds the path to the srs and exposes methods to extract the srs elements - std::shared_ptr> crs_factory_; bool computed_witness = false; @@ -37,11 +36,7 @@ class UltraComposer { // vanishing_polynomial cannot be trivially fetched here, I am directly setting this to 4 - 1 = 3. static constexpr size_t s_randomness = 3; - UltraComposer() { crs_factory_ = barretenberg::srs::get_crs_factory(); } - - explicit UltraComposer(std::shared_ptr> crs_factory) - : crs_factory_(std::move(crs_factory)) - {} + UltraComposer() = default; UltraComposer(std::shared_ptr p_key, std::shared_ptr v_key) : circuit_proving_key(std::move(p_key))