From a485b041b6a32a015cc3453d3bb2b312129dd933 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 17 Jan 2024 20:30:23 +0000 Subject: [PATCH 01/20] split honk acir composer from original --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 3 +- .../dsl/acir_proofs/acir_composer.cpp | 27 ------------- .../dsl/acir_proofs/acir_composer.hpp | 8 ---- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 5 ++- .../dsl/acir_proofs/honk_acir_composer.cpp | 40 +++++++++++++++++++ .../dsl/acir_proofs/honk_acir_composer.hpp | 39 ++++++++++++++++++ 6 files changed, 84 insertions(+), 38 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp create mode 100644 barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 5f75206108e..ae976b54a47 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -135,7 +136,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); - acir_proofs::AcirComposer acir_composer; + acir_proofs::HonkAcirComposer acir_composer; acir_composer.create_goblin_circuit(constraint_system, witness); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set 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 a17e430d937..b11a2fb6fd0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -3,7 +3,6 @@ #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/dsl/acir_format/acir_format.hpp" #include "barretenberg/dsl/types.hpp" -#include "barretenberg/goblin/mock_circuits.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" @@ -61,27 +60,6 @@ std::vector AcirComposer::create_proof(bool is_recursive) return proof; } -void AcirComposer::create_goblin_circuit(acir_format::acir_format& constraint_system, - acir_format::WitnessVector& witness) -{ - // Construct a builder using the witness and public input data from acir - goblin_builder_ = acir_format::GoblinBuilder{ - goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum - }; - - // Populate constraints in the builder via the data in constraint_system - acir_format::build_constraints(goblin_builder_, constraint_system, true); - - // TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the - // associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process. - GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_); -} - -std::vector AcirComposer::create_goblin_proof() -{ - return goblin.construct_proof(goblin_builder_); -} - std::shared_ptr AcirComposer::init_verification_key() { if (!proving_key_) { @@ -132,11 +110,6 @@ bool AcirComposer::verify_proof(std::vector const& proof, bool is_recur } } -bool AcirComposer::verify_goblin_proof(std::vector const& proof) -{ - return goblin.verify_proof({ proof }); -} - std::string AcirComposer::get_solidity_verifier() { std::ostringstream stream; 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 aaf77de67fa..e421d269ffe 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp @@ -1,6 +1,5 @@ #pragma once #include -#include namespace acir_proofs { @@ -38,15 +37,8 @@ class AcirComposer { std::vector serialize_verification_key_into_fields(); - // Goblin specific methods - void create_goblin_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); - std::vector create_goblin_proof(); - bool verify_goblin_proof(std::vector const& proof); - private: acir_format::Builder builder_; - acir_format::GoblinBuilder goblin_builder_; - Goblin goblin; size_t size_hint_; std::shared_ptr proving_key_; std::shared_ptr 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 954fe16832e..fdc9b516a33 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -6,6 +6,7 @@ #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/dsl/acir_format/acir_format.hpp" +#include "barretenberg/dsl/acir_proofs/honk_acir_composer.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" #include "barretenberg/srs/global_crs.hpp" @@ -62,7 +63,7 @@ WASM_EXPORT void acir_create_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* witness_vec, uint8_t** out) { - auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto acir_composer = reinterpret_cast(*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)); @@ -104,7 +105,7 @@ WASM_EXPORT void acir_get_proving_key(in_ptr acir_composer_ptr, uint8_t const* a WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) { - auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); *result = acir_composer->verify_goblin_proof(proof); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp new file mode 100644 index 00000000000..e4a6ea66bf2 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp @@ -0,0 +1,40 @@ +#include "honk_acir_composer.hpp" +#include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/dsl/acir_format/acir_format.hpp" +#include "barretenberg/dsl/types.hpp" +#include "barretenberg/goblin/mock_circuits.hpp" + +namespace acir_proofs { + +HonkAcirComposer::HonkAcirComposer(size_t size_hint, bool verbose) + : size_hint_(size_hint) + , verbose_(verbose) +{} + +void HonkAcirComposer::create_goblin_circuit(acir_format::acir_format& constraint_system, + acir_format::WitnessVector& witness) +{ + // Construct a builder using the witness and public input data from acir + goblin_builder_ = acir_format::GoblinBuilder{ + goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum + }; + + // Populate constraints in the builder via the data in constraint_system + acir_format::build_constraints(goblin_builder_, constraint_system, true); + + // TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the + // associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process. + GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_); +} + +std::vector HonkAcirComposer::create_goblin_proof() +{ + return goblin.construct_proof(goblin_builder_); +} + +bool HonkAcirComposer::verify_goblin_proof(std::vector const& proof) +{ + return goblin.verify_proof({ proof }); +} + +} // namespace acir_proofs diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp new file mode 100644 index 00000000000..05b82fac451 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp @@ -0,0 +1,39 @@ +#pragma once +#include +#include + +namespace acir_proofs { + +/** + * @brief A class responsible for marshalling construction of keys and prover and verifier instances used to prove + * satisfiability of circuits written in ACIR. + * @todo: This reflects the design of Plonk. Perhaps we should author new classes to better reflect the + * structure of the newer code since there's much more of that code now? + */ +class HonkAcirComposer { + + using WitnessVector = std::vector>; + + public: + HonkAcirComposer(size_t size_hint = 0, bool verbose = true); + + // Goblin specific methods + void create_goblin_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); + std::vector create_goblin_proof(); + bool verify_goblin_proof(std::vector const& proof); + + private: + acir_format::GoblinBuilder goblin_builder_; + Goblin goblin; + size_t size_hint_; + bool verbose_ = true; + + template inline void vinfo(Args... args) + { + if (verbose_) { + info(args...); + } + } +}; + +} // namespace acir_proofs From 44259eec61d02a473f2f40b6d3e4e4bcaeb9d9b5 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 17 Jan 2024 21:33:33 +0000 Subject: [PATCH 02/20] use accumulate framework for basic GUH --- barretenberg/acir_tests/Dockerfile.bb.js | 3 ++- barretenberg/cpp/src/barretenberg/bb/main.cpp | 6 +++--- .../src/barretenberg/dsl/acir_proofs/c_bind.cpp | 6 +++--- .../dsl/acir_proofs/honk_acir_composer.cpp | 16 ++++++---------- .../dsl/acir_proofs/honk_acir_composer.hpp | 9 ++++----- .../cpp/src/barretenberg/goblin/goblin.hpp | 17 ++++++++++++++--- 6 files changed, 32 insertions(+), 25 deletions(-) diff --git a/barretenberg/acir_tests/Dockerfile.bb.js b/barretenberg/acir_tests/Dockerfile.bb.js index 4409bf7ce22..c0f0e32463f 100644 --- a/barretenberg/acir_tests/Dockerfile.bb.js +++ b/barretenberg/acir_tests/Dockerfile.bb.js @@ -14,7 +14,8 @@ COPY . . ENV VERBOSE=1 # Run double_verify_proof through bb.js on node to check 512k support. RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh double_verify_proof -RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin ./run_acir_tests.sh double_verify_proof +# Run a single arbitrary test not involving recursion through bb.js for Honk +RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array # Run 1_mul through bb.js build, all_cmds flow, to test all cli args. RUN BIN=../ts/dest/node/main.js FLOW=all_cmds ./run_acir_tests.sh 1_mul # Run double_verify_proof through bb.js on chrome testing multi-threaded browser support. diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index ae976b54a47..952ddc84fb9 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -137,7 +137,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, auto witness = get_witness(witnessPath); acir_proofs::HonkAcirComposer acir_composer; - acir_composer.create_goblin_circuit(constraint_system, witness); + acir_composer.create_circuit(constraint_system, witness); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set // to max circuit size present in acir tests suite. @@ -146,9 +146,9 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); - auto proof = acir_composer.create_goblin_proof(); + auto proof = acir_composer.create_proof(); - auto verified = acir_composer.verify_goblin_proof(proof); + auto verified = acir_composer.verify_proof(proof); return verified; } 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 fdc9b516a33..cc962ece3b3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -67,8 +67,8 @@ WASM_EXPORT void acir_create_goblin_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)); - acir_composer->create_goblin_circuit(constraint_system, witness); - auto proof_data = acir_composer->create_goblin_proof(); + acir_composer->create_circuit(constraint_system, witness); + auto proof_data = acir_composer->create_proof(); *out = to_heap_buffer(proof_data); } @@ -107,7 +107,7 @@ WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t cons { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); - *result = acir_composer->verify_goblin_proof(proof); + *result = acir_composer->verify_proof(proof); } WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp index e4a6ea66bf2..82bd792428e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp @@ -6,13 +6,9 @@ namespace acir_proofs { -HonkAcirComposer::HonkAcirComposer(size_t size_hint, bool verbose) - : size_hint_(size_hint) - , verbose_(verbose) -{} +HonkAcirComposer::HonkAcirComposer() {} -void HonkAcirComposer::create_goblin_circuit(acir_format::acir_format& constraint_system, - acir_format::WitnessVector& witness) +void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness) { // Construct a builder using the witness and public input data from acir goblin_builder_ = acir_format::GoblinBuilder{ @@ -27,14 +23,14 @@ void HonkAcirComposer::create_goblin_circuit(acir_format::acir_format& constrain GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_); } -std::vector HonkAcirComposer::create_goblin_proof() +std::vector HonkAcirComposer::create_proof() { - return goblin.construct_proof(goblin_builder_); + return goblin.accumulate_for_acir(goblin_builder_); } -bool HonkAcirComposer::verify_goblin_proof(std::vector const& proof) +bool HonkAcirComposer::verify_proof(std::vector const& proof) { - return goblin.verify_proof({ proof }); + return goblin.verify_accumulator(proof); } } // namespace acir_proofs diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp index 05b82fac451..731c9fa104a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp @@ -15,17 +15,16 @@ class HonkAcirComposer { using WitnessVector = std::vector>; public: - HonkAcirComposer(size_t size_hint = 0, bool verbose = true); + HonkAcirComposer(); // Goblin specific methods - void create_goblin_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); - std::vector create_goblin_proof(); - bool verify_goblin_proof(std::vector const& proof); + void create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); + std::vector create_proof(); + bool verify_proof(std::vector const& proof); private: acir_format::GoblinBuilder goblin_builder_; Goblin goblin; - size_t size_hint_; bool verbose_ = true; template inline void vinfo(Args... args) diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 1d669484f93..80bb86af40a 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -164,7 +164,7 @@ class Goblin { }; // ACIRHACK - AccumulationOutput accumulate_for_acir(GoblinUltraCircuitBuilder& circuit_builder) + std::vector accumulate_for_acir(GoblinUltraCircuitBuilder& circuit_builder) { // Complete the circuit logic by recursively verifying previous merge proof if it exists if (merge_proof_exists) { @@ -178,6 +178,8 @@ class Goblin { auto prover = composer.create_prover(instance); auto ultra_proof = prover.construct_proof(); + accumulator = { ultra_proof, instance->verification_key }; + // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): no merge prover for now since we're not // mocking the first set of ecc ops // // Construct and store the merge proof to be recursively verified on the next call to accumulate @@ -188,8 +190,7 @@ class Goblin { // merge_proof_exists = true; // } - accumulator = { ultra_proof, instance->verification_key }; - return accumulator; + return accumulator.proof.proof_data; }; // ACIRHACK @@ -271,5 +272,15 @@ class Goblin { return verified; } + + // ACIRHACK + bool verify_accumulator(const std::vector& proof_buf) const + { + GoblinUltraVerifier verifier{ accumulator.verification_key }; + HonkProof proof{ proof_buf }; + bool verified = verifier.verify_proof(proof); + + return verified; + } }; } // namespace bb \ No newline at end of file From 735fd297a44a08f15e5a4fe5150e19301fdcb401 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 17 Jan 2024 21:54:39 +0000 Subject: [PATCH 03/20] use accumulate nomenclature --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 6 ++++-- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 4 ++-- .../dsl/acir_proofs/honk_acir_composer.cpp | 6 +++--- .../dsl/acir_proofs/honk_acir_composer.hpp | 4 ++-- .../cpp/src/barretenberg/goblin/goblin.hpp | 21 ------------------- 5 files changed, 11 insertions(+), 30 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 952ddc84fb9..0d564ff2629 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -146,9 +146,11 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); - auto proof = acir_composer.create_proof(); + // Call accumulate to generate a GoblinUltraHonk proof + auto proof = acir_composer.accumulate(); - auto verified = acir_composer.verify_proof(proof); + // Verify the GoblinUltraHonk proof + auto verified = acir_composer.verify_accumulator(proof); return verified; } 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 cc962ece3b3..f5341382db3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -68,7 +68,7 @@ WASM_EXPORT void acir_create_goblin_proof(in_ptr acir_composer_ptr, auto witness = acir_format::witness_buf_to_witness_data(from_buffer>(witness_vec)); acir_composer->create_circuit(constraint_system, witness); - auto proof_data = acir_composer->create_proof(); + auto proof_data = acir_composer->accumulate(); *out = to_heap_buffer(proof_data); } @@ -107,7 +107,7 @@ WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t cons { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); - *result = acir_composer->verify_proof(proof); + *result = acir_composer->verify_accumulator(proof); } WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp index 82bd792428e..14aefd1b0d2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp @@ -10,7 +10,7 @@ HonkAcirComposer::HonkAcirComposer() {} void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness) { - // Construct a builder using the witness and public input data from acir + // Construct a builder using the witness and public input data from acir and with the goblin-owned op_queue goblin_builder_ = acir_format::GoblinBuilder{ goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum }; @@ -23,12 +23,12 @@ void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_syste GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_); } -std::vector HonkAcirComposer::create_proof() +std::vector HonkAcirComposer::accumulate() { return goblin.accumulate_for_acir(goblin_builder_); } -bool HonkAcirComposer::verify_proof(std::vector const& proof) +bool HonkAcirComposer::verify_accumulator(std::vector const& proof) { return goblin.verify_accumulator(proof); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp index 731c9fa104a..4b237e33d04 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp @@ -19,8 +19,8 @@ class HonkAcirComposer { // Goblin specific methods void create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); - std::vector create_proof(); - bool verify_proof(std::vector const& proof); + std::vector accumulate(); + bool verify_accumulator(std::vector const& proof); private: acir_format::GoblinBuilder goblin_builder_; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 80bb86af40a..90b2b3b993c 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -235,27 +235,6 @@ class Goblin { return /* merge_verified && */ eccvm_verified && accumulator_construction_verified && translation_verified; }; - // ACIRHACK - std::vector construct_proof(GoblinUltraCircuitBuilder& builder) - { - // Construct a GUH proof - accumulate_for_acir(builder); - - std::vector result(accumulator.proof.proof_data.size()); - - const auto insert = [&result](const std::vector& buf) { - result.insert(result.end(), buf.begin(), buf.end()); - }; - - insert(accumulator.proof.proof_data); - - // TODO(https://github.com/AztecProtocol/barretenberg/issues/819): Skip ECCVM/Translator proof for now - // std::vector goblin_proof = prove_for_acir().to_buffer(); - // insert(goblin_proof); - - return result; - } - // ACIRHACK bool verify_proof([[maybe_unused]] const proof_system::plonk::proof& proof) const { From ebbc8f76e8a5981c0468d7f7e9ca5ec157f1e944 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 18:01:08 +0000 Subject: [PATCH 04/20] update to use accumulate nomenclature everywhere --- .../flows/accumulate_and_verify_goblin.sh | 6 +++ barretenberg/cpp/src/barretenberg/bb/main.cpp | 38 +++++++++++++++++ .../barretenberg/dsl/acir_proofs/c_bind.cpp | 8 ++-- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 8 ++-- .../dsl/acir_proofs/honk_acir_composer.hpp | 24 +++++++++-- barretenberg/exports.json | 2 +- barretenberg/ts/src/barretenberg_api/index.ts | 8 ++-- barretenberg/ts/src/main.ts | 41 ++++++++++++++++++- 8 files changed, 118 insertions(+), 17 deletions(-) create mode 100755 barretenberg/acir_tests/flows/accumulate_and_verify_goblin.sh diff --git a/barretenberg/acir_tests/flows/accumulate_and_verify_goblin.sh b/barretenberg/acir_tests/flows/accumulate_and_verify_goblin.sh new file mode 100755 index 00000000000..a89e1a1dba1 --- /dev/null +++ b/barretenberg/acir_tests/flows/accumulate_and_verify_goblin.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -eu + +VFLAG=${VERBOSE:+-v} + +$BIN accumulate_and_verify_goblin $VFLAG -c $CRS_PATH -b ./target/acir.gz \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 0d564ff2629..917e497a29a 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -116,6 +116,41 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP return verified; } +/** + * @brief Constructs and verifies a Honk proof for an ACIR circuit via the Goblin accumulate mechanism + * + * Communication: + * - proc_exit: A boolean value is returned indicating whether the proof is valid. + * an exit code of 0 will be returned for success and 1 for failure. + * + * @param bytecodePath Path to the file containing the serialized acir constraint system + * @param witnessPath Path to the file containing the serialized witness + * @return verified + */ +bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::string& witnessPath) +{ + auto constraint_system = get_constraint_system(bytecodePath); + auto witness = get_witness(witnessPath); + + acir_proofs::HonkAcirComposer acir_composer; + acir_composer.create_circuit(constraint_system, witness); + + // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set + // to max circuit size present in acir tests suite. + size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; + init_bn254_crs(hardcoded_bn254_dyadic_size_hack); + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only + init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); + + // Call accumulate to generate a GoblinUltraHonk proof + auto proof = acir_composer.accumulate(); + + // Verify the GoblinUltraHonk proof + auto verified = acir_composer.verify_accumulator(proof); + + return verified; +} + /** * @brief Proves and Verifies an ACIR circuit * @@ -461,6 +496,9 @@ int main(int argc, char* argv[]) if (command == "prove_and_verify") { return proveAndVerify(bytecode_path, witness_path, recursive) ? 0 : 1; } + if (command == "accumulate_and_verify_goblin") { + return accumulateAndVerifyGoblin(bytecode_path, witness_path) ? 0 : 1; + } if (command == "prove_and_verify_goblin") { return proveAndVerifyGoblin(bytecode_path, witness_path, recursive) ? 0 : 1; } 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 f5341382db3..8c14cad39be 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -58,10 +58,10 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr, *out = to_heap_buffer(proof_data); } -WASM_EXPORT void acir_create_goblin_proof(in_ptr acir_composer_ptr, - uint8_t const* acir_vec, - uint8_t const* witness_vec, - uint8_t** out) +WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, + uint8_t const* acir_vec, + uint8_t const* witness_vec, + uint8_t** out) { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto constraint_system = acir_format::circuit_buf_to_acir_format(from_buffer>(acir_vec)); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index cb6b8643512..0e7126bb5ef 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -32,10 +32,10 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr, bool const* is_recursive, uint8_t** out); -WASM_EXPORT void acir_create_goblin_proof(in_ptr acir_composer_ptr, - uint8_t const* constraint_system_buf, - uint8_t const* witness_buf, - uint8_t** out); +WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, + uint8_t const* constraint_system_buf, + uint8_t const* witness_buf, + uint8_t** out); WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp index 4b237e33d04..c40268c2675 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp @@ -7,8 +7,7 @@ namespace acir_proofs { /** * @brief A class responsible for marshalling construction of keys and prover and verifier instances used to prove * satisfiability of circuits written in ACIR. - * @todo: This reflects the design of Plonk. Perhaps we should author new classes to better reflect the - * structure of the newer code since there's much more of that code now? + * */ class HonkAcirComposer { @@ -17,9 +16,28 @@ class HonkAcirComposer { public: HonkAcirComposer(); - // Goblin specific methods + /** + * @brief Create a GUH circuit from an acir constraint system and a witness + * + * @param constraint_system ACIR representation of the constraints defining the circuit + * @param witness The witness values known to ACIR during construction of the constraint system + */ void create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness); + + /** + * @brief Accumulate a circuit via Goblin + * @details For the present circuit, construct a GUH proof and the vkey needed to verify it + * + * @return std::vector The GUH proof bytes + */ std::vector accumulate(); + + /** + * @brief Verify the Goblin accumulator (the GUH proof) using the vkey internal to Goblin + * + * @param proof + * @return bool Whether or not the proof was verified + */ bool verify_accumulator(std::vector const& proof); private: diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 6a8bd360ccf..b7a8dca7a5e 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -540,7 +540,7 @@ "isAsync": false }, { - "functionName": "acir_create_goblin_proof", + "functionName": "acir_goblin_accumulate", "inArgs": [ { "name": "acir_composer_ptr", diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 9ee50ba908b..ebd5c8fc713 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -357,7 +357,7 @@ export class BarretenbergApi { return out[0]; } - async acirCreateGoblinProof( + async acirGoblinAccumulate( acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, @@ -365,7 +365,7 @@ export class BarretenbergApi { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; const result = await this.wasm.callWasmExport( - 'acir_create_goblin_proof', + 'acir_goblin_accumulate', inArgs, outTypes.map(t => t.SIZE_IN_BYTES), ); @@ -830,11 +830,11 @@ export class BarretenbergApiSync { return out[0]; } - acirCreateGoblinProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; const result = this.wasm.callWasmExport( - 'acir_create_goblin_proof', + 'acir_goblin_accumulate', inArgs, outTypes.map(t => t.SIZE_IN_BYTES), ); diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 208c4851a1f..aa80bbdb00d 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -128,6 +128,34 @@ export async function proveAndVerify(bytecodePath: string, witnessPath: string, /* eslint-enable camelcase */ } +export async function accumulateAndVerifyGoblin(bytecodePath: string, witnessPath: string, crsPath: string) { + /* eslint-disable camelcase */ + const acir_test = path.basename(process.cwd()); + + const { api, acirComposer, circuitSize, subgroupSize } = await initGoblin(bytecodePath, crsPath); + try { + debug(`creating proof...`); + const bytecode = getBytecode(bytecodePath); + const witness = getWitness(witnessPath); + + writeBenchmark('gate_count', circuitSize, { acir_test, threads }); + writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); + + const proofTimer = new Timer(); + const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); + writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); + + debug(`verifying...`); + const verified = await api.acirVerifyGoblinProof(acirComposer, proof); + debug(`verified: ${verified}`); + console.log({ verified }); + return verified; + } finally { + await api.destroy(); + } + /* eslint-enable camelcase */ +} + export async function proveAndVerifyGoblin(bytecodePath: string, witnessPath: string, crsPath: string) { /* eslint-disable camelcase */ const acir_test = path.basename(process.cwd()); @@ -142,7 +170,7 @@ export async function proveAndVerifyGoblin(bytecodePath: string, witnessPath: st writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); const proofTimer = new Timer(); - const proof = await api.acirCreateGoblinProof(acirComposer, bytecode, witness); + const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); debug(`verifying...`); @@ -356,6 +384,17 @@ program process.exit(result ? 0 : 1); }); +program + .command('accumulate_and_verify_goblin') + .description('Generate a proof and verify it. Process exits with success or failure code.') + .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/acir.gz') + .option('-w, --witness-path ', 'Specify the witness path', './target/witness.gz') + .action(async ({ bytecodePath, witnessPath, crsPath }) => { + handleGlobalOptions(); + const result = await accumulateAndVerifyGoblin(bytecodePath, witnessPath, crsPath); + process.exit(result ? 0 : 1); + }); + program .command('prove_and_verify_goblin') .description('Generate a proof and verify it. Process exits with success or failure code.') From f95a12a204317f8f99e3c2ad60c029b7957b11b6 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 19:04:47 +0000 Subject: [PATCH 05/20] update docker files to use accumulate --- barretenberg/acir_tests/Dockerfile.bb | 2 +- barretenberg/acir_tests/Dockerfile.bb.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/acir_tests/Dockerfile.bb b/barretenberg/acir_tests/Dockerfile.bb index a20d3d53280..3b59140e35b 100644 --- a/barretenberg/acir_tests/Dockerfile.bb +++ b/barretenberg/acir_tests/Dockerfile.bb @@ -11,6 +11,6 @@ COPY . . # This ensures we test independent pk construction through real/garbage witness data paths. RUN FLOW=prove_then_verify ./run_acir_tests.sh # TODO(https://github.com/AztecProtocol/barretenberg/issues/811) make this able to run the default test -RUN FLOW=prove_and_verify_goblin ./run_acir_tests.sh +RUN FLOW=accumulate_and_verify_goblin ./run_acir_tests.sh # Run 1_mul through native bb build, all_cmds flow, to test all cli args. RUN VERBOSE=1 FLOW=all_cmds ./run_acir_tests.sh 1_mul diff --git a/barretenberg/acir_tests/Dockerfile.bb.js b/barretenberg/acir_tests/Dockerfile.bb.js index c0f0e32463f..5ca0ddc1515 100644 --- a/barretenberg/acir_tests/Dockerfile.bb.js +++ b/barretenberg/acir_tests/Dockerfile.bb.js @@ -15,7 +15,7 @@ ENV VERBOSE=1 # Run double_verify_proof through bb.js on node to check 512k support. RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh double_verify_proof # Run a single arbitrary test not involving recursion through bb.js for Honk -RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array +RUN BIN=../ts/dest/node/main.js FLOW=accumulate_and_verify_goblin ./run_acir_tests.sh 6_array # Run 1_mul through bb.js build, all_cmds flow, to test all cli args. RUN BIN=../ts/dest/node/main.js FLOW=all_cmds ./run_acir_tests.sh 1_mul # Run double_verify_proof through bb.js on chrome testing multi-threaded browser support. From 22bfac8d3578de045a2eb113e9e89ce158984a16 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 19:26:15 +0000 Subject: [PATCH 06/20] debug prints --- barretenberg/ts/src/main.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index aa80bbdb00d..dc66cf2aa29 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -134,18 +134,21 @@ export async function accumulateAndVerifyGoblin(bytecodePath: string, witnessPat const { api, acirComposer, circuitSize, subgroupSize } = await initGoblin(bytecodePath, crsPath); try { - debug(`creating proof...`); + debug(`In accumulateAndVerifyGoblin:`); + debug(`getBytecode()`); const bytecode = getBytecode(bytecodePath); + debug(`getWitness()`); const witness = getWitness(witnessPath); writeBenchmark('gate_count', circuitSize, { acir_test, threads }); writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); + debug(`acirGoblinAccumulate()`); const proofTimer = new Timer(); const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); - debug(`verifying...`); + debug(`acirVerifyGoblinProof()`); const verified = await api.acirVerifyGoblinProof(acirComposer, proof); debug(`verified: ${verified}`); console.log({ verified }); From 934e38ab74a5444f23d102ebcf2e7609885c4d31 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 20:38:35 +0000 Subject: [PATCH 07/20] full goblin verifies --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 8 ++-- .../dsl/acir_proofs/honk_acir_composer.cpp | 31 +++++++++++-- .../dsl/acir_proofs/honk_acir_composer.hpp | 19 +++++++- .../cpp/src/barretenberg/goblin/goblin.hpp | 43 +++++++++++-------- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 917e497a29a..5da57564a8d 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -181,11 +181,11 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); - // Call accumulate to generate a GoblinUltraHonk proof - auto proof = acir_composer.accumulate(); + // Generate a GoblinUltraHonk proof and a full Goblin proof + auto proof = acir_composer.accumulate_and_prove(); - // Verify the GoblinUltraHonk proof - auto verified = acir_composer.verify_accumulator(proof); + // Verify the GoblinUltraHonk proof and the full Goblin proof + auto verified = acir_composer.verify(proof); return verified; } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp index 14aefd1b0d2..c31a7a31d6a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp @@ -11,21 +11,22 @@ HonkAcirComposer::HonkAcirComposer() {} void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness) { // Construct a builder using the witness and public input data from acir and with the goblin-owned op_queue - goblin_builder_ = acir_format::GoblinBuilder{ + builder_ = acir_format::GoblinBuilder{ goblin.op_queue, witness, constraint_system.public_inputs, constraint_system.varnum }; // Populate constraints in the builder via the data in constraint_system - acir_format::build_constraints(goblin_builder_, constraint_system, true); + acir_format::build_constraints(builder_, constraint_system, true); // TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the // associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process. - GoblinMockCircuits::construct_goblin_ecc_op_circuit(goblin_builder_); + GoblinMockCircuits::construct_goblin_ecc_op_circuit(builder_); } std::vector HonkAcirComposer::accumulate() { - return goblin.accumulate_for_acir(goblin_builder_); + // Construct a GUH proof for the circuit via the accumulate mechanism + return goblin.accumulate_for_acir(builder_); } bool HonkAcirComposer::verify_accumulator(std::vector const& proof) @@ -33,4 +34,26 @@ bool HonkAcirComposer::verify_accumulator(std::vector const& proof) return goblin.verify_accumulator(proof); } +std::vector HonkAcirComposer::accumulate_and_prove() +{ + // Construct one final GUH proof via the accumulate mechanism + std::vector ultra_proof = goblin.accumulate_for_acir(builder_); + + // Construct a Goblin proof (ECCVM, Translator, Merge); result stored internally + goblin.prove_for_acir(); + + return ultra_proof; +} + +bool HonkAcirComposer::verify(std::vector const& proof) +{ + // Verify the final GUH proof + bool ultra_verified = goblin.verify_accumulator(proof); + + // Verify the Goblin proof (ECCVM, Translator, Merge) + bool goblin_verified = goblin.verify_for_acir(); + + return ultra_verified && goblin_verified; +} + } // namespace acir_proofs diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp index c40268c2675..e6aa283d029 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp @@ -40,8 +40,25 @@ class HonkAcirComposer { */ bool verify_accumulator(std::vector const& proof); + /** + * @brief Accumulate a final circuit and construct a full Goblin proof + * @details Accumulation means constructing a GUH proof of a single (final) circuit. A full Goblin proof consists of + * a merge proof, an ECCVM proof and a Translator proof. The Goblin proof is only constructed at the end of the + * accumulation phase and establishes the correctness of the ECC operations written to the op queue throughout the + * accumulation phase. + * + */ + std::vector accumulate_and_prove(); + + /** + * @brief Verify the final GUH proof and the full Goblin proof + * + * @return bool verified + */ + bool verify(std::vector const& proof); + private: - acir_format::GoblinBuilder goblin_builder_; + acir_format::GoblinBuilder builder_; Goblin goblin; bool verbose_ = true; diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 90b2b3b993c..3da8870b399 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -163,6 +163,9 @@ class Goblin { return merge_verified && eccvm_verified && accumulator_construction_verified && translation_verified; }; + // The methods below this point are to be used only for ACIR. They exist while the interface is in flux. Eventually + // there will be agreement and no acir-specific methods should be needed. + // ACIRHACK std::vector accumulate_for_acir(GoblinUltraCircuitBuilder& circuit_builder) { @@ -217,40 +220,42 @@ class Goblin { }; // ACIRHACK - bool verify_for_acir(const Proof& proof) const + bool verify_for_acir() const { // ACIRHACK // MergeVerifier merge_verifier; - // bool merge_verified = merge_verifier.verify_proof(proof.merge_proof); + // bool merge_verified = merge_verifier.verify_proof(proof_.merge_proof); auto eccvm_verifier = eccvm_composer->create_verifier(*eccvm_builder); - bool eccvm_verified = eccvm_verifier.verify_proof(proof.eccvm_proof); + bool eccvm_verified = eccvm_verifier.verify_proof(proof_.eccvm_proof); auto translator_verifier = translator_composer->create_verifier(*translator_builder, eccvm_verifier.transcript); - bool accumulator_construction_verified = translator_verifier.verify_proof(proof.translator_proof); + bool translation_accumulator_construction_verified = translator_verifier.verify_proof(proof_.translator_proof); // TODO(https://github.com/AztecProtocol/barretenberg/issues/799): Ensure translation_evaluations are passed // correctly - bool translation_verified = translator_verifier.verify_translation(proof.translation_evaluations); + bool translation_verified = translator_verifier.verify_translation(proof_.translation_evaluations); - return /* merge_verified && */ eccvm_verified && accumulator_construction_verified && translation_verified; + return /* merge_verified && */ eccvm_verified && translation_accumulator_construction_verified && + translation_verified; }; - // ACIRHACK - bool verify_proof([[maybe_unused]] const proof_system::plonk::proof& proof) const - { - // ACIRHACK: to do this properly, extract the proof correctly or maybe share transcripts. - const auto extract_final_kernel_proof = [&]([[maybe_unused]] auto& input_proof) { return accumulator.proof; }; + // // ACIRHACK + // bool verify_proof([[maybe_unused]] const proof_system::plonk::proof& proof) const + // { + // // ACIRHACK: to do this properly, extract the proof correctly or maybe share transcripts. + // const auto extract_final_kernel_proof = [&]([[maybe_unused]] auto& input_proof) { return accumulator.proof; + // }; - GoblinUltraVerifier verifier{ accumulator.verification_key }; - bool verified = verifier.verify_proof(extract_final_kernel_proof(proof)); + // GoblinUltraVerifier verifier{ accumulator.verification_key }; + // bool verified = verifier.verify_proof(extract_final_kernel_proof(proof)); - // TODO(https://github.com/AztecProtocol/barretenberg/issues/819): Skip ECCVM/Translator verification for now - // const auto extract_goblin_proof = [&]([[maybe_unused]] auto& input_proof) { return proof_; }; - // auto goblin_proof = extract_goblin_proof(proof); - // verified = verified && verify_for_acir(goblin_proof); + // // TODO(https://github.com/AztecProtocol/barretenberg/issues/819): Skip ECCVM/Translator verification for now + // // const auto extract_goblin_proof = [&]([[maybe_unused]] auto& input_proof) { return proof_; }; + // // auto goblin_proof = extract_goblin_proof(proof); + // // verified = verified && verify_for_acir(goblin_proof); - return verified; - } + // return verified; + // } // ACIRHACK bool verify_accumulator(const std::vector& proof_buf) const From 1402ef720f6287e12b957b5fe33fb92fca86f1e9 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 21:07:40 +0000 Subject: [PATCH 08/20] cleanup and commenting --- .../dsl/acir_proofs/honk_acir_composer.cpp | 4 +- .../cpp/src/barretenberg/goblin/goblin.hpp | 135 +++++++++--------- 2 files changed, 72 insertions(+), 67 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp index c31a7a31d6a..26e0ef2bb11 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp @@ -31,7 +31,7 @@ std::vector HonkAcirComposer::accumulate() bool HonkAcirComposer::verify_accumulator(std::vector const& proof) { - return goblin.verify_accumulator(proof); + return goblin.verify_accumulator_for_acir(proof); } std::vector HonkAcirComposer::accumulate_and_prove() @@ -48,7 +48,7 @@ std::vector HonkAcirComposer::accumulate_and_prove() bool HonkAcirComposer::verify(std::vector const& proof) { // Verify the final GUH proof - bool ultra_verified = goblin.verify_accumulator(proof); + bool ultra_verified = goblin.verify_accumulator_for_acir(proof); // Verify the Goblin proof (ECCVM, Translator, Merge) bool goblin_verified = goblin.verify_for_acir(); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 3da8870b399..d1fed426ee8 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -85,12 +85,12 @@ class Goblin { std::unique_ptr eccvm_prover; std::unique_ptr translator_composer; - AccumulationOutput accumulator; // ACIRHACK - Proof proof_; // ACIRHACK + AccumulationOutput accumulator; // Used only for ACIR methods public: /** - * @brief If there is a previous merge proof, recursively verify it. Generate next accmulated proof and merge proof. + * @brief Construct a GUH proof and a merge proof for the present circuit. + * @details If there is a previous merge proof, recursively verify it. * * @param circuit_builder */ @@ -119,10 +119,12 @@ class Goblin { return { ultra_proof, instance->verification_key }; }; + /** + * @brief Construct an ECCVM proof and the translation polynomial evaluations + * + */ void prove_eccvm() { - goblin_proof.merge_proof = std::move(merge_proof); - eccvm_builder = std::make_unique(op_queue); eccvm_composer = std::make_unique(); eccvm_prover = std::make_unique(eccvm_composer->create_prover(*eccvm_builder)); @@ -130,6 +132,10 @@ class Goblin { goblin_proof.translation_evaluations = eccvm_prover->translation_evaluations; }; + /** + * @brief Construct a translator proof + * + */ void prove_translator() { translator_builder = std::make_unique( @@ -139,13 +145,28 @@ class Goblin { goblin_proof.translator_proof = translator_prover.construct_proof(); }; + /** + * @brief Constuct a full Goblin proof (ECCVM, Translator, merge) + * @details The merge proof is assumed to already have been constucted in the last accumulate step. It is simply + * copied into the final proof here. + * + * @return Proof + */ Proof prove() { + goblin_proof.merge_proof = std::move(merge_proof); prove_eccvm(); prove_translator(); return goblin_proof; }; + /** + * @brief Verify a full Goblin proof (ECCVM, Translator, merge) + * + * @param proof + * @return true + * @return false + */ bool verify(const Proof& proof) { MergeVerifier merge_verifier; @@ -166,14 +187,20 @@ class Goblin { // The methods below this point are to be used only for ACIR. They exist while the interface is in flux. Eventually // there will be agreement and no acir-specific methods should be needed. - // ACIRHACK + /** + * @brief Construct a GUH proof for the given circuit. (No merge proof for now) + * + * @param circuit_builder + * @return std::vector + */ std::vector accumulate_for_acir(GoblinUltraCircuitBuilder& circuit_builder) { - // Complete the circuit logic by recursively verifying previous merge proof if it exists - if (merge_proof_exists) { - RecursiveMergeVerifier merge_verifier{ &circuit_builder }; - [[maybe_unused]] auto pairing_points = merge_verifier.verify_proof(merge_proof); - } + // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): no merge prover for now + // // Complete the circuit logic by recursively verifying previous merge proof if it exists + // if (merge_proof_exists) { + // RecursiveMergeVerifier merge_verifier{ &circuit_builder }; + // [[maybe_unused]] auto pairing_points = merge_verifier.verify_proof(merge_proof); + // } // Construct a Honk proof for the main circuit GoblinUltraComposer composer; @@ -193,78 +220,56 @@ class Goblin { // merge_proof_exists = true; // } - return accumulator.proof.proof_data; + return ultra_proof.proof_data; }; - // ACIRHACK - Proof prove_for_acir() + /** + * @brief Verify a GUH proof + * + * @param proof_buf + * @return true + * @return false + */ + bool verify_accumulator_for_acir(const std::vector& proof_buf) const { - Proof proof; - - proof.merge_proof = std::move(merge_proof); - - eccvm_builder = std::make_unique(op_queue); - eccvm_composer = std::make_unique(); - auto eccvm_prover = eccvm_composer->create_prover(*eccvm_builder); - proof.eccvm_proof = eccvm_prover.construct_proof(); - proof.translation_evaluations = eccvm_prover.translation_evaluations; + GoblinUltraVerifier verifier{ accumulator.verification_key }; + HonkProof proof{ proof_buf }; + bool verified = verifier.verify_proof(proof); - translator_builder = std::make_unique( - eccvm_prover.translation_batching_challenge_v, eccvm_prover.evaluation_challenge_x, op_queue); - translator_composer = std::make_unique(); - auto translator_prover = translator_composer->create_prover(*translator_builder, eccvm_prover.transcript); - proof.translator_proof = translator_prover.construct_proof(); + return verified; + } - proof_ = proof; // ACIRHACK - return proof; - }; + /** + * @brief Construct a Goblin proof + * + * @return Proof + */ + Proof prove_for_acir() { return prove(); }; - // ACIRHACK + /** + * @brief Verify a Goblin proof (excluding the merge proof for now) + * + * @return true + * @return false + */ bool verify_for_acir() const { - // ACIRHACK + // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): No merge proof for now // MergeVerifier merge_verifier; - // bool merge_verified = merge_verifier.verify_proof(proof_.merge_proof); + // bool merge_verified = merge_verifier.verify_proof(goblin_proof.merge_proof); auto eccvm_verifier = eccvm_composer->create_verifier(*eccvm_builder); - bool eccvm_verified = eccvm_verifier.verify_proof(proof_.eccvm_proof); + bool eccvm_verified = eccvm_verifier.verify_proof(goblin_proof.eccvm_proof); auto translator_verifier = translator_composer->create_verifier(*translator_builder, eccvm_verifier.transcript); - bool translation_accumulator_construction_verified = translator_verifier.verify_proof(proof_.translator_proof); + bool translation_accumulator_construction_verified = + translator_verifier.verify_proof(goblin_proof.translator_proof); // TODO(https://github.com/AztecProtocol/barretenberg/issues/799): Ensure translation_evaluations are passed // correctly - bool translation_verified = translator_verifier.verify_translation(proof_.translation_evaluations); + bool translation_verified = translator_verifier.verify_translation(goblin_proof.translation_evaluations); return /* merge_verified && */ eccvm_verified && translation_accumulator_construction_verified && translation_verified; }; - - // // ACIRHACK - // bool verify_proof([[maybe_unused]] const proof_system::plonk::proof& proof) const - // { - // // ACIRHACK: to do this properly, extract the proof correctly or maybe share transcripts. - // const auto extract_final_kernel_proof = [&]([[maybe_unused]] auto& input_proof) { return accumulator.proof; - // }; - - // GoblinUltraVerifier verifier{ accumulator.verification_key }; - // bool verified = verifier.verify_proof(extract_final_kernel_proof(proof)); - - // // TODO(https://github.com/AztecProtocol/barretenberg/issues/819): Skip ECCVM/Translator verification for now - // // const auto extract_goblin_proof = [&]([[maybe_unused]] auto& input_proof) { return proof_; }; - // // auto goblin_proof = extract_goblin_proof(proof); - // // verified = verified && verify_for_acir(goblin_proof); - - // return verified; - // } - - // ACIRHACK - bool verify_accumulator(const std::vector& proof_buf) const - { - GoblinUltraVerifier verifier{ accumulator.verification_key }; - HonkProof proof{ proof_buf }; - bool verified = verifier.verify_proof(proof); - - return verified; - } }; } // namespace bb \ No newline at end of file From 851d430b91cde69ef6c4841a1bb581b566225055 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 21:13:47 +0000 Subject: [PATCH 09/20] Add goblin flow to docker --- barretenberg/acir_tests/Dockerfile.bb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/barretenberg/acir_tests/Dockerfile.bb b/barretenberg/acir_tests/Dockerfile.bb index 3b59140e35b..c3ce87378ba 100644 --- a/barretenberg/acir_tests/Dockerfile.bb +++ b/barretenberg/acir_tests/Dockerfile.bb @@ -7,10 +7,12 @@ COPY --from=0 /usr/src/barretenberg/cpp/build /usr/src/barretenberg/cpp/build COPY --from=noir-acir-tests /usr/src/noir/test_programs /usr/src/noir/test_programs WORKDIR /usr/src/barretenberg/acir_tests COPY . . -# Run every acir test through native bb build prove_then_verify flow. +# Run every acir test through native bb build prove_then_verify flow for UltraPlonk. # This ensures we test independent pk construction through real/garbage witness data paths. RUN FLOW=prove_then_verify ./run_acir_tests.sh -# TODO(https://github.com/AztecProtocol/barretenberg/issues/811) make this able to run the default test +# This flow is essentially the GoblinUltraHonk equivalent to the UltraPlonk "prove and verify". This functionality is accessed via the goblin "accumulate" mechanism. RUN FLOW=accumulate_and_verify_goblin ./run_acir_tests.sh +# This is a "full" Goblin flow. It constructs and verifies four proofs: GoblinUltraHonk, ECCVM, Translator, and merge +RUN FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array # Run 1_mul through native bb build, all_cmds flow, to test all cli args. RUN VERBOSE=1 FLOW=all_cmds ./run_acir_tests.sh 1_mul From f3704002d3946ba691412ef01475698bcecb6892 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 21:33:28 +0000 Subject: [PATCH 10/20] name change honk to goblin --- barretenberg/acir_tests/Dockerfile.bb | 3 ++- barretenberg/cpp/src/barretenberg/bb/main.cpp | 8 +++----- .../src/barretenberg/dsl/acir_proofs/c_bind.cpp | 6 +++--- ...acir_composer.cpp => goblin_acir_composer.cpp} | 15 ++++++++------- ...acir_composer.hpp => goblin_acir_composer.hpp} | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) rename barretenberg/cpp/src/barretenberg/dsl/acir_proofs/{honk_acir_composer.cpp => goblin_acir_composer.cpp} (76%) rename barretenberg/cpp/src/barretenberg/dsl/acir_proofs/{honk_acir_composer.hpp => goblin_acir_composer.hpp} (97%) diff --git a/barretenberg/acir_tests/Dockerfile.bb b/barretenberg/acir_tests/Dockerfile.bb index c3ce87378ba..006db0e5333 100644 --- a/barretenberg/acir_tests/Dockerfile.bb +++ b/barretenberg/acir_tests/Dockerfile.bb @@ -10,7 +10,8 @@ COPY . . # Run every acir test through native bb build prove_then_verify flow for UltraPlonk. # This ensures we test independent pk construction through real/garbage witness data paths. RUN FLOW=prove_then_verify ./run_acir_tests.sh -# This flow is essentially the GoblinUltraHonk equivalent to the UltraPlonk "prove and verify". This functionality is accessed via the goblin "accumulate" mechanism. +# This flow is essentially the GoblinUltraHonk equivalent to the UltraPlonk "prove and verify". (This functionality is +# accessed via the goblin "accumulate" mechanism). RUN FLOW=accumulate_and_verify_goblin ./run_acir_tests.sh # This is a "full" Goblin flow. It constructs and verifies four proofs: GoblinUltraHonk, ECCVM, Translator, and merge RUN FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 5da57564a8d..77f7f797713 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -132,7 +132,7 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); - acir_proofs::HonkAcirComposer acir_composer; + acir_proofs::GoblinAcirComposer acir_composer; acir_composer.create_circuit(constraint_system, witness); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set @@ -171,15 +171,13 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); - acir_proofs::HonkAcirComposer acir_composer; + acir_proofs::GoblinAcirComposer acir_composer; acir_composer.create_circuit(constraint_system, witness); // TODO(https://github.com/AztecProtocol/barretenberg/issues/811): Don't hardcode dyadic circuit size. Currently set // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); - size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only - init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Generate a GoblinUltraHonk proof and a full Goblin proof auto proof = acir_composer.accumulate_and_prove(); 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 8c14cad39be..9ce2b55d009 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -6,7 +6,7 @@ #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/slab_allocator.hpp" #include "barretenberg/dsl/acir_format/acir_format.hpp" -#include "barretenberg/dsl/acir_proofs/honk_acir_composer.hpp" +#include "barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" #include "barretenberg/srs/global_crs.hpp" @@ -63,7 +63,7 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, uint8_t const* witness_vec, uint8_t** out) { - auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto acir_composer = reinterpret_cast(*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)); @@ -105,7 +105,7 @@ WASM_EXPORT void acir_get_proving_key(in_ptr acir_composer_ptr, uint8_t const* a WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) { - auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); *result = acir_composer->verify_accumulator(proof); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp similarity index 76% rename from barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp rename to barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp index 26e0ef2bb11..1127de60fb2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp @@ -1,4 +1,4 @@ -#include "honk_acir_composer.hpp" +#include "goblin_acir_composer.hpp" #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/dsl/acir_format/acir_format.hpp" #include "barretenberg/dsl/types.hpp" @@ -6,9 +6,10 @@ namespace acir_proofs { -HonkAcirComposer::HonkAcirComposer() {} +GoblinAcirComposer::GoblinAcirComposer() {} -void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_system, acir_format::WitnessVector& witness) +void GoblinAcirComposer::create_circuit(acir_format::acir_format& constraint_system, + acir_format::WitnessVector& witness) { // Construct a builder using the witness and public input data from acir and with the goblin-owned op_queue builder_ = acir_format::GoblinBuilder{ @@ -23,18 +24,18 @@ void HonkAcirComposer::create_circuit(acir_format::acir_format& constraint_syste GoblinMockCircuits::construct_goblin_ecc_op_circuit(builder_); } -std::vector HonkAcirComposer::accumulate() +std::vector GoblinAcirComposer::accumulate() { // Construct a GUH proof for the circuit via the accumulate mechanism return goblin.accumulate_for_acir(builder_); } -bool HonkAcirComposer::verify_accumulator(std::vector const& proof) +bool GoblinAcirComposer::verify_accumulator(std::vector const& proof) { return goblin.verify_accumulator_for_acir(proof); } -std::vector HonkAcirComposer::accumulate_and_prove() +std::vector GoblinAcirComposer::accumulate_and_prove() { // Construct one final GUH proof via the accumulate mechanism std::vector ultra_proof = goblin.accumulate_for_acir(builder_); @@ -45,7 +46,7 @@ std::vector HonkAcirComposer::accumulate_and_prove() return ultra_proof; } -bool HonkAcirComposer::verify(std::vector const& proof) +bool GoblinAcirComposer::verify(std::vector const& proof) { // Verify the final GUH proof bool ultra_verified = goblin.verify_accumulator_for_acir(proof); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp similarity index 97% rename from barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp rename to barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp index e6aa283d029..d8169202e62 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/honk_acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.hpp @@ -9,12 +9,12 @@ namespace acir_proofs { * satisfiability of circuits written in ACIR. * */ -class HonkAcirComposer { +class GoblinAcirComposer { using WitnessVector = std::vector>; public: - HonkAcirComposer(); + GoblinAcirComposer(); /** * @brief Create a GUH circuit from an acir constraint system and a witness From 8fc65a4806588fe20d4fabaf0485939a44a2bbae Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 22:00:55 +0000 Subject: [PATCH 11/20] fix wasm: create goblin acir composer --- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 5 + .../barretenberg/dsl/acir_proofs/c_bind.hpp | 2 + barretenberg/exports.json | 11 + barretenberg/ts/src/barretenberg_api/index.ts | 537 ++++-------------- barretenberg/ts/src/main.ts | 1 + 5 files changed, 123 insertions(+), 433 deletions(-) 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 9ce2b55d009..45ff98dc8ab 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -27,6 +27,11 @@ WASM_EXPORT void acir_new_acir_composer(uint32_t const* size_hint, out_ptr out) *out = new acir_proofs::AcirComposer(ntohl(*size_hint)); } +WASM_EXPORT void acir_new_goblin_acir_composer(out_ptr out) +{ + *out = new acir_proofs::GoblinAcirComposer(); +} + WASM_EXPORT void acir_delete_acir_composer(in_ptr acir_composer_ptr) { delete reinterpret_cast(*acir_composer_ptr); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index 0e7126bb5ef..be3a37e6728 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -13,6 +13,8 @@ WASM_EXPORT void acir_get_circuit_sizes(uint8_t const* constraint_system_buf, WASM_EXPORT void acir_new_acir_composer(uint32_t const* size_hint, out_ptr out); +WASM_EXPORT void acir_new_goblin_acir_composer(out_ptr out); + WASM_EXPORT void acir_delete_acir_composer(in_ptr acir_composer_ptr); WASM_EXPORT void acir_create_circuit(in_ptr acir_composer_ptr, diff --git a/barretenberg/exports.json b/barretenberg/exports.json index b7a8dca7a5e..25d4d6c81cf 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -466,6 +466,17 @@ ], "isAsync": false }, + { + "functionName": "acir_new_goblin_acir_composer", + "inArgs": [], + "outArgs": [ + { + "name": "out", + "type": "out_ptr" + } + ], + "isAsync": false + }, { "functionName": "acir_delete_acir_composer", "inArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index ebd5c8fc713..379e3332c18 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,28 +1,18 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergWasmWorker, BarretenbergWasm } from '../barretenberg_wasm/index.js'; -import { - BufferDeserializer, - NumberDeserializer, - VectorDeserializer, - BoolDeserializer, - StringDeserializer, - serializeBufferable, - OutputType, -} from '../serialize/index.js'; +import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer, serializeBufferable, OutputType } from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; + export class BarretenbergApi { constructor(protected wasm: BarretenbergWasmWorker) {} + async pedersenCommit(inputsBuffer: Fr[]): Promise { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'pedersen_commit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -30,11 +20,7 @@ export class BarretenbergApi { async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'pedersen_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -42,11 +28,7 @@ export class BarretenbergApi { async pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Promise { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'pedersen_hash_buffer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -54,11 +36,7 @@ export class BarretenbergApi { async blake2s(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = await this.wasm.callWasmExport( - 'blake2s', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -66,11 +44,7 @@ export class BarretenbergApi { async blake2sToField(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport( - 'blake2s_to_field_', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -78,11 +52,7 @@ export class BarretenbergApi { async schnorrComputePublicKey(privateKey: Fr): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'schnorr_compute_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -90,11 +60,7 @@ export class BarretenbergApi { async schnorrNegatePublicKey(publicKeyBuffer: Point): Promise { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport( - 'schnorr_negate_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -102,11 +68,7 @@ export class BarretenbergApi { async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = await this.wasm.callWasmExport( - 'schnorr_construct_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -114,11 +76,7 @@ export class BarretenbergApi { async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_verify_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -126,11 +84,7 @@ export class BarretenbergApi { async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -138,11 +92,7 @@ export class BarretenbergApi { async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -150,48 +100,23 @@ export class BarretenbergApi { async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fq, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): Promise<[Fq, boolean]> { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( - serializeBufferable, - ); + async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fq[], - ): Promise<[Buffer32, Buffer32, boolean]> { + async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): Promise<[Buffer32, Buffer32, boolean]> { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'schnorr_multisig_combine_signatures', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -199,11 +124,7 @@ export class BarretenbergApi { async aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'aes_encrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -211,11 +132,7 @@ export class BarretenbergApi { async aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'aes_decrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -223,11 +140,7 @@ export class BarretenbergApi { async srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): Promise { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'srs_init_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -235,11 +148,7 @@ export class BarretenbergApi { async srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): Promise { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'srs_init_grumpkin_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -247,11 +156,7 @@ export class BarretenbergApi { async examplesSimpleCreateAndVerifyProof(): Promise { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'examples_simple_create_and_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -259,11 +164,7 @@ export class BarretenbergApi { async testThreads(threads: number, iterations: number): Promise { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = await this.wasm.callWasmExport( - 'test_threads', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -271,11 +172,7 @@ export class BarretenbergApi { async commonInitSlabAllocator(circuitSize: number): Promise { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'common_init_slab_allocator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -283,11 +180,7 @@ export class BarretenbergApi { async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_circuit_sizes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -295,11 +188,15 @@ export class BarretenbergApi { async acirNewAcirComposer(sizeHint: number): Promise { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport( - 'acir_new_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirNewGoblinAcirComposer(): Promise { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = await this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -307,11 +204,7 @@ export class BarretenbergApi { async acirDeleteAcirComposer(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_delete_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -319,11 +212,7 @@ export class BarretenbergApi { async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_create_circuit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -331,44 +220,23 @@ export class BarretenbergApi { async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_init_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } - async acirCreateProof( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - isRecursive: boolean, - ): Promise { + async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_create_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirGoblinAccumulate( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - ): Promise { + async acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_accumulate', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -376,11 +244,7 @@ export class BarretenbergApi { async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_load_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -388,11 +252,7 @@ export class BarretenbergApi { async acirInitVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport( - 'acir_init_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -400,11 +260,7 @@ export class BarretenbergApi { async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -412,11 +268,7 @@ export class BarretenbergApi { async acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Promise { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -424,11 +276,7 @@ export class BarretenbergApi { async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { const inArgs = [acirComposerPtr, proofBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -436,11 +284,7 @@ export class BarretenbergApi { async acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_verify_goblin_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_verify_goblin_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -448,27 +292,15 @@ export class BarretenbergApi { async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_get_solidity_verifier', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirSerializeProofIntoFields( - acirComposerPtr: Ptr, - proofBuf: Uint8Array, - numInnerPublicInputs: number, - ): Promise { + async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = await this.wasm.callWasmExport( - 'acir_serialize_proof_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -476,11 +308,7 @@ export class BarretenbergApi { async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = await this.wasm.callWasmExport( - 'acir_serialize_verification_key_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = await this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -488,14 +316,11 @@ export class BarretenbergApi { export class BarretenbergApiSync { constructor(protected wasm: BarretenbergWasm) {} + pedersenCommit(inputsBuffer: Fr[]): Point { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'pedersen_commit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -503,11 +328,7 @@ export class BarretenbergApiSync { pedersenHash(inputsBuffer: Fr[], hashIndex: number): Fr { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'pedersen_hash', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -515,11 +336,7 @@ export class BarretenbergApiSync { pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Fr { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'pedersen_hash_buffer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -527,11 +344,7 @@ export class BarretenbergApiSync { blake2s(data: Uint8Array): Buffer32 { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = this.wasm.callWasmExport( - 'blake2s', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -539,11 +352,7 @@ export class BarretenbergApiSync { blake2sToField(data: Uint8Array): Fr { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport( - 'blake2s_to_field_', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -551,11 +360,7 @@ export class BarretenbergApiSync { schnorrComputePublicKey(privateKey: Fr): Point { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'schnorr_compute_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -563,11 +368,7 @@ export class BarretenbergApiSync { schnorrNegatePublicKey(publicKeyBuffer: Point): Point { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport( - 'schnorr_negate_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -575,11 +376,7 @@ export class BarretenbergApiSync { schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = this.wasm.callWasmExport( - 'schnorr_construct_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -587,11 +384,7 @@ export class BarretenbergApiSync { schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_verify_signature', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -599,11 +392,7 @@ export class BarretenbergApiSync { schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Buffer128 { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_create_multisig_public_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -611,11 +400,7 @@ export class BarretenbergApiSync { schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_validate_and_combine_signer_pubkeys', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -623,48 +408,23 @@ export class BarretenbergApiSync { schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_1', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigConstructSignatureRound2( - message: Uint8Array, - privateKey: Fq, - signerRoundOnePrivateBuf: Buffer128, - signerPubkeysBuf: Buffer128[], - roundOnePublicBuf: Buffer128[], - ): [Fq, boolean] { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( - serializeBufferable, - ); + schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): [Fq, boolean] { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_construct_signature_round_2', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigCombineSignatures( - message: Uint8Array, - signerPubkeysBuf: Buffer128[], - roundOneBuf: Buffer128[], - roundTwoBuf: Fq[], - ): [Buffer32, Buffer32, boolean] { + schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): [Buffer32, Buffer32, boolean] { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'schnorr_multisig_combine_signatures', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -672,11 +432,7 @@ export class BarretenbergApiSync { aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'aes_encrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -684,11 +440,7 @@ export class BarretenbergApiSync { aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'aes_decrypt_buffer_cbc', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -696,11 +448,7 @@ export class BarretenbergApiSync { srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): void { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'srs_init_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -708,11 +456,7 @@ export class BarretenbergApiSync { srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): void { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'srs_init_grumpkin_srs', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -720,11 +464,7 @@ export class BarretenbergApiSync { examplesSimpleCreateAndVerifyProof(): boolean { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'examples_simple_create_and_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -732,11 +472,7 @@ export class BarretenbergApiSync { testThreads(threads: number, iterations: number): number { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = this.wasm.callWasmExport( - 'test_threads', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -744,11 +480,7 @@ export class BarretenbergApiSync { commonInitSlabAllocator(circuitSize: number): void { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'common_init_slab_allocator', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -756,11 +488,7 @@ export class BarretenbergApiSync { acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_circuit_sizes', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -768,11 +496,15 @@ export class BarretenbergApiSync { acirNewAcirComposer(sizeHint: number): Ptr { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport( - 'acir_new_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirNewGoblinAcirComposer(): Ptr { + const inArgs = [].map(serializeBufferable); + const outTypes: OutputType[] = [Ptr]; + const result = this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -780,11 +512,7 @@ export class BarretenbergApiSync { acirDeleteAcirComposer(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_delete_acir_composer', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -792,11 +520,7 @@ export class BarretenbergApiSync { acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_create_circuit', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -804,28 +528,15 @@ export class BarretenbergApiSync { acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_init_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } - acirCreateProof( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - isRecursive: boolean, - ): Uint8Array { + acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_create_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -833,11 +544,7 @@ export class BarretenbergApiSync { acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_accumulate', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -845,11 +552,7 @@ export class BarretenbergApiSync { acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_load_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -857,11 +560,7 @@ export class BarretenbergApiSync { acirInitVerificationKey(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport( - 'acir_init_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -869,11 +568,7 @@ export class BarretenbergApiSync { acirGetVerificationKey(acirComposerPtr: Ptr): Uint8Array { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_verification_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -881,11 +576,7 @@ export class BarretenbergApiSync { acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_proving_key', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -893,11 +584,7 @@ export class BarretenbergApiSync { acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): boolean { const inArgs = [acirComposerPtr, proofBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_verify_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -905,11 +592,7 @@ export class BarretenbergApiSync { acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_verify_goblin_proof', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_verify_goblin_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -917,11 +600,7 @@ export class BarretenbergApiSync { acirGetSolidityVerifier(acirComposerPtr: Ptr): string { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_get_solidity_verifier', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -929,11 +608,7 @@ export class BarretenbergApiSync { acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = this.wasm.callWasmExport( - 'acir_serialize_proof_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -941,11 +616,7 @@ export class BarretenbergApiSync { acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = this.wasm.callWasmExport( - 'acir_serialize_verification_key_into_fields', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); + const result = this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index dc66cf2aa29..caf2d8aa9d0 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -76,6 +76,7 @@ async function initGoblin(bytecodePath: string, crsPath: string) { const hardcodedGrumpkinSubgroupSizeHack = 262144; const initData = await init(bytecodePath, crsPath, hardcodedGrumpkinSubgroupSizeHack); const { api } = initData; + initData.acirComposer = await api.acirNewGoblinAcirComposer(); // Plus 1 needed! (Move +1 into Crs?) // Need both grumpkin and bn254 SRS's currently From d9f5b67360f664b6776b83bb238cdce1564f5817 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 22:04:40 +0000 Subject: [PATCH 12/20] fix index ts formatting --- barretenberg/ts/src/barretenberg_api/index.ts | 533 +++++++++++++++--- 1 file changed, 443 insertions(+), 90 deletions(-) diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 379e3332c18..7d712842b37 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -1,18 +1,28 @@ // WARNING: FILE CODE GENERATED BY BINDGEN UTILITY. DO NOT EDIT! /* eslint-disable @typescript-eslint/no-unused-vars */ import { BarretenbergWasmWorker, BarretenbergWasm } from '../barretenberg_wasm/index.js'; -import { BufferDeserializer, NumberDeserializer, VectorDeserializer, BoolDeserializer, StringDeserializer, serializeBufferable, OutputType } from '../serialize/index.js'; +import { + BufferDeserializer, + NumberDeserializer, + VectorDeserializer, + BoolDeserializer, + StringDeserializer, + serializeBufferable, + OutputType, +} from '../serialize/index.js'; import { Fr, Fq, Point, Buffer32, Buffer128, Ptr } from '../types/index.js'; - export class BarretenbergApi { constructor(protected wasm: BarretenbergWasmWorker) {} - async pedersenCommit(inputsBuffer: Fr[]): Promise { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_commit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -20,7 +30,11 @@ export class BarretenbergApi { async pedersenHash(inputsBuffer: Fr[], hashIndex: number): Promise { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -28,7 +42,11 @@ export class BarretenbergApi { async pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Promise { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'pedersen_hash_buffer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -36,7 +54,11 @@ export class BarretenbergApi { async blake2s(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = await this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'blake2s', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -44,7 +66,11 @@ export class BarretenbergApi { async blake2sToField(data: Uint8Array): Promise { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = await this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'blake2s_to_field_', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -52,7 +78,11 @@ export class BarretenbergApi { async schnorrComputePublicKey(privateKey: Fr): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_compute_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -60,7 +90,11 @@ export class BarretenbergApi { async schnorrNegatePublicKey(publicKeyBuffer: Point): Promise { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = await this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_negate_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -68,7 +102,11 @@ export class BarretenbergApi { async schnorrConstructSignature(message: Uint8Array, privateKey: Fr): Promise<[Buffer32, Buffer32]> { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = await this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_construct_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -76,7 +114,11 @@ export class BarretenbergApi { async schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): Promise { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_verify_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -84,7 +126,11 @@ export class BarretenbergApi { async schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Promise { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = await this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -92,7 +138,11 @@ export class BarretenbergApi { async schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): Promise<[Point, boolean]> { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -100,23 +150,48 @@ export class BarretenbergApi { async schnorrMultisigConstructSignatureRound1(): Promise<[Buffer128, Buffer128]> { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): Promise<[Fq, boolean]> { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + async schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fq, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): Promise<[Fq, boolean]> { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( + serializeBufferable, + ); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - async schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): Promise<[Buffer32, Buffer32, boolean]> { + async schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fq[], + ): Promise<[Buffer32, Buffer32, boolean]> { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = await this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'schnorr_multisig_combine_signatures', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -124,7 +199,11 @@ export class BarretenbergApi { async aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'aes_encrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -132,7 +211,11 @@ export class BarretenbergApi { async aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Promise { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'aes_decrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -140,7 +223,11 @@ export class BarretenbergApi { async srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): Promise { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'srs_init_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -148,7 +235,11 @@ export class BarretenbergApi { async srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): Promise { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'srs_init_grumpkin_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -156,7 +247,11 @@ export class BarretenbergApi { async examplesSimpleCreateAndVerifyProof(): Promise { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'examples_simple_create_and_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -164,7 +259,11 @@ export class BarretenbergApi { async testThreads(threads: number, iterations: number): Promise { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = await this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'test_threads', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -172,7 +271,11 @@ export class BarretenbergApi { async commonInitSlabAllocator(circuitSize: number): Promise { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'common_init_slab_allocator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -180,7 +283,11 @@ export class BarretenbergApi { async acirGetCircuitSizes(constraintSystemBuf: Uint8Array): Promise<[number, number, number]> { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_circuit_sizes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -188,7 +295,11 @@ export class BarretenbergApi { async acirNewAcirComposer(sizeHint: number): Promise { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_new_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -196,7 +307,11 @@ export class BarretenbergApi { async acirNewGoblinAcirComposer(): Promise { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = await this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_new_goblin_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -204,7 +319,11 @@ export class BarretenbergApi { async acirDeleteAcirComposer(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_delete_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -212,7 +331,11 @@ export class BarretenbergApi { async acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_create_circuit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -220,23 +343,44 @@ export class BarretenbergApi { async acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_init_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } - async acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Promise { + async acirCreateProof( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + isRecursive: boolean, + ): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_create_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Promise { + async acirGoblinAccumulate( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_goblin_accumulate', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -244,7 +388,11 @@ export class BarretenbergApi { async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_load_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -252,7 +400,11 @@ export class BarretenbergApi { async acirInitVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = await this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_init_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -260,7 +412,11 @@ export class BarretenbergApi { async acirGetVerificationKey(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -268,7 +424,11 @@ export class BarretenbergApi { async acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Promise { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -276,7 +436,11 @@ export class BarretenbergApi { async acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): Promise { const inArgs = [acirComposerPtr, proofBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -284,7 +448,11 @@ export class BarretenbergApi { async acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport('acir_verify_goblin_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_verify_goblin_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -292,15 +460,27 @@ export class BarretenbergApi { async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = await this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_get_solidity_verifier', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } - async acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Promise { + async acirSerializeProofIntoFields( + acirComposerPtr: Ptr, + proofBuf: Uint8Array, + numInnerPublicInputs: number, + ): Promise { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = await this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_serialize_proof_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -308,7 +488,11 @@ export class BarretenbergApi { async acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): Promise<[Fr[], Fr]> { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = await this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = await this.wasm.callWasmExport( + 'acir_serialize_verification_key_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -316,11 +500,14 @@ export class BarretenbergApi { export class BarretenbergApiSync { constructor(protected wasm: BarretenbergWasm) {} - pedersenCommit(inputsBuffer: Fr[]): Point { const inArgs = [inputsBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('pedersen_commit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_commit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -328,7 +515,11 @@ export class BarretenbergApiSync { pedersenHash(inputsBuffer: Fr[], hashIndex: number): Fr { const inArgs = [inputsBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('pedersen_hash', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_hash', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -336,7 +527,11 @@ export class BarretenbergApiSync { pedersenHashBuffer(inputBuffer: Uint8Array, hashIndex: number): Fr { const inArgs = [inputBuffer, hashIndex].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('pedersen_hash_buffer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'pedersen_hash_buffer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -344,7 +539,11 @@ export class BarretenbergApiSync { blake2s(data: Uint8Array): Buffer32 { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32]; - const result = this.wasm.callWasmExport('blake2s', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'blake2s', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -352,7 +551,11 @@ export class BarretenbergApiSync { blake2sToField(data: Uint8Array): Fr { const inArgs = [data].map(serializeBufferable); const outTypes: OutputType[] = [Fr]; - const result = this.wasm.callWasmExport('blake2s_to_field_', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'blake2s_to_field_', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -360,7 +563,11 @@ export class BarretenbergApiSync { schnorrComputePublicKey(privateKey: Fr): Point { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('schnorr_compute_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_compute_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -368,7 +575,11 @@ export class BarretenbergApiSync { schnorrNegatePublicKey(publicKeyBuffer: Point): Point { const inArgs = [publicKeyBuffer].map(serializeBufferable); const outTypes: OutputType[] = [Point]; - const result = this.wasm.callWasmExport('schnorr_negate_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_negate_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -376,7 +587,11 @@ export class BarretenbergApiSync { schnorrConstructSignature(message: Uint8Array, privateKey: Fr): [Buffer32, Buffer32] { const inArgs = [message, privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32]; - const result = this.wasm.callWasmExport('schnorr_construct_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_construct_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -384,7 +599,11 @@ export class BarretenbergApiSync { schnorrVerifySignature(message: Uint8Array, pubKey: Point, sigS: Buffer32, sigE: Buffer32): boolean { const inArgs = [message, pubKey, sigS, sigE].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_verify_signature', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_verify_signature', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -392,7 +611,11 @@ export class BarretenbergApiSync { schnorrMultisigCreateMultisigPublicKey(privateKey: Fq): Buffer128 { const inArgs = [privateKey].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128]; - const result = this.wasm.callWasmExport('schnorr_multisig_create_multisig_public_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_create_multisig_public_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -400,7 +623,11 @@ export class BarretenbergApiSync { schnorrMultisigValidateAndCombineSignerPubkeys(signerPubkeyBuf: Buffer128[]): [Point, boolean] { const inArgs = [signerPubkeyBuf].map(serializeBufferable); const outTypes: OutputType[] = [Point, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_validate_and_combine_signer_pubkeys', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_validate_and_combine_signer_pubkeys', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -408,23 +635,48 @@ export class BarretenbergApiSync { schnorrMultisigConstructSignatureRound1(): [Buffer128, Buffer128] { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Buffer128, Buffer128]; - const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_1', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_1', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigConstructSignatureRound2(message: Uint8Array, privateKey: Fq, signerRoundOnePrivateBuf: Buffer128, signerPubkeysBuf: Buffer128[], roundOnePublicBuf: Buffer128[]): [Fq, boolean] { - const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map(serializeBufferable); + schnorrMultisigConstructSignatureRound2( + message: Uint8Array, + privateKey: Fq, + signerRoundOnePrivateBuf: Buffer128, + signerPubkeysBuf: Buffer128[], + roundOnePublicBuf: Buffer128[], + ): [Fq, boolean] { + const inArgs = [message, privateKey, signerRoundOnePrivateBuf, signerPubkeysBuf, roundOnePublicBuf].map( + serializeBufferable, + ); const outTypes: OutputType[] = [Fq, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_construct_signature_round_2', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_construct_signature_round_2', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } - schnorrMultisigCombineSignatures(message: Uint8Array, signerPubkeysBuf: Buffer128[], roundOneBuf: Buffer128[], roundTwoBuf: Fq[]): [Buffer32, Buffer32, boolean] { + schnorrMultisigCombineSignatures( + message: Uint8Array, + signerPubkeysBuf: Buffer128[], + roundOneBuf: Buffer128[], + roundTwoBuf: Fq[], + ): [Buffer32, Buffer32, boolean] { const inArgs = [message, signerPubkeysBuf, roundOneBuf, roundTwoBuf].map(serializeBufferable); const outTypes: OutputType[] = [Buffer32, Buffer32, BoolDeserializer()]; - const result = this.wasm.callWasmExport('schnorr_multisig_combine_signatures', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'schnorr_multisig_combine_signatures', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -432,7 +684,11 @@ export class BarretenbergApiSync { aesEncryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('aes_encrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'aes_encrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -440,7 +696,11 @@ export class BarretenbergApiSync { aesDecryptBufferCbc(input: Uint8Array, iv: Uint8Array, key: Uint8Array, length: number): Uint8Array { const inArgs = [input, iv, key, length].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('aes_decrypt_buffer_cbc', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'aes_decrypt_buffer_cbc', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -448,7 +708,11 @@ export class BarretenbergApiSync { srsInitSrs(pointsBuf: Uint8Array, numPoints: number, g2PointBuf: Uint8Array): void { const inArgs = [pointsBuf, numPoints, g2PointBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('srs_init_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'srs_init_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -456,7 +720,11 @@ export class BarretenbergApiSync { srsInitGrumpkinSrs(pointsBuf: Uint8Array, numPoints: number): void { const inArgs = [pointsBuf, numPoints].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('srs_init_grumpkin_srs', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'srs_init_grumpkin_srs', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -464,7 +732,11 @@ export class BarretenbergApiSync { examplesSimpleCreateAndVerifyProof(): boolean { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('examples_simple_create_and_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'examples_simple_create_and_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -472,7 +744,11 @@ export class BarretenbergApiSync { testThreads(threads: number, iterations: number): number { const inArgs = [threads, iterations].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer()]; - const result = this.wasm.callWasmExport('test_threads', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'test_threads', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -480,7 +756,11 @@ export class BarretenbergApiSync { commonInitSlabAllocator(circuitSize: number): void { const inArgs = [circuitSize].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('common_init_slab_allocator', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'common_init_slab_allocator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -488,7 +768,11 @@ export class BarretenbergApiSync { acirGetCircuitSizes(constraintSystemBuf: Uint8Array): [number, number, number] { const inArgs = [constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = [NumberDeserializer(), NumberDeserializer(), NumberDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_circuit_sizes', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_circuit_sizes', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } @@ -496,7 +780,11 @@ export class BarretenbergApiSync { acirNewAcirComposer(sizeHint: number): Ptr { const inArgs = [sizeHint].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport('acir_new_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_new_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -504,7 +792,11 @@ export class BarretenbergApiSync { acirNewGoblinAcirComposer(): Ptr { const inArgs = [].map(serializeBufferable); const outTypes: OutputType[] = [Ptr]; - const result = this.wasm.callWasmExport('acir_new_goblin_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_new_goblin_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -512,7 +804,11 @@ export class BarretenbergApiSync { acirDeleteAcirComposer(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_delete_acir_composer', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_delete_acir_composer', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -520,7 +816,11 @@ export class BarretenbergApiSync { acirCreateCircuit(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, sizeHint: number): void { const inArgs = [acirComposerPtr, constraintSystemBuf, sizeHint].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_create_circuit', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_create_circuit', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -528,15 +828,28 @@ export class BarretenbergApiSync { acirInitProvingKey(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array): void { const inArgs = [acirComposerPtr, constraintSystemBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_init_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_init_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } - acirCreateProof(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array, isRecursive: boolean): Uint8Array { + acirCreateProof( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + isRecursive: boolean, + ): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_create_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_create_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -544,7 +857,11 @@ export class BarretenbergApiSync { acirGoblinAccumulate(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_goblin_accumulate', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_goblin_accumulate', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -552,7 +869,11 @@ export class BarretenbergApiSync { acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_load_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_load_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -560,7 +881,11 @@ export class BarretenbergApiSync { acirInitVerificationKey(acirComposerPtr: Ptr): void { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = []; - const result = this.wasm.callWasmExport('acir_init_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_init_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return; } @@ -568,7 +893,11 @@ export class BarretenbergApiSync { acirGetVerificationKey(acirComposerPtr: Ptr): Uint8Array { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_verification_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_verification_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -576,7 +905,11 @@ export class BarretenbergApiSync { acirGetProvingKey(acirComposerPtr: Ptr, acirVec: Uint8Array): Uint8Array { const inArgs = [acirComposerPtr, acirVec].map(serializeBufferable); const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_proving_key', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_proving_key', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -584,7 +917,11 @@ export class BarretenbergApiSync { acirVerifyProof(acirComposerPtr: Ptr, proofBuf: Uint8Array, isRecursive: boolean): boolean { const inArgs = [acirComposerPtr, proofBuf, isRecursive].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('acir_verify_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_verify_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -592,7 +929,11 @@ export class BarretenbergApiSync { acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport('acir_verify_goblin_proof', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_verify_goblin_proof', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -600,7 +941,11 @@ export class BarretenbergApiSync { acirGetSolidityVerifier(acirComposerPtr: Ptr): string { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; - const result = this.wasm.callWasmExport('acir_get_solidity_verifier', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_get_solidity_verifier', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -608,7 +953,11 @@ export class BarretenbergApiSync { acirSerializeProofIntoFields(acirComposerPtr: Ptr, proofBuf: Uint8Array, numInnerPublicInputs: number): Fr[] { const inArgs = [acirComposerPtr, proofBuf, numInnerPublicInputs].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr)]; - const result = this.wasm.callWasmExport('acir_serialize_proof_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_serialize_proof_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out[0]; } @@ -616,7 +965,11 @@ export class BarretenbergApiSync { acirSerializeVerificationKeyIntoFields(acirComposerPtr: Ptr): [Fr[], Fr] { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [VectorDeserializer(Fr), Fr]; - const result = this.wasm.callWasmExport('acir_serialize_verification_key_into_fields', inArgs, outTypes.map(t=>t.SIZE_IN_BYTES)); + const result = this.wasm.callWasmExport( + 'acir_serialize_verification_key_into_fields', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); const out = result.map((r, i) => outTypes[i].fromBuffer(r)); return out as any; } From a05e3b40dd3cace4b4075a43bb05a4d75f261d9d Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Thu, 18 Jan 2024 22:08:49 +0000 Subject: [PATCH 13/20] removed grumpkin from the wrong flow --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 77f7f797713..72fa6756524 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -139,8 +139,6 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); - size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only - init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Call accumulate to generate a GoblinUltraHonk proof auto proof = acir_composer.accumulate(); @@ -178,6 +176,8 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only + init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Generate a GoblinUltraHonk proof and a full Goblin proof auto proof = acir_composer.accumulate_and_prove(); From d415de298517963c8b2bcaae14109a5b6c64d97a Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 19 Jan 2024 03:48:00 +0000 Subject: [PATCH 14/20] js flow for full goblin prove and verify --- barretenberg/acir_tests/Dockerfile.bb.js | 4 +- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 23 ++++++- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 9 ++- barretenberg/exports.json | 46 +++++++++++++- barretenberg/ts/src/barretenberg_api/index.ts | 60 +++++++++++++++++-- barretenberg/ts/src/main.ts | 8 +-- 6 files changed, 137 insertions(+), 13 deletions(-) diff --git a/barretenberg/acir_tests/Dockerfile.bb.js b/barretenberg/acir_tests/Dockerfile.bb.js index 5ca0ddc1515..b894826a5c2 100644 --- a/barretenberg/acir_tests/Dockerfile.bb.js +++ b/barretenberg/acir_tests/Dockerfile.bb.js @@ -14,8 +14,10 @@ COPY . . ENV VERBOSE=1 # Run double_verify_proof through bb.js on node to check 512k support. RUN BIN=../ts/dest/node/main.js FLOW=prove_then_verify ./run_acir_tests.sh double_verify_proof -# Run a single arbitrary test not involving recursion through bb.js for Honk +# Run a single arbitrary test not involving recursion through bb.js for GoblinUltraHonk RUN BIN=../ts/dest/node/main.js FLOW=accumulate_and_verify_goblin ./run_acir_tests.sh 6_array +# Run a single arbitrary test not involving recursion through bb.js for full Goblin +RUN BIN=../ts/dest/node/main.js FLOW=prove_and_verify_goblin ./run_acir_tests.sh 6_array # Run 1_mul through bb.js build, all_cmds flow, to test all cli args. RUN BIN=../ts/dest/node/main.js FLOW=all_cmds ./run_acir_tests.sh 1_mul # Run double_verify_proof through bb.js on chrome testing multi-threaded browser support. 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 45ff98dc8ab..18d44941e56 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -77,6 +77,20 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, *out = to_heap_buffer(proof_data); } +WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, + uint8_t const* acir_vec, + uint8_t const* witness_vec, + uint8_t** out) +{ + auto acir_composer = reinterpret_cast(*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)); + + acir_composer->create_circuit(constraint_system, witness); + auto proof_data = acir_composer->accumulate_and_prove(); + *out = to_heap_buffer(proof_data); +} + WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf) { auto acir_composer = reinterpret_cast(*acir_composer_ptr); @@ -108,13 +122,20 @@ WASM_EXPORT void acir_get_proving_key(in_ptr acir_composer_ptr, uint8_t const* a *out = to_heap_buffer(to_buffer(*pk)); } -WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) +WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); *result = acir_composer->verify_accumulator(proof); } +WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) +{ + auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto proof = from_buffer>(proof_buf); + *result = acir_composer->verify(proof); +} + WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool const* is_recursive, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index be3a37e6728..91de508104a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -39,6 +39,11 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, uint8_t const* witness_buf, uint8_t** out); +WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, + uint8_t const* constraint_system_buf, + uint8_t const* witness_buf, + uint8_t** out); + WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf); WASM_EXPORT void acir_init_verification_key(in_ptr acir_composer_ptr); @@ -52,7 +57,9 @@ WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, bool const* is_recursive, bool* result); -WASM_EXPORT void acir_verify_goblin_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); +WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); + +WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); WASM_EXPORT void acir_get_solidity_verifier(in_ptr acir_composer_ptr, out_str_buf out); diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 25d4d6c81cf..3925ff1fa54 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -574,6 +574,30 @@ ], "isAsync": false }, + { + "functionName": "acir_goblin_prove", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + }, + { + "name": "witness_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "uint8_t **" + } + ], + "isAsync": false + }, { "functionName": "acir_load_verification_key", "inArgs": [ @@ -661,7 +685,27 @@ "isAsync": false }, { - "functionName": "acir_verify_goblin_proof", + "functionName": "acir_goblin_verify_accumulator", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "proof_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "result", + "type": "bool *" + } + ], + "isAsync": false + }, + { + "functionName": "acir_goblin_verify", "inArgs": [ { "name": "acir_composer_ptr", diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 7d712842b37..d6280851562 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -385,6 +385,22 @@ export class BarretenbergApi { return out[0]; } + async acirGoblinProve( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -445,11 +461,23 @@ export class BarretenbergApi { return out[0]; } - async acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + async acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_goblin_verify_accumulator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; const result = await this.wasm.callWasmExport( - 'acir_verify_goblin_proof', + 'acir_goblin_verify', inArgs, outTypes.map(t => t.SIZE_IN_BYTES), ); @@ -866,6 +894,18 @@ export class BarretenbergApiSync { return out[0]; } + acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -926,11 +966,23 @@ export class BarretenbergApiSync { return out[0]; } - acirVerifyGoblinProof(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + acirGoblinVerifyAccumulator(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport( + 'acir_goblin_verify_accumulator', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + + acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); const outTypes: OutputType[] = [BoolDeserializer()]; const result = this.wasm.callWasmExport( - 'acir_verify_goblin_proof', + 'acir_goblin_verify', inArgs, outTypes.map(t => t.SIZE_IN_BYTES), ); diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index caf2d8aa9d0..e9824f2826c 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -136,9 +136,7 @@ export async function accumulateAndVerifyGoblin(bytecodePath: string, witnessPat const { api, acirComposer, circuitSize, subgroupSize } = await initGoblin(bytecodePath, crsPath); try { debug(`In accumulateAndVerifyGoblin:`); - debug(`getBytecode()`); const bytecode = getBytecode(bytecodePath); - debug(`getWitness()`); const witness = getWitness(witnessPath); writeBenchmark('gate_count', circuitSize, { acir_test, threads }); @@ -150,7 +148,7 @@ export async function accumulateAndVerifyGoblin(bytecodePath: string, witnessPat writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); debug(`acirVerifyGoblinProof()`); - const verified = await api.acirVerifyGoblinProof(acirComposer, proof); + const verified = await api.acirGoblinVerifyAccumulator(acirComposer, proof); debug(`verified: ${verified}`); console.log({ verified }); return verified; @@ -174,11 +172,11 @@ export async function proveAndVerifyGoblin(bytecodePath: string, witnessPath: st writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); const proofTimer = new Timer(); - const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); + const proof = await api.acirGoblinProve(acirComposer, bytecode, witness); writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); debug(`verifying...`); - const verified = await api.acirVerifyGoblinProof(acirComposer, proof); + const verified = await api.acirGoblinVerify(acirComposer, proof); debug(`verified: ${verified}`); console.log({ verified }); return verified; From 4a14cdc201627101e2b153c165f5f17e27806c7d Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 19 Jan 2024 04:09:11 +0000 Subject: [PATCH 15/20] debug --- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 38 +++++++------- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 10 ++-- barretenberg/exports.json | 44 ---------------- barretenberg/ts/src/barretenberg_api/index.ts | 52 ------------------- barretenberg/ts/src/main.ts | 8 +-- 5 files changed, 28 insertions(+), 124 deletions(-) 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 18d44941e56..2bcc994a81b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -77,19 +77,19 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, *out = to_heap_buffer(proof_data); } -WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, - uint8_t const* acir_vec, - uint8_t const* witness_vec, - uint8_t** out) -{ - auto acir_composer = reinterpret_cast(*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)); - - acir_composer->create_circuit(constraint_system, witness); - auto proof_data = acir_composer->accumulate_and_prove(); - *out = to_heap_buffer(proof_data); -} +// WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, +// uint8_t const* acir_vec, +// uint8_t const* witness_vec, +// uint8_t** out) +// { +// auto acir_composer = reinterpret_cast(*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)); + +// acir_composer->create_circuit(constraint_system, witness); +// auto proof_data = acir_composer->accumulate_and_prove(); +// *out = to_heap_buffer(proof_data); +// } WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf) { @@ -129,12 +129,12 @@ WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_ *result = acir_composer->verify_accumulator(proof); } -WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) -{ - auto acir_composer = reinterpret_cast(*acir_composer_ptr); - auto proof = from_buffer>(proof_buf); - *result = acir_composer->verify(proof); -} +// WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) +// { +// auto acir_composer = reinterpret_cast(*acir_composer_ptr); +// auto proof = from_buffer>(proof_buf); +// *result = acir_composer->verify(proof); +// } WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index 91de508104a..d7c502c3bae 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -39,10 +39,10 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, uint8_t const* witness_buf, uint8_t** out); -WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, - uint8_t const* constraint_system_buf, - uint8_t const* witness_buf, - uint8_t** out); +// WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, +// uint8_t const* constraint_system_buf, +// uint8_t const* witness_buf, +// uint8_t** out); WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf); @@ -59,7 +59,7 @@ WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); -WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); +// WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); WASM_EXPORT void acir_get_solidity_verifier(in_ptr acir_composer_ptr, out_str_buf out); diff --git a/barretenberg/exports.json b/barretenberg/exports.json index 3925ff1fa54..e6cd51d981b 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -574,30 +574,6 @@ ], "isAsync": false }, - { - "functionName": "acir_goblin_prove", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "constraint_system_buf", - "type": "const uint8_t *" - }, - { - "name": "witness_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "out", - "type": "uint8_t **" - } - ], - "isAsync": false - }, { "functionName": "acir_load_verification_key", "inArgs": [ @@ -704,26 +680,6 @@ ], "isAsync": false }, - { - "functionName": "acir_goblin_verify", - "inArgs": [ - { - "name": "acir_composer_ptr", - "type": "in_ptr" - }, - { - "name": "proof_buf", - "type": "const uint8_t *" - } - ], - "outArgs": [ - { - "name": "result", - "type": "bool *" - } - ], - "isAsync": false - }, { "functionName": "acir_get_solidity_verifier", "inArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index d6280851562..85cc9481c44 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -385,22 +385,6 @@ export class BarretenbergApi { return out[0]; } - async acirGoblinProve( - acirComposerPtr: Ptr, - constraintSystemBuf: Uint8Array, - witnessBuf: Uint8Array, - ): Promise { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_prove', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -473,18 +457,6 @@ export class BarretenbergApi { return out[0]; } - async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = await this.wasm.callWasmExport( - 'acir_goblin_verify', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; @@ -894,18 +866,6 @@ export class BarretenbergApiSync { return out[0]; } - acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { - const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BufferDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_prove', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -978,18 +938,6 @@ export class BarretenbergApiSync { return out[0]; } - acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { - const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); - const outTypes: OutputType[] = [BoolDeserializer()]; - const result = this.wasm.callWasmExport( - 'acir_goblin_verify', - inArgs, - outTypes.map(t => t.SIZE_IN_BYTES), - ); - const out = result.map((r, i) => outTypes[i].fromBuffer(r)); - return out[0]; - } - acirGetSolidityVerifier(acirComposerPtr: Ptr): string { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index e9824f2826c..1378719234c 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -172,11 +172,11 @@ export async function proveAndVerifyGoblin(bytecodePath: string, witnessPath: st writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); const proofTimer = new Timer(); - const proof = await api.acirGoblinProve(acirComposer, bytecode, witness); + const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); debug(`verifying...`); - const verified = await api.acirGoblinVerify(acirComposer, proof); + const verified = await api.acirGoblinVerifyAccumulator(acirComposer, proof); debug(`verified: ${verified}`); console.log({ verified }); return verified; @@ -388,7 +388,7 @@ program program .command('accumulate_and_verify_goblin') - .description('Generate a proof and verify it. Process exits with success or failure code.') + .description('Generate a GUH proof and verify it. Process exits with success or failure code.') .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/acir.gz') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.gz') .action(async ({ bytecodePath, witnessPath, crsPath }) => { @@ -399,7 +399,7 @@ program program .command('prove_and_verify_goblin') - .description('Generate a proof and verify it. Process exits with success or failure code.') + .description('Generate a Goblin proof and verify it. Process exits with success or failure code.') .option('-b, --bytecode-path ', 'Specify the bytecode path', './target/acir.gz') .option('-w, --witness-path ', 'Specify the witness path', './target/witness.gz') .action(async ({ bytecodePath, witnessPath, crsPath }) => { From 8b71f47c4861114e7b1fccdae51438508f5b4c6f Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 19 Jan 2024 04:25:21 +0000 Subject: [PATCH 16/20] test faking it with accum methods --- .../barretenberg/dsl/acir_proofs/c_bind.cpp | 40 +++++++------- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 10 ++-- barretenberg/exports.json | 44 ++++++++++++++++ barretenberg/ts/src/barretenberg_api/index.ts | 52 +++++++++++++++++++ barretenberg/ts/src/main.ts | 4 +- 5 files changed, 124 insertions(+), 26 deletions(-) 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 2bcc994a81b..7566bc9491b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -77,19 +77,20 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, *out = to_heap_buffer(proof_data); } -// WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, -// uint8_t const* acir_vec, -// uint8_t const* witness_vec, -// uint8_t** out) -// { -// auto acir_composer = reinterpret_cast(*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)); - -// acir_composer->create_circuit(constraint_system, witness); -// auto proof_data = acir_composer->accumulate_and_prove(); -// *out = to_heap_buffer(proof_data); -// } +WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, + uint8_t const* acir_vec, + uint8_t const* witness_vec, + uint8_t** out) +{ + auto acir_composer = reinterpret_cast(*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)); + + acir_composer->create_circuit(constraint_system, witness); + auto proof_data = acir_composer->accumulate(); + // auto proof_data = acir_composer->accumulate_and_prove(); + *out = to_heap_buffer(proof_data); +} WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf) { @@ -129,12 +130,13 @@ WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_ *result = acir_composer->verify_accumulator(proof); } -// WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) -// { -// auto acir_composer = reinterpret_cast(*acir_composer_ptr); -// auto proof = from_buffer>(proof_buf); -// *result = acir_composer->verify(proof); -// } +WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result) +{ + auto acir_composer = reinterpret_cast(*acir_composer_ptr); + auto proof = from_buffer>(proof_buf); + *result = acir_composer->verify_accumulator(proof); + // *result = acir_composer->verify(proof); +} WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, uint8_t const* proof_buf, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index d7c502c3bae..91de508104a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -39,10 +39,10 @@ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, uint8_t const* witness_buf, uint8_t** out); -// WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, -// uint8_t const* constraint_system_buf, -// uint8_t const* witness_buf, -// uint8_t** out); +WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, + uint8_t const* constraint_system_buf, + uint8_t const* witness_buf, + uint8_t** out); WASM_EXPORT void acir_load_verification_key(in_ptr acir_composer_ptr, uint8_t const* vk_buf); @@ -59,7 +59,7 @@ WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); -// WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); +WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); WASM_EXPORT void acir_get_solidity_verifier(in_ptr acir_composer_ptr, out_str_buf out); diff --git a/barretenberg/exports.json b/barretenberg/exports.json index e6cd51d981b..3925ff1fa54 100644 --- a/barretenberg/exports.json +++ b/barretenberg/exports.json @@ -574,6 +574,30 @@ ], "isAsync": false }, + { + "functionName": "acir_goblin_prove", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "constraint_system_buf", + "type": "const uint8_t *" + }, + { + "name": "witness_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "out", + "type": "uint8_t **" + } + ], + "isAsync": false + }, { "functionName": "acir_load_verification_key", "inArgs": [ @@ -680,6 +704,26 @@ ], "isAsync": false }, + { + "functionName": "acir_goblin_verify", + "inArgs": [ + { + "name": "acir_composer_ptr", + "type": "in_ptr" + }, + { + "name": "proof_buf", + "type": "const uint8_t *" + } + ], + "outArgs": [ + { + "name": "result", + "type": "bool *" + } + ], + "isAsync": false + }, { "functionName": "acir_get_solidity_verifier", "inArgs": [ diff --git a/barretenberg/ts/src/barretenberg_api/index.ts b/barretenberg/ts/src/barretenberg_api/index.ts index 85cc9481c44..d6280851562 100644 --- a/barretenberg/ts/src/barretenberg_api/index.ts +++ b/barretenberg/ts/src/barretenberg_api/index.ts @@ -385,6 +385,22 @@ export class BarretenbergApi { return out[0]; } + async acirGoblinProve( + acirComposerPtr: Ptr, + constraintSystemBuf: Uint8Array, + witnessBuf: Uint8Array, + ): Promise { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + async acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): Promise { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -457,6 +473,18 @@ export class BarretenbergApi { return out[0]; } + async acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): Promise { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = await this.wasm.callWasmExport( + 'acir_goblin_verify', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + async acirGetSolidityVerifier(acirComposerPtr: Ptr): Promise { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; @@ -866,6 +894,18 @@ export class BarretenbergApiSync { return out[0]; } + acirGoblinProve(acirComposerPtr: Ptr, constraintSystemBuf: Uint8Array, witnessBuf: Uint8Array): Uint8Array { + const inArgs = [acirComposerPtr, constraintSystemBuf, witnessBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BufferDeserializer()]; + const result = this.wasm.callWasmExport( + 'acir_goblin_prove', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + acirLoadVerificationKey(acirComposerPtr: Ptr, vkBuf: Uint8Array): void { const inArgs = [acirComposerPtr, vkBuf].map(serializeBufferable); const outTypes: OutputType[] = []; @@ -938,6 +978,18 @@ export class BarretenbergApiSync { return out[0]; } + acirGoblinVerify(acirComposerPtr: Ptr, proofBuf: Uint8Array): boolean { + const inArgs = [acirComposerPtr, proofBuf].map(serializeBufferable); + const outTypes: OutputType[] = [BoolDeserializer()]; + const result = this.wasm.callWasmExport( + 'acir_goblin_verify', + inArgs, + outTypes.map(t => t.SIZE_IN_BYTES), + ); + const out = result.map((r, i) => outTypes[i].fromBuffer(r)); + return out[0]; + } + acirGetSolidityVerifier(acirComposerPtr: Ptr): string { const inArgs = [acirComposerPtr].map(serializeBufferable); const outTypes: OutputType[] = [StringDeserializer()]; diff --git a/barretenberg/ts/src/main.ts b/barretenberg/ts/src/main.ts index 1378719234c..d06de96431d 100755 --- a/barretenberg/ts/src/main.ts +++ b/barretenberg/ts/src/main.ts @@ -172,11 +172,11 @@ export async function proveAndVerifyGoblin(bytecodePath: string, witnessPath: st writeBenchmark('subgroup_size', subgroupSize, { acir_test, threads }); const proofTimer = new Timer(); - const proof = await api.acirGoblinAccumulate(acirComposer, bytecode, witness); + const proof = await api.acirGoblinProve(acirComposer, bytecode, witness); writeBenchmark('proof_construction_time', proofTimer.ms(), { acir_test, threads }); debug(`verifying...`); - const verified = await api.acirGoblinVerifyAccumulator(acirComposer, proof); + const verified = await api.acirGoblinVerify(acirComposer, proof); debug(`verified: ${verified}`); console.log({ verified }); return verified; From 52c52a22f7f63d9e3dae8f2aad70672c639aafd2 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 19 Jan 2024 19:09:13 +0000 Subject: [PATCH 17/20] WiP debug --- barretenberg/acir_tests/run_acir_tests.sh | 5 ++++- .../dsl/acir_proofs/goblin_acir_composer.cpp | 12 ++++++++++-- barretenberg/cpp/src/barretenberg/goblin/goblin.hpp | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index ee28c975113..657f2b97eaf 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -11,7 +11,9 @@ source ./bash_helpers/catch.sh trap handle_sigchild SIGCHLD BIN=${BIN:-../cpp/build/bin/bb} -FLOW=${FLOW:-prove_and_verify} +FLOW=${FLOW:-prove_and_verify_goblin} +# FLOW=${FLOW:-accumulate_and_verify_goblin} +# FLOW=${FLOW:-prove_and_verify} CRS_PATH=~/.bb-crs BRANCH=master VERBOSE=${VERBOSE:-} @@ -29,6 +31,7 @@ fi export BIN CRS_PATH VERBOSE BRANCH +# copy the gzipped acir test data from noir/test_programs to barretenberg/acir_tests ./clone_test_vectors.sh cd acir_tests diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp index 1127de60fb2..c5e3698d182 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/goblin_acir_composer.cpp @@ -26,8 +26,16 @@ void GoblinAcirComposer::create_circuit(acir_format::acir_format& constraint_sys std::vector GoblinAcirComposer::accumulate() { - // Construct a GUH proof for the circuit via the accumulate mechanism - return goblin.accumulate_for_acir(builder_); + // // Construct a GUH proof for the circuit via the accumulate mechanism + // return goblin.accumulate_for_acir(builder_); + + // Construct one final GUH proof via the accumulate mechanism + std::vector ultra_proof = goblin.accumulate_for_acir(builder_); + + // Construct a Goblin proof (ECCVM, Translator, Merge); result stored internally + goblin.prove_for_acir(); + + return ultra_proof; } bool GoblinAcirComposer::verify_accumulator(std::vector const& proof) diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 80283e72025..f151069bd84 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -155,7 +155,11 @@ class Goblin { Proof prove() { goblin_proof.merge_proof = std::move(merge_proof); - prove_eccvm(); + eccvm_builder = std::make_unique(op_queue); + eccvm_composer = std::make_unique(); + eccvm_prover = std::make_unique(eccvm_composer->create_prover(*eccvm_builder)); + goblin_proof.eccvm_proof = eccvm_prover->construct_proof(); + // prove_eccvm(); prove_translator(); return goblin_proof; }; From 28c085c362411e7a04cfa69acdbbe97a42f4c272 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 19 Jan 2024 19:21:28 +0000 Subject: [PATCH 18/20] bring it all together --- barretenberg/acir_tests/run_acir_tests.sh | 4 +--- .../cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp | 6 ++---- barretenberg/cpp/src/barretenberg/goblin/goblin.hpp | 7 +------ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index 657f2b97eaf..5c7bb60c9e2 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -11,9 +11,7 @@ source ./bash_helpers/catch.sh trap handle_sigchild SIGCHLD BIN=${BIN:-../cpp/build/bin/bb} -FLOW=${FLOW:-prove_and_verify_goblin} -# FLOW=${FLOW:-accumulate_and_verify_goblin} -# FLOW=${FLOW:-prove_and_verify} +FLOW=${FLOW:-prove_and_verify} CRS_PATH=~/.bb-crs BRANCH=master VERBOSE=${VERBOSE:-} 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 7566bc9491b..18d44941e56 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -87,8 +87,7 @@ WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, auto witness = acir_format::witness_buf_to_witness_data(from_buffer>(witness_vec)); acir_composer->create_circuit(constraint_system, witness); - auto proof_data = acir_composer->accumulate(); - // auto proof_data = acir_composer->accumulate_and_prove(); + auto proof_data = acir_composer->accumulate_and_prove(); *out = to_heap_buffer(proof_data); } @@ -134,8 +133,7 @@ WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* pro { auto acir_composer = reinterpret_cast(*acir_composer_ptr); auto proof = from_buffer>(proof_buf); - *result = acir_composer->verify_accumulator(proof); - // *result = acir_composer->verify(proof); + *result = acir_composer->verify(proof); } WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 9107951ed12..2a86f1782c9 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -153,12 +153,7 @@ class Goblin { */ Proof prove() { - goblin_proof.merge_proof = std::move(merge_proof); - eccvm_builder = std::make_unique(op_queue); - eccvm_composer = std::make_unique(); - eccvm_prover = std::make_unique(eccvm_composer->create_prover(*eccvm_builder)); - goblin_proof.eccvm_proof = eccvm_prover->construct_proof(); - // prove_eccvm(); + prove_eccvm(); prove_translator(); return goblin_proof; }; From 91fc81e727ea4940dc91cb266166395a58ee4a19 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 22 Jan 2024 16:22:00 +0000 Subject: [PATCH 19/20] fix bberg and acir --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 4 +++- barretenberg/cpp/src/barretenberg/goblin/goblin.hpp | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 72fa6756524..d5d626bd8f2 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -139,6 +139,8 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; + init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Call accumulate to generate a GoblinUltraHonk proof auto proof = acir_composer.accumulate(); @@ -176,7 +178,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); - size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Generate a GoblinUltraHonk proof and a full Goblin proof diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index 2a86f1782c9..a20bfdccb4e 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -147,12 +147,13 @@ class Goblin { /** * @brief Constuct a full Goblin proof (ECCVM, Translator, merge) * @details The merge proof is assumed to already have been constucted in the last accumulate step. It is simply - * copied into the final proof here. + * moved into the final proof here. * * @return Proof */ Proof prove() { + goblin_proof.merge_proof = std::move(merge_proof); prove_eccvm(); prove_translator(); return goblin_proof; From 57af750a69f09a926d5ec33e383e086c79b337f1 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Mon, 22 Jan 2024 17:45:40 +0000 Subject: [PATCH 20/20] additional comments --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 14 ++++++++++++-- .../barretenberg/dsl/acir_proofs/c_bind.hpp | 18 ++++++++++++++++++ .../cpp/src/barretenberg/goblin/goblin.hpp | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index d5d626bd8f2..b3d45629600 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -44,6 +44,12 @@ void init_bn254_crs(size_t dyadic_circuit_size) srs::init_crs_factory(bn254_g1_data, bn254_g2_data); } +/** + * @brief Initialize the global crs_factory for grumpkin based on a known dyadic circuit size + * @details Grumpkin crs is required only for the ECCVM + * + * @param dyadic_circuit_size power-of-2 circuit size + */ void init_grumpkin_crs(size_t eccvm_dyadic_circuit_size) { auto grumpkin_g1_data = get_grumpkin_g1_data(CRS_PATH, eccvm_dyadic_circuit_size); @@ -129,9 +135,11 @@ bool proveAndVerify(const std::string& bytecodePath, const std::string& witnessP */ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::string& witnessPath) { + // Populate the acir constraint system and witness from gzipped data auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); + // Instantiate a Goblin acir composer and construct a bberg circuit from the acir representation acir_proofs::GoblinAcirComposer acir_composer; acir_composer.create_circuit(constraint_system, witness); @@ -139,7 +147,7 @@ bool accumulateAndVerifyGoblin(const std::string& bytecodePath, const std::strin // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); - size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Call accumulate to generate a GoblinUltraHonk proof @@ -168,9 +176,11 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, const std::string& witnessPath, [[maybe_unused]] bool recursive) { + // Populate the acir constraint system and witness from gzipped data auto constraint_system = get_constraint_system(bytecodePath); auto witness = get_witness(witnessPath); + // Instantiate a Goblin acir composer and construct a bberg circuit from the acir representation acir_proofs::GoblinAcirComposer acir_composer; acir_composer.create_circuit(constraint_system, witness); @@ -178,7 +188,7 @@ bool proveAndVerifyGoblin(const std::string& bytecodePath, // to max circuit size present in acir tests suite. size_t hardcoded_bn254_dyadic_size_hack = 1 << 18; init_bn254_crs(hardcoded_bn254_dyadic_size_hack); - size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; + size_t hardcoded_grumpkin_dyadic_size_hack = 1 << 10; // For eccvm only init_grumpkin_crs(hardcoded_grumpkin_dyadic_size_hack); // Generate a GoblinUltraHonk proof and a full Goblin proof diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp index 91de508104a..76b24886b1d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.hpp @@ -34,11 +34,21 @@ WASM_EXPORT void acir_create_proof(in_ptr acir_composer_ptr, bool const* is_recursive, uint8_t** out); +/** + * @brief Perform the goblin accumulate operation + * @details Constructs a GUH proof and possibly handles transcript merge logic + * + */ WASM_EXPORT void acir_goblin_accumulate(in_ptr acir_composer_ptr, uint8_t const* constraint_system_buf, uint8_t const* witness_buf, uint8_t** out); +/** + * @brief Construct a full goblin proof + * @details Makes a call to accumulate to a final circuit before constructing a Goblin proof + * + */ WASM_EXPORT void acir_goblin_prove(in_ptr acir_composer_ptr, uint8_t const* constraint_system_buf, uint8_t const* witness_buf, @@ -57,8 +67,16 @@ WASM_EXPORT void acir_verify_proof(in_ptr acir_composer_ptr, bool const* is_recursive, bool* result); +/** + * @brief Verifies a GUH proof produced during goblin accumulation + * + */ WASM_EXPORT void acir_goblin_verify_accumulator(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); +/** + * @brief Verifies a full goblin proof (and the GUH proof produced by accumulation) + * + */ WASM_EXPORT void acir_goblin_verify(in_ptr acir_composer_ptr, uint8_t const* proof_buf, bool* result); WASM_EXPORT void acir_get_solidity_verifier(in_ptr acir_composer_ptr, out_str_buf out); diff --git a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp index a20bfdccb4e..aac0ef305ca 100644 --- a/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp +++ b/barretenberg/cpp/src/barretenberg/goblin/goblin.hpp @@ -84,7 +84,7 @@ class Goblin { std::unique_ptr eccvm_prover; std::unique_ptr translator_composer; - AccumulationOutput accumulator; // Used only for ACIR methods + AccumulationOutput accumulator; // Used only for ACIR methods for now public: /**