diff --git a/barretenberg/.circleci/config.yml b/barretenberg/.circleci/config.yml index fb7648019e6b..cc2d7acff62b 100644 --- a/barretenberg/.circleci/config.yml +++ b/barretenberg/.circleci/config.yml @@ -182,6 +182,18 @@ jobs: command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 stdlib-tests - *save_logs + acir-format-tests: + docker: + - image: aztecprotocol/alpine-build-image + resource_class: small + steps: + - *checkout + - *setup_env + - run: + name: "Test" + command: cond_spot_run_tests barretenberg-x86_64-linux-clang-assert 1 acir_format_tests + - *save_logs + barretenberg-tests: docker: - image: aztecprotocol/alpine-build-image @@ -375,6 +387,7 @@ workflows: - wasm-linux-clang: *defaults - proof-system-tests: *bb_test - honk-tests: *bb_test + - acir-format-tests: *bb_test - barretenberg-tests: *bb_test - stdlib-tests: *bb_test - stdlib-recursion-turbo-tests: *bb_test diff --git a/barretenberg/cpp/.aztec-packages-commit b/barretenberg/cpp/.aztec-packages-commit index 8b25206ff90e..919244865180 100644 --- a/barretenberg/cpp/.aztec-packages-commit +++ b/barretenberg/cpp/.aztec-packages-commit @@ -1 +1 @@ -master \ No newline at end of file +64c8ba700b75df07a8452a6f2eae3d23cf7625a6 \ No newline at end of file diff --git a/barretenberg/cpp/.clangd b/barretenberg/cpp/.clangd index 599f23163a28..06f5d0d0590b 100644 --- a/barretenberg/cpp/.clangd +++ b/barretenberg/cpp/.clangd @@ -59,8 +59,6 @@ Diagnostics: - readability-function-cognitive-complexity # It is often nicer to not be explicit - google-explicit-constructor - CheckOptions: - - cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: True --- # this divider is necessary # Disable some checks for Google Test/Bench diff --git a/barretenberg/cpp/src/barretenberg/barretenberg.hpp b/barretenberg/cpp/src/barretenberg/barretenberg.hpp index 726da8350024..fc5a162068ec 100644 --- a/barretenberg/cpp/src/barretenberg/barretenberg.hpp +++ b/barretenberg/cpp/src/barretenberg/barretenberg.hpp @@ -21,8 +21,8 @@ #include "ecc/curves/grumpkin/grumpkin.hpp" #include "numeric/random/engine.hpp" #include "numeric/uint256/uint256.hpp" -#include "plonk/composer/turbo_plonk_composer.hpp" -#include "plonk/composer/ultra_plonk_composer.hpp" +#include "proof_system/circuit_constructors/turbo_circuit_constructor.hpp" +#include "proof_system/circuit_constructors/ultra_circuit_constructor.hpp" #include "plonk/proof_system/types/proof.hpp" #include "plonk/proof_system/verification_key/verification_key.hpp" #include "proof_system/types/composer_type.hpp" diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/benchmark_utilities.hpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/benchmark_utilities.hpp index 81a12b129eff..2508b5130e64 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/benchmark_utilities.hpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/benchmark_utilities.hpp @@ -1,11 +1,5 @@ -#include "barretenberg/crypto/ecdsa/ecdsa.hpp" -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/honk/proof_system/ultra_prover.hpp" -#include "barretenberg/honk/proof_system/ultra_verifier.hpp" #include -#include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" + #include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp" #include "barretenberg/stdlib/hash/keccak/keccak.hpp" #include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" @@ -41,11 +35,13 @@ struct BenchParams { * @param composer * @param num_iterations */ -template void generate_basic_arithmetic_circuit(Composer& composer, size_t num_gates) +template void generate_basic_arithmetic_circuit(Builder& builder, size_t num_gates) { - plonk::stdlib::field_t a(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element())); - plonk::stdlib::field_t b(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element())); - plonk::stdlib::field_t c(&composer); + proof_system::plonk::stdlib::field_t a( + proof_system::plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); + proof_system::plonk::stdlib::field_t b( + proof_system::plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); + proof_system::plonk::stdlib::field_t c(&builder); for (size_t i = 0; i < (num_gates / 4) - 4; ++i) { c = a + b; c = a * c; @@ -57,47 +53,47 @@ template void generate_basic_arithmetic_circuit(Composer& co /** * @brief Generate test circuit with specified number of sha256 hashes * - * @param composer + * @param builder * @param num_iterations */ -template void generate_sha256_test_circuit(Composer& composer, size_t num_iterations) +template void generate_sha256_test_circuit(Builder& builder, size_t num_iterations) { std::string in; in.resize(32); for (size_t i = 0; i < 32; ++i) { in[i] = 0; } - proof_system::plonk::stdlib::packed_byte_array input(&composer, in); + proof_system::plonk::stdlib::packed_byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = proof_system::plonk::stdlib::sha256(input); + input = proof_system::plonk::stdlib::sha256(input); } } /** * @brief Generate test circuit with specified number of keccak hashes * - * @param composer + * @param builder * @param num_iterations */ -template void generate_keccak_test_circuit(Composer& composer, size_t num_iterations) +template void generate_keccak_test_circuit(Builder& builder, size_t num_iterations) { std::string in = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01"; - proof_system::plonk::stdlib::byte_array input(&composer, in); + proof_system::plonk::stdlib::byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = proof_system::plonk::stdlib::keccak::hash(input); + input = proof_system::plonk::stdlib::keccak::hash(input); } } /** * @brief Generate test circuit with specified number of ecdsa verifications * - * @param composer + * @param builder * @param num_iterations */ -template void generate_ecdsa_verification_test_circuit(Composer& composer, size_t num_iterations) +template void generate_ecdsa_verification_test_circuit(Builder& builder, size_t num_iterations) { - using curve = proof_system::plonk::stdlib::secp256k1; + using curve = proof_system::plonk::stdlib::secp256k1; using fr = typename curve::fr; using fq = typename curve::fq; using g1 = typename curve::g1; @@ -115,22 +111,23 @@ template void generate_ecdsa_verification_test_circuit(Compo bool first_result = crypto::ecdsa::verify_signature(message_string, account.public_key, signature); + static_cast(first_result); // TODO(Cody): This is not used anywhere. std::vector rr(signature.r.begin(), signature.r.end()); std::vector ss(signature.s.begin(), signature.s.end()); uint8_t vv = signature.v; - typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&composer, account.public_key); + typename curve::g1_bigfr_ct public_key = curve::g1_bigfr_ct::from_witness(&builder, account.public_key); - proof_system::plonk::stdlib::ecdsa::signature sig{ typename curve::byte_array_ct(&composer, rr), - typename curve::byte_array_ct(&composer, ss), - proof_system::plonk::stdlib::uint8( - &composer, vv) }; + proof_system::plonk::stdlib::ecdsa::signature sig{ typename curve::byte_array_ct(&builder, rr), + typename curve::byte_array_ct(&builder, ss), + proof_system::plonk::stdlib::uint8( + &builder, vv) }; - typename curve::byte_array_ct message(&composer, message_string); + typename curve::byte_array_ct message(&builder, message_string); // Verify ecdsa signature - proof_system::plonk::stdlib::ecdsa::verify_signature void generate_ecdsa_verification_test_circuit(Compo /** * @brief Generate test circuit with specified number of merkle membership checks * - * @param composer + * @param builder * @param num_iterations */ -template void generate_merkle_membership_test_circuit(Composer& composer, size_t num_iterations) +template void generate_merkle_membership_test_circuit(Builder& builder, size_t num_iterations) { using namespace proof_system::plonk::stdlib; - using field_ct = field_t; - using witness_ct = witness_t; - using witness_ct = witness_t; + using field_ct = field_t; + using witness_ct = witness_t; + using witness_ct = witness_t; using MemStore = merkle_tree::MemoryStore; using MerkleTree_ct = merkle_tree::MerkleTree; @@ -163,12 +160,12 @@ template void generate_merkle_membership_test_circuit(Compos size_t value = i * 2; merkle_tree.update_element(idx, value); - field_ct root_ct = witness_ct(&composer, merkle_tree.root()); - auto idx_ct = field_ct(witness_ct(&composer, fr(idx))).decompose_into_bits(); + field_ct root_ct = witness_ct(&builder, merkle_tree.root()); + auto idx_ct = field_ct(witness_ct(&builder, fr(idx))).decompose_into_bits(); auto value_ct = field_ct(value); merkle_tree::check_membership( - root_ct, merkle_tree::create_witness_hash_path(composer, merkle_tree.get_hash_path(idx)), value_ct, idx_ct); + root_ct, merkle_tree::create_witness_hash_path(builder, merkle_tree.get_hash_path(idx)), value_ct, idx_ct); } } @@ -177,21 +174,25 @@ template void generate_merkle_membership_test_circuit(Compos * * @details This function assumes state.range refers to num_gates which is the size of the underlying circuit * - * @tparam Composer + * @tparam Builder * @param state * @param test_circuit_function */ template -void construct_proof_with_specified_num_gates(State& state, void (*test_circuit_function)(Composer&, size_t)) noexcept +void construct_proof_with_specified_num_gates(State& state, + void (*test_circuit_function)(typename Composer::CircuitConstructor&, + size_t)) noexcept { barretenberg::srs::init_crs_factory("../srs_db/ignition"); auto num_gates = static_cast(1 << (size_t)state.range(0)); for (auto _ : state) { // Constuct circuit and prover; don't include this part in measurement state.PauseTiming(); + auto builder = typename Composer::CircuitConstructor(); + test_circuit_function(builder, num_gates); + auto composer = Composer(); - test_circuit_function(composer, num_gates); - auto ext_prover = composer.create_prover(); + auto ext_prover = composer.create_prover(builder); state.ResumeTiming(); // Construct proof @@ -205,22 +206,25 @@ void construct_proof_with_specified_num_gates(State& state, void (*test_circuit_ * @details This function assumes state.range refers to num_iterations which is the number of times to perform a given * basic operation in the circuit, e.g. number of hashes * - * @tparam Composer + * @tparam Builder * @param state * @param test_circuit_function */ template void construct_proof_with_specified_num_iterations(State& state, - void (*test_circuit_function)(Composer&, size_t)) noexcept + void (*test_circuit_function)(typename Composer::CircuitConstructor&, + size_t)) noexcept { barretenberg::srs::init_crs_factory("../srs_db/ignition"); auto num_iterations = static_cast(state.range(0)); for (auto _ : state) { // Constuct circuit and prover; don't include this part in measurement state.PauseTiming(); + auto builder = typename Composer::CircuitConstructor(); + test_circuit_function(builder, num_iterations); + auto composer = Composer(); - test_circuit_function(composer, num_iterations); - auto ext_prover = composer.create_prover(); + auto ext_prover = composer.create_prover(builder); state.ResumeTiming(); // Construct proof diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp index 831b7c16c1f4..ce798db11055 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/honk.bench.cpp @@ -1,7 +1,6 @@ -#include "barretenberg/ecc/curves/bn254/fr.hpp" #include #include -#include "barretenberg/honk/composer/standard_honk_composer.hpp" +#include "barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" @@ -10,18 +9,20 @@ using namespace proof_system::plonk::stdlib; namespace standard_honk_bench { -using Composer = proof_system::honk::StandardHonkComposer; +using Builder = proof_system::StandardCircuitConstructor; +using Composer = proof_system::honk::StandardHonkComposerHelper; constexpr size_t MIN_LOG_NUM_GATES = 16; constexpr size_t MAX_LOG_NUM_GATES = 16; // To get good statistics, number of Repetitions must be sufficient. ~30 Repetitions gives good results. constexpr size_t NUM_REPETITIONS = 5; -void generate_test_circuit(auto& composer, size_t num_gates) +void generate_test_circuit(auto& builder, size_t num_gates) { - field_t a(witness_t(&composer, barretenberg::fr::random_element())); - field_t b(witness_t(&composer, barretenberg::fr::random_element())); - field_t c(&composer); + barretenberg::srs::init_crs_factory("../srs_db/ignition"); + field_t a(witness_t(&builder, barretenberg::fr::random_element())); + field_t b(witness_t(&builder, barretenberg::fr::random_element())); + field_t c(&builder); for (size_t i = 0; i < (num_gates / 4) - 4; ++i) { c = a + b; c = a * c; @@ -38,11 +39,12 @@ void create_prover_standard(State& state) noexcept for (auto _ : state) { state.PauseTiming(); auto num_gates = 1 << (size_t)state.range(0); - auto composer = Composer(static_cast(num_gates)); - generate_test_circuit(composer, static_cast(num_gates)); + auto builder = Builder(static_cast(num_gates)); + generate_test_circuit(builder, static_cast(num_gates)); state.ResumeTiming(); - composer.create_prover(); + auto composer = Composer(); + composer.create_prover(builder); } } BENCHMARK(create_prover_standard)->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, 1)->Repetitions(NUM_REPETITIONS); @@ -55,9 +57,11 @@ void construct_proof_standard(State& state) noexcept auto num_gates = 1 << (size_t)state.range(0); for (auto _ : state) { state.PauseTiming(); - auto composer = Composer(static_cast(num_gates)); - generate_test_circuit(composer, static_cast(num_gates)); - auto ext_prover = composer.create_prover(); + auto builder = Builder(static_cast(num_gates)); + generate_test_circuit(builder, static_cast(num_gates)); + + auto composer = Composer(); + auto ext_prover = composer.create_prover(builder); state.ResumeTiming(); auto proof = ext_prover.construct_proof(); @@ -77,11 +81,12 @@ void create_verifier_standard(State& state) noexcept for (auto _ : state) { state.PauseTiming(); auto num_gates = 1 << (size_t)state.range(0); - auto composer = Composer(static_cast(num_gates)); - generate_test_circuit(composer, static_cast(num_gates)); + auto builder = Builder(static_cast(num_gates)); + generate_test_circuit(builder, static_cast(num_gates)); state.ResumeTiming(); - composer.create_verifier(); + auto composer = Composer(); + composer.create_verifier(builder); } } // BENCHMARK(create_verifier_standard)->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES, @@ -95,11 +100,13 @@ void verify_proof_standard(State& state) noexcept for (auto _ : state) { state.PauseTiming(); auto num_gates = (size_t)state.range(0); - auto composer = Composer(static_cast(num_gates)); - generate_test_circuit(composer, static_cast(num_gates)); - auto prover = composer.create_prover(); + auto builder = Builder(static_cast(num_gates)); + generate_test_circuit(builder, static_cast(num_gates)); + + auto composer = Composer(); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_verifier(builder); state.ResumeTiming(); verifier.verify_proof(proof); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_honk.bench.cpp index c88d80292da9..dd965342c13e 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_honk.bench.cpp @@ -1,10 +1,13 @@ #include "barretenberg/benchmark/honk_bench/benchmark_utilities.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp" using namespace benchmark; namespace standard_honk_bench { -using StandardHonk = proof_system::honk::StandardHonkComposer; +using StandardBuilder = proof_system::StandardCircuitConstructor; +using StandardHonk = proof_system::honk::StandardHonkComposerHelper; // Log number of gates for test circuit constexpr size_t MIN_LOG_NUM_GATES = bench_utils::BenchParams::MIN_LOG_NUM_GATES; @@ -15,12 +18,14 @@ constexpr size_t NUM_REPETITIONS = bench_utils::BenchParams::NUM_REPETITIONS; /** * @brief Benchmark: Construction of a Standard proof for a circuit determined by the provided circuit function */ -void construct_proof_standard(State& state, void (*test_circuit_function)(StandardHonk&, size_t)) noexcept +void construct_proof_standard(State& state, void (*test_circuit_function)(StandardBuilder&, size_t)) noexcept { - bench_utils::construct_proof_with_specified_num_gates(state, test_circuit_function); + bench_utils::construct_proof_with_specified_num_gates(state, test_circuit_function); } -BENCHMARK_CAPTURE(construct_proof_standard, arithmetic, &bench_utils::generate_basic_arithmetic_circuit) +BENCHMARK_CAPTURE(construct_proof_standard, + arithmetic, + &bench_utils::generate_basic_arithmetic_circuit) ->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_plonk.bench.cpp index 106fd00f190a..f41e4bd500f0 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/standard_plonk.bench.cpp @@ -1,10 +1,13 @@ #include "barretenberg/benchmark/honk_bench/benchmark_utilities.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" using namespace benchmark; namespace standard_plonk_bench { -using StandardPlonk = proof_system::plonk::StandardPlonkComposer; +using StandardBuilder = proof_system::StandardCircuitConstructor; +using StandardPlonk = proof_system::plonk::StandardPlonkComposerHelper; // Log number of gates for test circuit constexpr size_t MIN_LOG_NUM_GATES = bench_utils::BenchParams::MIN_LOG_NUM_GATES; @@ -15,12 +18,14 @@ constexpr size_t NUM_REPETITIONS = bench_utils::BenchParams::NUM_REPETITIONS; /** * @brief Benchmark: Construction of a Standard proof for a circuit determined by the provided circuit function */ -void construct_proof_standard(State& state, void (*test_circuit_function)(StandardPlonk&, size_t)) noexcept +void construct_proof_standard(State& state, void (*test_circuit_function)(StandardBuilder&, size_t)) noexcept { - bench_utils::construct_proof_with_specified_num_gates(state, test_circuit_function); + bench_utils::construct_proof_with_specified_num_gates(state, test_circuit_function); } -BENCHMARK_CAPTURE(construct_proof_standard, arithmetic, &bench_utils::generate_basic_arithmetic_circuit) +BENCHMARK_CAPTURE(construct_proof_standard, + arithmetic, + &bench_utils::generate_basic_arithmetic_circuit) ->DenseRange(MIN_LOG_NUM_GATES, MAX_LOG_NUM_GATES) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp index e834d83ff95d..db26e29e7354 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_honk.bench.cpp @@ -1,10 +1,16 @@ +#include + +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" +#include "barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp" #include "barretenberg/benchmark/honk_bench/benchmark_utilities.hpp" using namespace benchmark; +using namespace proof_system::plonk; namespace ultra_honk_bench { -using UltraHonk = proof_system::honk::UltraHonkComposer; +using UltraBuilder = proof_system::UltraCircuitConstructor; +using UltraHonk = proof_system::honk::UltraHonkComposerHelper; // Number of times to perform operation of interest in the benchmark circuits, e.g. # of hashes to perform constexpr size_t MIN_NUM_ITERATIONS = bench_utils::BenchParams::MIN_NUM_ITERATIONS; @@ -15,29 +21,29 @@ constexpr size_t NUM_REPETITIONS = bench_utils::BenchParams::NUM_REPETITIONS; /** * @brief Benchmark: Construction of a Ultra Honk proof for a circuit determined by the provided circuit function */ -void construct_proof_ultra(State& state, void (*test_circuit_function)(UltraHonk&, size_t)) noexcept +void construct_proof_ultra(State& state, void (*test_circuit_function)(UltraBuilder&, size_t)) noexcept { - bench_utils::construct_proof_with_specified_num_iterations(state, test_circuit_function); + bench_utils::construct_proof_with_specified_num_iterations(state, test_circuit_function); } // Define benchmarks -BENCHMARK_CAPTURE(construct_proof_ultra, sha256, &bench_utils::generate_sha256_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultra, sha256, &bench_utils::generate_sha256_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); -BENCHMARK_CAPTURE(construct_proof_ultra, keccak, &bench_utils::generate_keccak_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultra, keccak, &bench_utils::generate_keccak_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); BENCHMARK_CAPTURE(construct_proof_ultra, ecdsa_verification, - &bench_utils::generate_ecdsa_verification_test_circuit) + &bench_utils::generate_ecdsa_verification_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); BENCHMARK_CAPTURE(construct_proof_ultra, merkle_membership, - &bench_utils::generate_merkle_membership_test_circuit) + &bench_utils::generate_merkle_membership_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_plonk.bench.cpp index 064d5ef204bf..6554cbb33883 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/honk_bench/ultra_plonk.bench.cpp @@ -1,10 +1,13 @@ #include "barretenberg/benchmark/honk_bench/benchmark_utilities.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" using namespace benchmark; namespace ultra_plonk_bench { -using UltraPlonk = proof_system::plonk::UltraPlonkComposer; +using UltraBuilder = proof_system::UltraCircuitConstructor; +using UltraPlonk = proof_system::plonk::UltraPlonkComposerHelper; // Number of times to perform operation of interest in the benchmark circuits, e.g. # of hashes to perform constexpr size_t MIN_NUM_ITERATIONS = bench_utils::BenchParams::MIN_NUM_ITERATIONS; @@ -15,28 +18,28 @@ constexpr size_t NUM_REPETITIONS = bench_utils::BenchParams::NUM_REPETITIONS; /** * @brief Benchmark: Construction of a Ultra Honk proof for a circuit determined by the provided circuit function */ -void construct_proof_ultra(State& state, void (*test_circuit_function)(UltraPlonk&, size_t)) noexcept +void construct_proof_ultra(State& state, void (*test_circuit_function)(UltraBuilder&, size_t)) noexcept { - bench_utils::construct_proof_with_specified_num_iterations(state, test_circuit_function); + bench_utils::construct_proof_with_specified_num_iterations(state, test_circuit_function); } -BENCHMARK_CAPTURE(construct_proof_ultra, sha256, &bench_utils::generate_sha256_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultra, sha256, &bench_utils::generate_sha256_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); -BENCHMARK_CAPTURE(construct_proof_ultra, keccak, &bench_utils::generate_keccak_test_circuit) +BENCHMARK_CAPTURE(construct_proof_ultra, keccak, &bench_utils::generate_keccak_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); BENCHMARK_CAPTURE(construct_proof_ultra, ecdsa_verification, - &bench_utils::generate_ecdsa_verification_test_circuit) + &bench_utils::generate_ecdsa_verification_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); BENCHMARK_CAPTURE(construct_proof_ultra, merkle_membership, - &bench_utils::generate_merkle_membership_test_circuit) + &bench_utils::generate_merkle_membership_test_circuit) ->DenseRange(MIN_NUM_ITERATIONS, MAX_NUM_ITERATIONS) ->Repetitions(NUM_REPETITIONS) ->Unit(::benchmark::kSecond); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp index ae56f38de6bb..a0c41dff1e3e 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/plonk_bench/plonk.bench.cpp @@ -1,9 +1,6 @@ #include -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/numeric/bitop/get_msb.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/proof_system/prover/prover.hpp" -#include "barretenberg/plonk/proof_system/verifier/verifier.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" using namespace benchmark; @@ -15,11 +12,14 @@ constexpr size_t START = (MAX_GATES) >> (NUM_CIRCUITS - 1); // constexpr size_t MAX_HASH_ROUNDS = 8192; // constexpr size_t START_HASH_ROUNDS = 64; -void generate_test_plonk_circuit(plonk::StandardPlonkComposer& composer, size_t num_gates) +using Builder = proof_system::StandardCircuitConstructor; +using Composer = proof_system::plonk::StandardPlonkComposerHelper; + +void generate_test_plonk_circuit(Builder& builder, size_t num_gates) { - plonk::stdlib::field_t a(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element())); - plonk::stdlib::field_t b(plonk::stdlib::witness_t(&composer, barretenberg::fr::random_element())); - plonk::stdlib::field_t c(&composer); + plonk::stdlib::field_t a(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); + plonk::stdlib::field_t b(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); + plonk::stdlib::field_t c(&builder); for (size_t i = 0; i < (num_gates / 4) - 4; ++i) { c = a + b; c = a * c; @@ -36,13 +36,13 @@ void construct_witnesses_bench(State& state) noexcept { for (auto _ : state) { state.PauseTiming(); - plonk::StandardPlonkComposer composer = - proof_system::plonk::StandardPlonkComposer(static_cast(state.range(0))); - generate_test_plonk_circuit(composer, static_cast(state.range(0))); - composer.compute_proving_key(); + auto builder = Builder(static_cast(state.range(0))); + generate_test_plonk_circuit(builder, static_cast(state.range(0))); + auto composer = Composer(); + composer.compute_proving_key(builder); state.ResumeTiming(); - composer.compute_witness(); + composer.compute_witness(builder); } } BENCHMARK(construct_witnesses_bench)->RangeMultiplier(2)->Range(START, MAX_GATES); @@ -50,14 +50,14 @@ BENCHMARK(construct_witnesses_bench)->RangeMultiplier(2)->Range(START, MAX_GATES void construct_proving_keys_bench(State& state) noexcept { for (auto _ : state) { - plonk::StandardPlonkComposer composer = - proof_system::plonk::StandardPlonkComposer(static_cast(state.range(0))); - generate_test_plonk_circuit(composer, static_cast(state.range(0))); + auto builder = Builder(static_cast(state.range(0))); + generate_test_plonk_circuit(builder, static_cast(state.range(0))); size_t idx = static_cast(numeric::get_msb((uint64_t)state.range(0))) - static_cast(numeric::get_msb(START)); - composer.compute_proving_key(); + auto composer = Composer(); + composer.compute_proving_key(builder); state.PauseTiming(); - provers[idx] = composer.create_prover(); + provers[idx] = composer.create_prover(builder); state.ResumeTiming(); } } @@ -67,14 +67,14 @@ void construct_instances_bench(State& state) noexcept { for (auto _ : state) { state.PauseTiming(); - plonk::StandardPlonkComposer composer = - proof_system::plonk::StandardPlonkComposer(static_cast(state.range(0))); - generate_test_plonk_circuit(composer, static_cast(state.range(0))); + auto builder = Builder(static_cast(state.range(0))); + generate_test_plonk_circuit(builder, static_cast(state.range(0))); size_t idx = static_cast(numeric::get_msb((uint64_t)state.range(0))) - static_cast(numeric::get_msb(START)); - composer.create_prover(); + auto composer = Composer(); + composer.create_prover(builder); state.ResumeTiming(); - verifiers[idx] = composer.create_verifier(); + verifiers[idx] = composer.create_verifier(builder); } } BENCHMARK(construct_instances_bench)->RangeMultiplier(2)->Range(START, MAX_GATES); diff --git a/barretenberg/cpp/src/barretenberg/common/log.hpp b/barretenberg/cpp/src/barretenberg/common/log.hpp index a347f0bd5f13..cbbeac735bfa 100644 --- a/barretenberg/cpp/src/barretenberg/common/log.hpp +++ b/barretenberg/cpp/src/barretenberg/common/log.hpp @@ -1,34 +1,16 @@ #pragma once -#include #include #include #include #include +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" +#include "barretenberg/env/logstr.hpp" #define BENCHMARK_INFO_PREFIX "##BENCHMARK_INFO_PREFIX##" #define BENCHMARK_INFO_SEPARATOR "#" #define BENCHMARK_INFO_SUFFIX "##BENCHMARK_INFO_SUFFIX##" -#define GET_COMPOSER_NAME_STRING(composer) \ - (typeid(composer) == typeid(plonk::StandardPlonkComposer) \ - ? "StandardPlonk" \ - : typeid(composer) == typeid(plonk::TurboPlonkComposer) \ - ? "TurboPlonk" \ - : typeid(composer) == typeid(plonk::UltraPlonkComposer) \ - ? "UltraPlonk" \ - : typeid(composer) == typeid(honk::StandardHonkComposer) \ - ? "StandardHonk" \ - : typeid(composer) == typeid(honk::UltraHonkComposer) \ - ? "UltraHonk" \ - : typeid(composer) == typeid(proof_system::StandardCircuitConstructor) \ - ? "StandardArithemtization" \ - : typeid(composer) == typeid(proof_system::TurboCircuitConstructor) \ - ? "TurboArithemtization" \ - : typeid(composer) == typeid(proof_system::UltraCircuitConstructor) \ - ? "UltraArithmetization" \ - : "NullPlonk") namespace { - template std::string format(Args... args) { std::ostringstream os; diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index 9a7ca427671e..0f136e572af7 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -3,15 +3,15 @@ namespace acir_format { -void read_witness(Composer& composer, WitnessVector const& witness) +void read_witness(Builder& builder, WitnessVector const& witness) { - composer.variables[0] = 0; + builder.variables[0] = 0; for (size_t i = 0; i < witness.size(); ++i) { - composer.variables[i + 1] = witness[i]; + builder.variables[i + 1] = witness[i]; } } -void create_circuit(Composer& composer, acir_format const& constraint_system) +void create_circuit(Builder& builder, acir_format const& constraint_system) { if (constraint_system.public_inputs.size() > constraint_system.varnum) { info("create_circuit: too many public inputs!"); @@ -22,80 +22,80 @@ void create_circuit(Composer& composer, acir_format const& constraint_system) if (std::find(constraint_system.public_inputs.begin(), constraint_system.public_inputs.end(), i) != constraint_system.public_inputs.end()) { - composer.add_public_variable(0); + builder.add_public_variable(0); } else { - composer.add_variable(0); + builder.add_variable(0); } } // Add arithmetic gates for (const auto& constraint : constraint_system.constraints) { - composer.create_poly_gate(constraint); + builder.create_poly_gate(constraint); } // Add and constraint for (const auto& constraint : constraint_system.logic_constraints) { create_logic_gate( - composer, constraint.a, constraint.b, constraint.result, constraint.num_bits, constraint.is_xor_gate); + builder, constraint.a, constraint.b, constraint.result, constraint.num_bits, constraint.is_xor_gate); } // Add range constraint for (const auto& constraint : constraint_system.range_constraints) { - composer.create_range_constraint(constraint.witness, constraint.num_bits, ""); + builder.create_range_constraint(constraint.witness, constraint.num_bits, ""); } // Add sha256 constraints for (const auto& constraint : constraint_system.sha256_constraints) { - create_sha256_constraints(composer, constraint); + create_sha256_constraints(builder, constraint); } // Add schnorr constraints for (const auto& constraint : constraint_system.schnorr_constraints) { - create_schnorr_verify_constraints(composer, constraint); + create_schnorr_verify_constraints(builder, constraint); } // Add ECDSA constraints for (const auto& constraint : constraint_system.ecdsa_constraints) { - create_ecdsa_verify_constraints(composer, constraint, false); + create_ecdsa_verify_constraints(builder, constraint, false); } // Add blake2s constraints for (const auto& constraint : constraint_system.blake2s_constraints) { - create_blake2s_constraints(composer, constraint); + create_blake2s_constraints(builder, constraint); } // Add keccak constraints for (const auto& constraint : constraint_system.keccak_constraints) { - create_keccak_constraints(composer, constraint); + create_keccak_constraints(builder, constraint); } for (const auto& constraint : constraint_system.keccak_var_constraints) { - create_keccak_var_constraints(composer, constraint); + create_keccak_var_constraints(builder, constraint); } // Add pedersen constraints for (const auto& constraint : constraint_system.pedersen_constraints) { - create_pedersen_constraint(composer, constraint); + create_pedersen_constraint(builder, constraint); } // Add fixed base scalar mul constraints for (const auto& constraint : constraint_system.fixed_base_scalar_mul_constraints) { - create_fixed_base_constraint(composer, constraint); + create_fixed_base_constraint(builder, constraint); } // Add hash to field constraints for (const auto& constraint : constraint_system.hash_to_field_constraints) { - create_hash_to_field_constraints(composer, constraint); + create_hash_to_field_constraints(builder, constraint); } // Add block constraints for (const auto& constraint : constraint_system.block_constraints) { - create_block_constraints(composer, constraint, false); + create_block_constraints(builder, constraint, false); } // Add recursion constraints for (size_t i = 0; i < constraint_system.recursion_constraints.size(); ++i) { auto& constraint = constraint_system.recursion_constraints[i]; - create_recursion_constraints(composer, constraint); + create_recursion_constraints(builder, constraint); // make sure the verification key records the public input indices of the final recursion output // (N.B. up to the ACIR description to make sure that the final output aggregation object wires are public @@ -103,38 +103,28 @@ void create_circuit(Composer& composer, acir_format const& constraint_system) if (i == constraint_system.recursion_constraints.size() - 1) { std::vector proof_output_witness_indices(constraint.output_aggregation_object.begin(), constraint.output_aggregation_object.end()); - composer.circuit_constructor.set_recursive_proof(proof_output_witness_indices); + builder.set_recursive_proof(proof_output_witness_indices); } } } -Composer create_circuit(const acir_format& constraint_system, - std::shared_ptr const& crs_factory, - size_t size_hint) +Builder create_circuit(const acir_format& constraint_system, size_t size_hint) { - Composer composer(crs_factory, size_hint); - create_circuit(composer, constraint_system); - return composer; + Builder builder(size_hint); + create_circuit(builder, constraint_system); + return builder; } -Composer create_circuit_with_witness(acir_format const& constraint_system, - WitnessVector const& witness, - std::shared_ptr const& crs_factory, - size_t size_hint) +Builder create_circuit_with_witness(acir_format const& constraint_system, + WitnessVector const& witness, + size_t size_hint) { - Composer composer(crs_factory, size_hint); - create_circuit_with_witness(composer, constraint_system, witness); - return composer; + Builder builder(size_hint); + create_circuit_with_witness(builder, constraint_system, witness); + return builder; } -Composer create_circuit_with_witness(const acir_format& constraint_system, WitnessVector const& witness) -{ - auto composer = Composer(); - create_circuit_with_witness(composer, constraint_system, witness); - return composer; -} - -void create_circuit_with_witness(Composer& composer, acir_format const& constraint_system, WitnessVector const& witness) +void create_circuit_with_witness(Builder& builder, acir_format const& constraint_system, WitnessVector const& witness) { if (constraint_system.public_inputs.size() > constraint_system.varnum) { info("create_circuit_with_witness: too many public inputs!"); @@ -146,83 +136,83 @@ void create_circuit_with_witness(Composer& composer, acir_format const& constrai if (std::find(constraint_system.public_inputs.begin(), constraint_system.public_inputs.end(), i) != constraint_system.public_inputs.end()) { - composer.add_public_variable(0); + builder.add_public_variable(0); } else { - composer.add_variable(0); + builder.add_variable(0); } } - read_witness(composer, witness); + read_witness(builder, witness); // Add arithmetic gates for (const auto& constraint : constraint_system.constraints) { - composer.create_poly_gate(constraint); + builder.create_poly_gate(constraint); } // Add logic constraint for (const auto& constraint : constraint_system.logic_constraints) { create_logic_gate( - composer, constraint.a, constraint.b, constraint.result, constraint.num_bits, constraint.is_xor_gate); + builder, constraint.a, constraint.b, constraint.result, constraint.num_bits, constraint.is_xor_gate); } // Add range constraint for (const auto& constraint : constraint_system.range_constraints) { - composer.create_range_constraint(constraint.witness, constraint.num_bits, ""); + builder.create_range_constraint(constraint.witness, constraint.num_bits, ""); } // Add sha256 constraints for (const auto& constraint : constraint_system.sha256_constraints) { - create_sha256_constraints(composer, constraint); + create_sha256_constraints(builder, constraint); } // Add schnorr constraints for (const auto& constraint : constraint_system.schnorr_constraints) { - create_schnorr_verify_constraints(composer, constraint); + create_schnorr_verify_constraints(builder, constraint); } // Add ECDSA constraints for (const auto& constraint : constraint_system.ecdsa_constraints) { - create_ecdsa_verify_constraints(composer, constraint); + create_ecdsa_verify_constraints(builder, constraint); } // Add blake2s constraints for (const auto& constraint : constraint_system.blake2s_constraints) { - create_blake2s_constraints(composer, constraint); + create_blake2s_constraints(builder, constraint); } // Add keccak constraints for (const auto& constraint : constraint_system.keccak_constraints) { - create_keccak_constraints(composer, constraint); + create_keccak_constraints(builder, constraint); } for (const auto& constraint : constraint_system.keccak_var_constraints) { - create_keccak_var_constraints(composer, constraint); + create_keccak_var_constraints(builder, constraint); } // Add pedersen constraints for (const auto& constraint : constraint_system.pedersen_constraints) { - create_pedersen_constraint(composer, constraint); + create_pedersen_constraint(builder, constraint); } // Add fixed base scalar mul constraints for (const auto& constraint : constraint_system.fixed_base_scalar_mul_constraints) { - create_fixed_base_constraint(composer, constraint); + create_fixed_base_constraint(builder, constraint); } // Add hash to field constraints for (const auto& constraint : constraint_system.hash_to_field_constraints) { - create_hash_to_field_constraints(composer, constraint); + create_hash_to_field_constraints(builder, constraint); } // Add block constraints for (const auto& constraint : constraint_system.block_constraints) { - create_block_constraints(composer, constraint); + create_block_constraints(builder, constraint); } // Add recursion constraints for (size_t i = 0; i < constraint_system.recursion_constraints.size(); ++i) { auto& constraint = constraint_system.recursion_constraints[i]; - create_recursion_constraints(composer, constraint, true); + create_recursion_constraints(builder, constraint, true); // make sure the verification key records the public input indices of the final recursion output // (N.B. up to the ACIR description to make sure that the final output aggregation object wires are public @@ -230,7 +220,7 @@ void create_circuit_with_witness(Composer& composer, acir_format const& constrai if (i == constraint_system.recursion_constraints.size() - 1) { std::vector proof_output_witness_indices(constraint.output_aggregation_object.begin(), constraint.output_aggregation_object.end()); - composer.circuit_constructor.set_recursive_proof(proof_output_witness_indices); + builder.set_recursive_proof(proof_output_witness_indices); } } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp index 6e6857d83ad9..cf8068bbb83d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.hpp @@ -45,24 +45,17 @@ struct acir_format { using WitnessVector = std::vector>; -void read_witness(Composer& composer, std::vector const& witness); +void read_witness(Builder& builder, std::vector const& witness); -void create_circuit(Composer& composer, const acir_format& constraint_system); +void create_circuit(Builder& builder, const acir_format& constraint_system); -Composer create_circuit(const acir_format& constraint_system, - std::shared_ptr const& crs_factory, - size_t size_hint = 0); +Builder create_circuit(const acir_format& constraint_system, size_t size_hint = 0); -Composer create_circuit_with_witness(const acir_format& constraint_system, - WitnessVector const& witness, - std::shared_ptr const& crs_factory, - size_t size_hint = 0); +Builder create_circuit_with_witness(const acir_format& constraint_system, + WitnessVector const& witness, + size_t size_hint = 0); -Composer create_circuit_with_witness(const acir_format& constraint_system, WitnessVector const& witness); - -void create_circuit_with_witness(Composer& composer, - const acir_format& constraint_system, - WitnessVector const& witness); +void create_circuit_with_witness(Builder& builder, const acir_format& constraint_system, WitnessVector const& witness); // Serialisation template inline void read(B& buf, acir_format& data) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index 545cab88b5f2..8da37992f5c5 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -1,11 +1,14 @@ +#include +#include + #include "acir_format.hpp" +#include "ecdsa_secp256k1.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" -#include -#include #include "barretenberg/common/streams.hpp" #include "barretenberg/serialize/test_helper.hpp" #include "ecdsa_secp256k1.hpp" +namespace acir_format::tests { TEST(acir_format, test_a_single_constraint_no_pub_inputs) { @@ -20,7 +23,7 @@ TEST(acir_format, test_a_single_constraint_no_pub_inputs) .q_c = 0, }; - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = 4, .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -39,19 +42,20 @@ TEST(acir_format, test_a_single_constraint_no_pub_inputs) .constraints = { constraint }, }; - auto composer = acir_format::create_circuit_with_witness(constraint_system, { 0, 0, 1 }); + auto builder = create_circuit_with_witness(constraint_system, { 0, 0, 1 }); - auto prover = composer.create_ultra_with_keccak_prover(); + auto composer = Composer(); + auto prover = composer.create_ultra_with_keccak_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), false); } TEST(acir_format, msgpack_logic_constraint) { - auto [actual, expected] = msgpack_roundtrip(acir_format::LogicConstraint{}); + auto [actual, expected] = msgpack_roundtrip(LogicConstraint{}); EXPECT_EQ(actual, expected); } TEST(acir_format, test_logic_gate_from_noir_circuit) @@ -64,16 +68,16 @@ TEST(acir_format, test_logic_gate_from_noir_circuit) * constrain z != 10; * } **/ - acir_format::RangeConstraint range_a{ + RangeConstraint range_a{ .witness = 1, .num_bits = 32, }; - acir_format::RangeConstraint range_b{ + RangeConstraint range_b{ .witness = 2, .num_bits = 32, }; - acir_format::LogicConstraint logic_constraint{ + LogicConstraint logic_constraint{ .a = 1, .b = 2, .result = 3, @@ -125,7 +129,7 @@ TEST(acir_format, test_logic_gate_from_noir_circuit) // EXPR [ (1, _4, _6) (-1, _4) 0 ] // EXPR [ (-1, _6) 1 ] - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = 7, .public_inputs = { 2 }, .fixed_base_scalar_mul_constraints = {}, @@ -145,29 +149,30 @@ TEST(acir_format, test_logic_gate_from_noir_circuit) }; uint256_t inverse_of_five = fr(5).invert(); - auto composer = acir_format::create_circuit_with_witness(constraint_system, - { - 5, - 10, - 15, - 5, - inverse_of_five, - 1, - }); + auto builder = create_circuit_with_witness(constraint_system, + { + 5, + 10, + 15, + 5, + inverse_of_five, + 1, + }); - auto prover = composer.create_ultra_with_keccak_prover(); + auto composer = Composer(); + auto prover = composer.create_ultra_with_keccak_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } TEST(acir_format, test_schnorr_verify_pass) { - std::vector range_constraints; + std::vector range_constraints; for (uint32_t i = 0; i < 10; i++) { - range_constraints.push_back(acir_format::RangeConstraint{ + range_constraints.push_back(RangeConstraint{ .witness = i + 1, .num_bits = 15, }); @@ -176,13 +181,13 @@ TEST(acir_format, test_schnorr_verify_pass) std::vector signature(64); for (uint32_t i = 0, value = 13; i < 64; i++, value++) { signature[i] = value; - range_constraints.push_back(acir_format::RangeConstraint{ + range_constraints.push_back(RangeConstraint{ .witness = value, .num_bits = 15, }); } - acir_format::SchnorrConstraint schnorr_constraint{ + SchnorrConstraint schnorr_constraint{ .message = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, .public_key_x = 11, .public_key_y = 12, @@ -190,7 +195,7 @@ TEST(acir_format, test_schnorr_verify_pass) .signature = signature, }; - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = 82, .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -220,26 +225,27 @@ TEST(acir_format, test_schnorr_verify_pass) uint256_t pub_x = uint256_t("17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"); uint256_t pub_y = uint256_t("0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"); - auto composer = acir_format::create_circuit_with_witness( + auto builder = create_circuit_with_witness( constraint_system, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, pub_x, pub_y, 5, 202, 31, 146, 81, 242, 246, 69, 43, 107, 249, 153, 198, 44, 14, 111, 191, 121, 137, 166, 160, 103, 18, 181, 243, 233, 226, 95, 67, 16, 37, 128, 85, 76, 19, 253, 30, 77, 192, 53, 138, 205, 69, 33, 236, 163, 83, 194, 84, 137, 184, 221, 176, 121, 179, 27, 63, 70, 54, 16, 176, 250, 39, 239, 1, 0, 0, 0 }); - auto prover = composer.create_ultra_with_keccak_prover(); + auto composer = Composer(); + auto prover = composer.create_ultra_with_keccak_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } TEST(acir_format, test_schnorr_verify_small_range) { - std::vector range_constraints; + std::vector range_constraints; for (uint32_t i = 0; i < 10; i++) { - range_constraints.push_back(acir_format::RangeConstraint{ + range_constraints.push_back(RangeConstraint{ .witness = i + 1, .num_bits = 8, }); @@ -248,13 +254,13 @@ TEST(acir_format, test_schnorr_verify_small_range) std::vector signature(64); for (uint32_t i = 0, value = 13; i < 64; i++, value++) { signature[i] = value; - range_constraints.push_back(acir_format::RangeConstraint{ + range_constraints.push_back(RangeConstraint{ .witness = value, .num_bits = 8, }); } - acir_format::SchnorrConstraint schnorr_constraint{ + SchnorrConstraint schnorr_constraint{ .message = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, .public_key_x = 11, .public_key_y = 12, @@ -262,7 +268,7 @@ TEST(acir_format, test_schnorr_verify_small_range) .signature = signature, }; - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = 82, .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -292,17 +298,17 @@ TEST(acir_format, test_schnorr_verify_small_range) uint256_t pub_x = uint256_t("17cbd3ed3151ccfd170efe1d54280a6a4822640bf5c369908ad74ea21518a9c5"); uint256_t pub_y = uint256_t("0e0456e3795c1a31f20035b741cd6158929eeccd320d299cfcac962865a6bc74"); - auto composer = acir_format::create_circuit_with_witness( + auto builder = create_circuit_with_witness( constraint_system, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, pub_x, pub_y, 5, 202, 31, 146, 81, 242, 246, 69, 43, 107, 249, 153, 198, 44, 14, 111, 191, 121, 137, 166, 160, 103, 18, 181, 243, 233, 226, 95, 67, 16, 37, 128, 85, 76, 19, 253, 30, 77, 192, 53, 138, 205, 69, 33, 236, 163, 83, 194, 84, 137, 184, 221, 176, 121, 179, 27, 63, 70, 54, 16, 176, 250, 39, 239, 1, 0, 0, 0 }); - auto prover = composer.create_ultra_with_keccak_prover(); + auto composer = Composer(); + auto prover = composer.create_ultra_with_keccak_prover(builder); auto proof = prover.construct_proof(); - - auto verifier = composer.create_ultra_with_keccak_verifier(); - + auto verifier = composer.create_ultra_with_keccak_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } +} // namespace acir_format::tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp index 8cd00269afd0..e5fc04696ade 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.cpp @@ -3,11 +3,11 @@ namespace acir_format { -void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& constraint) +void create_blake2s_constraints(Builder& builder, const Blake2sConstraint& constraint) { // Create byte array struct - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -18,19 +18,19 @@ void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& con // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); byte_array_ct element_bytes(element, num_bytes); arr.write(element_bytes); } - byte_array_ct output_bytes = proof_system::plonk::stdlib::blake2s(arr); + byte_array_ct output_bytes = proof_system::plonk::stdlib::blake2s(arr); // Convert byte array to vector of field_t auto bytes = output_bytes.bytes(); for (size_t i = 0; i < bytes.size(); ++i) { - composer.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); + builder.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp index f68bf2019a35..f78dd46ac53b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/blake2s_constraint.hpp @@ -19,7 +19,7 @@ struct Blake2sConstraint { friend bool operator==(Blake2sConstraint const& lhs, Blake2sConstraint const& rhs) = default; }; -void create_blake2s_constraints(Composer& composer, const Blake2sConstraint& constraint); +void create_blake2s_constraints(Builder& builder, const Blake2sConstraint& constraint); template inline void read(B& buf, Blake2sInput& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp index 1d76f7ea584e..811421aa9b1a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp @@ -5,7 +5,7 @@ using namespace proof_system::plonk; namespace acir_format { -field_ct poly_to_field_ct(const poly_triple poly, Composer& composer) +field_ct poly_to_field_ct(const poly_triple poly, Builder& builder) { ASSERT(poly.q_m == 0); ASSERT(poly.q_r == 0); @@ -13,17 +13,17 @@ field_ct poly_to_field_ct(const poly_triple poly, Composer& composer) if (poly.q_l == 0) { return field_ct(poly.q_c); } - field_ct x = field_ct::from_witness_index(&composer, poly.a); + field_ct x = field_ct::from_witness_index(&builder, poly.a); x.additive_constant = poly.q_c; x.multiplicative_constant = poly.q_l; return x; } -void create_block_constraints(Composer& composer, const BlockConstraint constraint, bool has_valid_witness_assignments) +void create_block_constraints(Builder& builder, const BlockConstraint constraint, bool has_valid_witness_assignments) { std::vector init; for (auto i : constraint.init) { - field_ct value = poly_to_field_ct(i, composer); + field_ct value = poly_to_field_ct(i, builder); init.push_back(value); } @@ -32,8 +32,8 @@ void create_block_constraints(Composer& composer, const BlockConstraint constrai rom_table_ct table(init); for (auto& op : constraint.trace) { ASSERT(op.access_type == 0); - field_ct value = poly_to_field_ct(op.value, composer); - field_ct index = poly_to_field_ct(op.index, composer); + field_ct value = poly_to_field_ct(op.value, builder); + field_ct index = poly_to_field_ct(op.index, builder); // For a ROM table, constant read should be optimised out: // The rom_table won't work with a constant read because the table may not be initialised ASSERT(op.index.q_l != 0); @@ -44,7 +44,7 @@ void create_block_constraints(Composer& composer, const BlockConstraint constrai // If witness are assigned, we use the correct value for w w_value = index.get_value(); } - field_ct w = field_ct::from_witness(&composer, w_value); + field_ct w = field_ct::from_witness(&builder, w_value); value.assert_equal(table[w]); w.assert_equal(index); } @@ -52,8 +52,8 @@ void create_block_constraints(Composer& composer, const BlockConstraint constrai case BlockType::RAM: { ram_table_ct table(init); for (auto& op : constraint.trace) { - field_ct value = poly_to_field_ct(op.value, composer); - field_ct index = poly_to_field_ct(op.index, composer); + field_ct value = poly_to_field_ct(op.value, builder); + field_ct index = poly_to_field_ct(op.index, builder); if (has_valid_witness_assignments == false) { index = field_ct(0); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp index 7c1418ccf894..a3b04d93bbf4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.hpp @@ -1,7 +1,6 @@ #pragma once #include #include -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/dsl/types.hpp" @@ -24,7 +23,7 @@ struct BlockConstraint { BlockType type; }; -void create_block_constraints(Composer& composer, +void create_block_constraints(Builder& builder, const BlockConstraint constraint, bool has_valid_witness_assignments = true); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp index 4c443e7e351a..a8c14e24554d 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/block_constraint.test.cpp @@ -6,7 +6,8 @@ #include #include -size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_format::WitnessVector& witness_values) +namespace acir_format::tests { +size_t generate_block_constraint(BlockConstraint& constraint, WitnessVector& witness_values) { size_t witness_len = 1; witness_values.emplace_back(1); @@ -78,20 +79,20 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_ }; witness_values.emplace_back(3); witness_len++; - acir_format::MemOp op1 = acir_format::MemOp{ + MemOp op1 = MemOp{ .access_type = 0, .index = r1, .value = y, }; - acir_format::MemOp op2 = acir_format::MemOp{ + MemOp op2 = MemOp{ .access_type = 0, .index = r2, .value = z, }; - constraint = acir_format::BlockConstraint{ + constraint = BlockConstraint{ .init = { a0, a1 }, .trace = { op1, op2 }, - .type = acir_format::BlockType::ROM, + .type = BlockType::ROM, }; return witness_len; @@ -99,10 +100,10 @@ size_t generate_block_constraint(acir_format::BlockConstraint& constraint, acir_ TEST(up_ram, TestBlockConstraint) { - acir_format::BlockConstraint block; - acir_format::WitnessVector witness_values; + BlockConstraint block; + WitnessVector witness_values; size_t num_variables = generate_block_constraint(block, witness_values); - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -121,11 +122,13 @@ TEST(up_ram, TestBlockConstraint) .constraints = {}, }; - auto composer = acir_format::create_circuit_with_witness(constraint_system, witness_values); + auto builder = create_circuit_with_witness(constraint_system, witness_values); - auto prover = composer.create_prover(); + auto composer = Composer(); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } +} // namespace acir_format::tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp index 31cddb3e2f63..0bfe09ada228 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.cpp @@ -6,7 +6,7 @@ namespace acir_format { using namespace proof_system::plonk; -crypto::ecdsa::signature ecdsa_convert_signature(Composer& composer, std::vector signature) +crypto::ecdsa::signature ecdsa_convert_signature(Builder& builder, std::vector signature) { crypto::ecdsa::signature signature_cr; @@ -19,7 +19,7 @@ crypto::ecdsa::signature ecdsa_convert_signature(Composer& composer, std::vector std::vector fr_bytes(sizeof(fr)); - fr value = composer.get_variable(witness_index); + fr value = builder.get_variable(witness_index); fr::serialize_to_buffer(value, &fr_bytes[0]); @@ -31,7 +31,7 @@ crypto::ecdsa::signature ecdsa_convert_signature(Composer& composer, std::vector std::vector fr_bytes(sizeof(fr)); - fr value = composer.get_variable(witness_index); + fr value = builder.get_variable(witness_index); fr::serialize_to_buffer(value, &fr_bytes[0]); @@ -43,7 +43,7 @@ crypto::ecdsa::signature ecdsa_convert_signature(Composer& composer, std::vector return signature_cr; } -secp256k1_ct::g1_ct ecdsa_convert_inputs(Composer* ctx, const secp256k1::g1::affine_element& input) +secp256k1_ct::g1_ct ecdsa_convert_inputs(Builder* ctx, const secp256k1::g1::affine_element& input) { uint256_t x_u256(input.x); uint256_t y_u256(input.y); @@ -62,15 +62,15 @@ secp256k1_ct::g1_ct ecdsa_convert_inputs(Composer* ctx, const secp256k1::g1::aff // vector of bytes here, assumes that the witness indices point to a field element which can be represented // with just a byte. // notice that this function truncates each field_element to a byte -byte_array_ct ecdsa_vector_of_bytes_to_byte_array(Composer& composer, std::vector vector_of_bytes) +byte_array_ct ecdsa_vector_of_bytes_to_byte_array(Builder& builder, std::vector vector_of_bytes) { - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array for (const auto& witness_index : vector_of_bytes) { - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); size_t num_bytes = 1; byte_array_ct element_bytes(element, num_bytes); @@ -78,26 +78,26 @@ byte_array_ct ecdsa_vector_of_bytes_to_byte_array(Composer& composer, std::vecto } return arr; } -witness_ct ecdsa_index_to_witness(Composer& composer, uint32_t index) +witness_ct ecdsa_index_to_witness(Builder& builder, uint32_t index) { - fr value = composer.get_variable(index); - return { &composer, value }; + fr value = builder.get_variable(index); + return { &builder, value }; } -void create_ecdsa_verify_constraints(Composer& composer, +void create_ecdsa_verify_constraints(Builder& builder, const EcdsaSecp256k1Constraint& input, bool has_valid_witness_assignments) { if (has_valid_witness_assignments == false) { - dummy_ecdsa_constraint(composer, input); + dummy_ecdsa_constraint(builder, input); } - auto new_sig = ecdsa_convert_signature(composer, input.signature); + auto new_sig = ecdsa_convert_signature(builder, input.signature); - auto message = ecdsa_vector_of_bytes_to_byte_array(composer, input.hashed_message); - auto pub_key_x_byte_arr = ecdsa_vector_of_bytes_to_byte_array(composer, input.pub_x_indices); - auto pub_key_y_byte_arr = ecdsa_vector_of_bytes_to_byte_array(composer, input.pub_y_indices); + auto message = ecdsa_vector_of_bytes_to_byte_array(builder, input.hashed_message); + auto pub_key_x_byte_arr = ecdsa_vector_of_bytes_to_byte_array(builder, input.pub_x_indices); + auto pub_key_y_byte_arr = ecdsa_vector_of_bytes_to_byte_array(builder, input.pub_y_indices); auto pub_key_x_fq = secp256k1_ct::fq_ct(pub_key_x_byte_arr); auto pub_key_y_fq = secp256k1_ct::fq_ct(pub_key_y_byte_arr); @@ -106,31 +106,31 @@ void create_ecdsa_verify_constraints(Composer& composer, std::vector ss(new_sig.s.begin(), new_sig.s.end()); uint8_t vv = new_sig.v; - stdlib::ecdsa::signature sig{ stdlib::byte_array(&composer, rr), - stdlib::byte_array(&composer, ss), - stdlib::uint8(&composer, vv) }; + stdlib::ecdsa::signature sig{ stdlib::byte_array(&builder, rr), + stdlib::byte_array(&builder, ss), + stdlib::uint8(&builder, vv) }; pub_key_x_fq.assert_is_in_field(); pub_key_y_fq.assert_is_in_field(); secp256k1_ct::g1_bigfr_ct public_key = secp256k1_ct::g1_bigfr_ct(pub_key_x_fq, pub_key_y_fq); for (size_t i = 0; i < 32; ++i) { - sig.r[i].assert_equal(field_ct::from_witness_index(&composer, input.signature[i])); - sig.s[i].assert_equal(field_ct::from_witness_index(&composer, input.signature[i + 32])); - pub_key_x_byte_arr[i].assert_equal(field_ct::from_witness_index(&composer, input.pub_x_indices[i])); - pub_key_y_byte_arr[i].assert_equal(field_ct::from_witness_index(&composer, input.pub_y_indices[i])); + sig.r[i].assert_equal(field_ct::from_witness_index(&builder, input.signature[i])); + sig.s[i].assert_equal(field_ct::from_witness_index(&builder, input.signature[i + 32])); + pub_key_x_byte_arr[i].assert_equal(field_ct::from_witness_index(&builder, input.pub_x_indices[i])); + pub_key_y_byte_arr[i].assert_equal(field_ct::from_witness_index(&builder, input.pub_y_indices[i])); } for (size_t i = 0; i < input.hashed_message.size(); ++i) { - message[i].assert_equal(field_ct::from_witness_index(&composer, input.hashed_message[i])); + message[i].assert_equal(field_ct::from_witness_index(&builder, input.hashed_message[i])); } bool_ct signature_result = - stdlib::ecdsa::verify_signature_prehashed_message_noassert(message, public_key, sig); bool_ct signature_result_normalized = signature_result.normalize(); - composer.assert_equal(signature_result_normalized.witness_index, input.result); + builder.assert_equal(signature_result_normalized.witness_index, input.result); } // Add dummy constraints for ECDSA because when the verifier creates the @@ -138,7 +138,7 @@ void create_ecdsa_verify_constraints(Composer& composer, // // This does not work for ECDSA as the signature, r, s and public key need // to be valid. -void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256k1Constraint const& input) +void dummy_ecdsa_constraint(Builder& builder, EcdsaSecp256k1Constraint const& input) { std::vector pub_x_indices_; @@ -161,10 +161,10 @@ void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256k1Constraint const& // We don't use them in a gate, so when we call assert_equal, they will be // replaced as if they never existed. for (size_t i = 0; i < 32; ++i) { - uint32_t x_wit = composer.add_variable(pub_x_value.slice(248 - i * 8, 256 - i * 8)); - uint32_t y_wit = composer.add_variable(pub_y_value.slice(248 - i * 8, 256 - i * 8)); - uint32_t r_wit = composer.add_variable(signature.r[i]); - uint32_t s_wit = composer.add_variable(signature.s[i]); + uint32_t x_wit = builder.add_variable(pub_x_value.slice(248 - i * 8, 256 - i * 8)); + uint32_t y_wit = builder.add_variable(pub_y_value.slice(248 - i * 8, 256 - i * 8)); + uint32_t r_wit = builder.add_variable(signature.r[i]); + uint32_t s_wit = builder.add_variable(signature.s[i]); pub_x_indices_.emplace_back(x_wit); pub_y_indices_.emplace_back(y_wit); signature_[i] = r_wit; @@ -173,13 +173,13 @@ void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256k1Constraint const& // Call assert_equal(from, to) to replace the value in `to` by the value in `from` for (size_t i = 0; i < input.pub_x_indices.size(); ++i) { - composer.assert_equal(pub_x_indices_[i], input.pub_x_indices[i]); + builder.assert_equal(pub_x_indices_[i], input.pub_x_indices[i]); } for (size_t i = 0; i < input.pub_y_indices.size(); ++i) { - composer.assert_equal(pub_y_indices_[i], input.pub_y_indices[i]); + builder.assert_equal(pub_y_indices_[i], input.pub_y_indices[i]); } for (size_t i = 0; i < input.signature.size(); ++i) { - composer.assert_equal(signature_[i], input.signature[i]); + builder.assert_equal(signature_[i], input.signature[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp index 59d1fe48e02b..75ff0bd42c6e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.hpp @@ -26,11 +26,11 @@ struct EcdsaSecp256k1Constraint { friend bool operator==(EcdsaSecp256k1Constraint const& lhs, EcdsaSecp256k1Constraint const& rhs) = default; }; -void create_ecdsa_verify_constraints(Composer& composer, +void create_ecdsa_verify_constraints(Builder& builder, const EcdsaSecp256k1Constraint& input, bool has_valid_witness_assignments = true); -void dummy_ecdsa_constraint(Composer& composer, EcdsaSecp256k1Constraint const& input); +void dummy_ecdsa_constraint(Builder& builder, EcdsaSecp256k1Constraint const& input); template inline void read(B& buf, EcdsaSecp256k1Constraint& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp index 95a2551511b8..21de8fcc2fcb 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ecdsa_secp256k1.test.cpp @@ -7,10 +7,10 @@ #include #include -using curve_ct = proof_system::plonk::stdlib::secp256k1; +namespace acir_format::tests { +using curve_ct = proof_system::plonk::stdlib::secp256k1; -size_t generate_ecdsa_constraint(acir_format::EcdsaSecp256k1Constraint& ecdsa_constraint, - acir_format::WitnessVector& witness_values) +size_t generate_ecdsa_constraint(EcdsaSecp256k1Constraint& ecdsa_constraint, WitnessVector& witness_values) { std::string message_string = "Instructions unclear, ask again later."; @@ -69,7 +69,7 @@ size_t generate_ecdsa_constraint(acir_format::EcdsaSecp256k1Constraint& ecdsa_co offset += 1; witness_values.emplace_back(1); - ecdsa_constraint = acir_format::EcdsaSecp256k1Constraint{ + ecdsa_constraint = EcdsaSecp256k1Constraint{ .hashed_message = message_in, .pub_x_indices = pub_x_indices_in, .pub_y_indices = pub_y_indices_in, @@ -81,10 +81,10 @@ size_t generate_ecdsa_constraint(acir_format::EcdsaSecp256k1Constraint& ecdsa_co TEST(ECDSASecp256k1, TestECDSAConstraintSucceed) { - acir_format::EcdsaSecp256k1Constraint ecdsa_constraint; - acir_format::WitnessVector witness_values; + EcdsaSecp256k1Constraint ecdsa_constraint; + WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_constraint, witness_values); - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -103,13 +103,15 @@ TEST(ECDSASecp256k1, TestECDSAConstraintSucceed) .constraints = {}, }; - auto composer = acir_format::create_circuit_with_witness(constraint_system, witness_values); + auto builder = create_circuit_with_witness(constraint_system, witness_values); - EXPECT_EQ(composer.get_variable(ecdsa_constraint.result), 1); - auto prover = composer.create_prover(); + EXPECT_EQ(builder.get_variable(ecdsa_constraint.result), 1); + + auto composer = Composer(); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } @@ -118,10 +120,10 @@ TEST(ECDSASecp256k1, TestECDSAConstraintSucceed) // even though we are just building the circuit. TEST(ECDSASecp256k1, TestECDSACompilesForVerifier) { - acir_format::EcdsaSecp256k1Constraint ecdsa_constraint; - acir_format::WitnessVector witness_values; + EcdsaSecp256k1Constraint ecdsa_constraint; + WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_constraint, witness_values); - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -139,14 +141,13 @@ TEST(ECDSASecp256k1, TestECDSACompilesForVerifier) .recursion_constraints = {}, .constraints = {}, }; - auto crs_factory = std::make_unique(); - auto composer = create_circuit(constraint_system, std::move(crs_factory)); + auto builder = create_circuit(constraint_system); } TEST(ECDSASecp256k1, TestECDSAConstraintFail) { - acir_format::EcdsaSecp256k1Constraint ecdsa_constraint; - acir_format::WitnessVector witness_values; + EcdsaSecp256k1Constraint ecdsa_constraint; + WitnessVector witness_values; size_t num_variables = generate_ecdsa_constraint(ecdsa_constraint, witness_values); // set result value to be false @@ -155,7 +156,7 @@ TEST(ECDSASecp256k1, TestECDSAConstraintFail) // tamper with signature witness_values[witness_values.size() - 20] += 1; - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = static_cast(num_variables), .public_inputs = {}, .fixed_base_scalar_mul_constraints = {}, @@ -174,12 +175,13 @@ TEST(ECDSASecp256k1, TestECDSAConstraintFail) .constraints = {}, }; - auto composer = acir_format::create_circuit_with_witness(constraint_system, witness_values); - - EXPECT_EQ(composer.get_variable(ecdsa_constraint.result), 0); - auto prover = composer.create_prover(); + auto builder = create_circuit_with_witness(constraint_system, witness_values); + EXPECT_EQ(builder.get_variable(ecdsa_constraint.result), 0); + auto composer = Composer(); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_verifier(builder); EXPECT_EQ(verifier.verify_proof(proof), true); } +} // namespace acir_format::tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp index 453ab56f4749..18f1b59f4cd1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.cpp @@ -2,14 +2,14 @@ namespace acir_format { -void create_fixed_base_constraint(Composer& composer, const FixedBaseScalarMul& input) +void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input) { - field_ct scalar_as_field = field_ct::from_witness_index(&composer, input.scalar); + field_ct scalar_as_field = field_ct::from_witness_index(&builder, input.scalar); auto public_key = group_ct::fixed_base_scalar_mul_g1<254>(scalar_as_field); - composer.assert_equal(public_key.x.witness_index, input.pub_key_x); - composer.assert_equal(public_key.y.witness_index, input.pub_key_y); + builder.assert_equal(public_key.x.witness_index, input.pub_key_x); + builder.assert_equal(public_key.y.witness_index, input.pub_key_y); } } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp index 80e52e03db81..a96c743e698c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/fixed_base_scalar_mul.hpp @@ -12,7 +12,7 @@ struct FixedBaseScalarMul { friend bool operator==(FixedBaseScalarMul const& lhs, FixedBaseScalarMul const& rhs) = default; }; -void create_fixed_base_constraint(Composer& composer, const FixedBaseScalarMul& input); +void create_fixed_base_constraint(Builder& builder, const FixedBaseScalarMul& input); template inline void read(B& buf, FixedBaseScalarMul& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp index afc3e2cf9f72..ec29a2cec6c7 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.cpp @@ -5,11 +5,11 @@ namespace acir_format { using namespace proof_system::plonk; -void create_hash_to_field_constraints(Composer& composer, const HashToFieldConstraint constraint) +void create_hash_to_field_constraints(Builder& builder, const HashToFieldConstraint constraint) { // Create byte array struct - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -20,7 +20,7 @@ void create_hash_to_field_constraints(Composer& composer, const HashToFieldConst // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); byte_array_ct element_bytes(element, num_bytes); byte_array_ct reversed_bytes = element_bytes.reverse(); @@ -30,12 +30,12 @@ void create_hash_to_field_constraints(Composer& composer, const HashToFieldConst // Hash To Field using blake2s. // Note: It does not need to be blake2s in the future - byte_array_ct out_bytes = stdlib::blake2s(arr); + byte_array_ct out_bytes = stdlib::blake2s(arr); field_ct out(out_bytes); field_ct normalised_out = out.normalize(); - composer.assert_equal(normalised_out.witness_index, constraint.result); + builder.assert_equal(normalised_out.witness_index, constraint.result); } } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp index 504493ce3ec5..d08c399c23bb 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/hash_to_field.hpp @@ -19,7 +19,7 @@ struct HashToFieldConstraint { friend bool operator==(HashToFieldConstraint const& lhs, HashToFieldConstraint const& rhs) = default; }; -void create_hash_to_field_constraints(Composer& composer, HashToFieldConstraint constraint); +void create_hash_to_field_constraints(Builder& builder, HashToFieldConstraint constraint); template inline void read(B& buf, HashToFieldInput& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp index b573e571533e..048bcf9c22dd 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.cpp @@ -4,11 +4,11 @@ namespace acir_format { -void create_keccak_constraints(Composer& composer, const KeccakConstraint& constraint) +void create_keccak_constraints(Builder& builder, const KeccakConstraint& constraint) { // Create byte array struct - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -19,27 +19,27 @@ void create_keccak_constraints(Composer& composer, const KeccakConstraint& const // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); byte_array_ct element_bytes(element, num_bytes); arr.write(element_bytes); } - byte_array_ct output_bytes = proof_system::plonk::stdlib::keccak::hash(arr); + byte_array_ct output_bytes = proof_system::plonk::stdlib::keccak::hash(arr); // Convert byte array to vector of field_t auto bytes = output_bytes.bytes(); for (size_t i = 0; i < bytes.size(); ++i) { - composer.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); + builder.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); } } -void create_keccak_var_constraints(Composer& composer, const KeccakVarConstraint& constraint) +void create_keccak_var_constraints(Builder& builder, const KeccakVarConstraint& constraint) { // Create byte array struct - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -50,21 +50,21 @@ void create_keccak_var_constraints(Composer& composer, const KeccakVarConstraint // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); byte_array_ct element_bytes(element, num_bytes); arr.write(element_bytes); } - uint32_ct length = field_ct::from_witness_index(&composer, constraint.var_message_size); + uint32_ct length = field_ct::from_witness_index(&builder, constraint.var_message_size); - byte_array_ct output_bytes = proof_system::plonk::stdlib::keccak::hash(arr, length); + byte_array_ct output_bytes = proof_system::plonk::stdlib::keccak::hash(arr, length); // Convert byte array to vector of field_t auto bytes = output_bytes.bytes(); for (size_t i = 0; i < bytes.size(); ++i) { - composer.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); + builder.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp index 95fabe00d589..8f97fbe5f5a4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/keccak_constraint.hpp @@ -27,8 +27,8 @@ struct KeccakVarConstraint { friend bool operator==(KeccakVarConstraint const& lhs, KeccakVarConstraint const& rhs) = default; }; -void create_keccak_constraints(Composer& composer, const KeccakConstraint& constraint); -void create_keccak_var_constraints(Composer& composer, const KeccakVarConstraint& constraint); +void create_keccak_constraints(Builder& builder, const KeccakConstraint& constraint); +void create_keccak_var_constraints(Builder& builder, const KeccakVarConstraint& constraint); template inline void read(B& buf, HashInput& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp index 09990fe04b57..9b77101b89db 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.cpp @@ -5,7 +5,7 @@ namespace acir_format { using namespace proof_system::plonk; -void create_logic_gate(Composer& composer, +void create_logic_gate(Builder& builder, const uint32_t a, const uint32_t b, const uint32_t result, @@ -13,11 +13,11 @@ void create_logic_gate(Composer& composer, const bool is_xor_gate) { - field_ct left = field_ct::from_witness_index(&composer, a); - field_ct right = field_ct::from_witness_index(&composer, b); + field_ct left = field_ct::from_witness_index(&builder, a); + field_ct right = field_ct::from_witness_index(&builder, b); - field_ct res = stdlib::logic::create_logic_constraint(left, right, num_bits, is_xor_gate); - field_ct our_res = field_ct::from_witness_index(&composer, result); + field_ct res = stdlib::logic::create_logic_constraint(left, right, num_bits, is_xor_gate); + field_ct our_res = field_ct::from_witness_index(&builder, result); res.assert_equal(our_res); } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp index d2ed943398c4..c74817e4c700 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/logic_constraint.hpp @@ -17,11 +17,11 @@ struct LogicConstraint { MSGPACK_FIELDS(a, b, result, num_bits, is_xor_gate); }; -void create_logic_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result, size_t num_bits, bool is_xor_gate); +void create_logic_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result, size_t num_bits, bool is_xor_gate); -void xor_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result); +void xor_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result); -void and_gate(Composer& composer, uint32_t a, uint32_t b, uint32_t result); +void and_gate(Builder& builder, uint32_t a, uint32_t b, uint32_t result); template inline void read(B& buf, LogicConstraint& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp index f31b7b1a4d4d..b6ff3ddd5224 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.cpp @@ -4,21 +4,21 @@ namespace acir_format { using namespace proof_system::plonk; -void create_pedersen_constraint(Composer& composer, const PedersenConstraint& input) +void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input) { std::vector scalars; for (const auto& scalar : input.scalars) { // convert input indices to field_ct - field_ct scalar_as_field = field_ct::from_witness_index(&composer, scalar); + field_ct scalar_as_field = field_ct::from_witness_index(&builder, scalar); scalars.push_back(scalar_as_field); } // TODO: Does Noir need additive homomorphic Pedersen hash? If so, using plookup version won't help. - auto point = stdlib::pedersen_plookup_commitment::commit(scalars, input.hash_index); + auto point = stdlib::pedersen_plookup_commitment::commit(scalars, input.hash_index); - composer.assert_equal(point.x.witness_index, input.result_x); - composer.assert_equal(point.y.witness_index, input.result_y); + builder.assert_equal(point.x.witness_index, input.result_x); + builder.assert_equal(point.y.witness_index, input.result_y); } } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp index e966f0a20b82..52815fcdb5be 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/pedersen.hpp @@ -15,7 +15,7 @@ struct PedersenConstraint { friend bool operator==(PedersenConstraint const& lhs, PedersenConstraint const& rhs) = default; }; -void create_pedersen_constraint(Composer& composer, const PedersenConstraint& input); +void create_pedersen_constraint(Builder& builder, const PedersenConstraint& input); template inline void read(B& buf, PedersenConstraint& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.cpp index f368df89a8e8..236ee1480cb2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.cpp @@ -18,7 +18,7 @@ void generate_dummy_proof() {} /** * @brief Add constraints required to recursively verify an UltraPlonk proof * - * @param composer + * @param builder * @param input * @tparam has_valid_witness_assignment. Do we have witnesses or are we just generating keys? * @tparam inner_proof_contains_recursive_proof. Do we expect the inner proof to also have performed recursive @@ -28,7 +28,7 @@ void generate_dummy_proof() {} * We would either need a separate ACIR opcode where inner_proof_contains_recursive_proof = true, * or we need non-witness data to be provided as metadata in the ACIR opcode */ -void create_recursion_constraints(Composer& composer, +void create_recursion_constraints(Builder& builder, const RecursionConstraint& input, bool has_valid_witness_assignments) { @@ -43,7 +43,7 @@ void create_recursion_constraints(Composer& composer, // on-curve errors and inverting-zero errors { // get a fake key/proof that satisfies on-curve + inversion-zero checks - const std::vector dummy_key = export_dummy_key_in_recursion_format(PolynomialManifest(Composer::type), + const std::vector dummy_key = export_dummy_key_in_recursion_format(PolynomialManifest(Builder::type), inner_proof_contains_recursive_proof); const auto manifest = Composer::create_manifest(input.public_inputs.size()); const std::vector dummy_proof = @@ -51,22 +51,22 @@ void create_recursion_constraints(Composer& composer, for (size_t i = 0; i < input.proof.size(); ++i) { const auto proof_field_idx = input.proof[i]; // if we do NOT have a witness assignment (i.e. are just building the proving/verification keys), - // we add our dummy proof values as Composer variables. + // we add our dummy proof values as Builder variables. // if we DO have a valid witness assignment, we use the real witness assignment barretenberg::fr dummy_field = - has_valid_witness_assignments ? composer.get_variable(proof_field_idx) : dummy_proof[i]; + has_valid_witness_assignments ? builder.get_variable(proof_field_idx) : dummy_proof[i]; // Create a copy constraint between our dummy field and the witness index provided by RecursionConstraint. // This will make the RecursionConstraint idx equal to `dummy_field`. // In the case of a valid witness assignment, this does nothing (as dummy_field = real value) // In the case of no valid witness assignment, this makes sure that the RecursionConstraint witness indices // will not trigger basic errors (check inputs are on-curve, check we are not inverting 0) - composer.assert_equal(composer.add_variable(dummy_field), proof_field_idx); + builder.assert_equal(builder.add_variable(dummy_field), proof_field_idx); } for (size_t i = 0; i < input.key.size(); ++i) { const auto key_field_idx = input.key[i]; barretenberg::fr dummy_field = - has_valid_witness_assignments ? composer.get_variable(key_field_idx) : dummy_key[i]; - composer.assert_equal(composer.add_variable(dummy_field), key_field_idx); + has_valid_witness_assignments ? builder.get_variable(key_field_idx) : dummy_key[i]; + builder.assert_equal(builder.add_variable(dummy_field), key_field_idx); } } @@ -87,10 +87,10 @@ void create_recursion_constraints(Composer& composer, std::array aggregation_elements; for (size_t i = 0; i < 4; ++i) { aggregation_elements[i] = - bn254::fq_ct(field_ct::from_witness_index(&composer, aggregation_input[4 * i]), - field_ct::from_witness_index(&composer, aggregation_input[4 * i + 1]), - field_ct::from_witness_index(&composer, aggregation_input[4 * i + 2]), - field_ct::from_witness_index(&composer, aggregation_input[4 * i + 3])); + bn254::fq_ct(field_ct::from_witness_index(&builder, aggregation_input[4 * i]), + field_ct::from_witness_index(&builder, aggregation_input[4 * i + 1]), + field_ct::from_witness_index(&builder, aggregation_input[4 * i + 2]), + field_ct::from_witness_index(&builder, aggregation_input[4 * i + 3])); aggregation_elements[i].assert_is_in_field(); } // If we have a previous aggregation object, assign it to `previous_aggregation` so that it is included @@ -107,39 +107,39 @@ void create_recursion_constraints(Composer& composer, std::vector key_fields; key_fields.reserve(input.key.size()); for (const auto& idx : input.key) { - auto field = field_ct::from_witness_index(&composer, idx); + auto field = field_ct::from_witness_index(&builder, idx); key_fields.emplace_back(field); } std::vector proof_fields; proof_fields.reserve(input.proof.size()); for (const auto& idx : input.proof) { - auto field = field_ct::from_witness_index(&composer, idx); + auto field = field_ct::from_witness_index(&builder, idx); proof_fields.emplace_back(field); } // recursively verify the proof std::shared_ptr vkey = verification_key_ct::from_field_elements( - &composer, key_fields, inner_proof_contains_recursive_proof, nested_aggregation_indices); + &builder, key_fields, inner_proof_contains_recursive_proof, nested_aggregation_indices); vkey->program_width = noir_recursive_settings::program_width; - Transcript_ct transcript(&composer, manifest, proof_fields, input.public_inputs.size()); + Transcript_ct transcript(&builder, manifest, proof_fields, input.public_inputs.size()); aggregation_state_ct result = proof_system::plonk::stdlib::recursion::verify_proof_( - &composer, vkey, transcript, previous_aggregation); + &builder, vkey, transcript, previous_aggregation); // Assign correct witness value to the verification key hash - vkey->compress().assert_equal(field_ct::from_witness_index(&composer, input.key_hash)); + vkey->compress().assert_equal(field_ct::from_witness_index(&builder, input.key_hash)); ASSERT(result.public_inputs.size() == input.public_inputs.size()); // Assign the `public_input` field to the public input of the inner proof for (size_t i = 0; i < input.public_inputs.size(); ++i) { - result.public_inputs[i].assert_equal(field_ct::from_witness_index(&composer, input.public_inputs[i])); + result.public_inputs[i].assert_equal(field_ct::from_witness_index(&builder, input.public_inputs[i])); } // Assign the recursive proof outputs to `output_aggregation_object` for (size_t i = 0; i < result.proof_witness_indices.size(); ++i) { - const auto lhs = field_ct::from_witness_index(&composer, result.proof_witness_indices[i]); - const auto rhs = field_ct::from_witness_index(&composer, input.output_aggregation_object[i]); + const auto lhs = field_ct::from_witness_index(&builder, result.proof_witness_indices[i]); + const auto rhs = field_ct::from_witness_index(&builder, input.output_aggregation_object[i]); lhs.assert_equal(rhs); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.hpp index f99dc21230df..d1a20a4855a1 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.hpp @@ -60,7 +60,7 @@ struct RecursionConstraint { friend bool operator==(RecursionConstraint const& lhs, RecursionConstraint const& rhs) = default; }; -void create_recursion_constraints(Composer& composer, +void create_recursion_constraints(Builder& builder, const RecursionConstraint& input, bool has_valid_witness_assignments = false); diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp index 992a0c8f7be7..6c947a18514b 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/recursion_constraint.test.cpp @@ -8,7 +8,8 @@ using namespace proof_system::plonk; -acir_format::Composer create_inner_circuit() +namespace acir_format::test { +Builder create_inner_circuit() { /** * constraints produced by Noir program: @@ -18,16 +19,16 @@ acir_format::Composer create_inner_circuit() * constrain z != 10; * } **/ - acir_format::RangeConstraint range_a{ + RangeConstraint range_a{ .witness = 1, .num_bits = 32, }; - acir_format::RangeConstraint range_b{ + RangeConstraint range_b{ .witness = 2, .num_bits = 32, }; - acir_format::LogicConstraint logic_constraint{ + LogicConstraint logic_constraint{ .a = 1, .b = 2, .result = 3, @@ -76,7 +77,7 @@ acir_format::Composer create_inner_circuit() .q_c = 1, }; - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = 7, .public_inputs = { 2, 3 }, .fixed_base_scalar_mul_constraints = {}, @@ -96,54 +97,53 @@ acir_format::Composer create_inner_circuit() }; uint256_t inverse_of_five = fr(5).invert(); - auto composer = acir_format::create_circuit_with_witness(constraint_system, - { - 5, - 10, - 15, - 5, - inverse_of_five, - 1, - }); - - return composer; + auto builder = create_circuit_with_witness(constraint_system, + { + 5, + 10, + 15, + 5, + inverse_of_five, + 1, + }); + + return builder; } /** * @brief Create a circuit that recursively verifies one or more inner circuits * - * @param inner_composers - * @return acir_format::Composer + * @param inner_circuits + * @return Composer */ -acir_format::Composer create_outer_circuit(std::vector& inner_composers) +Builder create_outer_circuit(std::vector& inner_circuits) { - std::vector recursion_constraints; + std::vector recursion_constraints; // witness count starts at 1 (Composer reserves 1st witness to be the zero-valued zero_idx) size_t witness_offset = 1; - std::array output_aggregation_object; + std::array output_aggregation_object; std::vector> witness; - for (size_t i = 0; i < inner_composers.size(); ++i) { - const bool has_input_aggregation_object = i > 0; + size_t circuit_idx = 0; + for (auto& inner_circuit : inner_circuits) { + const bool has_input_aggregation_object = circuit_idx > 0; - auto& inner_composer = inner_composers[i]; - auto inner_prover = inner_composer.create_prover(); + auto inner_composer = Composer(); + auto inner_prover = inner_composer.create_prover(inner_circuit); auto inner_proof = inner_prover.construct_proof(); - auto inner_verifier = inner_composer.create_verifier(); + auto inner_verifier = inner_composer.create_verifier(inner_circuit); const bool has_nested_proof = inner_verifier.key->contains_recursive_proof; - const size_t num_inner_public_inputs = inner_composer.get_public_inputs().size(); + const size_t num_inner_public_inputs = inner_circuit.get_public_inputs().size(); transcript::StandardTranscript transcript(inner_proof.proof_data, - acir_format::Composer::create_manifest(num_inner_public_inputs), + Composer::create_manifest(num_inner_public_inputs), transcript::HashType::PlookupPedersenBlake3s, 16); - const std::vector proof_witnesses = - acir_format::export_transcript_in_recursion_format(transcript); - const std::vector key_witnesses = - acir_format::export_key_in_recursion_format(inner_verifier.key); + const std::vector proof_witnesses = export_transcript_in_recursion_format(transcript); + const std::vector key_witnesses = export_key_in_recursion_format(inner_verifier.key); const uint32_t key_hash_start_idx = static_cast(witness_offset); const uint32_t public_input_start_idx = key_hash_start_idx + 1; @@ -155,8 +155,8 @@ acir_format::Composer create_outer_circuit(std::vector& i std::vector proof_indices; std::vector key_indices; std::vector inner_public_inputs; - std::array input_aggregation_object = {}; - std::array nested_aggregation_object = {}; + std::array input_aggregation_object = {}; + std::array nested_aggregation_object = {}; if (has_input_aggregation_object) { input_aggregation_object = output_aggregation_object; } @@ -165,7 +165,7 @@ acir_format::Composer create_outer_circuit(std::vector& i } if (has_nested_proof) { for (size_t i = 0; i < 16; ++i) { - nested_aggregation_object[i] = inner_composer.recursive_proof_public_input_indices[i]; + nested_aggregation_object[i] = inner_circuit.recursive_proof_public_input_indices[i]; } } for (size_t i = 0; i < proof_witnesses.size(); ++i) { @@ -179,7 +179,7 @@ acir_format::Composer create_outer_circuit(std::vector& i inner_public_inputs.push_back(static_cast(i + public_input_start_idx)); } - acir_format::RecursionConstraint recursion_constraint{ + RecursionConstraint recursion_constraint{ .key = key_indices, .proof = proof_indices, .public_inputs = inner_public_inputs, @@ -199,11 +199,12 @@ acir_format::Composer create_outer_circuit(std::vector& i witness.emplace_back(wit); } witness_offset = key_indices_start_idx + key_witnesses.size(); + circuit_idx++; } std::vector public_inputs(output_aggregation_object.begin(), output_aggregation_object.end()); - acir_format::acir_format constraint_system{ + acir_format constraint_system{ .varnum = static_cast(witness.size() + 1), .public_inputs = public_inputs, .fixed_base_scalar_mul_constraints = {}, @@ -222,25 +223,27 @@ acir_format::Composer create_outer_circuit(std::vector& i .constraints = {}, }; - auto composer = acir_format::create_circuit_with_witness(constraint_system, witness); + auto outer_circuit = create_circuit_with_witness(constraint_system, witness); - return composer; + return outer_circuit; } TEST(RecursionConstraint, TestBasicDoubleRecursionConstraints) { - std::vector layer_1_composers; - layer_1_composers.push_back(create_inner_circuit()); + std::vector layer_1_circuits; + layer_1_circuits.push_back(create_inner_circuit()); - layer_1_composers.push_back(create_inner_circuit()); + layer_1_circuits.push_back(create_inner_circuit()); - auto layer_2_composer = create_outer_circuit(layer_1_composers); + auto layer_2_circuit = create_outer_circuit(layer_1_circuits); - std::cout << "composer gates = " << layer_2_composer.get_num_gates() << std::endl; - auto prover = layer_2_composer.create_ultra_with_keccak_prover(); - std::cout << "prover gates = " << prover.circuit_size << std::endl; + info("circuit gates = ", layer_2_circuit.get_num_gates()); + + auto layer_2_composer = Composer(); + auto prover = layer_2_composer.create_ultra_with_keccak_prover(layer_2_circuit); + info("prover gates = ", prover.circuit_size); auto proof = prover.construct_proof(); - auto verifier = layer_2_composer.create_ultra_with_keccak_verifier(); + auto verifier = layer_2_composer.create_ultra_with_keccak_verifier(layer_2_circuit); EXPECT_EQ(verifier.verify_proof(proof), true); } @@ -278,52 +281,55 @@ TEST(RecursionConstraint, TestOneOuterRecursiveCircuit) * * Final aggregation object contains aggregated proofs for 2 instances of A and 1 instance of B */ - std::vector layer_1_composers; - layer_1_composers.push_back(create_inner_circuit()); - std::cout << "created first inner circuit\n"; - std::vector layer_2_composers; + std::vector layer_1_circuits; + layer_1_circuits.push_back(create_inner_circuit()); + info("created first inner circuit"); - layer_2_composers.push_back(create_inner_circuit()); - std::cout << "created second inner circuit\n"; + std::vector layer_2_circuits; + layer_2_circuits.push_back(create_inner_circuit()); + info("created second inner circuit"); - layer_2_composers.push_back(create_outer_circuit(layer_1_composers)); - std::cout << "created first outer circuit\n"; + layer_2_circuits.push_back(create_outer_circuit(layer_1_circuits)); + info("created first outer circuit"); - auto layer_3_composer = create_outer_circuit(layer_2_composers); - std::cout << "created second outer circuit\n"; + auto layer_3_circuit = create_outer_circuit(layer_2_circuits); + info("created second outer circuit"); + info("number of gates in layer 3 = ", layer_3_circuit.get_num_gates()); - std::cout << "composer gates = " << layer_3_composer.get_num_gates() << std::endl; - auto prover = layer_3_composer.create_ultra_with_keccak_prover(); - std::cout << "prover gates = " << prover.circuit_size << std::endl; + auto layer_3_composer = Composer(); + auto prover = layer_3_composer.create_ultra_with_keccak_prover(layer_3_circuit); + info("prover gates = ", prover.circuit_size); auto proof = prover.construct_proof(); - auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(); + auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(layer_3_circuit); EXPECT_EQ(verifier.verify_proof(proof), true); } TEST(RecursionConstraint, TestFullRecursiveComposition) { - std::vector layer_b_1_composers; - layer_b_1_composers.push_back(create_inner_circuit()); - std::cout << "created first inner circuit\n"; + std::vector layer_b_1_circuits; + layer_b_1_circuits.push_back(create_inner_circuit()); + info("created first inner circuit"); - std::vector layer_b_2_composers; - layer_b_2_composers.push_back(create_inner_circuit()); - std::cout << "created second inner circuit\n"; + std::vector layer_b_2_circuits; + layer_b_2_circuits.push_back(create_inner_circuit()); + info("created second inner circuit"); - std::vector layer_2_composers; - layer_2_composers.push_back(create_outer_circuit(layer_b_1_composers)); - std::cout << "created first outer circuit\n"; + std::vector layer_2_circuits; + layer_2_circuits.push_back(create_outer_circuit(layer_b_1_circuits)); + info("created first outer circuit"); - layer_2_composers.push_back(create_outer_circuit(layer_b_2_composers)); - std::cout << "created second outer circuit\n"; + layer_2_circuits.push_back(create_outer_circuit(layer_b_2_circuits)); + info("created second outer circuit"); - auto layer_3_composer = create_outer_circuit(layer_2_composers); - std::cout << "created third outer circuit\n"; + auto layer_3_circuit = create_outer_circuit(layer_2_circuits); + info("created third outer circuit"); + info("number of gates in layer 3 circuit = ", layer_3_circuit.get_num_gates()); - std::cout << "composer gates = " << layer_3_composer.get_num_gates() << std::endl; - auto prover = layer_3_composer.create_ultra_with_keccak_prover(); - std::cout << "prover gates = " << prover.circuit_size << std::endl; + auto layer_3_composer = Composer(); + auto prover = layer_3_composer.create_ultra_with_keccak_prover(layer_3_circuit); + info("prover gates = ", prover.circuit_size); auto proof = prover.construct_proof(); - auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(); + auto verifier = layer_3_composer.create_ultra_with_keccak_verifier(layer_3_circuit); EXPECT_EQ(verifier.verify_proof(proof), true); -} \ No newline at end of file +} +} // namespace acir_format::test \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp index cb717ed99a2f..d520dc32be3c 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.cpp @@ -6,7 +6,7 @@ namespace acir_format { using namespace proof_system::plonk::stdlib; -crypto::schnorr::signature convert_signature(Composer& composer, std::vector signature) +crypto::schnorr::signature convert_signature(Builder& builder, std::vector signature) { crypto::schnorr::signature signature_cr; @@ -19,7 +19,7 @@ crypto::schnorr::signature convert_signature(Composer& composer, std::vector fr_bytes(sizeof(fr)); - fr value = composer.get_variable(witness_index); + fr value = builder.get_variable(witness_index); fr::serialize_to_buffer(value, &fr_bytes[0]); @@ -31,7 +31,7 @@ crypto::schnorr::signature convert_signature(Composer& composer, std::vector fr_bytes(sizeof(fr)); - fr value = composer.get_variable(witness_index); + fr value = builder.get_variable(witness_index); fr::serialize_to_buffer(value, &fr_bytes[0]); @@ -43,15 +43,15 @@ crypto::schnorr::signature convert_signature(Composer& composer, std::vector vector_of_bytes) +byte_array_ct vector_of_bytes_to_byte_array(Builder& builder, std::vector vector_of_bytes) { - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array for (const auto& witness_index : vector_of_bytes) { - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); size_t num_bytes = 1; byte_array_ct element_bytes(element, num_bytes); @@ -59,16 +59,16 @@ byte_array_ct vector_of_bytes_to_byte_array(Composer& composer, std::vector BitArray // This may not be the most efficient way to do it. It is being used as it is known to work, // optimisations are welcome! @@ -76,20 +76,20 @@ void create_schnorr_verify_constraints(Composer& composer, const SchnorrConstrai // First convert the message of u8 witnesses into a byte_array // Do this by taking each element as a u8 and writing it to the byte array - auto message = vector_of_bytes_to_byte_array(composer, input.message); + auto message = vector_of_bytes_to_byte_array(builder, input.message); - fr pubkey_value_x = composer.get_variable(input.public_key_x); - fr pubkey_value_y = composer.get_variable(input.public_key_y); + fr pubkey_value_x = builder.get_variable(input.public_key_x); + fr pubkey_value_y = builder.get_variable(input.public_key_y); - point_ct pub_key{ witness_ct(&composer, pubkey_value_x), witness_ct(&composer, pubkey_value_y) }; + point_ct pub_key{ witness_ct(&builder, pubkey_value_x), witness_ct(&builder, pubkey_value_y) }; - schnorr_signature_bits_ct sig = schnorr::convert_signature(&composer, new_sig); + schnorr_signature_bits_ct sig = schnorr::convert_signature(&builder, new_sig); bool_ct signature_result = schnorr::signature_verification_result(message, pub_key, sig); bool_ct signature_result_normalized = signature_result.normalize(); - composer.assert_equal(signature_result_normalized.witness_index, input.result); + builder.assert_equal(signature_result_normalized.witness_index, input.result); } } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp index 7b6b98429459..d610f89b8635 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/schnorr_verify.hpp @@ -25,7 +25,7 @@ struct SchnorrConstraint { friend bool operator==(SchnorrConstraint const& lhs, SchnorrConstraint const& rhs) = default; }; -void create_schnorr_verify_constraints(Composer& composer, const SchnorrConstraint& input); +void create_schnorr_verify_constraints(Builder& builder, const SchnorrConstraint& input); template inline void read(B& buf, SchnorrConstraint& constraint) { diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp index 07c8166bd1d9..ed4fe5d80747 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.cpp @@ -7,11 +7,11 @@ namespace acir_format { // This function does not work (properly) because the stdlib:sha256 function is not working correctly for 512 bits // pair -void create_sha256_constraints(Composer& composer, const Sha256Constraint& constraint) +void create_sha256_constraints(Builder& builder, const Sha256Constraint& constraint) { // Create byte array struct - byte_array_ct arr(&composer); + byte_array_ct arr(&builder); // Get the witness assignment for each witness index // Write the witness assignment to the byte_array @@ -22,20 +22,20 @@ void create_sha256_constraints(Composer& composer, const Sha256Constraint& const // XXX: The implementation requires us to truncate the element to the nearest byte and not bit auto num_bytes = round_to_nearest_byte(num_bits); - field_ct element = field_ct::from_witness_index(&composer, witness_index); + field_ct element = field_ct::from_witness_index(&builder, witness_index); byte_array_ct element_bytes(element, num_bytes); arr.write(element_bytes); } // Compute sha256 - byte_array_ct output_bytes = proof_system::plonk::stdlib::sha256(arr); + byte_array_ct output_bytes = proof_system::plonk::stdlib::sha256(arr); // Convert byte array to vector of field_t auto bytes = output_bytes.bytes(); for (size_t i = 0; i < bytes.size(); ++i) { - composer.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); + builder.assert_equal(bytes[i].normalize().witness_index, constraint.result[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp index 3c434bae26d6..a88612f3e43a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/sha256_constraint.hpp @@ -25,7 +25,7 @@ struct Sha256Constraint { // This function does not work (properly) because the stdlib:sha256 function is not working correctly for 512 bits // pair -void create_sha256_constraints(Composer& composer, const Sha256Constraint& constraint); +void create_sha256_constraints(Builder& builder, const Sha256Constraint& constraint); template inline void read(B& buf, Sha256Input& constraint) { 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 cbc5f6233f35..b2e8458045a3 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.cpp @@ -13,21 +13,21 @@ namespace acir_proofs { AcirComposer::AcirComposer(size_t size_hint) - : composer_(0, 0, 0) + : composer_(/*p_key=*/0, /*v_key=*/0) , size_hint_(size_hint) {} void AcirComposer::create_circuit(acir_format::acir_format& constraint_system) { - composer_ = acir_format::create_circuit(constraint_system, nullptr, size_hint_); + builder_ = acir_format::create_circuit(constraint_system, size_hint_); // We are done with the constraint system at this point, and we need the memory slab back. constraint_system.constraints.clear(); constraint_system.constraints.shrink_to_fit(); - exact_circuit_size_ = composer_.get_num_gates(); - total_circuit_size_ = composer_.get_total_circuit_size(); - circuit_subgroup_size_ = composer_.get_circuit_subgroup_size(total_circuit_size_); + exact_circuit_size_ = builder_.get_num_gates(); + total_circuit_size_ = builder_.get_total_circuit_size(); + circuit_subgroup_size_ = builder_.get_circuit_subgroup_size(total_circuit_size_); size_hint_ = circuit_subgroup_size_; } @@ -35,19 +35,20 @@ void AcirComposer::init_proving_key(std::shared_ptr AcirComposer::create_proof( @@ -57,24 +58,24 @@ std::vector AcirComposer::create_proof( bool is_recursive) { // Release prior memory first. - composer_ = acir_format::Composer(0, 0, 0); + composer_ = acir_format::Composer(/*p_key=*/0, /*v_key=*/0); info("building circuit..."); + create_circuit_with_witness(builder_, constraint_system, witness); + composer_ = [&]() { if (proving_key_) { - auto composer = acir_format::Composer(proving_key_, verification_key_, size_hint_); + auto composer = acir_format::Composer(proving_key_, verification_key_); // You can't produce the verification key unless you manually set the crs. Which seems like a bug. - composer_.composer_helper.crs_factory_ = crs_factory; + composer_.crs_factory_ = crs_factory; return composer; } else { - return acir_format::Composer(crs_factory, size_hint_); + return acir_format::Composer(crs_factory); } }(); - create_circuit_with_witness(composer_, constraint_system, witness); - if (!proving_key_) { info("computing proving key..."); - proving_key_ = composer_.compute_proving_key(); + proving_key_ = composer_.compute_proving_key(builder_); } // We are done with the constraint system at this point, and we need the memory slab back. @@ -86,10 +87,10 @@ std::vector AcirComposer::create_proof( info("creating proof..."); std::vector proof; if (is_recursive) { - auto prover = composer_.create_prover(); + auto prover = composer_.create_prover(builder_); proof = prover.construct_proof().proof_data; } else { - auto prover = composer_.create_ultra_with_keccak_prover(); + auto prover = composer_.create_ultra_with_keccak_prover(builder_); proof = prover.construct_proof().proof_data; } info("done."); @@ -98,7 +99,7 @@ std::vector AcirComposer::create_proof( std::shared_ptr AcirComposer::init_verification_key() { - return verification_key_ = composer_.compute_verification_key(); + return verification_key_ = composer_.compute_verification_key(builder_); } void AcirComposer::load_verification_key(std::shared_ptr const& crs_factory, @@ -106,24 +107,24 @@ void AcirComposer::load_verification_key(std::shared_ptr(std::move(data), crs_factory->get_verifier_crs()); - composer_ = acir_format::Composer(proving_key_, verification_key_, circuit_subgroup_size_); + composer_ = acir_format::Composer(proving_key_, verification_key_); } bool AcirComposer::verify_proof(std::vector const& proof, bool is_recursive) { if (!verification_key_) { info("computing verification key..."); - verification_key_ = composer_.compute_verification_key(); + verification_key_ = composer_.compute_verification_key(builder_); } // Hack. Shouldn't need to do this. 2144 is size with no public inputs. - composer_.circuit_constructor.public_inputs.resize((proof.size() - 2144) / 32); + builder_.public_inputs.resize((proof.size() - 2144) / 32); if (is_recursive) { - auto verifier = composer_.create_verifier(); + auto verifier = composer_.create_verifier(builder_); return verifier.verify_proof({ proof }); } else { - auto verifier = composer_.create_ultra_with_keccak_verifier(); + auto verifier = composer_.create_ultra_with_keccak_verifier(builder_); return verifier.verify_proof({ proof }); } } 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 86d765b796b0..186aa9517593 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/acir_composer.hpp @@ -38,6 +38,7 @@ class AcirComposer { std::vector serialize_verification_key_into_fields(); private: + acir_format::Builder builder_; acir_format::Composer composer_; size_t size_hint_; size_t exact_circuit_size_; 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 78bc41434eef..e04b96e05660 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_proofs/c_bind.cpp @@ -17,7 +17,7 @@ WASM_EXPORT void acir_get_circuit_sizes(uint8_t const* constraint_system_buf, { auto constraint_system = from_buffer(constraint_system_buf); free_mem_slab_raw((void*)constraint_system_buf); - auto composer = acir_format::create_circuit(constraint_system, nullptr, 1 << 19); + auto composer = acir_format::create_circuit(constraint_system, 1 << 19); *exact = htonl((uint32_t)composer.get_num_gates()); *total = htonl((uint32_t)composer.get_total_circuit_size()); *subgroup = htonl((uint32_t)composer.get_circuit_subgroup_size(composer.get_total_circuit_size())); diff --git a/barretenberg/cpp/src/barretenberg/dsl/types.hpp b/barretenberg/cpp/src/barretenberg/dsl/types.hpp index b2050ce403a3..b431b0cde5db 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/types.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/types.hpp @@ -1,6 +1,8 @@ #pragma once -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" +#include "barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" @@ -26,51 +28,52 @@ namespace acir_format { -using Composer = plonk::UltraPlonkComposer; +using Builder = proof_system::UltraCircuitConstructor; +using Composer = plonk::UltraPlonkComposerHelper; using Prover = std::conditional_t< - std::same_as, + std::same_as, plonk::UltraWithKeccakProver, - std::conditional_t, plonk::TurboProver, plonk::Prover>>; + std::conditional_t, plonk::TurboProver, plonk::Prover>>; using Verifier = std::conditional_t< - std::same_as, + std::same_as, plonk::UltraWithKeccakVerifier, - std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; + std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; using RecursiveProver = plonk::UltraProver; -using witness_ct = proof_system::plonk::stdlib::witness_t; -using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; -using bool_ct = proof_system::plonk::stdlib::bool_t; -using byte_array_ct = proof_system::plonk::stdlib::byte_array; -using packed_byte_array_ct = proof_system::plonk::stdlib::packed_byte_array; -using field_ct = proof_system::plonk::stdlib::field_t; -using suint_ct = proof_system::plonk::stdlib::safe_uint_t; -using uint8_ct = proof_system::plonk::stdlib::uint8; -using uint16_ct = proof_system::plonk::stdlib::uint16; -using uint32_ct = proof_system::plonk::stdlib::uint32; -using uint64_ct = proof_system::plonk::stdlib::uint64; -using bit_array_ct = proof_system::plonk::stdlib::bit_array; -using fq_ct = proof_system::plonk::stdlib::bigfield; -using biggroup_ct = proof_system::plonk::stdlib::element; -using point_ct = proof_system::plonk::stdlib::point; -using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; -using group_ct = proof_system::plonk::stdlib::group; -using bn254 = proof_system::plonk::stdlib::bn254; -using secp256k1_ct = proof_system::plonk::stdlib::secp256k1; +using witness_ct = proof_system::plonk::stdlib::witness_t; +using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; +using bool_ct = proof_system::plonk::stdlib::bool_t; +using byte_array_ct = proof_system::plonk::stdlib::byte_array; +using packed_byte_array_ct = proof_system::plonk::stdlib::packed_byte_array; +using field_ct = proof_system::plonk::stdlib::field_t; +using suint_ct = proof_system::plonk::stdlib::safe_uint_t; +using uint8_ct = proof_system::plonk::stdlib::uint8; +using uint16_ct = proof_system::plonk::stdlib::uint16; +using uint32_ct = proof_system::plonk::stdlib::uint32; +using uint64_ct = proof_system::plonk::stdlib::uint64; +using bit_array_ct = proof_system::plonk::stdlib::bit_array; +using fq_ct = proof_system::plonk::stdlib::bigfield; +using biggroup_ct = proof_system::plonk::stdlib::element; +using point_ct = proof_system::plonk::stdlib::point; +using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; +using group_ct = proof_system::plonk::stdlib::group; +using bn254 = proof_system::plonk::stdlib::bn254; +using secp256k1_ct = proof_system::plonk::stdlib::secp256k1; -using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; +using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; -using schnorr_signature_bits_ct = proof_system::plonk::stdlib::schnorr::signature_bits; +using schnorr_signature_bits_ct = proof_system::plonk::stdlib::schnorr::signature_bits; // Ultra-composer specific typesv -using rom_table_ct = proof_system::plonk::stdlib::rom_table; -using ram_table_ct = proof_system::plonk::stdlib::ram_table; +using rom_table_ct = proof_system::plonk::stdlib::rom_table; +using ram_table_ct = proof_system::plonk::stdlib::ram_table; using verification_key_ct = proof_system::plonk::stdlib::recursion::verification_key; using aggregation_state_ct = proof_system::plonk::stdlib::recursion::aggregation_state; using noir_recursive_settings = proof_system::plonk::stdlib::recursion::recursive_ultra_verifier_settings; -using Transcript_ct = proof_system::plonk::stdlib::recursion::Transcript; +using Transcript_ct = proof_system::plonk::stdlib::recursion::Transcript; } // namespace acir_format diff --git a/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp b/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp index cdc25c6b77c1..8ae3229f918a 100644 --- a/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/c_bind.cpp @@ -6,8 +6,8 @@ using namespace proof_system::plonk::stdlib::types; WASM_EXPORT void examples_simple_create_and_verify_proof(bool* valid) { - auto* composer_ptr = examples::simple::create_composer(barretenberg::srs::get_crs_factory()); - auto proof = examples::simple::create_proof(composer_ptr); - *valid = examples::simple::verify_proof(composer_ptr, proof); - examples::simple::delete_composer(composer_ptr); + auto ptrs = examples::simple::create_builder_and_composer(barretenberg::srs::get_crs_factory()); + auto proof = examples::simple::create_proof(ptrs); + *valid = examples::simple::verify_proof(ptrs, proof); + examples::simple::delete_builder_and_composer(ptrs); } diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp index 28af84250294..9ca873389953 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.cpp @@ -11,58 +11,61 @@ using namespace stdlib::types; const size_t CIRCUIT_SIZE = 1 << 19; -void build_circuit(Composer& composer) +void build_circuit(Builder& builder) { - while (composer.get_num_gates() <= CIRCUIT_SIZE / 2) { - plonk::stdlib::pedersen_commitment::compress(field_ct(witness_ct(&composer, 1)), - field_ct(witness_ct(&composer, 1))); + while (builder.get_num_gates() <= CIRCUIT_SIZE / 2) { + plonk::stdlib::pedersen_commitment::compress(field_ct(witness_ct(&builder, 1)), + field_ct(witness_ct(&builder, 1))); } } -Composer* create_composer(std::shared_ptr const& crs_factory) +BuilderComposerPtrs create_builder_and_composer( + std::shared_ptr const& crs_factory) { // WARNING: Size hint is essential to perform 512k circuits! - auto composer = std::make_unique(crs_factory, CIRCUIT_SIZE); + auto builder = std::make_unique(CIRCUIT_SIZE); info("building circuit..."); - build_circuit(*composer); + build_circuit(*builder); - if (composer->failed()) { - std::string error = format("composer logic failed: ", composer->err()); + if (builder->failed()) { + std::string error = format("builder logic failed: ", builder->err()); throw_or_abort(error); } - info("public inputs: ", composer->get_public_inputs().size()); - info("composer gates: ", composer->get_num_gates()); + info("public inputs: ", builder->get_public_inputs().size()); + info("composer gates: ", builder->get_num_gates()); info("computing proving key..."); - auto pk = composer->compute_proving_key(); + auto composer = std::make_unique(crs_factory); + auto pk = composer->compute_proving_key(*builder); - return composer.release(); + return { builder.release(), composer.release() }; } -proof create_proof(Composer* composer) +proof create_proof(BuilderComposerPtrs pair) { Timer timer; info("computing proof..."); - auto prover = composer->create_ultra_with_keccak_prover(); + auto prover = pair.composer->create_ultra_with_keccak_prover(*pair.builder); auto proof = prover.construct_proof(); info("proof construction took ", timer.seconds(), "s"); return proof; } -bool verify_proof(Composer* composer, proof_system::plonk::proof const& proof) +bool verify_proof(BuilderComposerPtrs pair, proof_system::plonk::proof const& proof) { info("computing verification key..."); - composer->compute_verification_key(); - auto verifier = composer->create_ultra_with_keccak_verifier(); + pair.composer->compute_verification_key(*pair.builder); + auto verifier = pair.composer->create_ultra_with_keccak_verifier(*pair.builder); auto valid = verifier.verify_proof(proof); info("proof validity: ", valid); return valid; } -void delete_composer(Composer* composer) +void delete_builder_and_composer(BuilderComposerPtrs pair) { - delete composer; + delete pair.builder; + delete pair.composer; } } // namespace examples::simple diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp index a3695899f8a6..8915a3f8283a 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.hpp @@ -7,12 +7,18 @@ namespace examples::simple { using namespace proof_system::plonk; using namespace stdlib::types; -Composer* create_composer(std::shared_ptr const& crs_factory); +struct BuilderComposerPtrs { + Builder* builder; + Composer* composer; +}; -proof create_proof(Composer* composer); +BuilderComposerPtrs create_builder_and_composer( + std::shared_ptr const& crs_factory); -bool verify_proof(Composer* composer, proof_system::plonk::proof const& proof); +proof create_proof(BuilderComposerPtrs pair); -void delete_composer(Composer* composer); +bool verify_proof(BuilderComposerPtrs pair, proof_system::plonk::proof const& proof); + +void delete_builder_and_composer(BuilderComposerPtrs pair); } // namespace examples::simple diff --git a/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp b/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp index 95fb679b2eaa..3faa4090dd08 100644 --- a/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp +++ b/barretenberg/cpp/src/barretenberg/examples/simple/simple.test.cpp @@ -9,10 +9,10 @@ TEST(examples_simple, create_proof) { auto srs_path = std::filesystem::absolute("../srs_db/ignition"); auto crs_factory = std::make_shared(srs_path); - auto* composer = create_composer(crs_factory); - auto proof = create_proof(composer); - bool valid = verify_proof(composer, proof); - delete_composer(composer); + auto ptrs = create_builder_and_composer(crs_factory); + auto proof = create_proof(ptrs); + bool valid = verify_proof(ptrs, proof); + delete_builder_and_composer(ptrs); EXPECT_TRUE(valid); } diff --git a/barretenberg/cpp/src/barretenberg/honk/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/honk/CMakeLists.txt index 1e687ab04b8d..ac0dc30fd080 100644 --- a/barretenberg/cpp/src/barretenberg/honk/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/honk/CMakeLists.txt @@ -1,4 +1,3 @@ -# TODO(Cody): Remove plonk dependency barretenberg_module(honk numeric ecc srs proof_system transcript) if(TESTING) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp index ace2cac67506..7b21f549d596 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/standard_honk_composer_helper.hpp @@ -20,6 +20,8 @@ template class StandardHonkComposerHelper_ { using VerificationKey = typename Flavor::VerificationKey; using PCSCommitmentKey = typename PCSParams::CommitmentKey; + static constexpr std::string_view NAME_STRING = "StandardHonk"; + static constexpr ComposerType type = ComposerType::STANDARD_HONK; // TODO(Cody): Get rid of this. static constexpr size_t NUM_RESERVED_GATES = 2; // equal to the number of multilinear evaluations leaked static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; std::shared_ptr proving_key; diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp index 3a6e670c36f5..caa32331ef23 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp @@ -21,6 +21,8 @@ template class UltraHonkComposerHelper_ { using PCSCommitmentKey = typename PCSParams::CommitmentKey; using PCSVerificationKey = typename PCSParams::VerificationKey; + static constexpr std::string_view NAME_STRING = "UltraHonk"; + static constexpr ComposerType type = ComposerType::PLOOKUP; static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of multilinear evaluations leaked static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; std::shared_ptr proving_key; diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp deleted file mode 100644 index 2ff404ead18c..000000000000 --- a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp +++ /dev/null @@ -1,198 +0,0 @@ -#pragma once - -#include "composer_helper/standard_honk_composer_helper.hpp" -#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" -#include "barretenberg/proof_system/types/merkle_hash_type.hpp" -#include "barretenberg/proof_system/types/pedersen_commitment_type.hpp" - -namespace proof_system::honk { -/** - * @brief Standard Honk Composer has everything required to construct a prover and verifier, just as the legacy classes. - * - * @details However, it has a lot of its logic separated into subclasses and simply proxies the calls. - * - */ -template class StandardHonkComposer_ { - public: - // TODO(#426): This doesn't belong here - static constexpr merkle::HashType merkle_hash_type = merkle::HashType::LOOKUP_PEDERSEN; - static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN; - - using CircuitConstructor = StandardCircuitConstructor; - using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; - static constexpr ComposerType type = ComposerType::STANDARD_HONK; // TODO(Cody): Get rid of this. - - static constexpr size_t UINT_LOG2_BASE = 2; - // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system - CircuitConstructor circuit_constructor; - // Composer helper contains all proof-related material that is separate from circuit creation such as: - // 1) Proving and verification keys - // 2) CRS - // 3) Converting variables to witness vectors/polynomials - StandardHonkComposerHelper_ composer_helper; - - // Leaving it in for now just in case - bool contains_recursive_proof = false; - static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; - - /**Standard methods*/ - - StandardHonkComposer_(const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables){}; - - StandardHonkComposer_(std::string const& crs_path, const size_t size_hint = 0) - : StandardHonkComposer_(barretenberg::srs::get_crs_factory(), size_hint){}; - - StandardHonkComposer_(std::shared_ptr const& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , composer_helper(crs_factory) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - - {} - StandardHonkComposer_(std::unique_ptr&& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , composer_helper(std::move(crs_factory)) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - - {} - - StandardHonkComposer_(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0) - : circuit_constructor(size_hint) - , composer_helper(p_key, v_key) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - {} - - StandardHonkComposer_(const StandardHonkComposer_& other) = delete; - StandardHonkComposer_(StandardHonkComposer_&& other) = default; - StandardHonkComposer_& operator=(const StandardHonkComposer_& other) = delete; - // TODO(#230)(Cody): This constructor started to be implicitly deleted when I added `n` and `variables` members. - // This is a temporary measure until we can rewrite Plonk and all tests using circuit builder methods in place of - // composer methods, where appropriate. StandardHonkComposer_& operator=(StandardHonkComposer_&& other) = default; - ~StandardHonkComposer_() = default; - - size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } - - /**Methods related to circuit construction - * They simply get proxied to the circuit constructor - */ - void assert_equal(const uint32_t a_variable_idx, const uint32_t b_variable_idx, std::string const& msg) - { - circuit_constructor.assert_equal(a_variable_idx, b_variable_idx, msg); - } - void assert_equal_constant(uint32_t const a_idx, - barretenberg::fr const& b, - std::string const& msg = "assert equal constant") - { - circuit_constructor.assert_equal_constant(a_idx, b, msg); - } - - void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); } - void create_mul_gate(const mul_triple& in) { circuit_constructor.create_mul_gate(in); } - void create_bool_gate(const uint32_t a) { circuit_constructor.create_bool_gate(a); } - void create_poly_gate(const poly_triple& in) { circuit_constructor.create_poly_gate(in); } - void create_big_add_gate(const add_quad& in) { circuit_constructor.create_big_add_gate(in); } - void create_big_add_gate_with_bit_extraction(const add_quad& in) - { - circuit_constructor.create_big_add_gate_with_bit_extraction(in); - } - void create_big_mul_gate(const mul_quad& in) { circuit_constructor.create_big_mul_gate(in); } - void create_balanced_add_gate(const add_quad& in) { circuit_constructor.create_balanced_add_gate(in); } - - void fix_witness(const uint32_t witness_index, const barretenberg::fr& witness_value) - { - circuit_constructor.fix_witness(witness_index, witness_value); - } - - std::vector decompose_into_base4_accumulators(const uint32_t witness_index, - - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - return circuit_constructor.decompose_into_base4_accumulators(witness_index, num_bits, msg); - } - - void create_range_constraint(const uint32_t variable_index, - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - circuit_constructor.create_range_constraint(variable_index, num_bits, msg); - } - - accumulator_triple create_logic_constraint(const uint32_t a, - const uint32_t b, - const size_t num_bits, - bool is_xor_gate) - { - return circuit_constructor.create_logic_constraint(a, b, num_bits, is_xor_gate); - } - - accumulator_triple create_and_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_and_constraint(a, b, num_bits); - } - - accumulator_triple create_xor_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_xor_constraint(a, b, num_bits); - } - uint32_t add_variable(const barretenberg::fr& in) { return circuit_constructor.add_variable(in); } - - uint32_t add_public_variable(const barretenberg::fr& in) { return circuit_constructor.add_public_variable(in); } - - virtual void set_public_input(const uint32_t witness_index) - { - return circuit_constructor.set_public_input(witness_index); - } - - uint32_t put_constant_variable(const barretenberg::fr& variable) - { - return circuit_constructor.put_constant_variable(variable); - } - - size_t get_num_constant_gates() const { return circuit_constructor.get_num_constant_gates(); } - - bool check_circuit() { return circuit_constructor.check_circuit(); } - - barretenberg::fr get_variable(const uint32_t index) const { return circuit_constructor.get_variable(index); } - - /**Proof and verification-related methods*/ - - std::shared_ptr compute_proving_key() - { - return composer_helper.compute_proving_key(circuit_constructor); - } - - std::shared_ptr compute_verification_key() - { - return composer_helper.compute_verification_key(circuit_constructor); - } - - uint32_t zero_idx = 0; - - void compute_witness() { composer_helper.compute_witness(circuit_constructor); }; - - StandardVerifier_ create_verifier() { return composer_helper.create_verifier(circuit_constructor); } - StandardProver_ create_prover() { return composer_helper.create_prover(circuit_constructor); }; - - size_t& num_gates; - std::vector& variables; - bool failed() const { return circuit_constructor.failed(); }; - const std::string& err() const { return circuit_constructor.err(); }; - void failure(std::string msg) { circuit_constructor.failure(msg); } -}; - -// TODO(#532): These using declarations instantiate the templates? -using StandardHonkComposer = StandardHonkComposer_; -using StandardGrumpkinHonkComposer = StandardHonkComposer_; -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp index 2d3c1e42d019..04ada2ef9b69 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp @@ -361,10 +361,11 @@ TEST_F(StandardHonkComposerTests, TwoGates) auto composer = StandardHonkComposerHelper(); auto prover = composer.create_prover(circuit_constructor); - auto proof = prover.construct_proof(); + auto verifier = composer.create_verifier(circuit_constructor); bool verified = verifier.verify_proof(proof); + EXPECT_EQ(verified, expect_verified); }; diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp deleted file mode 100644 index db214e0d1bd4..000000000000 --- a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.hpp +++ /dev/null @@ -1,297 +0,0 @@ -#pragma once -#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" -#include "barretenberg/honk/proof_system/ultra_prover.hpp" -#include "barretenberg/honk/proof_system/ultra_verifier.hpp" -#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" -#include "barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp" -#include "barretenberg/honk/flavor/ultra.hpp" -namespace proof_system::honk { - -template class UltraHonkComposer_ { - - public: - // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system - UltraCircuitConstructor circuit_constructor; - // Composer helper contains all proof-related material that is separate from circuit creation such as: - // 1) Proving and verification keys - // 2) CRS - // 3) Converting variables to witness vectors/polynomials - using CircuitConstructor = UltraCircuitConstructor; - using ProvingKey = typename Flavor::ProvingKey; - using VerificationKey = typename Flavor::VerificationKey; - - // TODO(#426): This don't belong here - static constexpr ComposerType type = ComposerType::PLOOKUP; - static_assert(type == CircuitConstructor::type); - static constexpr merkle::HashType merkle_hash_type = CircuitConstructor::merkle_hash_type; - static constexpr pedersen::CommitmentType commitment_type = CircuitConstructor::commitment_type; - static constexpr size_t DEFAULT_PLOOKUP_RANGE_BITNUM = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM; - - UltraHonkComposerHelper_ composer_helper; - size_t& num_gates; - std::vector& variables; - // While we always have it set to zero, feels wrong to have a potentially broken dependency - uint32_t& zero_idx; - bool& contains_recursive_proof; - std::vector& recursive_proof_public_input_indices; - - UltraHonkComposer_() - : UltraHonkComposer_(barretenberg::srs::get_crs_factory(), 0){}; - - UltraHonkComposer_(std::string const& crs_path, const size_t size_hint) - : UltraHonkComposer_(std::unique_ptr( - new barretenberg::srs::factories::FileCrsFactory(crs_path)), - size_hint){}; - - UltraHonkComposer_(std::shared_ptr const& crs_factory, - const size_t size_hint) - : circuit_constructor(size_hint) - , composer_helper(crs_factory) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices) - { - // TODO(#217/#423): Related to issue of ensuring no identically 0 polynomials - add_gates_to_ensure_all_polys_are_non_zero(); - }; - - UltraHonkComposer_(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0); - UltraHonkComposer_(UltraHonkComposer_&& other) = default; - UltraHonkComposer_& operator=(UltraHonkComposer_&& other) = delete; - ~UltraHonkComposer_() = default; - - size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } - uint32_t get_zero_idx() { return circuit_constructor.zero_idx; } - - bool check_circuit() { return circuit_constructor.check_circuit(); } - - uint32_t add_variable(const barretenberg::fr& in) { return circuit_constructor.add_variable(in); } - - virtual void set_public_input(const uint32_t witness_index) - { - return circuit_constructor.set_public_input(witness_index); - } - - barretenberg::fr get_variable(const uint32_t index) const { return circuit_constructor.get_variable(index); } - - UltraProver_ create_prover() { return composer_helper.create_prover(circuit_constructor); }; - UltraVerifier_ create_verifier() { return composer_helper.create_verifier(circuit_constructor); }; - - void add_gates_to_ensure_all_polys_are_non_zero() - { - circuit_constructor.add_gates_to_ensure_all_polys_are_non_zero(); - } - - void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); } - - void create_big_add_gate(const add_quad& in, const bool use_next_gate_w_4 = false) - { - circuit_constructor.create_big_add_gate(in, use_next_gate_w_4); - }; - - void create_mul_gate(const mul_triple& in) { circuit_constructor.create_mul_gate(in); } - - void create_bool_gate(const uint32_t a) { circuit_constructor.create_bool_gate(a); } - - void create_poly_gate(const poly_triple& in) { circuit_constructor.create_poly_gate(in); } - - void create_big_mul_gate(const mul_quad& in) { circuit_constructor.create_big_mul_gate(in); } - - void create_balanced_add_gate(const add_quad& in) { circuit_constructor.create_balanced_add_gate(in); } - - void create_ecc_add_gate(const ecc_add_gate& in) { circuit_constructor.create_ecc_add_gate(in); }; - - void fix_witness(const uint32_t witness_index, const barretenberg::fr& witness_value) - { - circuit_constructor.fix_witness(witness_index, witness_value); - } - - void create_new_range_constraint(const uint32_t variable_index, - const uint64_t target_range, - std::string const msg = "create_new_range_constraint") - { - circuit_constructor.create_new_range_constraint(variable_index, target_range, msg); - }; - - uint32_t put_constant_variable(const barretenberg::fr& variable) - { - return circuit_constructor.put_constant_variable(variable); - }; - - void assert_equal(const uint32_t a_variable_idx, - const uint32_t b_variable_idx, - std::string const& msg = "assert_equal") - { - circuit_constructor.assert_equal(a_variable_idx, b_variable_idx, msg); - } - - void assert_equal_constant(uint32_t const a_idx, - barretenberg::fr const& b, - std::string const& msg = "assert equal constant") - { - circuit_constructor.assert_equal_constant(a_idx, b, msg); - } - - plookup::ReadData create_gates_from_plookup_accumulators( - const plookup::MultiTableId& id, - const plookup::ReadData& read_values, - const uint32_t key_a_index, - std::optional key_b_index = std::nullopt) - { - return circuit_constructor.create_gates_from_plookup_accumulators(id, read_values, key_a_index, key_b_index); - }; - - // /** - // * Generalized Permutation Methods - // **/ - std::vector decompose_into_default_range( - const uint32_t variable_index, - const uint64_t num_bits, - const uint64_t target_range_bitnum = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM, - std::string const& msg = "decompose_into_default_range") - { - return circuit_constructor.decompose_into_default_range(variable_index, num_bits, target_range_bitnum, msg); - }; - - void create_dummy_constraints(const std::vector& variable_index) - { - circuit_constructor.create_dummy_constraints(variable_index); - }; - void create_sort_constraint(const std::vector& variable_index) - { - circuit_constructor.create_sort_constraint(variable_index); - }; - void create_sort_constraint_with_edges(const std::vector& variable_index, - const barretenberg::fr& start, - const barretenberg::fr& end) - { - circuit_constructor.create_sort_constraint_with_edges(variable_index, start, end); - }; - - void assign_tag(const uint32_t variable_index, const uint32_t tag) - { - circuit_constructor.assign_tag(variable_index, tag); - } - - // void assign_tag(const uint32_t variable_index, const uint32_t tag) - // { - // ASSERT(tag <= current_tag); - // ASSERT(real_variable_tags[real_variable_index[variable_index]] == DUMMY_TAG); - // real_variable_tags[real_variable_index[variable_index]] = tag; - // } - - uint32_t create_tag(const uint32_t tag_index, const uint32_t tau_index) - { - return circuit_constructor.create_tag(tag_index, tau_index); - } - - // /** - // * Non Native Field Arithmetic - // **/ - void range_constrain_two_limbs( - const uint32_t lo_idx, - const uint32_t hi_idx, - const size_t lo_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS, - const size_t hi_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS) - { - circuit_constructor.range_constrain_two_limbs(lo_idx, hi_idx, lo_limb_bits, hi_limb_bits); - }; - std::array evaluate_non_native_field_multiplication( - const UltraCircuitConstructor::non_native_field_witnesses& input, - const bool range_constrain_quotient_and_remainder = true) - { - return circuit_constructor.evaluate_non_native_field_multiplication(input, - range_constrain_quotient_and_remainder); - }; - - // /** - // * Memory - // **/ - - size_t create_RAM_array(const size_t array_size) { return circuit_constructor.create_RAM_array(array_size); }; - size_t create_ROM_array(const size_t array_size) { return circuit_constructor.create_ROM_array(array_size); }; - - void set_ROM_element(const size_t rom_id, const size_t index_value, const uint32_t value_witness) - { - circuit_constructor.set_ROM_element(rom_id, index_value, value_witness); - }; - void set_ROM_element_pair(const size_t rom_id, - const size_t index_value, - const std::array& value_witnesses) - { - circuit_constructor.set_ROM_element_pair(rom_id, index_value, value_witnesses); - } - - uint32_t read_ROM_array(const size_t rom_id, const uint32_t index_witness) - { - return circuit_constructor.read_ROM_array(rom_id, index_witness); - }; - std::array read_ROM_array_pair(const size_t rom_id, const uint32_t index_witness) - { - return circuit_constructor.read_ROM_array_pair(rom_id, index_witness); - } - - void init_RAM_element(const size_t ram_id, const size_t index_value, const uint32_t value_witness) - { - circuit_constructor.init_RAM_element(ram_id, index_value, value_witness); - }; - uint32_t read_RAM_array(const size_t ram_id, const uint32_t index_witness) - { - return circuit_constructor.read_RAM_array(ram_id, index_witness); - }; - void write_RAM_array(const size_t ram_id, const uint32_t index_witness, const uint32_t value_witness) - { - circuit_constructor.write_RAM_array(ram_id, index_witness, value_witness); - }; - - void create_range_constraint(const uint32_t variable_index, - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - circuit_constructor.create_range_constraint(variable_index, num_bits, msg); - } - - std::array decompose_non_native_field_double_width_limb( - const uint32_t limb_idx, - const size_t num_limb_bits = (2 * UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)) - { - return circuit_constructor.decompose_non_native_field_double_width_limb(limb_idx, num_limb_bits); - } - - using add_simple = proof_system::UltraCircuitConstructor::add_simple; - std::array evaluate_non_native_field_subtraction( - add_simple limb0, - add_simple limb1, - add_simple limb2, - add_simple limb3, - std::tuple limbp) - { - return circuit_constructor.evaluate_non_native_field_subtraction(limb0, limb1, limb2, limb3, limbp); - } - std::array evaluate_non_native_field_addition(add_simple limb0, - add_simple limb1, - add_simple limb2, - add_simple limb3, - std::tuple limbp) - { - return circuit_constructor.evaluate_non_native_field_addition(limb0, limb1, limb2, limb3, limbp); - }; - - std::array queue_partial_non_native_field_multiplication( - const proof_system::UltraCircuitConstructor::non_native_field_witnesses& input) - { - return circuit_constructor.queue_partial_non_native_field_multiplication(input); - } - - bool failed() const { return circuit_constructor.failed(); }; - const std::string& err() const { return circuit_constructor.err(); }; - void failure(std::string msg) { circuit_constructor.failure(msg); } -}; -using UltraHonkComposer = UltraHonkComposer_; -using UltraGrumpkinHonkComposer = UltraHonkComposer_; - -} // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp index 5daabab7aa3d..392d4a821bc4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/ultra_honk_composer.test.cpp @@ -66,7 +66,6 @@ class UltraHonkComposerTests : public ::testing::Test { TEST_F(UltraHonkComposerTests, ANonZeroPolynomialIsAGoodPolynomial) { auto circuit_constructor = UltraCircuitConstructor(); - circuit_constructor.add_gates_to_ensure_all_polys_are_non_zero(); auto composer = UltraHonkComposerHelper(); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp index 2a55efb057f7..42d9b01f582d 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp @@ -1,10 +1,12 @@ #pragma once -#include "join_split/join_split.hpp" -#include "mock/mock_circuit.hpp" -#include "../constants.hpp" #include #include + +#include "mock/mock_circuit.hpp" +#include "../constants.hpp" +#include "join_split/join_split.hpp" #include "barretenberg/common/timer.hpp" +#include "barretenberg/common/log.hpp" #include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" #ifndef __wasm__ @@ -35,7 +37,7 @@ inline bool exists(std::string const& path) } } // namespace -template +template circuit_data get_circuit_data(std::string const& name, std::string const& path_name, std::shared_ptr const& srs, @@ -46,15 +48,18 @@ circuit_data get_circuit_data(std::string const& name, bool pk, bool vk, bool padding, - bool mock, + bool mock, // TODO(#541) F const& build_circuit, std::string const name_suffix_for_benchmarks = "") { + using Builder = typename Composer::CircuitConstructor; circuit_data data; data.srs = srs; data.mock = mock; - ComposerType composer(srs); - ComposerType mock_proof_composer(srs); + Composer composer(srs); + Builder builder; + Composer mock_proof_composer(srs); + Builder mock_builder; BenchmarkInfoCollator benchmark_collator; auto circuit_key_path = key_path + "/" + path_name; @@ -68,29 +73,23 @@ circuit_data get_circuit_data(std::string const& name, (compute && !load)) { info(name, ": Building circuit..."); Timer timer; - build_circuit(composer); + build_circuit(builder); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), - "Core", - name + name_suffix_for_benchmarks, - "Build time", - timer.toString()); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), - "Core", - name + name_suffix_for_benchmarks, - "Gates", - composer.get_num_gates()); + benchmark_collator.benchmark_info_deferred( + Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Build time", timer.toString()); + benchmark_collator.benchmark_info_deferred( + Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Gates", builder.get_num_gates()); info(name, ": Circuit built in: ", timer.toString(), "s"); - info(name, ": Circuit size: ", composer.get_num_gates()); + info(name, ": Circuit size: ", builder.get_num_gates()); if (mock) { - auto public_inputs = composer.get_public_inputs(); - ::join_split_example::proofs::mock::mock_circuit(mock_proof_composer, public_inputs); - info(name, ": Mock circuit size: ", mock_proof_composer.get_num_gates()); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + auto public_inputs = builder.get_public_inputs(); + ::join_split_example::proofs::mock::mock_circuit(mock_builder, public_inputs); + info(name, ": Mock circuit size: ", mock_builder.get_num_gates()); + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Mock Gates", - composer.get_num_gates()); + builder.get_num_gates()); } } @@ -113,30 +112,26 @@ circuit_data get_circuit_data(std::string const& name, std::make_shared(std::move(pk_data), srs->get_prover_crs(pk_data.circuit_size + 1)); data.num_gates = pk_data.circuit_size; info(name, ": Circuit size 2^n: ", data.num_gates); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), - "Core", - name + name_suffix_for_benchmarks, - "Gates 2^n", - data.num_gates); + benchmark_collator.benchmark_info_deferred( + Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Gates 2^n", data.num_gates); } else if (compute) { Timer timer; info(name, ": Computing proving key..."); if (!mock) { - data.num_gates = composer.get_num_gates(); - data.proving_key = composer.compute_proving_key(); + data.num_gates = builder.get_num_gates(); + data.proving_key = composer.compute_proving_key(builder); info(name, ": Circuit size 2^n: ", data.proving_key->circuit_size); - - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Gates 2^n", data.proving_key->circuit_size); } else { - data.num_gates = mock_proof_composer.get_num_gates(); - data.proving_key = mock_proof_composer.compute_proving_key(); + data.num_gates = mock_builder.get_num_gates(); + data.proving_key = mock_proof_composer.compute_proving_key(mock_builder); info(name, ": Mock circuit size 2^n: ", data.proving_key->circuit_size); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Mock Gates 2^n", @@ -144,8 +139,7 @@ circuit_data get_circuit_data(std::string const& name, } info(name, ": Proving key computed in ", timer.toString(), "s"); - - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Proving key computed in", @@ -175,7 +169,7 @@ circuit_data get_circuit_data(std::string const& name, data.verification_key = std::make_shared(std::move(vk_data), data.srs->get_verifier_crs()); info(name, ": Verification key hash: ", data.verification_key->sha256_hash()); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Verification key hash", @@ -185,19 +179,19 @@ circuit_data get_circuit_data(std::string const& name, Timer timer; if (!mock) { - data.verification_key = composer.compute_verification_key(); + data.verification_key = composer.compute_verification_key(builder); } else { - data.verification_key = mock_proof_composer.compute_verification_key(); + data.verification_key = mock_proof_composer.compute_verification_key(mock_builder); } info(name, ": Computed verification key in ", timer.toString(), "s"); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Verification key computed in", timer.toString()); info(name, ": Verification key hash: ", data.verification_key->sha256_hash()); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Verification key hash", @@ -222,31 +216,31 @@ circuit_data get_circuit_data(std::string const& name, } else if (data.proving_key) { info(name, ": Computing padding proof..."); - if (composer.failed()) { - info(name, ": Composer logic failed: ", composer.err()); + if (builder.failed()) { + info(name, ": Composer logic failed: ", builder.err()); info(name, ": Warning, padding proof can only be used to aid upstream pk construction!"); } Timer timer; if (!mock) { - auto prover = composer.create_prover(); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; - data.num_gates = composer.get_num_gates(); + data.num_gates = builder.get_num_gates(); info(name, ": Circuit size: ", data.num_gates); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_verifier(builder); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } else { - auto prover = mock_proof_composer.create_prover(); + auto prover = mock_proof_composer.create_prover(mock_builder); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; - data.num_gates = mock_proof_composer.get_num_gates(); + data.num_gates = mock_builder.get_num_gates(); info(name, ": Mock circuit size: ", data.num_gates); - auto verifier = mock_proof_composer.create_verifier(); + auto verifier = mock_proof_composer.create_verifier(mock_builder); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } info(name, ": Padding proof computed in ", timer.toString(), "s"); - benchmark_collator.benchmark_info_deferred(GET_COMPOSER_NAME_STRING(proof_system::ComposerType), + benchmark_collator.benchmark_info_deferred(Composer::NAME_STRING, "Core", name + name_suffix_for_benchmarks, "Padding proof computed in", diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp index 402ac96af5d0..b92bf13c73be 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/compute_circuit_data.cpp @@ -63,9 +63,9 @@ circuit_data get_circuit_data(std::shared_ptr( diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp index 03539185f60a..dddc0b91d641 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp @@ -10,14 +10,15 @@ namespace join_split { inline std::vector create_proof(join_split_tx const& tx, circuit_data const& cd) { - Composer composer = Composer(cd.proving_key, cd.verification_key, cd.num_gates); - join_split_circuit(composer, tx); + Builder builder(cd.num_gates); + join_split_circuit(builder, tx); - if (composer.failed()) { - info("Join-split circuit logic failed: ", composer.err()); + if (builder.failed()) { + info("Join-split circuit logic failed: ", builder.err()); } - auto prover = composer.create_prover(); + Composer composer = Composer(cd.proving_key, cd.verification_key); + auto prover = composer.create_prover(builder); auto proof = prover.construct_proof(); return proof.proof_data; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp index 96e504c9f697..c6e7789c1114 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp @@ -24,15 +24,16 @@ void init_proving_key(std::shared_ptr join_split_tx tx = noop_tx(); if (!mock) { + Builder builder; + join_split_circuit(builder, tx); Composer composer(crs_factory); - join_split_circuit(composer, tx); - proving_key = composer.compute_proving_key(); + proving_key = composer.compute_proving_key(builder); } else { - Composer composer; - join_split_circuit(composer, tx); - Composer mock_proof_composer(crs_factory); - join_split_example::proofs::mock::mock_circuit(mock_proof_composer, composer.get_public_inputs()); - proving_key = mock_proof_composer.compute_proving_key(); + Builder builder; + join_split_circuit(builder, tx); + Composer composer(crs_factory); + join_split_example::proofs::mock::mock_circuit(builder, builder.get_public_inputs()); + proving_key = composer.compute_proving_key(builder); } } @@ -55,24 +56,25 @@ void init_verification_key(std::shared_ptr class join_split : public testing::Test { - - protected: - join_split_example::fixtures::user_context user; - std::unique_ptr store; - std::unique_ptr> tree; - - virtual void SetUp() - { - store = std::make_unique(); - tree = std::make_unique>(*store, 32); - user = join_split_example::fixtures::create_user_context(); - } - - public: - /** - * Return a join split tx with 0-valued input notes. - */ - join_split_tx zero_input_setup() - { - using namespace join_split_example::proofs::notes::native; - - value::value_note input_note1 = { - 0, 0, false, user.owner.public_key, user.note_secret, 0, fr::random_element() - }; - value::value_note input_note2 = { - 0, 0, false, user.owner.public_key, user.note_secret, 0, fr::random_element() - }; - auto input_nullifier1 = compute_nullifier(input_note1.commit(), user.owner.private_key, false); - auto input_nullifier2 = compute_nullifier(input_note2.commit(), user.owner.private_key, false); - value::value_note output_note1 = { 0, 0, false, user.owner.public_key, user.note_secret, 0, input_nullifier1 }; - value::value_note output_note2 = { 0, 0, false, user.owner.public_key, user.note_secret, 0, input_nullifier2 }; - - join_split_tx tx; - tx.proof_id = ProofIds::SEND; - tx.public_value = 0; - tx.public_owner = 0; - tx.asset_id = 0; - tx.num_input_notes = 0; - tx.input_index = { 0, 1 }; - tx.old_data_root = tree->root(); - tx.input_path = { tree->get_hash_path(0), tree->get_hash_path(1) }; - tx.input_note = { input_note1, input_note2 }; - tx.output_note = { output_note1, output_note2 }; - tx.partial_claim_note.input_nullifier = 0; - tx.account_private_key = user.owner.private_key; - tx.alias_hash = join_split_example::fixtures::generate_alias_hash("penguin"); - tx.account_required = false; - tx.account_note_index = 0; - tx.account_note_path = tree->get_hash_path(0); - tx.signing_pub_key = user.signing_keys[0].public_key; - tx.backward_link = 0; - tx.allow_chain = 0; - return tx; - } -}; - -using ComposerTypes = testing::Types; - -TYPED_TEST_SUITE(join_split, ComposerTypes); - -// This is derived from the Aztec Connect test -// join_split_tests.test_deposit_construct_proof -TYPED_TEST(join_split, deposit) -{ - join_split_tx tx = TestFixture::zero_input_setup(); - tx.proof_id = ProofIds::DEPOSIT; - tx.public_value = 10; - tx.public_owner = fr::random_element(); - tx.output_note[0].value = 7; - - /** - * DEPOSIT tx represents: - * - public_value = 10 - * - out1 = 7 - * - fee = 3 - */ - - // sign_and_create_proof - tx.signature = sign_join_split_tx(tx, TestFixture::user.owner); - - auto composer = Composer(); - join_split_circuit(composer, tx); - - BenchmarkInfoCollator benchmark_collator; - Timer timer; - auto prover = composer.create_prover(); - auto build_time = timer.toString(); - benchmark_collator.benchmark_info_deferred( - GET_COMPOSER_NAME_STRING(Composer::type), "Core", "join split", "Build time", build_time); - - auto proof = prover.construct_proof(); - - auto verifier = composer.create_verifier(); - bool verified = verifier.verify_proof(proof); - - ASSERT_TRUE(verified); -} - /* Old join-split tests below. The value of having all of these logic tests is unclear, but we'll leave them around, at least for a while. */ @@ -388,12 +286,12 @@ class join_split_tests : public ::testing::Test { verify_result verify_logic(join_split_tx& tx) { - Composer composer(get_proving_key(), nullptr); - join_split_circuit(composer, tx); - if (composer.failed()) { - std::cout << "Logic failed: " << composer.err() << std::endl; + Builder builder; + join_split_circuit(builder, tx); + if (builder.failed()) { + std::cout << "Logic failed: " << builder.err() << std::endl; } - return { !composer.failed(), composer.err(), composer.get_public_inputs(), composer.get_num_gates() }; + return { !builder.failed(), builder.err(), builder.get_public_inputs(), builder.get_num_gates() }; } verify_result sign_and_verify_logic(join_split_tx& tx, key_pair const& signing_key) @@ -825,7 +723,7 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change) // For the next power of two limit, we need to consider that we reserve four gates for adding // randomness/zero-knowledge - EXPECT_LE(number_of_gates_js, GATES_NEXT_POWER_OF_TWO - Composer::ComposerHelper::NUM_RESERVED_GATES) + EXPECT_LE(number_of_gates_js, GATES_NEXT_POWER_OF_TWO - Composer::NUM_RESERVED_GATES) << "You have exceeded the next power of two limit for the join_split circuit."; } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp index c93f887947c0..4efa78f2d58a 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.cpp @@ -269,39 +269,39 @@ join_split_outputs join_split_circuit_component(join_split_inputs const& inputs) public_asset_id, tx_fee, bridge_call_data, defi_deposit_value }; } -void join_split_circuit(Composer& composer, join_split_tx const& tx) +void join_split_circuit(Builder& builder, join_split_tx const& tx) { join_split_inputs inputs = { - .proof_id = witness_ct(&composer, tx.proof_id), - .public_value = suint_ct(witness_ct(&composer, tx.public_value), NOTE_VALUE_BIT_LENGTH, "public_value"), - .public_owner = witness_ct(&composer, tx.public_owner), - .asset_id = suint_ct(witness_ct(&composer, tx.asset_id), ASSET_ID_BIT_LENGTH, "asset_id"), - .num_input_notes = witness_ct(&composer, tx.num_input_notes), - .input_note1_index = suint_ct(witness_ct(&composer, tx.input_index[0]), DATA_TREE_DEPTH, "input_index0"), - .input_note2_index = suint_ct(witness_ct(&composer, tx.input_index[1]), DATA_TREE_DEPTH, "input_index1"), - .input_note1 = value::witness_data(composer, tx.input_note[0]), - .input_note2 = value::witness_data(composer, tx.input_note[1]), - .output_note1 = value::witness_data(composer, tx.output_note[0]), - .output_note2 = value::witness_data(composer, tx.output_note[1]), + .proof_id = witness_ct(&builder, tx.proof_id), + .public_value = suint_ct(witness_ct(&builder, tx.public_value), NOTE_VALUE_BIT_LENGTH, "public_value"), + .public_owner = witness_ct(&builder, tx.public_owner), + .asset_id = suint_ct(witness_ct(&builder, tx.asset_id), ASSET_ID_BIT_LENGTH, "asset_id"), + .num_input_notes = witness_ct(&builder, tx.num_input_notes), + .input_note1_index = suint_ct(witness_ct(&builder, tx.input_index[0]), DATA_TREE_DEPTH, "input_index0"), + .input_note2_index = suint_ct(witness_ct(&builder, tx.input_index[1]), DATA_TREE_DEPTH, "input_index1"), + .input_note1 = value::witness_data(builder, tx.input_note[0]), + .input_note2 = value::witness_data(builder, tx.input_note[1]), + .output_note1 = value::witness_data(builder, tx.output_note[0]), + .output_note2 = value::witness_data(builder, tx.output_note[1]), // Construction of partial_claim_note_witness_data includes construction of bridge_call_data, which contains // many constraints on the bridge_call_data's format and the bit_config's format: - .partial_claim_note = claim::partial_claim_note_witness_data(composer, tx.partial_claim_note), - .signing_pub_key = stdlib::create_point_witness(composer, tx.signing_pub_key), - .signature = stdlib::schnorr::convert_signature(&composer, tx.signature), - .merkle_root = witness_ct(&composer, tx.old_data_root), - .input_path1 = stdlib::merkle_tree::create_witness_hash_path(composer, tx.input_path[0]), - .input_path2 = stdlib::merkle_tree::create_witness_hash_path(composer, tx.input_path[1]), + .partial_claim_note = claim::partial_claim_note_witness_data(builder, tx.partial_claim_note), + .signing_pub_key = stdlib::create_point_witness(builder, tx.signing_pub_key), + .signature = stdlib::schnorr::convert_signature(&builder, tx.signature), + .merkle_root = witness_ct(&builder, tx.old_data_root), + .input_path1 = stdlib::merkle_tree::create_witness_hash_path(builder, tx.input_path[0]), + .input_path2 = stdlib::merkle_tree::create_witness_hash_path(builder, tx.input_path[1]), .account_note_index = - suint_ct(witness_ct(&composer, tx.account_note_index), DATA_TREE_DEPTH, "account_note_index"), - .account_note_path = merkle_tree::create_witness_hash_path(composer, tx.account_note_path), - .account_private_key = witness_ct(&composer, static_cast(tx.account_private_key)), - .alias_hash = suint_ct(witness_ct(&composer, tx.alias_hash), ALIAS_HASH_BIT_LENGTH, "alias_hash"), - .account_required = bool_ct(witness_ct(&composer, tx.account_required)), - .backward_link = witness_ct(&composer, tx.backward_link), - .allow_chain = witness_ct(&composer, tx.allow_chain), + suint_ct(witness_ct(&builder, tx.account_note_index), DATA_TREE_DEPTH, "account_note_index"), + .account_note_path = merkle_tree::create_witness_hash_path(builder, tx.account_note_path), + .account_private_key = witness_ct(&builder, static_cast(tx.account_private_key)), + .alias_hash = suint_ct(witness_ct(&builder, tx.alias_hash), ALIAS_HASH_BIT_LENGTH, "alias_hash"), + .account_required = bool_ct(witness_ct(&builder, tx.account_required)), + .backward_link = witness_ct(&builder, tx.backward_link), + .allow_chain = witness_ct(&builder, tx.allow_chain), }; auto outputs = join_split_circuit_component(inputs); - const field_ct defi_root = witness_ct(&composer, 0); + const field_ct defi_root = witness_ct(&builder, 0); defi_root.assert_is_zero(); // The following make up the public inputs to the circuit. diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp index bde45a710c37..5ae3e23ed632 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split_circuit.hpp @@ -50,7 +50,7 @@ struct join_split_outputs { join_split_outputs join_split_circuit_component(join_split_inputs const& inputs); -void join_split_circuit(Composer& composer, join_split_tx const& tx); +void join_split_circuit(Builder& builder, join_split_tx const& tx); } // namespace join_split } // namespace proofs diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.hpp index 05e99f612ab1..ba299de9ca9b 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.hpp @@ -8,14 +8,14 @@ namespace mock { using namespace proof_system::plonk::stdlib; -template void mock_circuit(Composer& composer, std::vector const& public_inputs_) +template void mock_circuit(Builder& builder, std::vector const& public_inputs_) { - const auto public_inputs = map(public_inputs_, [&](auto& i) { return field_t(witness_t(&composer, i)); }); + const auto public_inputs = map(public_inputs_, [&](auto& i) { return field_t(witness_t(&builder, i)); }); for (auto& p : public_inputs) { p.set_public(); } - plonk::stdlib::pedersen_commitment::compress(field_t(witness_t(&composer, 1)), - field_t(witness_t(&composer, 1))); + plonk::stdlib::pedersen_commitment::compress(field_t(witness_t(&builder, 1)), + field_t(witness_t(&builder, 1))); } } // namespace mock diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp index f8ea94116736..c1f49ad7a01a 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/bridge_call_data.hpp @@ -37,14 +37,14 @@ struct bridge_call_data { bool_ct second_output_in_use; bit_config(){}; - bit_config(Composer* composer, uint256_t const& bridge_call_data) + bit_config(Builder* builder, uint256_t const& bridge_call_data) { - ASSERT(composer != nullptr); + ASSERT(builder != nullptr); constexpr auto bitconfig_mask = (1ULL << DEFI_BRIDGE_BITCONFIG_LEN) - 1; uint32_t config_u32 = uint32_t((bridge_call_data >> bitconfig_shift) & bitconfig_mask); - second_input_in_use = witness_ct(composer, config_u32 & 1ULL); - second_output_in_use = witness_ct(composer, (config_u32 >> 1) & 1ULL); + second_input_in_use = witness_ct(builder, config_u32 & 1ULL); + second_output_in_use = witness_ct(builder, (config_u32 >> 1) & 1ULL); } suint_ct to_suint() const @@ -88,11 +88,11 @@ struct bridge_call_data { suint_ct aux_data = 0; bridge_call_data(){}; - bridge_call_data(Composer* composer, const native::bridge_call_data& native_id) - : bridge_call_data(composer, native_id.to_uint256_t()) + bridge_call_data(Builder* builder, const native::bridge_call_data& native_id) + : bridge_call_data(builder, native_id.to_uint256_t()) {} - bridge_call_data(Composer* composer, uint256_t const& bridge_call_data) + bridge_call_data(Builder* builder, uint256_t const& bridge_call_data) { // constants constexpr auto one = uint256_t(1); @@ -109,18 +109,18 @@ struct bridge_call_data { auto aux_data_value = (bridge_call_data >> aux_data_shift) & uint256_t((one << DEFI_BRIDGE_AUX_DATA) - 1); bridge_address_id = - suint_ct(witness_ct(composer, bridge_address_id_value), DEFI_BRIDGE_ADDRESS_ID_LEN, "bridge_address"); - input_asset_id_a = suint_ct( - witness_ct(composer, input_asset_id_a_value), DEFI_BRIDGE_INPUT_A_ASSET_ID_LEN, "input_asset_id_a"); - input_asset_id_b = suint_ct( - witness_ct(composer, input_asset_id_b_value), DEFI_BRIDGE_INPUT_B_ASSET_ID_LEN, "input_asset_id_b"); + suint_ct(witness_ct(builder, bridge_address_id_value), DEFI_BRIDGE_ADDRESS_ID_LEN, "bridge_address"); + input_asset_id_a = + suint_ct(witness_ct(builder, input_asset_id_a_value), DEFI_BRIDGE_INPUT_A_ASSET_ID_LEN, "input_asset_id_a"); + input_asset_id_b = + suint_ct(witness_ct(builder, input_asset_id_b_value), DEFI_BRIDGE_INPUT_B_ASSET_ID_LEN, "input_asset_id_b"); output_asset_id_a = suint_ct( - witness_ct(composer, output_asset_id_a_value), DEFI_BRIDGE_OUTPUT_A_ASSET_ID_LEN, "output_asset_id_a"); + witness_ct(builder, output_asset_id_a_value), DEFI_BRIDGE_OUTPUT_A_ASSET_ID_LEN, "output_asset_id_a"); output_asset_id_b = suint_ct( - witness_ct(composer, output_asset_id_b_value), DEFI_BRIDGE_OUTPUT_B_ASSET_ID_LEN, "output_asset_id_b"); - aux_data = suint_ct(witness_ct(composer, aux_data_value), DEFI_BRIDGE_AUX_DATA, "aux_data"); + witness_ct(builder, output_asset_id_b_value), DEFI_BRIDGE_OUTPUT_B_ASSET_ID_LEN, "output_asset_id_b"); + aux_data = suint_ct(witness_ct(builder, aux_data_value), DEFI_BRIDGE_AUX_DATA, "aux_data"); - config = bit_config(composer, bridge_call_data); + config = bit_config(builder, bridge_call_data); validate_bit_config(); } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp index e5fc35fb39a4..e1bebb5e6d7b 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/claim/witness_data.hpp @@ -26,7 +26,7 @@ struct claim_note_witness_data { field_ct value_note_partial_commitment; field_ct input_nullifier; - claim_note_witness_data(Composer& composer, native::claim::claim_note const& note_data) + claim_note_witness_data(Builder& composer, native::claim::claim_note const& note_data) { deposit_value = suint_ct(witness_ct(&composer, note_data.deposit_value), DEFI_DEPOSIT_VALUE_BIT_LENGTH, "deposit_value"); @@ -51,7 +51,7 @@ struct partial_claim_note_witness_data { field_ct input_nullifier; partial_claim_note_witness_data(){}; - partial_claim_note_witness_data(Composer& composer, native::claim::partial_claim_note_data const& note_data) + partial_claim_note_witness_data(Builder& composer, native::claim::partial_claim_note_data const& note_data) { deposit_value = suint_ct(witness_ct(&composer, note_data.deposit_value), DEFI_DEPOSIT_VALUE_BIT_LENGTH, "deposit_value"); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp index 88198aa7c56e..906a12bd9970 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/compute_nullifier.test.cpp @@ -18,11 +18,11 @@ TEST(compute_nullifier_circuit, native_consistency) native::value::value_note{ 100, 0, 0, user.owner.public_key, user.note_secret, 0, fr::random_element() }; auto native_commitment = native_input_note.commit(); auto native_nullifier = native::compute_nullifier(native_commitment, priv_key, true); - Composer composer; - auto circuit_witness_data = circuit::value::witness_data(composer, native_input_note); + Builder builder; + auto circuit_witness_data = circuit::value::witness_data(builder, native_input_note); auto circuit_input_note = circuit::value::value_note(circuit_witness_data); auto circuit_nullifier = circuit::compute_nullifier( - circuit_input_note.commitment, field_ct(witness_ct(&composer, priv_key)), bool_ct(witness_ct(&composer, true))); + circuit_input_note.commitment, field_ct(witness_ct(&builder, priv_key)), bool_ct(witness_ct(&builder, true))); EXPECT_EQ(circuit_nullifier.get_value(), native_nullifier); } diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp index 55b65c994951..92ada18413fb 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp @@ -13,7 +13,7 @@ using namespace join_split_example::proofs::notes::circuit::value; TEST(value_note, commits) { auto user = join_split_example::fixtures::create_user_context(); - Composer composer = Composer(); + auto builder = Builder(); fr note_value = fr::random_element(); note_value.data[3] = note_value.data[3] & 0x0FFFFFFFFFFFFFFFULL; @@ -26,16 +26,17 @@ TEST(value_note, commits) note_value, asset_id_value, account_required, user.owner.public_key, user.note_secret, 0, fr::random_element() }; auto expected = note.commit(); - auto circuit_note = circuit::value::value_note(witness_data(composer, note)); + auto circuit_note = circuit::value::value_note(witness_data(builder, note)); auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + auto composer = Composer(); + auto prover = composer.create_prover(builder); - EXPECT_FALSE(composer.failed()); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + EXPECT_FALSE(builder.failed()); + printf("composer gates = %zu\n", builder.get_num_gates()); + auto verifier = composer.create_verifier(builder); plonk::proof proof = prover.construct_proof(); @@ -45,8 +46,9 @@ TEST(value_note, commits) TEST(value_note, commits_with_0_value) { + auto builder = Builder(); + auto user = join_split_example::fixtures::create_user_context(); - Composer composer = Composer(); uint32_t asset_id_value = 0x2abbccddULL; // needs to be less than 30 bits @@ -60,16 +62,18 @@ TEST(value_note, commits_with_0_value) .input_nullifier = fr::random_element(), }; auto expected = note.commit(); - auto circuit_note = circuit::value::value_note(witness_data(composer, note)); + auto circuit_note = circuit::value::value_note(witness_data(builder, note)); auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + Composer composer = Composer(); + + auto prover = composer.create_prover(builder); - EXPECT_FALSE(composer.failed()); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + EXPECT_FALSE(builder.failed()); + printf("composer gates = %zu\n", builder.get_num_gates()); + auto verifier = composer.create_verifier(builder); plonk::proof proof = prover.construct_proof(); @@ -79,8 +83,9 @@ TEST(value_note, commits_with_0_value) TEST(value_note, commit_with_oversized_asset_id_fails) { + auto builder = Builder(); + auto user = join_split_example::fixtures::create_user_context(); - Composer composer = Composer(); native::value::value_note note = { .value = 0, @@ -92,16 +97,17 @@ TEST(value_note, commit_with_oversized_asset_id_fails) .input_nullifier = fr::random_element(), }; auto expected = note.commit(); - auto circuit_note = circuit::value::value_note(witness_data(composer, note)); + auto circuit_note = circuit::value::value_note(witness_data(builder, note)); auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + Composer composer = Composer(); + auto prover = composer.create_prover(builder); - EXPECT_TRUE(composer.failed()); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + EXPECT_TRUE(builder.failed()); + printf("composer gates = %zu\n", builder.get_num_gates()); + auto verifier = composer.create_verifier(builder); plonk::proof proof = prover.construct_proof(); diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp index 367f0e704ee9..80e47ebf635b 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/witness_data.hpp @@ -19,16 +19,16 @@ struct witness_data { field_ct creator_pubkey; field_ct input_nullifier; - witness_data(Composer& composer, native::value::value_note const& note) + witness_data(Builder& builder, native::value::value_note const& note) { - secret = witness_ct(&composer, note.secret); - owner.x = witness_ct(&composer, note.owner.x); - owner.y = witness_ct(&composer, note.owner.y); - value = suint_ct(witness_ct(&composer, note.value), NOTE_VALUE_BIT_LENGTH, "note_value"); - asset_id = suint_ct(witness_ct(&composer, note.asset_id), ASSET_ID_BIT_LENGTH, "asset_id"); - account_required = bool_ct(witness_ct(&composer, note.account_required)); - creator_pubkey = witness_ct(&composer, note.creator_pubkey); - input_nullifier = witness_ct(&composer, note.input_nullifier); + secret = witness_ct(&builder, note.secret); + owner.x = witness_ct(&builder, note.owner.x); + owner.y = witness_ct(&builder, note.owner.y); + value = suint_ct(witness_ct(&builder, note.value), NOTE_VALUE_BIT_LENGTH, "note_value"); + asset_id = suint_ct(witness_ct(&builder, note.asset_id), ASSET_ID_BIT_LENGTH, "asset_id"); + account_required = bool_ct(witness_ct(&builder, note.account_required)); + creator_pubkey = witness_ct(&builder, note.creator_pubkey); + input_nullifier = witness_ct(&builder, note.input_nullifier); } }; diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/verify.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/verify.hpp index d01b409eddeb..2506e740cb35 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/proofs/verify.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/proofs/verify.hpp @@ -39,17 +39,17 @@ inline bool pairing_check(plonk::stdlib::recursion::aggregation_state -auto verify_logic_internal(Composer& composer, Tx& tx, CircuitData const& cd, char const* name, F const& build_circuit) +template +auto verify_logic_internal(Builder& builder, Tx& tx, CircuitData const& cd, char const* name, F const& build_circuit) { info(name, ": Building circuit..."); Timer timer; - auto result = build_circuit(composer, tx, cd); + auto result = build_circuit(builder, tx, cd); info(name, ": Circuit built in ", timer.toString(), "s"); - if (composer.failed()) { - info(name, ": Circuit logic failed: " + composer.err()); - result.err = composer.err(); + if (builder.failed()) { + info(name, ": Circuit logic failed: " + builder.err()); + result.err = builder.err(); return result; } @@ -63,86 +63,12 @@ auto verify_logic_internal(Composer& composer, Tx& tx, CircuitData const& cd, ch return result; } - result.public_inputs = composer.get_public_inputs(); + result.public_inputs = builder.get_public_inputs(); result.logic_verified = true; - result.number_of_gates = composer.get_num_gates(); + result.number_of_gates = builder.get_num_gates(); return result; } -template -auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char const* name, F const& build_circuit) -{ - Timer timer; - auto result = verify_logic_internal(composer, tx, cd, name, build_circuit); - - if (!result.logic_verified) { - return result; - } - - Timer proof_timer; - info(name, ": Creating proof..."); - - if (!cd.mock) { - if constexpr (std::is_same::value) { - if (std::string(name) == "root rollup") { - auto prover = composer.create_ultra_to_standard_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } else { - auto prover = composer.create_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } - } else { - auto prover = composer.create_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } - } else { - Composer mock_proof_composer = Composer(cd.proving_key, cd.verification_key, cd.num_gates); - ::join_split_example::proofs::mock::mock_circuit(mock_proof_composer, composer.get_public_inputs()); - if constexpr (std::is_same::value) { - if (std::string(name) == "root rollup") { - auto prover = mock_proof_composer.create_ultra_to_standard_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } else { - auto prover = mock_proof_composer.create_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } - } else { - auto prover = mock_proof_composer.create_prover(); - auto proof = prover.construct_proof(); - result.proof_data = proof.proof_data; - } - } - - info(name, ": Proof created in ", proof_timer.toString(), "s"); - info(name, ": Total time taken: ", timer.toString(), "s"); - if constexpr (std::is_same::value) { - if (std::string(name) == "root rollup") { - auto verifier = composer.create_ultra_to_standard_verifier(); - result.verified = verifier.verify_proof({ result.proof_data }); - } else { - auto verifier = composer.create_verifier(); - result.verified = verifier.verify_proof({ result.proof_data }); - } - } else { - auto verifier = composer.create_verifier(); - result.verified = verifier.verify_proof({ result.proof_data }); - } - - if (!result.verified) { - info(name, ": Proof validation failed."); - return result; - } else { - info(name, ": Verified successfully."); - } - result.verification_key = composer.circuit_verification_key; - return result; -} - } // namespace proofs } // namespace join_split_example diff --git a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp index 3ff15138e5c4..945aded7e990 100644 --- a/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp +++ b/barretenberg/cpp/src/barretenberg/join_split_example/types.hpp @@ -1,9 +1,9 @@ #pragma once -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" +#include "barretenberg/honk/composer/composer_helper/ultra_honk_composer_helper.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/stdlib/primitives/bool/bool.hpp" @@ -18,34 +18,35 @@ namespace join_split_example { -using Composer = plonk::UltraPlonkComposer; +using Builder = proof_system::UltraCircuitConstructor; +using Composer = plonk::UltraPlonkComposerHelper; using Prover = std::conditional_t< - std::same_as, + std::same_as, plonk::UltraProver, - std::conditional_t, plonk::TurboProver, plonk::Prover>>; + std::conditional_t, plonk::TurboProver, plonk::Prover>>; using Verifier = std::conditional_t< - std::same_as, + std::same_as, plonk::UltraVerifier, - std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; - -using witness_ct = proof_system::plonk::stdlib::witness_t; -using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; -using bool_ct = proof_system::plonk::stdlib::bool_t; -using byte_array_ct = proof_system::plonk::stdlib::byte_array; -using field_ct = proof_system::plonk::stdlib::field_t; -using suint_ct = proof_system::plonk::stdlib::safe_uint_t; -using uint32_ct = proof_system::plonk::stdlib::uint32; -using point_ct = proof_system::plonk::stdlib::point; -using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; -using group_ct = proof_system::plonk::stdlib::group; -using bn254 = proof_system::plonk::stdlib::bn254; - -using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; + std::conditional_t, plonk::TurboVerifier, plonk::Verifier>>; + +using witness_ct = proof_system::plonk::stdlib::witness_t; +using public_witness_ct = proof_system::plonk::stdlib::public_witness_t; +using bool_ct = proof_system::plonk::stdlib::bool_t; +using byte_array_ct = proof_system::plonk::stdlib::byte_array; +using field_ct = proof_system::plonk::stdlib::field_t; +using suint_ct = proof_system::plonk::stdlib::safe_uint_t; +using uint32_ct = proof_system::plonk::stdlib::uint32; +using point_ct = proof_system::plonk::stdlib::point; +using pedersen_commitment = proof_system::plonk::stdlib::pedersen_commitment; +using group_ct = proof_system::plonk::stdlib::group; +using bn254 = proof_system::plonk::stdlib::bn254; + +using hash_path_ct = proof_system::plonk::stdlib::merkle_tree::hash_path; namespace schnorr { -using signature_bits = proof_system::plonk::stdlib::schnorr::signature_bits; +using signature_bits = proof_system::plonk::stdlib::schnorr::signature_bits; } // namespace schnorr } // namespace join_split_example \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp index 82273ebda0c7..ec93293e9494 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp @@ -17,6 +17,8 @@ class StandardPlonkComposerHelper { public: using Flavor = plonk::flavor::Standard; using CircuitConstructor = StandardCircuitConstructor; + + static constexpr std::string_view NAME_STRING = "StandardPlonk"; static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of evaluations leaked static constexpr size_t program_width = CircuitConstructor::program_width; std::shared_ptr circuit_proving_key; diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp index 79bd7015e877..123271db7330 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp @@ -14,6 +14,7 @@ class TurboPlonkComposerHelper { using Flavor = plonk::flavor::Turbo; using CircuitConstructor = TurboCircuitConstructor; + static constexpr std::string_view NAME_STRING = "TurboPlonk"; static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of evaluations leaked static constexpr size_t program_width = CircuitConstructor::program_width; @@ -58,6 +59,7 @@ class TurboPlonkComposerHelper { }; return result; } + static transcript::Manifest create_manifest(const size_t num_public_inputs) { // add public inputs.... diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp index 8417a9f2e058..170a151aabb0 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp @@ -18,6 +18,8 @@ class UltraPlonkComposerHelper { using Flavor = flavor::Ultra; using CircuitConstructor = UltraCircuitConstructor; + static constexpr std::string_view NAME_STRING = "UltraPlonk"; + static constexpr ComposerType type = ComposerType::PLOOKUP; static constexpr size_t NUM_RESERVED_GATES = 4; // equal to the number of multilinear evaluations leaked static constexpr size_t program_width = CircuitConstructor::NUM_WIRES; std::shared_ptr circuit_proving_key; @@ -101,117 +103,7 @@ class UltraPlonkComposerHelper { */ static transcript::Manifest create_manifest(const size_t num_public_inputs) { - // add public inputs.... - constexpr size_t g1_size = 64; - constexpr size_t fr_size = 32; - const size_t public_input_size = fr_size * num_public_inputs; - transcript::Manifest output = transcript::Manifest( - - { transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier } - { "circuit_size", 4, true }, - { "public_input_size", 4, true } }, - "init", // challenge_name - 1 // num_challenges_in - ), - - transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier } - { "public_inputs", public_input_size, false }, - { "W_1", g1_size, false }, - { "W_2", g1_size, false }, - { "W_3", g1_size, false } }, - "eta", // challenge_name - 1 // num_challenges_in - ), - - transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier } - { "W_4", g1_size, false }, - { "S", g1_size, false } }, - "beta", // challenge_name - 2 // num_challenges_in - ), - - transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier } - { "Z_PERM", g1_size, false }, - { "Z_LOOKUP", g1_size, false } }, - "alpha", // challenge_name - 1 // num_challenges_in - ), - - transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier } - { "T_1", g1_size, false }, - { "T_2", g1_size, false }, - { "T_3", g1_size, false }, - { "T_4", g1_size, false } }, - "z", // challenge_name - 1 // num_challenges_in - ), - - // N.B. THE SHFITED EVALS (_omega) MUST HAVE THE SAME CHALLENGE INDEX AS THE NON SHIFTED VALUES - transcript::Manifest::RoundManifest( - { - // { name, num_bytes, derived_by_verifier, challenge_map_index } - { "t", fr_size, true, -1 }, // * - { "w_1", fr_size, false, 0 }, - { "w_2", fr_size, false, 1 }, - { "w_3", fr_size, false, 2 }, - { "w_4", fr_size, false, 3 }, - { "s", fr_size, false, 4 }, - { "z_perm", fr_size, false, 5 }, // * - { "z_lookup", fr_size, false, 6 }, - { "q_1", fr_size, false, 7 }, - { "q_2", fr_size, false, 8 }, - { "q_3", fr_size, false, 9 }, - { "q_4", fr_size, false, 10 }, - { "q_m", fr_size, false, 11 }, - { "q_c", fr_size, false, 12 }, - { "q_arith", fr_size, false, 13 }, - { "q_sort", fr_size, false, 14 }, // * - { "q_elliptic", fr_size, false, 15 }, // * - { "q_aux", fr_size, false, 16 }, - { "sigma_1", fr_size, false, 17 }, - { "sigma_2", fr_size, false, 18 }, - { "sigma_3", fr_size, false, 19 }, - { "sigma_4", fr_size, false, 20 }, - { "table_value_1", fr_size, false, 21 }, - { "table_value_2", fr_size, false, 22 }, - { "table_value_3", fr_size, false, 23 }, - { "table_value_4", fr_size, false, 24 }, - { "table_type", fr_size, false, 25 }, - { "id_1", fr_size, false, 26 }, - { "id_2", fr_size, false, 27 }, - { "id_3", fr_size, false, 28 }, - { "id_4", fr_size, false, 29 }, - { "w_1_omega", fr_size, false, 0 }, - { "w_2_omega", fr_size, false, 1 }, - { "w_3_omega", fr_size, false, 2 }, - { "w_4_omega", fr_size, false, 3 }, - { "s_omega", fr_size, false, 4 }, - { "z_perm_omega", fr_size, false, 5 }, - { "z_lookup_omega", fr_size, false, 6 }, - { "table_value_1_omega", fr_size, false, 21 }, - { "table_value_2_omega", fr_size, false, 22 }, - { "table_value_3_omega", fr_size, false, 23 }, - { "table_value_4_omega", fr_size, false, 24 }, - }, - "nu", // challenge_name - ULTRA_MANIFEST_SIZE, // num_challenges_in - true // map_challenges_in - ), - - transcript::Manifest::RoundManifest( - { // { name, num_bytes, derived_by_verifier, challenge_map_index } - { "PI_Z", g1_size, false }, - { "PI_Z_OMEGA", g1_size, false } }, - "separator", // challenge_name - 3 // num_challenges_in - ) }); - - return output; + return Flavor::create_manifest(num_public_inputs); } }; diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_plonk_composer.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/standard_plonk_composer.hpp deleted file mode 100644 index fcb2dfaf8303..000000000000 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/standard_plonk_composer.hpp +++ /dev/null @@ -1,253 +0,0 @@ -#pragma once - -#include "composer_helper/standard_plonk_composer_helper.hpp" -#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" -#include "barretenberg/transcript/manifest.hpp" -#include "barretenberg/proof_system/types/merkle_hash_type.hpp" -#include "barretenberg/proof_system/types/pedersen_commitment_type.hpp" - -namespace proof_system::plonk { -/** - * @brief Standard Plonk Composer has everything required to construct a prover and verifier, just as the legacy - * classes. - * - * @details However, it has a lot of its logic separated into subclasses and simply proxies the calls. - * - */ -class StandardPlonkComposer { - public: - using ComposerHelper = StandardPlonkComposerHelper; - using CircuitConstructor = StandardCircuitConstructor; - - static constexpr ComposerType type = ComposerType::STANDARD; - static_assert(type == CircuitConstructor::type); - static constexpr merkle::HashType merkle_hash_type = CircuitConstructor::merkle_hash_type; - static constexpr pedersen::CommitmentType commitment_type = CircuitConstructor::commitment_type; - - static constexpr size_t UINT_LOG2_BASE = 2; - // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system - StandardCircuitConstructor circuit_constructor; - - // References to circuit contructor's members for convenience - size_t& num_gates; - std::vector& variables; - // While we always have it set to zero, feels wrong to have a potentially broken dependency - uint32_t& zero_idx; - - // Composer helper contains all proof-related material that is separate from circuit creation such as: - // 1) Proving and verification keys - // 2) CRS - // 3) Converting variables to witness vectors/polynomials - StandardPlonkComposerHelper composer_helper; - - // References to composer helper's members for convenience - bool& contains_recursive_proof; - std::vector& recursive_proof_public_input_indices; - - static constexpr size_t program_width = StandardCircuitConstructor::program_width; - - /**Standard methods*/ - - StandardPlonkComposer(const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - StandardPlonkComposer(std::string const& crs_path, const size_t size_hint = 0) - : StandardPlonkComposer(std::unique_ptr( - new barretenberg::srs::factories::FileCrsFactory(crs_path)), - size_hint){}; - - StandardPlonkComposer(std::shared_ptr const& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(crs_factory) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices) - - {} - StandardPlonkComposer(std::unique_ptr&& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(std::move(crs_factory)) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices) - - {} - - StandardPlonkComposer(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(p_key, v_key) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices) - {} - - StandardPlonkComposer(const StandardPlonkComposer& other) = delete; - StandardPlonkComposer(StandardPlonkComposer&& other) - : circuit_constructor(std::move(other.circuit_constructor)) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(std::move(other.composer_helper)) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - StandardPlonkComposer& operator=(StandardPlonkComposer&& other) - { - circuit_constructor = std::move(other.circuit_constructor); - composer_helper = std::move(other.composer_helper); - num_gates = circuit_constructor.num_gates; - variables = circuit_constructor.variables; - zero_idx = circuit_constructor.zero_idx; - contains_recursive_proof = circuit_constructor.contains_recursive_proof; - recursive_proof_public_input_indices = circuit_constructor.recursive_proof_public_input_indices; - return *this; - }; - // TODO(#230)(Cody): This constructor started to be implicitly deleted when I added `n` and `variables` members. - // This is a temporary measure until we can rewrite Plonk and all tests using circuit builder methods in place of - // composer methods, where appropriate. StandardPlonkComposer& operator=(StandardPlonkComposer&& other) = default; - ~StandardPlonkComposer() = default; - - size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } - - /**Methods related to circuit construction - * They simply get proxied to the circuit constructor - */ - void assert_equal(const uint32_t a_variable_idx, const uint32_t b_variable_idx, std::string const& msg) - { - circuit_constructor.assert_equal(a_variable_idx, b_variable_idx, msg); - } - void assert_equal_constant(uint32_t const a_idx, - barretenberg::fr const& b, - std::string const& msg = "assert equal constant") - { - circuit_constructor.assert_equal_constant(a_idx, b, msg); - } - - void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); } - void create_mul_gate(const mul_triple& in) { circuit_constructor.create_mul_gate(in); } - void create_bool_gate(const uint32_t a) { circuit_constructor.create_bool_gate(a); } - void create_poly_gate(const poly_triple& in) { circuit_constructor.create_poly_gate(in); } - void create_big_add_gate(const add_quad& in) { circuit_constructor.create_big_add_gate(in); } - void create_big_add_gate_with_bit_extraction(const add_quad& in) - { - circuit_constructor.create_big_add_gate_with_bit_extraction(in); - } - void create_big_mul_gate(const mul_quad& in) { circuit_constructor.create_big_mul_gate(in); } - void create_balanced_add_gate(const add_quad& in) { circuit_constructor.create_balanced_add_gate(in); } - - void fix_witness(const uint32_t witness_index, const barretenberg::fr& witness_value) - { - circuit_constructor.fix_witness(witness_index, witness_value); - } - - std::vector decompose_into_base4_accumulators(const uint32_t witness_index, - - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - return circuit_constructor.decompose_into_base4_accumulators(witness_index, num_bits, msg); - } - - void create_range_constraint(const uint32_t variable_index, - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - circuit_constructor.create_range_constraint(variable_index, num_bits, msg); - } - - accumulator_triple create_logic_constraint(const uint32_t a, - const uint32_t b, - const size_t num_bits, - bool is_xor_gate) - { - return circuit_constructor.create_logic_constraint(a, b, num_bits, is_xor_gate); - } - - accumulator_triple create_and_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_and_constraint(a, b, num_bits); - } - - accumulator_triple create_xor_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_xor_constraint(a, b, num_bits); - } - uint32_t add_variable(const barretenberg::fr& in) { return circuit_constructor.add_variable(in); } - - uint32_t add_public_variable(const barretenberg::fr& in) { return circuit_constructor.add_public_variable(in); } - - virtual void set_public_input(const uint32_t witness_index) - { - return circuit_constructor.set_public_input(witness_index); - } - - uint32_t put_constant_variable(const barretenberg::fr& variable) - { - return circuit_constructor.put_constant_variable(variable); - } - - size_t get_num_constant_gates() const { return circuit_constructor.get_num_constant_gates(); } - - bool check_circuit() { return circuit_constructor.check_circuit(); } - - barretenberg::fr get_variable(const uint32_t index) const { return circuit_constructor.get_variable(index); } - - std::vector get_public_inputs() const { return circuit_constructor.get_public_inputs(); } - - /**Proof and verification-related methods*/ - - std::shared_ptr compute_proving_key() - { - return composer_helper.compute_proving_key(circuit_constructor); - } - - std::shared_ptr compute_verification_key() - { - return composer_helper.compute_verification_key(circuit_constructor); - } - - void compute_witness() { composer_helper.compute_witness(circuit_constructor); }; - // TODO(#230)(Cody): This will not be needed, but maybe something is required for ComposerHelper to be generic? - plonk::Verifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); } - /** - * Preprocess the circuit. Delegates to create_prover. - * - * @return A new initialized prover. - */ - /** - * Preprocess the circuit. Delegates to create_unrolled_prover. - * - * @return A new initialized prover. - */ - plonk::Prover create_prover() { return composer_helper.create_prover(circuit_constructor); }; - - static transcript::Manifest create_manifest(const size_t num_public_inputs) - { - return StandardPlonkComposerHelper::create_manifest(num_public_inputs); - } - - void add_recursive_proof(const std::vector& proof_output_witness_indices) - { - circuit_constructor.add_recursive_proof(proof_output_witness_indices); - } - bool failed() const { return circuit_constructor.failed(); }; - const std::string& err() const { return circuit_constructor.err(); }; - void failure(std::string msg) { circuit_constructor.failure(msg); } -}; -} // namespace proof_system::plonk diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/turbo_plonk_composer.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/turbo_plonk_composer.hpp deleted file mode 100644 index 21a650ecdc4e..000000000000 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/turbo_plonk_composer.hpp +++ /dev/null @@ -1,259 +0,0 @@ -#pragma once -#include "composer_helper/turbo_plonk_composer_helper.hpp" -#include "barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp" -#include "barretenberg/proof_system/types/merkle_hash_type.hpp" -#include "barretenberg/proof_system/types/pedersen_commitment_type.hpp" - -namespace proof_system::plonk { -/** - * @brief Standard Plonk Composer has everything required to construct a prover and verifier, just as the legacy - * classes. - * - * @details However, it has a lot of its logic separated into subclasses and simply proxies the calls. - * - */ -class TurboPlonkComposer { - public: - using ComposerHelper = TurboPlonkComposerHelper; - using CircuitConstructor = TurboCircuitConstructor; - static constexpr ComposerType type = ComposerType::TURBO; - static_assert(type == CircuitConstructor::type); - static constexpr merkle::HashType merkle_hash_type = CircuitConstructor::merkle_hash_type; - static constexpr pedersen::CommitmentType commitment_type = CircuitConstructor::commitment_type; - - static constexpr size_t UINT_LOG2_BASE = 2; - - // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system - TurboCircuitConstructor circuit_constructor; - - // References to circuit constructor's members for convenience - size_t& num_gates; - std::vector& variables; - - // While we always have it set to zero, feels wrong to have a potentially broken dependency - uint32_t& zero_idx; - // Composer helper contains all proof-related material that is separate from circuit creation such as: - // 1) Proving and verification keys - // 2) CRS - // 3) Converting variables to witness vectors/polynomials - TurboPlonkComposerHelper composer_helper; - - // References to composer helper's members for convenience - bool& contains_recursive_proof; - std::vector& recursive_proof_public_input_indices; - - static constexpr size_t program_width = TurboCircuitConstructor::program_width; - - /**Standard methods*/ - - TurboPlonkComposer(const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - TurboPlonkComposer(std::string const& crs_path, const size_t size_hint = 0) - : TurboPlonkComposer(std::unique_ptr( - new barretenberg::srs::factories::FileCrsFactory(crs_path)), - size_hint){}; - - TurboPlonkComposer(std::shared_ptr const& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(crs_factory) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - TurboPlonkComposer(std::unique_ptr&& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(std::move(crs_factory)) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - TurboPlonkComposer(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(p_key, v_key) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - TurboPlonkComposer(const TurboPlonkComposer& other) = delete; - - TurboPlonkComposer(TurboPlonkComposer&& other) - : circuit_constructor(std::move(other.circuit_constructor)) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(std::move(other.composer_helper)) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - TurboPlonkComposer& operator=(TurboPlonkComposer&& other) - { - circuit_constructor = std::move(other.circuit_constructor); - composer_helper = std::move(other.composer_helper); - num_gates = circuit_constructor.num_gates; - variables = circuit_constructor.variables; - zero_idx = circuit_constructor.zero_idx; - contains_recursive_proof = circuit_constructor.contains_recursive_proof; - recursive_proof_public_input_indices = circuit_constructor.recursive_proof_public_input_indices; - return *this; - }; - // TODO(#230)(Cody): This constructor started to be implicitly deleted when I added `n` and `variables` members. - // This is a temporary measure until we can rewrite Plonk and all tests using circuit builder methods in place of - // composer methods, where appropriate. TurboPlonkComposer& operator=(TurboPlonkComposer&& other) = default; - ~TurboPlonkComposer() = default; - - /**Methods related to circuit construction - * They simply get proxied to the circuit constructor - */ - - size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } - - void assert_equal(const uint32_t a_variable_idx, const uint32_t b_variable_idx, std::string const& msg) - { - circuit_constructor.assert_equal(a_variable_idx, b_variable_idx, msg); - } - void assert_equal_constant(uint32_t const a_idx, - barretenberg::fr const& b, - std::string const& msg = "assert equal constant") - { - circuit_constructor.assert_equal_constant(a_idx, b, msg); - } - - void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); } - void create_mul_gate(const mul_triple& in) { circuit_constructor.create_mul_gate(in); } - void create_bool_gate(const uint32_t a) { circuit_constructor.create_bool_gate(a); } - void create_poly_gate(const poly_triple& in) { circuit_constructor.create_poly_gate(in); } - void create_fixed_group_add_gate(const fixed_group_add_quad& in) - { - circuit_constructor.create_fixed_group_add_gate(in); - } - void create_fixed_group_add_gate_with_init(const fixed_group_add_quad& in, const fixed_group_init_quad& init) - { - circuit_constructor.create_fixed_group_add_gate_with_init(in, init); - } - void create_fixed_group_add_gate_final(const add_quad& in) - { - circuit_constructor.create_fixed_group_add_gate_final(in); - } - void create_big_add_gate(const add_quad& in) { circuit_constructor.create_big_add_gate(in); } - void create_big_add_gate_with_bit_extraction(const add_quad& in) - { - circuit_constructor.create_big_add_gate_with_bit_extraction(in); - } - void create_big_mul_gate(const mul_quad& in) { circuit_constructor.create_big_mul_gate(in); } - void create_balanced_add_gate(const add_quad& in) { circuit_constructor.create_balanced_add_gate(in); } - - void fix_witness(const uint32_t witness_index, const barretenberg::fr& witness_value) - { - circuit_constructor.fix_witness(witness_index, witness_value); - } - - std::vector decompose_into_base4_accumulators(const uint32_t witness_index, - - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - return circuit_constructor.decompose_into_base4_accumulators(witness_index, num_bits, msg); - } - - void create_range_constraint(const uint32_t variable_index, - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - circuit_constructor.create_range_constraint(variable_index, num_bits, msg); - } - - accumulator_triple create_logic_constraint(const uint32_t a, - const uint32_t b, - const size_t num_bits, - bool is_xor_gate) - { - return circuit_constructor.create_logic_constraint(a, b, num_bits, is_xor_gate); - } - - accumulator_triple create_and_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_and_constraint(a, b, num_bits); - } - - accumulator_triple create_xor_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_xor_constraint(a, b, num_bits); - } - uint32_t add_variable(const barretenberg::fr& in) { return circuit_constructor.add_variable(in); } - - uint32_t add_public_variable(const barretenberg::fr& in) { return circuit_constructor.add_public_variable(in); } - - virtual void set_public_input(const uint32_t witness_index) - { - return circuit_constructor.set_public_input(witness_index); - } - - uint32_t put_constant_variable(const barretenberg::fr& variable) - { - return circuit_constructor.put_constant_variable(variable); - } - - size_t get_num_constant_gates() const { return circuit_constructor.get_num_constant_gates(); } - - bool check_circuit() { return circuit_constructor.check_circuit(); } - - barretenberg::fr get_variable(const uint32_t index) const { return circuit_constructor.get_variable(index); } - std::vector get_public_inputs() const { return circuit_constructor.get_public_inputs(); } - - /**Proof and verification-related methods*/ - - std::shared_ptr compute_proving_key() - { - return composer_helper.compute_proving_key(circuit_constructor); - } - - std::shared_ptr compute_verification_key() - { - return composer_helper.compute_verification_key(circuit_constructor); - } - - void compute_witness() { composer_helper.compute_witness(circuit_constructor); }; - // TODO(#230)(Cody): This will not be needed, but maybe something is required for ComposerHelper to be generic? - plonk::TurboVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); } - /** - * Preprocess the circuit. Delegates to create_prover. - * - * @return A new initialized prover. - */ - /** - * Preprocess the circuit. Delegates to create_unrolled_prover. - * - * @return A new initialized prover. - */ - plonk::TurboProver create_prover() { return composer_helper.create_prover(circuit_constructor); }; - - static transcript::Manifest create_manifest(const size_t num_public_inputs) - { - return TurboPlonkComposerHelper::create_manifest(num_public_inputs); - } - - void add_recursive_proof(const std::vector& proof_output_witness_indices) - { - circuit_constructor.add_recursive_proof(proof_output_witness_indices); - } - bool failed() const { return circuit_constructor.failed(); }; - const std::string& err() const { return circuit_constructor.err(); }; - void failure(std::string msg) { circuit_constructor.failure(msg); } -}; -} // namespace proof_system::plonk diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_plonk_composer.hpp b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_plonk_composer.hpp deleted file mode 100644 index 4b86636e4ef8..000000000000 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_plonk_composer.hpp +++ /dev/null @@ -1,389 +0,0 @@ -#pragma once -#include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" -#include "barretenberg/plonk/proof_system/prover/prover.hpp" -#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" -#include "barretenberg/proof_system/types/merkle_hash_type.hpp" -#include "barretenberg/proof_system/types/pedersen_commitment_type.hpp" -#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" -#include "barretenberg/srs/factories/crs_factory.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" -#include - -namespace proof_system::plonk { - -class UltraPlonkComposer { - - public: - using ComposerHelper = UltraPlonkComposerHelper; - using CircuitConstructor = UltraCircuitConstructor; - - static constexpr ComposerType type = ComposerType::PLOOKUP; - static_assert(type == CircuitConstructor::type); - static constexpr merkle::HashType merkle_hash_type = CircuitConstructor::merkle_hash_type; - static constexpr pedersen::CommitmentType commitment_type = CircuitConstructor::commitment_type; - static constexpr size_t DEFAULT_PLOOKUP_RANGE_BITNUM = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM; - // An instantiation of the circuit constructor that only depends on arithmetization, not on the proof system - UltraCircuitConstructor circuit_constructor; - - // References to circuit_constructor's members for convenience - size_t& num_gates; - std::vector& variables; - // While we always have it set to zero, feels wrong to have a potentially broken dependency - uint32_t& zero_idx; - - // Composer helper contains all proof-related material that is separate from circuit creation such as: - // 1) Proving and verification keys - // 2) CRS - // 3) Converting variables to witness vectors/polynomials - UltraPlonkComposerHelper composer_helper; - - // References to composer helper's members for convenience - bool& contains_recursive_proof; - std::vector& recursive_proof_public_input_indices; - - UltraPlonkComposer() - : UltraPlonkComposer("../srs_db/ignition", 0){}; - - UltraPlonkComposer(std::string const& crs_path, const size_t size_hint = 0) - : UltraPlonkComposer(std::make_unique(crs_path), size_hint){}; - - UltraPlonkComposer(std::shared_ptr const& crs_factory, - const size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(crs_factory) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - UltraPlonkComposer(std::shared_ptr const& p_key, - std::shared_ptr const& v_key, - size_t size_hint = 0) - : circuit_constructor(size_hint) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(p_key, v_key) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - - UltraPlonkComposer(UltraPlonkComposer&& other) - : circuit_constructor(std::move(other.circuit_constructor)) - , num_gates(circuit_constructor.num_gates) - , variables(circuit_constructor.variables) - , zero_idx(circuit_constructor.zero_idx) - , composer_helper(std::move(other.composer_helper)) - , contains_recursive_proof(circuit_constructor.contains_recursive_proof) - , recursive_proof_public_input_indices(circuit_constructor.recursive_proof_public_input_indices){}; - UltraPlonkComposer& operator=(UltraPlonkComposer&& other) - { - circuit_constructor = std::move(other.circuit_constructor); - composer_helper = std::move(other.composer_helper); - num_gates = circuit_constructor.num_gates; - variables = circuit_constructor.variables; - zero_idx = circuit_constructor.zero_idx; - contains_recursive_proof = circuit_constructor.contains_recursive_proof; - recursive_proof_public_input_indices = circuit_constructor.recursive_proof_public_input_indices; - return *this; - }; - ~UltraPlonkComposer() = default; - - /**Methods related to circuit construction - * They simply get proxied to the circuit constructor - */ - void assert_equal(const uint32_t a_variable_idx, - const uint32_t b_variable_idx, - std::string const& msg = "assert equal") - { - circuit_constructor.assert_equal(a_variable_idx, b_variable_idx, msg); - } - void assert_equal_constant(uint32_t const a_idx, - barretenberg::fr const& b, - std::string const& msg = "assert equal constant") - { - circuit_constructor.assert_equal_constant(a_idx, b, msg); - } - - void create_add_gate(const add_triple& in) { circuit_constructor.create_add_gate(in); } - void create_mul_gate(const mul_triple& in) { circuit_constructor.create_mul_gate(in); } - void create_bool_gate(const uint32_t a) { circuit_constructor.create_bool_gate(a); } - void create_poly_gate(const poly_triple& in) { circuit_constructor.create_poly_gate(in); } - void create_big_add_gate(const add_quad& in, const bool include_next_gate_w_4 = false) - { - circuit_constructor.create_big_add_gate(in, include_next_gate_w_4); - } - void create_big_add_gate_with_bit_extraction(const add_quad& in) - { - circuit_constructor.create_big_add_gate_with_bit_extraction(in); - } - void create_big_mul_gate(const mul_quad& in) { circuit_constructor.create_big_mul_gate(in); } - void create_balanced_add_gate(const add_quad& in) { circuit_constructor.create_balanced_add_gate(in); } - void create_ecc_add_gate(const ecc_add_gate& in) { circuit_constructor.create_ecc_add_gate(in); } - - void fix_witness(const uint32_t witness_index, const barretenberg::fr& witness_value) - { - circuit_constructor.fix_witness(witness_index, witness_value); - } - - void create_range_constraint(const uint32_t variable_index, - const size_t num_bits, - std::string const& msg = "create_range_constraint") - { - circuit_constructor.create_range_constraint(variable_index, num_bits, msg); - } - accumulator_triple create_logic_constraint(const uint32_t a, - const uint32_t b, - const size_t num_bits, - bool is_xor_gate) - { - return circuit_constructor.create_logic_constraint(a, b, num_bits, is_xor_gate); - } - - accumulator_triple create_and_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_and_constraint(a, b, num_bits); - } - - accumulator_triple create_xor_constraint(const uint32_t a, const uint32_t b, const size_t num_bits) - { - return circuit_constructor.create_xor_constraint(a, b, num_bits); - } - size_t get_num_gates() const { return circuit_constructor.get_num_gates(); } - uint32_t get_zero_idx() { return circuit_constructor.zero_idx; } - - uint32_t add_variable(const barretenberg::fr& in) { return circuit_constructor.add_variable(in); } - - uint32_t add_public_variable(const barretenberg::fr& in) { return circuit_constructor.add_public_variable(in); } - - void set_public_input(const uint32_t witness_index) { return circuit_constructor.set_public_input(witness_index); } - - uint32_t get_public_input_index(const uint32_t witness_index) const - { - return circuit_constructor.get_public_input_index(witness_index); - } - - uint32_t put_constant_variable(const barretenberg::fr& variable) - { - return circuit_constructor.put_constant_variable(variable); - } - - size_t get_num_constant_gates() const { return circuit_constructor.get_num_constant_gates(); } - - size_t get_total_circuit_size() const { return circuit_constructor.get_total_circuit_size(); } - - size_t get_circuit_subgroup_size(size_t gates) const - { - return circuit_constructor.get_circuit_subgroup_size(gates); - } - - bool check_circuit() { return circuit_constructor.check_circuit(); } - - barretenberg::fr get_variable(const uint32_t index) const { return circuit_constructor.get_variable(index); } - - std::vector get_public_inputs() const { return circuit_constructor.get_public_inputs(); } - - void print_num_gates() { circuit_constructor.print_num_gates(); } - - /**Proof and verification-related methods*/ - - std::shared_ptr compute_proving_key() - { - return composer_helper.compute_proving_key(circuit_constructor); - } - - std::shared_ptr compute_verification_key() - { - return composer_helper.compute_verification_key(circuit_constructor); - } - - UltraProver create_prover() { return composer_helper.create_prover(circuit_constructor); }; - UltraVerifier create_verifier() { return composer_helper.create_verifier(circuit_constructor); }; - - UltraToStandardProver create_ultra_to_standard_prover() - { - return composer_helper.create_ultra_to_standard_prover(circuit_constructor); - }; - - UltraToStandardVerifier create_ultra_to_standard_verifier() - { - return composer_helper.create_ultra_to_standard_verifier(circuit_constructor); - }; - - UltraWithKeccakProver create_ultra_with_keccak_prover() - { - return composer_helper.create_ultra_with_keccak_prover(circuit_constructor); - }; - UltraWithKeccakVerifier create_ultra_with_keccak_verifier() - { - - return composer_helper.create_ultra_with_keccak_verifier(circuit_constructor); - }; - - static transcript::Manifest create_manifest(const size_t num_public_inputs) - { - return UltraPlonkComposerHelper::create_manifest(num_public_inputs); - } - void add_recursive_proof(const std::vector& proof_output_witness_indices) - { - circuit_constructor.add_recursive_proof(proof_output_witness_indices); - } - - void set_recursive_proof(const std::vector& proof_output_witness_indices) - { - circuit_constructor.set_recursive_proof(proof_output_witness_indices); - } - - void create_new_range_constraint(const uint32_t variable_index, - const uint64_t target_range, - std::string const msg = "create_new_range_constraint") - { - circuit_constructor.create_new_range_constraint(variable_index, target_range, msg); - }; - - // /** - // * Plookup Methods - // **/ - - plookup::ReadData create_gates_from_plookup_accumulators( - const plookup::MultiTableId& id, - const plookup::ReadData& read_values, - const uint32_t key_a_index, - std::optional key_b_index = std::nullopt) - { - return circuit_constructor.create_gates_from_plookup_accumulators(id, read_values, key_a_index, key_b_index); - }; - - // /** - // * Generalized Permutation Methods - // **/ - std::vector decompose_into_default_range( - const uint32_t variable_index, - const uint64_t num_bits, - const uint64_t target_range_bitnum = UltraCircuitConstructor::DEFAULT_PLOOKUP_RANGE_BITNUM, - std::string const& msg = "decompose_into_default_range") - { - return circuit_constructor.decompose_into_default_range(variable_index, num_bits, target_range_bitnum, msg); - }; - // std::vector decompose_into_default_range_better_for_oddlimbnum( - // const uint32_t variable_index, - // const size_t num_bits, - // std::string const& msg = "decompose_into_default_range_better_for_oddlimbnum"); - void create_dummy_constraints(const std::vector& variable_index) - { - circuit_constructor.create_dummy_constraints(variable_index); - }; - void create_sort_constraint(const std::vector& variable_index) - { - circuit_constructor.create_sort_constraint(variable_index); - }; - void create_sort_constraint_with_edges(const std::vector& variable_index, - const barretenberg::fr& start, - const barretenberg::fr& end) - { - circuit_constructor.create_sort_constraint_with_edges(variable_index, start, end); - }; - - void assign_tag(const uint32_t variable_index, const uint32_t tag) - { - circuit_constructor.assign_tag(variable_index, tag); - } - - uint32_t create_tag(const uint32_t tag_index, const uint32_t tau_index) - { - return circuit_constructor.create_tag(tag_index, tau_index); - } - - // /** - // * Non Native Field Arithmetic - // **/ - void range_constrain_two_limbs( - const uint32_t lo_idx, - const uint32_t hi_idx, - const size_t lo_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS, - const size_t hi_limb_bits = UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS) - { - circuit_constructor.range_constrain_two_limbs(lo_idx, hi_idx, lo_limb_bits, hi_limb_bits); - }; - std::array decompose_non_native_field_double_width_limb( - const uint32_t limb_idx, - const size_t num_limb_bits = (2 * UltraCircuitConstructor::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS)) - { - return circuit_constructor.decompose_non_native_field_double_width_limb(limb_idx, num_limb_bits); - } - std::array evaluate_non_native_field_multiplication( - const UltraCircuitConstructor::non_native_field_witnesses& input, - const bool range_constrain_quotient_and_remainder = true) - { - return circuit_constructor.evaluate_non_native_field_multiplication(input, - range_constrain_quotient_and_remainder); - }; - - std::array queue_partial_non_native_field_multiplication( - const proof_system::UltraCircuitConstructor::non_native_field_witnesses& input) - { - return circuit_constructor.queue_partial_non_native_field_multiplication(input); - } - using add_simple = proof_system::UltraCircuitConstructor::add_simple; - std::array evaluate_non_native_field_subtraction( - add_simple limb0, - add_simple limb1, - add_simple limb2, - add_simple limb3, - std::tuple limbp) - { - return circuit_constructor.evaluate_non_native_field_subtraction(limb0, limb1, limb2, limb3, limbp); - } - std::array evaluate_non_native_field_addition(add_simple limb0, - add_simple limb1, - add_simple limb2, - add_simple limb3, - std::tuple limbp) - { - return circuit_constructor.evaluate_non_native_field_addition(limb0, limb1, limb2, limb3, limbp); - }; - - // /** - // * Memory - // **/ - - size_t create_RAM_array(const size_t array_size) { return circuit_constructor.create_RAM_array(array_size); }; - size_t create_ROM_array(const size_t array_size) { return circuit_constructor.create_ROM_array(array_size); }; - - void set_ROM_element(const size_t rom_id, const size_t index_value, const uint32_t value_witness) - { - circuit_constructor.set_ROM_element(rom_id, index_value, value_witness); - }; - void set_ROM_element_pair(const size_t rom_id, - const size_t index_value, - const std::array& value_witnesses) - { - circuit_constructor.set_ROM_element_pair(rom_id, index_value, value_witnesses); - } - uint32_t read_ROM_array(const size_t rom_id, const uint32_t index_witness) - { - return circuit_constructor.read_ROM_array(rom_id, index_witness); - }; - std::array read_ROM_array_pair(const size_t rom_id, const uint32_t index_witness) - { - return circuit_constructor.read_ROM_array_pair(rom_id, index_witness); - } - - void init_RAM_element(const size_t ram_id, const size_t index_value, const uint32_t value_witness) - { - circuit_constructor.init_RAM_element(ram_id, index_value, value_witness); - }; - uint32_t read_RAM_array(const size_t ram_id, const uint32_t index_witness) - { - return circuit_constructor.read_RAM_array(ram_id, index_witness); - }; - void write_RAM_array(const size_t ram_id, const uint32_t index_witness, const uint32_t value_witness) - { - circuit_constructor.write_RAM_array(ram_id, index_witness, value_witness); - }; - - bool failed() const { return circuit_constructor.failed(); }; - const std::string& err() const { return circuit_constructor.err(); }; - void failure(std::string msg) { circuit_constructor.failure(msg); } -}; -} // namespace proof_system::plonk diff --git a/barretenberg/cpp/src/barretenberg/plonk/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/plonk/flavor/flavor.hpp index b9bfa7b0a477..463b33bd519b 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/flavor/flavor.hpp @@ -25,5 +25,127 @@ class Ultra { using CircuitConstructor = proof_system::UltraCircuitConstructor; using ProvingKey = plonk::proving_key; static constexpr size_t NUM_WIRES = CircuitConstructor::NUM_WIRES; + + /** + * @brief Create a manifest object + * + * @note UltraPlonk manifest does not use linearisation trick + * @param num_public_inputs + * @return transcript::Manifest + */ + static transcript::Manifest create_manifest(const size_t num_public_inputs) + { + // add public inputs.... + constexpr size_t g1_size = 64; + constexpr size_t fr_size = 32; + const size_t public_input_size = fr_size * num_public_inputs; + transcript::Manifest output = transcript::Manifest( + + { transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier } + { "circuit_size", 4, true }, + { "public_input_size", 4, true } }, + "init", // challenge_name + 1 // num_challenges_in + ), + + transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier } + { "public_inputs", public_input_size, false }, + { "W_1", g1_size, false }, + { "W_2", g1_size, false }, + { "W_3", g1_size, false } }, + "eta", // challenge_name + 1 // num_challenges_in + ), + + transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier } + { "W_4", g1_size, false }, + { "S", g1_size, false } }, + "beta", // challenge_name + 2 // num_challenges_in + ), + + transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier } + { "Z_PERM", g1_size, false }, + { "Z_LOOKUP", g1_size, false } }, + "alpha", // challenge_name + 1 // num_challenges_in + ), + + transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier } + { "T_1", g1_size, false }, + { "T_2", g1_size, false }, + { "T_3", g1_size, false }, + { "T_4", g1_size, false } }, + "z", // challenge_name + 1 // num_challenges_in + ), + + // N.B. THE SHFITED EVALS (_omega) MUST HAVE THE SAME CHALLENGE INDEX AS THE NON SHIFTED VALUES + transcript::Manifest::RoundManifest( + { + // { name, num_bytes, derived_by_verifier, challenge_map_index } + { "t", fr_size, true, -1 }, // * + { "w_1", fr_size, false, 0 }, + { "w_2", fr_size, false, 1 }, + { "w_3", fr_size, false, 2 }, + { "w_4", fr_size, false, 3 }, + { "s", fr_size, false, 4 }, + { "z_perm", fr_size, false, 5 }, // * + { "z_lookup", fr_size, false, 6 }, + { "q_1", fr_size, false, 7 }, + { "q_2", fr_size, false, 8 }, + { "q_3", fr_size, false, 9 }, + { "q_4", fr_size, false, 10 }, + { "q_m", fr_size, false, 11 }, + { "q_c", fr_size, false, 12 }, + { "q_arith", fr_size, false, 13 }, + { "q_sort", fr_size, false, 14 }, // * + { "q_elliptic", fr_size, false, 15 }, // * + { "q_aux", fr_size, false, 16 }, + { "sigma_1", fr_size, false, 17 }, + { "sigma_2", fr_size, false, 18 }, + { "sigma_3", fr_size, false, 19 }, + { "sigma_4", fr_size, false, 20 }, + { "table_value_1", fr_size, false, 21 }, + { "table_value_2", fr_size, false, 22 }, + { "table_value_3", fr_size, false, 23 }, + { "table_value_4", fr_size, false, 24 }, + { "table_type", fr_size, false, 25 }, + { "id_1", fr_size, false, 26 }, + { "id_2", fr_size, false, 27 }, + { "id_3", fr_size, false, 28 }, + { "id_4", fr_size, false, 29 }, + { "w_1_omega", fr_size, false, 0 }, + { "w_2_omega", fr_size, false, 1 }, + { "w_3_omega", fr_size, false, 2 }, + { "w_4_omega", fr_size, false, 3 }, + { "s_omega", fr_size, false, 4 }, + { "z_perm_omega", fr_size, false, 5 }, + { "z_lookup_omega", fr_size, false, 6 }, + { "table_value_1_omega", fr_size, false, 21 }, + { "table_value_2_omega", fr_size, false, 22 }, + { "table_value_3_omega", fr_size, false, 23 }, + { "table_value_4_omega", fr_size, false, 24 }, + }, + "nu", // challenge_name + ULTRA_MANIFEST_SIZE, // num_challenges_in + true // map_challenges_in + ), + + transcript::Manifest::RoundManifest( + { // { name, num_bytes, derived_by_verifier, challenge_map_index } + { "PI_Z", g1_size, false }, + { "PI_Z_OMEGA", g1_size, false } }, + "separator", // challenge_name + 3 // num_challenges_in + ) }); + + return output; + } }; } // namespace proof_system::plonk::flavor \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp index e2b4cc6e10d9..085d1c7288af 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/types/polynomial_manifest.hpp @@ -235,7 +235,7 @@ class PrecomputedPolyList { precomputed_poly_ids.emplace_back(label); precomputed_poly_ids.emplace_back(label + "_fft"); // Store all lagrange forms of selector polynomials for ultra - if (composer_type == ComposerType::PLOOKUP) { + if (composer_type == proof_system::ComposerType::PLOOKUP) { precomputed_poly_ids.emplace_back(label + "_lagrange"); } break; diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/kate_verification.hpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/kate_verification.hpp index 5fa5eeda390c..2f4a9bb47aa1 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/kate_verification.hpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/utils/kate_verification.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp index e60160615aca..c0799b420d90 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/proof_system/verification_key/verification_key.cpp @@ -76,7 +76,7 @@ barretenberg::fr verification_key_data::compress_native(const size_t hash_index) write(preimage_data, eval_domain.root); barretenberg::fr compressed_key; - if (proof_system::ComposerType(composer_type) == ComposerType::PLOOKUP) { + if (proof_system::ComposerType(composer_type) == proof_system::ComposerType::PLOOKUP) { compressed_key = from_buffer( crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index)); } else { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp index 0279701bcb5e..41c9c7ec974a 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp @@ -14,6 +14,7 @@ inline std::vector standard_selector_names() class StandardCircuitConstructor : public CircuitConstructorBase> { public: + static constexpr std::string_view NAME_STRING = "StandardArithmetization"; static constexpr ComposerType type = ComposerType::STANDARD; static constexpr merkle::HashType merkle_hash_type = merkle::HashType::FIXED_BASE_PEDERSEN; static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp index 33fbb001834c..5c1f44598f7e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp @@ -14,8 +14,8 @@ inline std::vector turbo_selector_names() return result; } class TurboCircuitConstructor : public CircuitConstructorBase> { - public: + static constexpr std::string_view NAME_STRING = "TurboArithmetization"; static constexpr ComposerType type = ComposerType::TURBO; static constexpr merkle::HashType merkle_hash_type = merkle::HashType::FIXED_BASE_PEDERSEN; static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp index 43a7eb7976f6..ca5c28d99d57 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp @@ -17,6 +17,7 @@ using namespace barretenberg; class UltraCircuitConstructor : public CircuitConstructorBase> { public: + static constexpr std::string_view NAME_STRING = "UltraArithmetization"; static constexpr ComposerType type = ComposerType::PLOOKUP; static constexpr merkle::HashType merkle_hash_type = merkle::HashType::LOOKUP_PEDERSEN; static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN; diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/add_2_circuit.hpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/add_2_circuit.hpp index 99f443faf4f6..8dbeec2e2616 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/add_2_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/add_2_circuit.hpp @@ -1,25 +1,22 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" -#include "barretenberg/stdlib/primitives/uint/uint.hpp" -#include "barretenberg/stdlib/primitives/bool/bool.hpp" -template class Add2Circuit { +template class Add2Circuit { public: - typedef stdlib::field_t field_ct; - typedef stdlib::witness_t witness_ct; - typedef stdlib::public_witness_t public_witness_ct; + typedef proof_system::plonk::stdlib::public_witness_t public_witness_ct; + typedef proof_system::plonk::stdlib::field_t field_ct; // Three public inputs - static Composer generate(std::string srs_path, uint256_t inputs[]) + static Builder generate(uint256_t inputs[]) { - Composer composer(srs_path); + Builder builder; - field_ct a(public_witness_ct(&composer, inputs[0])); - field_ct b(public_witness_ct(&composer, inputs[1])); - field_ct c(public_witness_ct(&composer, inputs[2])); + field_ct a(public_witness_ct(&builder, inputs[0])); + field_ct b(public_witness_ct(&builder, inputs[1])); + field_ct c(public_witness_ct(&builder, inputs[2])); c.assert_equal(a + b); - return composer; + return builder; } }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/blake_circuit.hpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/blake_circuit.hpp index 1b19bd8b3b09..1d28415857a8 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/blake_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/blake_circuit.hpp @@ -7,25 +7,25 @@ using namespace proof_system::plonk::stdlib; using numeric::uint256_t; -template class BlakeCircuit { +template class BlakeCircuit { public: - typedef stdlib::field_t field_ct; - typedef stdlib::public_witness_t public_witness_ct; - typedef stdlib::byte_array byte_array_ct; + typedef stdlib::field_t field_ct; + typedef stdlib::public_witness_t public_witness_ct; + typedef stdlib::byte_array byte_array_ct; static constexpr size_t NUM_PUBLIC_INPUTS = 4; - static Composer generate(std::string srs_path, uint256_t public_inputs[]) + static Builder generate(uint256_t public_inputs[]) { - Composer composer(srs_path); + Builder builder; - byte_array_ct input_buffer(&composer); + byte_array_ct input_buffer(&builder); for (size_t i = 0; i < NUM_PUBLIC_INPUTS; ++i) { - input_buffer.write(byte_array_ct(field_ct(public_witness_ct(&composer, public_inputs[i])))); + input_buffer.write(byte_array_ct(field_ct(public_witness_ct(&builder, public_inputs[i])))); } - stdlib::blake2s(input_buffer); + stdlib::blake2s(input_buffer); - return composer; + return builder; } }; \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/recursive_circuit.hpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/recursive_circuit.hpp index 58e72e8fa6f0..62f2e731cbfd 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/recursive_circuit.hpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/circuits/recursive_circuit.hpp @@ -11,10 +11,11 @@ using namespace proof_system::plonk; using numeric::uint256_t; template class RecursiveCircuit { - using InnerComposer = UltraPlonkComposer; + using InnerComposer = UltraPlonkComposerHelper; + using InnerBuilder = typename InnerComposer::CircuitConstructor; - typedef stdlib::field_t field_ct; - typedef stdlib::bn254 inner_curve; + typedef stdlib::field_t field_ct; + typedef stdlib::bn254 inner_curve; typedef stdlib::bn254 outer_curve; typedef stdlib::recursion::verification_key verification_key_pt; typedef stdlib::recursion::recursive_ultra_verifier_settings recursive_settings; @@ -29,11 +30,11 @@ template class RecursiveCircuit { std::shared_ptr verification_key; }; - static void create_inner_circuit_no_tables(InnerComposer& composer, uint256_t inputs[]) + static void create_inner_circuit_no_tables(InnerBuilder& builder, uint256_t inputs[]) { - field_ct a(public_witness_ct(&composer, inputs[0])); - field_ct b(public_witness_ct(&composer, inputs[1])); - field_ct c(public_witness_ct(&composer, inputs[2])); + field_ct a(public_witness_ct(&builder, inputs[0])); + field_ct b(public_witness_ct(&builder, inputs[1])); + field_ct c(public_witness_ct(&builder, inputs[2])); // @note For some reason, if we don't have this line, the circuit fails to verify. auto c_sq = c * c; @@ -42,7 +43,7 @@ template class RecursiveCircuit { c_sq.assert_equal(c * c); }; - static circuit_outputs create_outer_circuit(InnerComposer& inner_composer, OuterComposer& outer_composer) + static circuit_outputs create_outer_circuit(InnerBuilder& inner_circuit, OuterComposer& outer_composer) { // These constexpr definitions are to allow for the following: // An Ultra Pedersen hash evaluates to a different value from the Turbo/Standard versions of the Pedersen hash. @@ -51,9 +52,9 @@ template class RecursiveCircuit { // circuit which uses non-ultra-pedersen challenges. We need the prover and verifier hashes to be the same. The // solution is to select the relevant prover and verifier types (whose settings use the same hash for // fiat-shamir), depending on the Inner-Outer combo. It's a bit clunky, but the alternative is to have a - // template argument for the hashtype, and that would pervade the entire UltraPlonkComposer, which would be - // horrendous. - constexpr bool is_ultra_to_ultra = std::is_same::value; + // template argument for the hashtype, and that would pervade the entire UltraPlonkComposerHelper, which would + // be horrendous. + constexpr bool is_ultra_to_ultra = std::is_same::value; typedef typename std::conditional::type ProverOfInnerCircuit; typedef typename std::conditional::type @@ -62,14 +63,15 @@ template class RecursiveCircuit { typename std::conditional::type RecursiveSettings; + InnerComposer inner_composer; ProverOfInnerCircuit prover; if constexpr (is_ultra_to_ultra) { - prover = inner_composer.create_prover(); + prover = inner_composer.create_prover(inner_circuit); } else { - prover = inner_composer.create_ultra_to_standard_prover(); + prover = inner_composer.create_ultra_to_standard_prover(inner_circuit); } - const auto verification_key_native = inner_composer.compute_verification_key(); + const auto verification_key_native = inner_composer.compute_verification_key(inner_circuit); // Convert the verification key's elements into _circuit_ types, using the OUTER composer. std::shared_ptr verification_key = @@ -82,9 +84,9 @@ template class RecursiveCircuit { VerifierOfInnerProof native_verifier; if constexpr (is_ultra_to_ultra) { - native_verifier = inner_composer.create_verifier(); + native_verifier = inner_composer.create_verifier(inner_circuit); } else { - native_verifier = inner_composer.create_ultra_to_standard_verifier(); + native_verifier = inner_composer.create_ultra_to_standard_verifier(inner_circuit); } auto native_result = native_verifier.verify_proof(recursive_proof); if (native_result == false) { @@ -104,14 +106,14 @@ template class RecursiveCircuit { }; public: - static OuterComposer generate(std::string srs_path, uint256_t inputs[]) + static OuterComposer generate(uint256_t inputs[]) { - InnerComposer inner_composer = InnerComposer(srs_path); - OuterComposer outer_composer = OuterComposer(srs_path); + InnerBuilder inner_circuit; + OuterComposer outer_composer; - create_inner_circuit_no_tables(inner_composer, inputs); + create_inner_circuit_no_tables(inner_circuit, inputs); - auto circuit_output = create_outer_circuit(inner_composer, outer_composer); + auto circuit_output = create_outer_circuit(inner_circuit, outer_composer); g1::affine_element P[2]; P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/key_gen.cpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/key_gen.cpp index e1ce7ef223ca..b9d85c2c529c 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/key_gen.cpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/key_gen.cpp @@ -1,7 +1,7 @@ #include -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" #include "barretenberg/plonk/proof_system/verification_key/sol_gen.hpp" #include "circuits/blake_circuit.hpp" @@ -11,13 +11,14 @@ #include "utils/utils.hpp" #include "utils/instance_sol_gen.hpp" -template -void generate_keys(std::string output_path, std::string srs_path, std::string flavour_prefix, std::string circuit_name) +template typename Circuit> +void generate_keys(std::string output_path, std::string flavour_prefix, std::string circuit_name) { uint256_t public_inputs[4] = { 0, 0, 0, 0 }; - Composer composer = Circuit::generate(srs_path, public_inputs); + auto circuit = Circuit::generate(public_inputs); - std::shared_ptr vkey = composer.compute_verification_key(); + Composer composer; + std::shared_ptr vkey = composer.compute_verification_key(circuit); // Make verification key file upper case circuit_name.at(0) = static_cast(std::toupper(static_cast(circuit_name.at(0)))); @@ -62,6 +63,7 @@ int main(int argc, char** argv) const std::string output_path = args[3]; const std::string srs_path = args[4]; + barretenberg::srs::init_crs_factory(srs_path); // @todo - Add support for unrolled standard verifier. Needs a new solidity verifier contract. if (plonk_flavour != "ultra") { @@ -71,14 +73,11 @@ int main(int argc, char** argv) info("Generating ultra plonk keys for ", circuit_flavour, " circuit"); if (circuit_flavour == "blake") { - generate_keys>( - output_path, srs_path, plonk_flavour, circuit_flavour); + generate_keys(output_path, plonk_flavour, circuit_flavour); } else if (circuit_flavour == "add2") { - generate_keys>( - output_path, srs_path, plonk_flavour, circuit_flavour); + generate_keys(output_path, plonk_flavour, circuit_flavour); } else if (circuit_flavour == "recursive") { - generate_keys>( - output_path, srs_path, plonk_flavour, circuit_flavour); + generate_keys(output_path, plonk_flavour, circuit_flavour); } else { info("Only blake, add2 and recursive circuits are supported at the moment"); return 1; diff --git a/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp b/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp index c4d07c7e034f..508b56cf35d6 100644 --- a/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp +++ b/barretenberg/cpp/src/barretenberg/solidity_helpers/proof_gen.cpp @@ -2,8 +2,8 @@ #include #include -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" #include "circuits/blake_circuit.hpp" #include "circuits/add_2_circuit.hpp" @@ -13,15 +13,16 @@ using namespace numeric; using numeric::uint256_t; -template void generate_proof(std::string srs_path, uint256_t inputs[]) +template typename Circuit> void generate_proof(uint256_t inputs[]) { - Composer composer = Circuit::generate(srs_path, inputs); + auto builder = Circuit::generate(inputs); + Composer composer; // @todo this only works for ultra! Why is ultra part of function name on ultra composer? - auto prover = composer.create_ultra_with_keccak_prover(); + auto prover = composer.create_ultra_with_keccak_prover(builder); auto proof = prover.construct_proof(); { - auto verifier = composer.create_ultra_with_keccak_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(builder); if (!verifier.verify_proof(proof)) { throw_or_abort("Verification failed"); @@ -60,6 +61,8 @@ int main(int argc, char** argv) const std::string srs_path = args[3]; const std::string string_input = args[4]; + barretenberg::srs::init_crs_factory(srs_path); + // @todo dynamically allocate this uint256_t inputs[] = { 0, 0, 0, 0, 0 }; @@ -80,11 +83,11 @@ int main(int argc, char** argv) return 1; } else { if (circuit_flavour == "blake") { - generate_proof>(srs_path, inputs); + generate_proof(inputs); } else if (circuit_flavour == "add2") { - generate_proof>(srs_path, inputs); + generate_proof(inputs); } else if (circuit_flavour == "recursive") { - generate_proof>(srs_path, inputs); + generate_proof(inputs); } else { info("Invalid circuit flavour: " + circuit_flavour); return 1; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.bench.cpp index ad5a6be80d09..e3b4d0eea8ff 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.bench.cpp @@ -3,7 +3,7 @@ #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" @@ -12,6 +12,9 @@ using namespace benchmark; using namespace proof_system::plonk; +using Builder = proof_system::TurboCircuitConstructor; +using Composer = proof_system::plonk::TurboPlonkComposerHelper; + constexpr size_t NUM_CIRCUITS = 10; constexpr size_t get_circuit_size(const size_t target_count_base) @@ -36,15 +39,13 @@ constexpr size_t get_index(const size_t target_count_base) } return 0; } -void generate_test_pedersen_circuit(plonk::TurboPlonkComposer& turbo_plonk_composer, size_t num_repetitions) +void generate_test_pedersen_circuit(Builder& builder, size_t num_repetitions) { - plonk::stdlib::field_t left( - plonk::stdlib::witness_t(&turbo_plonk_composer, barretenberg::fr::random_element())); - plonk::stdlib::field_t out( - plonk::stdlib::witness_t(&turbo_plonk_composer, barretenberg::fr::random_element())); + plonk::stdlib::field_t left(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); + plonk::stdlib::field_t out(plonk::stdlib::witness_t(&builder, barretenberg::fr::random_element())); for (size_t i = 0; i < num_repetitions; ++i) { - out = proof_system::plonk::stdlib::pedersen_commitment::compress(left, out); + out = proof_system::plonk::stdlib::pedersen_commitment::compress(left, out); } } @@ -95,11 +96,12 @@ BENCHMARK(native_pedersen_eight_hash_bench)->MinTime(3); void construct_pedersen_witnesses_bench(State& state) noexcept { for (auto _ : state) { - plonk::TurboPlonkComposer composer = - plonk::TurboPlonkComposer(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); - generate_test_pedersen_circuit(composer, static_cast(state.range(0))); - std::cout << "composer gates = " << composer.get_num_gates() << std::endl; - composer.compute_witness(); + auto builder = Builder(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); + generate_test_pedersen_circuit(builder, static_cast(state.range(0))); + std::cout << "builder gates = " << builder.get_num_gates() << std::endl; + + auto composer = Composer(); + composer.compute_witness(builder); } } BENCHMARK(construct_pedersen_witnesses_bench) @@ -117,13 +119,14 @@ BENCHMARK(construct_pedersen_witnesses_bench) void construct_pedersen_proving_keys_bench(State& state) noexcept { for (auto _ : state) { - plonk::TurboPlonkComposer composer = - plonk::TurboPlonkComposer(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); - generate_test_pedersen_circuit(composer, static_cast(state.range(0))); + Builder builder = Builder(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); + generate_test_pedersen_circuit(builder, static_cast(state.range(0))); size_t idx = get_index(static_cast(state.range(0))); - composer.compute_proving_key(); + + auto composer = Composer(); + composer.compute_proving_key(builder); state.PauseTiming(); - pedersen_provers[idx] = composer.create_prover(); + pedersen_provers[idx] = composer.create_prover(builder); state.ResumeTiming(); } } @@ -143,13 +146,13 @@ void construct_pedersen_instances_bench(State& state) noexcept { for (auto _ : state) { state.PauseTiming(); - plonk::TurboPlonkComposer composer = - plonk::TurboPlonkComposer(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); - generate_test_pedersen_circuit(composer, static_cast(state.range(0))); + auto builder = Builder(BARRETENBERG_SRS_PATH, static_cast(state.range(0))); + generate_test_pedersen_circuit(builder, static_cast(state.range(0))); size_t idx = get_index(static_cast(state.range(0))); - composer.create_prover(); + auto composer = Composer(); + composer.create_prover(builder); state.ResumeTiming(); - pedersen_verifiers[idx] = composer.create_verifier(); + pedersen_verifiers[idx] = composer.create_verifier(builder); } } BENCHMARK(construct_pedersen_instances_bench) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.cpp index c6212093c243..2f96ba337ef7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.cpp @@ -3,7 +3,6 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "../../hash/pedersen/pedersen.hpp" -#include "../../primitives/composers/composers.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" namespace proof_system::plonk { @@ -16,7 +15,8 @@ using namespace crypto::pedersen_commitment; template point pedersen_commitment::commit(const std::vector& inputs, const size_t hash_index) { - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_commitment::commit(inputs, hash_index); } @@ -36,7 +36,8 @@ point pedersen_commitment::commit(const std::vector& inputs, throw_or_abort("Vector size mismatch."); } - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_commitment::commit(inputs, hash_generator_indices); } @@ -51,7 +52,8 @@ point pedersen_commitment::commit(const std::vector& inputs, template point pedersen_commitment::commit(const std::vector>& input_pairs) { - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_commitment::commit(input_pairs); } @@ -75,7 +77,8 @@ field_t pedersen_commitment::compress_unsafe(const field_t& in_left, const size_t hash_index, const bool validate_input_is_in_field) { - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_commitment::compress({ in_left, in_right }); } @@ -93,7 +96,8 @@ field_t pedersen_commitment::compress_unsafe(const field_t& in_left, template field_t pedersen_commitment::compress(const std::vector& inputs, const size_t hash_index) { - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_commitment::compress(inputs, hash_index); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.hpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.hpp index b33b6a2217fa..fa7761ea835e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/point/point.hpp" #include "../../primitives/byte_array/byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp index 7ef6aad95331..3225ca09f6a9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen.test.cpp @@ -350,7 +350,7 @@ template class stdlib_pedersen : public testing::Test { std::vector inputs; inputs.reserve(8); - std::vector> witness_inputs; + std::vector> witness_inputs; for (size_t i = 0; i < 8; ++i) { inputs.emplace_back(barretenberg::fr::random_element()); @@ -369,7 +369,7 @@ template class stdlib_pedersen : public testing::Test { Composer composer = Composer("../srs_db/ignition/"); std::vector inputs; - std::vector> witness_inputs; + std::vector> witness_inputs; for (size_t i = 0; i < 8; ++i) { inputs.push_back(barretenberg::fr::random_element()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.cpp index 12d2ad96e910..c10d78450b7a 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.cpp @@ -4,7 +4,6 @@ #include "../../hash/pedersen/pedersen_plookup.hpp" #include "barretenberg/proof_system/plookup_tables/types.hpp" -#include "../../primitives/composers/composers.hpp" #include "../../primitives/plookup/plookup.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp index 1df188768dca..e29be90285e8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/commitment/pedersen/pedersen_plookup.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/point/point.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.cpp index 83a82faa1d40..d553b59674c0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.cpp @@ -5,7 +5,7 @@ #include "barretenberg/crypto/aes128/aes128.hpp" #include "barretenberg/stdlib/primitives/plookup/plookup.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" using namespace crypto::aes128; using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp index 6ea96484aaa6..77c5026ddf8f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.hpp @@ -3,7 +3,7 @@ #include #include -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/witness/witness.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp index 6563fd8a9c36..d346ec8ce558 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/aes128/aes128.test.cpp @@ -1,5 +1,5 @@ #include "aes128.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" #include "barretenberg/crypto/aes128/aes128.hpp" #include @@ -32,7 +32,7 @@ TEST(stdlib_aes128, encrypt_64_bytes) return converted; }; - proof_system::UltraCircuitConstructor composer = UltraCircuitConstructor(); + auto composer = proof_system::UltraCircuitConstructor(); std::vector in_field{ witness_pt(&composer, fr(convert_bytes(in))), diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp index 0208b75595cf..83bb092a9dcf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp @@ -3,7 +3,7 @@ #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "../../primitives/byte_array/byte_array.hpp" #include "../../primitives/uint/uint.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" namespace proof_system::plonk { namespace stdlib { namespace ecdsa { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp index 28ef8726fd9a..ddbc3cea411c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa.test.cpp @@ -2,7 +2,6 @@ #include "../../primitives/biggroup/biggroup.hpp" #include "../../primitives/curves/secp256k1.hpp" #include "ecdsa.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/crypto/ecdsa/ecdsa.hpp" #include "barretenberg/common/test.hpp" @@ -50,11 +49,8 @@ TEST(stdlib_ecdsa, verify_signature) EXPECT_EQ(signature_result.get_value(), true); std::cerr << "composer gates = " << composer.get_num_gates() << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), - "ECDSA", - "Signature Verification Test", - "Gate Count", - composer.get_num_gates()); + benchmark_info( + Composer::NAME_STRING, "ECDSA", "Signature Verification Test", "Gate Count", composer.get_num_gates()); bool proof_result = composer.check_circuit(); EXPECT_EQ(proof_result, true); } @@ -98,11 +94,8 @@ TEST(stdlib_ecdsa, verify_signature_noassert_succeed) EXPECT_EQ(signature_result.get_value(), true); std::cerr << "composer gates = " << composer.get_num_gates() << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), - "ECDSA", - "Signature Verification Test", - "Gate Count", - composer.get_num_gates()); + benchmark_info( + Composer::NAME_STRING, "ECDSA", "Signature Verification Test", "Gate Count", composer.get_num_gates()); bool proof_result = composer.check_circuit(); EXPECT_EQ(proof_result, true); } @@ -146,11 +139,8 @@ TEST(stdlib_ecdsa, verify_signature_noassert_fail) EXPECT_EQ(signature_result.get_value(), false); std::cerr << "composer gates = " << composer.get_num_gates() << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), - "ECDSA", - "Signature Verification Test", - "Gate Count", - composer.get_num_gates()); + benchmark_info( + Composer::NAME_STRING, "ECDSA", "Signature Verification Test", "Gate Count", composer.get_num_gates()); bool proof_result = composer.check_circuit(); EXPECT_EQ(proof_result, true); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp index 097eab81a362..96e07e4d9c5e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/ecdsa/ecdsa_impl.hpp @@ -2,7 +2,6 @@ #include "../../hash/sha256/sha256.hpp" #include "../../primitives/bit_array/bit_array.hpp" -#include "../../primitives/composers/composers.hpp" namespace proof_system::plonk { namespace stdlib { @@ -79,7 +78,7 @@ bool_t verify_signature(const stdlib::byte_array& message, Fr u2 = r / s; G1 result; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { ASSERT(Curve::type == proof_system::CurveType::SECP256K1); public_key.validate_on_curve(); result = G1::secp256k1_ecdsa_mul(public_key, u1, u2); @@ -148,7 +147,7 @@ bool_t verify_signature_prehashed_message_noassert(const stdlib::byte_ Fr u2 = r / s; G1 result; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { ASSERT(Curve::type == proof_system::CurveType::SECP256K1); public_key.validate_on_curve(); result = G1::secp256k1_ecdsa_mul(public_key, u1, u2); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp index ba90731c8ca7..3d7303af655b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.cpp @@ -5,8 +5,6 @@ #include "barretenberg/stdlib/hash/blake2s/blake2s.hpp" #include "barretenberg/stdlib/commitment/pedersen/pedersen.hpp" -#include "../../primitives/composers/composers.hpp" - namespace proof_system::plonk { namespace stdlib { namespace schnorr { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp index 78b3d1290d38..21747581be01 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp @@ -1,12 +1,10 @@ +#include + #include "schnorr.hpp" #include "barretenberg/crypto/pedersen_commitment/pedersen.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/stdlib/primitives/field/field.hpp" -#include "barretenberg/stdlib/primitives/bool/bool.hpp" -#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" #include "barretenberg/stdlib/primitives/point/point.hpp" -#include namespace proof_system::test_stdlib_schnorr { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp index 9273000b4443..9b6b8d526baa 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/external/external.bench.cpp @@ -4,17 +4,17 @@ * @brief Benchmarks for external benchmarking projects (e.g. delendum-xyz) * */ -#include "../../sha256/sha256.hpp" -#include "../../blake3s/blake3s.hpp" #include -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/plonk/proof_system/prover/prover.hpp" -#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" + +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" +#include "barretenberg/stdlib/hash/sha256/sha256.hpp" +#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" using namespace benchmark; -using Composer = proof_system::plonk::UltraPlonkComposer; +using Builder = proof_system::UltraCircuitConstructor; +using Composer = proof_system::plonk::UltraPlonkComposerHelper; + using Prover = proof_system::plonk::UltraProver; using Verifier = proof_system::plonk::UltraVerifier; @@ -28,19 +28,20 @@ constexpr size_t NUM_PROOFS = 3; * @param composer * @param num_iterations */ -void generate_test_sha256_plonk_circuit(Composer& composer, size_t num_iterations) +void generate_test_sha256_plonk_circuit(Builder& builder, size_t num_iterations) { std::string in; in.resize(32); for (size_t i = 0; i < 32; ++i) { in[i] = 0; } - proof_system::plonk::stdlib::packed_byte_array input(&composer, in); + proof_system::plonk::stdlib::packed_byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = proof_system::plonk::stdlib::sha256(input); + input = proof_system::plonk::stdlib::sha256(input); } } +Builder external_builders[NUM_PROOFS]; Composer external_composers[NUM_PROOFS]; Prover external_provers[NUM_PROOFS]; Verifier external_verifiers[NUM_PROOFS]; @@ -61,8 +62,8 @@ void generate_sha256_proof_bench(State& state) noexcept num_iterations *= PROOF_COUNT_LOG; } external_composers[idx] = Composer(); - generate_test_sha256_plonk_circuit(external_composers[idx], num_iterations); - external_provers[idx] = external_composers[idx].create_prover(); + generate_test_sha256_plonk_circuit(external_builders[idx], num_iterations); + external_provers[idx] = external_composers[idx].create_prover(external_builders[idx]); external_proofs[idx] = external_provers[idx].construct_proof(); // info("Proof Size for SHA256 hash count ", num_iterations, ": ", external_proofs[idx].proof_data.size()); } @@ -84,7 +85,7 @@ static void generate_sha256_verifier(const State& state) { size_t idx = static_cast(state.range(0)); - external_verifiers[idx] = external_composers[idx].create_verifier(); + external_verifiers[idx] = external_composers[idx].create_verifier(external_builders[idx]); } /** * @brief Benchmark sha256 verification @@ -108,16 +109,16 @@ BENCHMARK(verify_sha256_proof_bench)->DenseRange(0, 2)->Setup(generate_sha256_ve * @param composer * @param num_iterations */ -void generate_test_blake3s_plonk_circuit(Composer& composer, size_t num_iterations) +void generate_test_blake3s_plonk_circuit(Builder& builder, size_t num_iterations) { std::string in; in.resize(32); for (size_t i = 0; i < 32; ++i) { in[i] = 0; } - proof_system::plonk::stdlib::packed_byte_array input(&composer, in); + proof_system::plonk::stdlib::packed_byte_array input(&builder, in); for (size_t i = 0; i < num_iterations; i++) { - input = proof_system::plonk::stdlib::blake3s(input); + input = proof_system::plonk::stdlib::blake3s(input); } } @@ -136,8 +137,8 @@ void generate_blake3s_proof_bench(State& state) noexcept num_iterations *= PROOF_COUNT_LOG; } external_composers[idx] = Composer(); - generate_test_blake3s_plonk_circuit(external_composers[idx], num_iterations); - external_provers[idx] = external_composers[idx].create_prover(); + generate_test_blake3s_plonk_circuit(external_builders[idx], num_iterations); + external_provers[idx] = external_composers[idx].create_prover(external_builders[idx]); external_proofs[idx] = external_provers[idx].construct_proof(); // Proof size with no public inputs is always 2144 // info("Proof Size for Blake3s hash count ", num_iterations, ": ", external_proofs[idx].proof_data.size()); @@ -157,7 +158,7 @@ static void generate_blake3s_verifier(const State& state) { size_t idx = static_cast(state.range(0)); - external_verifiers[idx] = external_composers[idx].create_verifier(); + external_verifiers[idx] = external_composers[idx].create_verifier(external_builders[idx]); } /** diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp index ef3bbd255fca..069dad1a2b08 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/benchmarks/sha256/sha256.bench.cpp @@ -1,13 +1,11 @@ -#include "../../sha256/sha256.hpp" #include -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/plonk/proof_system/prover/prover.hpp" -#include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" +#include "barretenberg/stdlib/hash/sha256/sha256.hpp" using namespace benchmark; -using Composer = proof_system::plonk::UltraPlonkComposer; +using Builder = proof_system::UltraCircuitConstructor; +using Composer = proof_system::plonk::UltraPlonkComposerHelper; using Prover = proof_system::plonk::UltraProver; using Verifier = proof_system::plonk::UltraVerifier; @@ -21,17 +19,18 @@ char get_random_char() return static_cast(barretenberg::fr::random_element().data[0] % 8); } -void generate_test_plonk_circuit(Composer& composer, size_t num_bytes) +void generate_test_plonk_circuit(Builder& builder, size_t num_bytes) { std::string in; in.resize(num_bytes); for (size_t i = 0; i < num_bytes; ++i) { in[i] = get_random_char(); } - proof_system::plonk::stdlib::packed_byte_array input(&composer, in); - proof_system::plonk::stdlib::sha256(input); + proof_system::plonk::stdlib::packed_byte_array input(&builder, in); + proof_system::plonk::stdlib::sha256(input); } +Builder builders[NUM_HASHES]; Composer composers[NUM_HASHES]; Prover provers[NUM_HASHES]; Verifier verifiers[NUM_HASHES]; @@ -41,8 +40,8 @@ void construct_witnesses_bench(State& state) noexcept { for (auto _ : state) { size_t idx = (static_cast((state.range(0))) - START_BYTES) / BYTES_PER_CHUNK; - composers[idx] = Composer(); - generate_test_plonk_circuit(composers[idx], static_cast(state.range(0))); + builders[idx] = Builder(); + generate_test_plonk_circuit(builders[idx], static_cast(state.range(0))); } } BENCHMARK(construct_witnesses_bench)->DenseRange(START_BYTES, MAX_BYTES, BYTES_PER_CHUNK); @@ -51,7 +50,8 @@ void preprocess_witnesses_bench(State& state) noexcept { for (auto _ : state) { size_t idx = (static_cast((state.range(0))) - START_BYTES) / BYTES_PER_CHUNK; - provers[idx] = composers[idx].create_prover(); + composers[idx] = Composer(); + provers[idx] = composers[idx].create_prover(builders[idx]); std::cout << "prover subgroup size = " << provers[idx].key->small_domain.size << std::endl; // printf("num bytes = %" PRIx64 ", num gates = %zu\n", state.range(0), composers[idx].get_num_gates()); } @@ -62,7 +62,7 @@ void construct_instances_bench(State& state) noexcept { for (auto _ : state) { size_t idx = (static_cast((state.range(0))) - START_BYTES) / BYTES_PER_CHUNK; - verifiers[idx] = composers[idx].create_verifier(); + verifiers[idx] = composers[idx].create_verifier(builders[idx]); } } BENCHMARK(construct_instances_bench)->DenseRange(START_BYTES, MAX_BYTES, BYTES_PER_CHUNK); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp index 6c581623fcab..754850b0f1e1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.cpp @@ -2,7 +2,6 @@ #include "blake2s_plookup.hpp" #include "blake_util.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace proof_system::plonk { namespace stdlib { @@ -117,7 +116,7 @@ template void blake2s(blake2s_state& S, byte_array template byte_array blake2s(const byte_array& input) { - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { return blake2s_plookup::blake2s(input); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp index f056a21c8349..fc4e21d4e40b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp index 97cd53f2dda5..ab0afa7f3ee7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp @@ -2,29 +2,27 @@ #include "blake2s_plookup.hpp" #include #include "barretenberg/crypto/blake2s/blake2s.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" using namespace barretenberg; -using namespace proof_system::plonk; +using namespace proof_system::plonk::stdlib; -using namespace plonk::stdlib; +using Builder = proof_system::UltraCircuitConstructor; -using Composer = proof_system::UltraCircuitConstructor; - -using field_ct = field_t; -using witness_ct = witness_t; -using byte_array_ct = stdlib::byte_array; -using byte_array_plookup = stdlib::byte_array; -using public_witness_t = stdlib::public_witness_t; -using public_witness_t_plookup = stdlib::public_witness_t; +using field_ct = field_t; +using witness_ct = witness_t; +using byte_array_ct = byte_array; +using byte_array_plookup = byte_array; +using public_witness_t = public_witness_t; // TEST(stdlib_blake2s, test_single_block) // { -// auto composer = Composer(); +// auto composer = Builder(); // std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01"; // std::vector input_v(input.begin(), input.end()); // byte_array_ct input_arr(&composer, input_v); -// byte_array_ct output = stdlib::blake2s(input_arr); +// byte_array_ct output = blake2s(input_arr); // std::vector expected = blake2::blake2s(input_v); @@ -38,31 +36,31 @@ using public_witness_t_plookup = stdlib::public_witness_t; TEST(stdlib_blake2s, test_single_block_plookup) { - proof_system::UltraCircuitConstructor composer = UltraCircuitConstructor(); + Builder builder; std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz01"; std::vector input_v(input.begin(), input.end()); - byte_array_plookup input_arr(&composer, input_v); - byte_array_plookup output = stdlib::blake2s(input_arr); + byte_array_plookup input_arr(&builder, input_v); + byte_array_plookup output = blake2s(input_arr); auto expected = blake2::blake2s(input_v); EXPECT_EQ(output.get_value(), std::vector(expected.begin(), expected.end())); - info("composer gates = ", composer.get_num_gates()); + info("builder gates = ", builder.get_num_gates()); - bool proof_result = composer.check_circuit(); + bool proof_result = builder.check_circuit(); EXPECT_EQ(proof_result, true); } // TEST(stdlib_blake2s, test_double_block) // { -// auto composer = Composer(); +// auto composer = Builder(); // std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"; // std::vector input_v(input.begin(), input.end()); // byte_array_ct input_arr(&composer, input_v); -// byte_array_ct output = stdlib::blake2s(input_arr); +// byte_array_ct output = blake2s(input_arr); // std::vector expected = blake2::blake2s(input_v); @@ -76,19 +74,19 @@ TEST(stdlib_blake2s, test_single_block_plookup) TEST(stdlib_blake2s, test_double_block_plookup) { - proof_system::UltraCircuitConstructor composer = UltraCircuitConstructor(); + Builder builder; std::string input = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"; std::vector input_v(input.begin(), input.end()); - byte_array_plookup input_arr(&composer, input_v); - byte_array_plookup output = stdlib::blake2s(input_arr); + byte_array_plookup input_arr(&builder, input_v); + byte_array_plookup output = blake2s(input_arr); auto expected = blake2::blake2s(input_v); EXPECT_EQ(output.get_value(), std::vector(expected.begin(), expected.end())); - info("composer gates = ", composer.get_num_gates()); + info("builder gates = ", builder.get_num_gates()); - bool proof_result = composer.check_circuit(); + bool proof_result = builder.check_circuit(); EXPECT_EQ(proof_result, true); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.cpp index 47416a8592cd..7062169830ff 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.cpp @@ -7,7 +7,6 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/plookup/plookup.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" /** * Optimizations: diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.hpp index 2340cf3305f9..8c34f95a39f5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s_plookup.hpp @@ -6,7 +6,7 @@ #include "barretenberg/numeric/bitop/sparse_form.hpp" #include "../../primitives/field/field.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake_util.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake_util.hpp index a31de38dc0b2..3cc506ed625d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake_util.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake2s/blake_util.hpp @@ -1,6 +1,4 @@ #pragma once -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp index 09d1c5b8ddc7..78681009a96e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.cpp @@ -2,7 +2,6 @@ #include "blake3s_plookup.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "../blake2s/blake_util.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace proof_system::plonk { namespace stdlib { @@ -245,7 +244,7 @@ using namespace blake3_internal; template byte_array blake3s(const byte_array& input) { - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { return blake3s_plookup::blake3s(input); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp index d5bd02f5d2ea..78d895f6b1f3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp index 6e951187c73f..70d6c6941ee8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s.test.cpp @@ -3,7 +3,6 @@ #include "barretenberg/crypto/blake3s/blake3s.hpp" #include "barretenberg/common/streams.hpp" #include -#include "barretenberg/stdlib/primitives/composers/composers.hpp" using namespace barretenberg; using namespace proof_system::plonk; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.cpp index 69849c7d71cc..252c5306f685 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.cpp @@ -6,7 +6,6 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/plookup/plookup.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.hpp index 8cccabb3c480..fc9d5f9923a3 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/blake3s/blake3s_plookup.hpp @@ -6,7 +6,7 @@ #include "barretenberg/numeric/bitop/sparse_form.hpp" #include "../../primitives/field/field.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp index 2d4cd026f276..7946f8b862d8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/keccak/keccak.cpp @@ -2,7 +2,6 @@ #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/numeric/bitop/sparse_form.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.cpp index 71534c1f3366..be86192db6a8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.cpp @@ -1,7 +1,6 @@ #include "pedersen.hpp" #include "pedersen_plookup.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#include "../../primitives/composers/composers.hpp" #include "pedersen_gates.hpp" namespace proof_system::plonk { @@ -206,7 +205,7 @@ point pedersen_hash::hash_single_internal(const field_t& in, if (i > 0) { gates.create_fixed_group_add_gate(round_quad); } else { - if constexpr (C::type == ComposerType::PLOOKUP && + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && (C::merkle_hash_type == merkle::HashType::FIXED_BASE_PEDERSEN || C::commitment_type == pedersen::CommitmentType::FIXED_BASE_PEDERSEN)) { /* In TurboPlonkComposer, the selector q_5 is used to show that w_1 and w_2 are properly initialized to @@ -283,7 +282,8 @@ point pedersen_hash::hash_single(const field_t& in, const generator_index_t hash_index, const bool validate_input_is_in_field) { - if constexpr (C::type == ComposerType::PLOOKUP && C::merkle_hash_type == merkle::HashType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::merkle_hash_type == merkle::HashType::LOOKUP_PEDERSEN) { return pedersen_plookup_hash::hash_single(in, hash_index.index == 0); } @@ -300,7 +300,8 @@ point pedersen_hash::commit_single(const field_t& in, const generator_index_t hash_index, const bool validate_input_is_in_field) { - if constexpr (C::type == ComposerType::PLOOKUP && C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::commitment_type == pedersen::CommitmentType::LOOKUP_PEDERSEN) { return pedersen_plookup_hash::hash_single(in, hash_index.index == 0); } @@ -479,7 +480,7 @@ template void pedersen_hash::validate_wnaf_is_in_field(C* ctx, c field_t y_lo = (-reconstructed_input).add_two(high_limb_with_skew * shift + (r_lo + shift), is_even); field_t y_overlap; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { // carve out the 2 high bits from y_lo and instantiate as y_overlap const uint256_t y_lo_value = y_lo.get_value(); const uint256_t y_overlap_value = y_lo_value >> 126; @@ -549,7 +550,8 @@ field_t pedersen_hash::hash_multiple(const std::vector& inputs, const size_t hash_index, const bool validate_inputs_in_field) { - if constexpr (C::type == ComposerType::PLOOKUP && C::merkle_hash_type == merkle::HashType::LOOKUP_PEDERSEN) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP && + C::merkle_hash_type == merkle::HashType::LOOKUP_PEDERSEN) { return pedersen_plookup_hash::hash_multiple(inputs, hash_index); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.hpp index 460443078b04..649e6616adf1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/point/point.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_gates.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_gates.hpp index 211b01e3fdbc..4d1049166a18 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_gates.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_gates.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/proof_system/arithmetization/gate_data.hpp" -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/point/point.hpp" #include "../../primitives/byte_array/byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.cpp index e610def7770a..9f27d3d701e9 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.cpp @@ -3,7 +3,6 @@ #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" #include "barretenberg/proof_system/plookup_tables/types.hpp" -#include "../../primitives/composers/composers.hpp" #include "../../primitives/plookup/plookup.hpp" using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.hpp index dd1c087bc304..7377b272863b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/pedersen/pedersen_plookup.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../../primitives/composers/composers_fwd.hpp" +#include "../../primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/point/point.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp index 406873b73d16..188c4f692502 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.cpp @@ -1,7 +1,7 @@ #include "sha256.hpp" #include "sha256_plookup.hpp" #include "barretenberg/stdlib/primitives/bit_array/bit_array.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" namespace proof_system::plonk { namespace stdlib { @@ -137,7 +137,7 @@ template byte_array sha256_block(const byte_array< template packed_byte_array sha256(const packed_byte_array& input) { - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { return sha256_plookup::sha256(input); } typedef field_t field_pt; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp index e123dc723a6b..5636d34b4015 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.hpp @@ -3,7 +3,7 @@ #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" #include "sha256_plookup.hpp" // namespace proof_system::plonk diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp index 9fb1261eb993..21564d325783 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -1,8 +1,9 @@ #include "sha256.hpp" #include "barretenberg/common/test.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/numeric/bitop/rotate.hpp" @@ -113,52 +114,24 @@ std::array inner_block(std::array& w) return output; } -TEST(stdlib_sha256, test_duplicate_proving_key) -{ - - auto first_composer = plonk::StandardPlonkComposer(); - plonk::stdlib::packed_byte_array input( - &first_composer, "An 8 character password? Snow White and the 7 Dwarves.."); - plonk::stdlib::sha256(input); - auto prover = first_composer.create_prover(); - auto verifier = first_composer.create_verifier(); - plonk::proof proof_one = prover.construct_proof(); - bool proof_result_one = verifier.verify_proof(proof_one); - EXPECT_EQ(proof_result_one, true); - auto proving_key = prover.key; - auto verification_key = verifier.key; - auto circuit_size = prover.circuit_size; - - // Test a second time with same keys and different input. - auto second_composer = plonk::StandardPlonkComposer(proving_key, verification_key, circuit_size); - plonk::stdlib::packed_byte_array input2( - &second_composer, "An 8 character password? Snow White and the 9 Dwarves.."); - plonk::stdlib::sha256(input2); - auto second_prover = second_composer.create_prover(); - auto second_verifier = second_composer.create_verifier(); - plonk::proof proof_two = second_prover.construct_proof(); - bool proof_result_two = second_verifier.verify_proof(proof_two); - EXPECT_EQ(proof_result_two, true); -} - // TEST(stdlib_sha256_plookup, test_round) // { // auto composer = UltraPlonkComposer(); // std::array w_inputs; -// std::array, 64> w_elements; +// std::array, 64> w_elements; // for (size_t i = 0; i < 64; ++i) { // w_inputs[i] = engine.get_random_uint32(); -// w_elements[i] = plonk::stdlib::witness_t(&composer, +// w_elements[i] = proof_system::plonk::stdlib::witness_t(&composer, // barretenberg::fr(w_inputs[i])); // } // const auto expected = inner_block(w_inputs); -// const std::array, 8> result = -// plonk::stdlib::sha256_inner_block(w_elements); +// const std::array, 8> result = +// proof_system::plonk::stdlib::sha256_inner_block(w_elements); // for (size_t i = 0; i < 8; ++i) { // EXPECT_EQ(uint256_t(result[i].get_value()).data[0] & 0xffffffffUL, // uint256_t(expected[i]).data[0] & 0xffffffffUL); @@ -168,22 +141,22 @@ TEST(stdlib_sha256, test_duplicate_proving_key) // auto prover = composer.create_prover(); // auto verifier = composer.create_verifier(); -// plonk::proof proof = prover.construct_proof(); +// proof_system::plonk::proof proof = prover.construct_proof(); // bool proof_result = composer.check_circuit(); // EXPECT_EQ(proof_result, true); // } TEST(stdlib_sha256, test_plookup_55_bytes) { - typedef plonk::stdlib::field_t field_pt; - typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; + typedef proof_system::plonk::stdlib::field_t field_pt; + typedef proof_system::plonk::stdlib::packed_byte_array packed_byte_array_pt; // 55 bytes is the largest number of bytes that can be hashed in a single block, // accounting for the single padding bit, and the 64 size bits required by the SHA-256 standard. auto composer = proof_system::UltraCircuitConstructor(); packed_byte_array_pt input(&composer, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); + packed_byte_array_pt output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -208,7 +181,7 @@ TEST(stdlib_sha256, test_55_bytes) auto composer = Composer(); packed_byte_array_ct input(&composer, "An 8 character password? Snow White and the 7 Dwarves.."); - packed_byte_array_ct output_bits = plonk::stdlib::sha256(input); + packed_byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -228,13 +201,13 @@ TEST(stdlib_sha256, test_55_bytes) TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) { - typedef plonk::stdlib::field_t field_pt; - typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; + typedef proof_system::plonk::stdlib::field_t field_pt; + typedef proof_system::plonk::stdlib::packed_byte_array packed_byte_array_pt; auto composer = proof_system::UltraCircuitConstructor(); packed_byte_array_pt input(&composer, "abc"); - packed_byte_array_pt output_bytes = plonk::stdlib::sha256(input); + packed_byte_array_pt output_bytes = proof_system::plonk::stdlib::sha256(input); std::vector output = output_bytes.to_unverified_byte_slices(4); EXPECT_EQ(uint256_t(output[0].get_value()).data[0], (uint64_t)0xBA7816BFU); EXPECT_EQ(uint256_t(output[1].get_value()).data[0], (uint64_t)0x8F01CFEAU); @@ -252,14 +225,14 @@ TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) TEST(stdlib_sha256, test_NIST_vector_one) { - typedef plonk::stdlib::field_t field_pt; - typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; + typedef proof_system::plonk::stdlib::field_t field_pt; + typedef proof_system::plonk::stdlib::packed_byte_array packed_byte_array_pt; auto composer = proof_system::UltraCircuitConstructor(); packed_byte_array_pt input(&composer, "abc"); - packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); + packed_byte_array_pt output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -283,7 +256,7 @@ TEST(stdlib_sha256, test_NIST_vector_two) byte_array_ct input(&composer, "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"); - byte_array_ct output_bits = plonk::stdlib::sha256(input); + byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -308,7 +281,7 @@ TEST(stdlib_sha256, test_NIST_vector_three) // one byte, 0xbd byte_array_ct input(&composer, std::vector{ 0xbd }); - byte_array_ct output_bits = plonk::stdlib::sha256(input); + byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -333,7 +306,7 @@ TEST(stdlib_sha256, test_NIST_vector_four) // 4 bytes, 0xc98c8e55 byte_array_ct input(&composer, std::vector{ 0xc9, 0x8c, 0x8e, 0x55 }); - byte_array_ct output_bits = plonk::stdlib::sha256(input); + byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); std::vector output = packed_byte_array_ct(output_bits).to_unverified_byte_slices(4); @@ -354,8 +327,8 @@ TEST(stdlib_sha256, test_NIST_vector_four) HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) { - typedef plonk::stdlib::field_t field_pt; - typedef plonk::stdlib::packed_byte_array packed_byte_array_pt; + typedef proof_system::plonk::stdlib::field_t field_pt; + typedef proof_system::plonk::stdlib::packed_byte_array packed_byte_array_pt; auto composer = proof_system::UltraCircuitConstructor(); @@ -372,7 +345,8 @@ HEAVY_TEST(stdlib_sha256, test_NIST_vector_five) "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAA"); - packed_byte_array_pt output_bits = plonk::stdlib::sha256(input); + packed_byte_array_pt output_bits = + proof_system::plonk::stdlib::sha256(input); std::vector output = output_bits.to_unverified_byte_slices(4); @@ -401,7 +375,7 @@ TEST(stdlib_sha256, test_input_len_multiple) auto input_buf = std::vector(inp, 1); byte_array_ct input(&composer, input_buf); - byte_array_ct output_bits = plonk::stdlib::sha256(input); + byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); auto circuit_output = output_bits.get_value(); @@ -445,7 +419,7 @@ TEST(stdlib_sha256, test_input_str_len_multiple) auto input_buf = std::vector(input_str.begin(), input_str.end()); byte_array_ct input(&composer, input_buf); - byte_array_ct output_bits = plonk::stdlib::sha256(input); + byte_array_ct output_bits = proof_system::plonk::stdlib::sha256(input); auto circuit_output = output_bits.get_value(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.cpp index 459f5d6dbfcd..2995a8184444 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.cpp @@ -6,7 +6,6 @@ #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/plookup/plookup.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp index 447ca209a4d0..6b374c07353e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/hash/sha256/sha256_plookup.hpp @@ -4,7 +4,7 @@ #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/numeric/bitop/sparse_form.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" #include "../../primitives/field/field.hpp" #include "../../primitives/packed_byte_array/packed_byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp index 1f19ded73cfc..1fce6924e2c6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp @@ -2,15 +2,13 @@ #include "memory_tree.hpp" #include -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/stdlib/primitives/field/field.hpp" -#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" #include "barretenberg/stdlib/merkle_tree/membership.hpp" namespace proof_system::stdlib_merkle_tree_hash_test { using namespace barretenberg; -using namespace plonk::stdlib; +using namespace proof_system::plonk::stdlib; using Composer = proof_system::UltraCircuitConstructor; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash_path.hpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash_path.hpp index e6e5bfcdf6d8..1c52ffc96171 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash_path.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/hash_path.hpp @@ -71,7 +71,7 @@ inline fr zero_hash_at_height(size_t height) // to achieve effective ADL. namespace std { template -inline std::ostream& operator<<(std::ostream& os, plonk::stdlib::merkle_tree::hash_path const& path) +inline std::ostream& operator<<(std::ostream& os, proof_system::plonk::stdlib::merkle_tree::hash_path const& path) { os << "[\n"; for (size_t i = 0; i < path.size(); ++i) { @@ -81,7 +81,7 @@ inline std::ostream& operator<<(std::ostream& os, plonk::stdlib::merkle_tree::ha return os; } -inline std::ostream& operator<<(std::ostream& os, plonk::stdlib::merkle_tree::fr_hash_path const& path) +inline std::ostream& operator<<(std::ostream& os, proof_system::plonk::stdlib::merkle_tree::fr_hash_path const& path) { os << "[\n"; for (size_t i = 0; i < path.size(); ++i) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp index 76251dc720e2..c5b2ec721aa7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp @@ -5,10 +5,7 @@ #include "memory_store.hpp" #include "memory_tree.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/stdlib/primitives/bool/bool.hpp" -#include "barretenberg/stdlib/primitives/field/field.hpp" -#include "barretenberg/stdlib/primitives/witness/witness.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" namespace { auto& engine = numeric::random::get_debug_engine(); @@ -18,7 +15,7 @@ namespace proof_system::stdlib_merkle_test { using namespace barretenberg; using namespace proof_system::plonk::stdlib::merkle_tree; -using namespace plonk::stdlib; +using namespace proof_system::plonk::stdlib; using Composer = proof_system::UltraCircuitConstructor; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp index 6f5bdf58d120..8b732e67a1f6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.test.cpp @@ -7,7 +7,7 @@ namespace proof_system::test_stdlib_merkle_tree { -using namespace plonk::stdlib; +using namespace proof_system::plonk::stdlib; using namespace proof_system::plonk::stdlib::merkle_tree; using Composer = proof_system::UltraCircuitConstructor; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp index 3b3bd34f6752..4b12a20eff9c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.hpp @@ -9,7 +9,7 @@ #include "../byte_array/byte_array.hpp" #include "../field/field.hpp" -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp index 567edcd7a5f9..2ec05ce652d1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield.test.cpp @@ -9,7 +9,7 @@ #include "../byte_array/byte_array.hpp" #include "../field/field.hpp" #include "./bigfield.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/plonk/proof_system/verifier/verifier.hpp" @@ -107,7 +107,7 @@ template class stdlib_bigfield : public testing::Test { // Don't profile 1st repetition. It sets up a lookup table, cost is not representative of a typical mul if (i == num_repetitions - 2) { std::cerr << "num gates per mul = " << after - before << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), "Bigfield", "MUL", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Bigfield", "MUL", "Gate Count", after - before); } // uint256_t modulus{ Bn254FqParams::modulus_0, // Bn254FqParams::modulus_1, @@ -145,7 +145,7 @@ template class stdlib_bigfield : public testing::Test { uint64_t after = composer.get_num_gates(); if (i == num_repetitions - 1) { std::cerr << "num gates per mul = " << after - before << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), "Bigfield", "SQR", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Bigfield", "SQR", "Gate Count", after - before); } // uint256_t modulus{ Bn254FqParams::modulus_0, // Bn254FqParams::modulus_1, @@ -191,7 +191,7 @@ template class stdlib_bigfield : public testing::Test { uint64_t after = composer.get_num_gates(); if (i == num_repetitions - 1) { std::cerr << "num gates per mul = " << after - before << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), "Bigfield", "MADD", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Bigfield", "MADD", "Gate Count", after - before); } // uint256_t modulus{ Bn254FqParams::modulus_0, // Bn254FqParams::modulus_1, @@ -251,8 +251,7 @@ template class stdlib_bigfield : public testing::Test { uint64_t after = composer.get_num_gates(); if (i == num_repetitions - 1) { std::cerr << "num gates with mult_madd = " << after - before << std::endl; - benchmark_info( - GET_COMPOSER_NAME_STRING(Composer), "Bigfield", "MULT_MADD", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Bigfield", "MULT_MADD", "Gate Count", after - before); } /** before = composer.get_num_gates(); @@ -359,7 +358,7 @@ template class stdlib_bigfield : public testing::Test { uint64_t after = composer.get_num_gates(); if (i == num_repetitions - 1) { std::cout << "num gates per div = " << after - before << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), "Bigfield", "DIV", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Bigfield", "DIV", "Gate Count", after - before); } // uint256_t modulus{ Bn254FqParams::modulus_0, // Bn254FqParams::modulus_1, diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp index 13371176015e..2a569e3d33e0 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/bigfield_impl.hpp @@ -4,7 +4,7 @@ #include "barretenberg/numeric/uintx/uintx.hpp" #include -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "../bit_array/bit_array.hpp" #include "../field/field.hpp" @@ -56,7 +56,7 @@ bigfield::bigfield(const field_t& low_bits_in, field_t limb_3(context); if (low_bits_in.witness_index != IS_CONSTANT) { std::vector low_accumulator; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { // MERGE NOTE: this was the if constexpr block introduced in ecebe7643 const auto limb_witnesses = context->decompose_non_native_field_double_width_limb(low_bits_in.normalize().witness_index); @@ -107,7 +107,7 @@ bigfield::bigfield(const field_t& low_bits_in, if (high_bits_in.witness_index != IS_CONSTANT) { std::vector high_accumulator; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { const auto limb_witnesses = context->decompose_non_native_field_double_width_limb( high_bits_in.normalize().witness_index, (size_t)num_high_limb_bits); limb_2.witness_index = limb_witnesses[0]; @@ -187,7 +187,7 @@ bigfield bigfield::create_from_u512_as_witness(C* ctx, limbs[2] = value.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3).lo; limbs[3] = value.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4).lo; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { field_t limb_0(ctx); field_t limb_1(ctx); field_t limb_2(ctx); @@ -384,7 +384,7 @@ template bigfield bigfield::operator+(const result.binary_basis_limbs[3].maximum_value = binary_basis_limbs[3].maximum_value + other.binary_basis_limbs[3].maximum_value; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { if (prime_basis_limb.multiplicative_constant == 1 && other.prime_basis_limb.multiplicative_constant == 1 && !is_constant() && !other.is_constant()) { bool limbconst = binary_basis_limbs[0].element.is_constant(); @@ -592,7 +592,7 @@ template bigfield bigfield::operator-(const result.binary_basis_limbs[2].element = binary_basis_limbs[2].element + barretenberg::fr(to_add_2); result.binary_basis_limbs[3].element = binary_basis_limbs[3].element + barretenberg::fr(to_add_3); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { if (prime_basis_limb.multiplicative_constant == 1 && other.prime_basis_limb.multiplicative_constant == 1 && !is_constant() && !other.is_constant()) { bool limbconst = result.binary_basis_limbs[0].element.is_constant(); @@ -1647,7 +1647,7 @@ template void bigfield::assert_is_in_field() cons r1 = r1.normalize(); r2 = r2.normalize(); r3 = r3.normalize(); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { context->decompose_into_default_range(r0.witness_index, static_cast(NUM_LIMB_BITS)); context->decompose_into_default_range(r1.witness_index, static_cast(NUM_LIMB_BITS)); context->decompose_into_default_range(r2.witness_index, static_cast(NUM_LIMB_BITS)); @@ -1780,7 +1780,7 @@ template void bigfield::self_reduce() const // TODO: implicit assumption here - NUM_LIMB_BITS large enough for all the quotient uint32_t quotient_limb_index = context->add_variable(barretenberg::fr(quotient_value.lo)); field_t quotient_limb = field_t::from_witness_index(context, quotient_limb_index); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { context->decompose_into_default_range(quotient_limb.witness_index, static_cast(maximum_quotient_bits)); } else { context->decompose_into_base4_accumulators(quotient_limb.witness_index, @@ -1882,7 +1882,7 @@ void bigfield::unsafe_evaluate_multiply_add(const bigfield& input_left, ++max_hi_bits; } - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { // The plookup custom bigfield gate requires inputs are witnesses. // If we're using constant values, instantiate them as circuit variables const auto convert_constant_to_fixed_witness = [ctx](const bigfield& input) { @@ -2240,7 +2240,7 @@ void bigfield::unsafe_evaluate_multiple_multiply_add(const std::vector::unsafe_evaluate_multiple_multiply_add(const std::vectordecompose_into_default_range(lo.normalize().witness_index, carry_lo_msb); } /* NOTE TO AUDITOR: An extraneous block - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { carry_lo = carry_lo.normalize(); carry_hi = carry_hi.normalize(); ctx->decompose_into_default_range(carry_lo.witness_index, static_cast(carry_lo_msb)); @@ -2606,7 +2606,7 @@ void bigfield::unsafe_evaluate_multiple_multiply_add(const std::vectordecompose_into_default_range(carry_lo.witness_index, static_cast(carry_lo_msb)); @@ -2645,7 +2645,7 @@ void bigfield::unsafe_evaluate_square_add(const bigfield& left, const bigfield& quotient, const bigfield& remainder) { - if (C::type == ComposerType::PLOOKUP) { + if (C::type == proof_system::ComposerType::PLOOKUP) { unsafe_evaluate_multiply_add(left, left, to_add, quotient, { remainder }); return; } @@ -2766,7 +2766,7 @@ void bigfield::unsafe_evaluate_square_add(const bigfield& left, const uint64_t carry_hi_msb = max_hi_bits - (2 * NUM_LIMB_BITS); const barretenberg::fr carry_lo_shift(uint256_t(uint256_t(1) << carry_lo_msb)); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { carry_lo = carry_lo.normalize(); carry_hi = carry_hi.normalize(); ctx->decompose_into_default_range(carry_lo.witness_index, static_cast(carry_lo_msb)); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp index c44f550ab789..53d70fed2c1b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.hpp @@ -5,7 +5,7 @@ #include "../field/field.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../memory/rom_table.hpp" #include "../memory/twin_rom_table.hpp" #include "barretenberg/ecc/curves/secp256k1/secp256k1.hpp" @@ -250,18 +250,20 @@ template class element { Fq y; private: - template > + template > static std::array, 5> create_group_element_rom_tables( const std::array& elements, std::array& limb_max); - template > + template > static element read_group_element_rom_tables(const std::array, 5>& tables, const field_t& index, const std::array& limb_max); static std::pair compute_offset_generators(const size_t num_rounds); - template > + template > struct four_bit_table_plookup { four_bit_table_plookup(){}; four_bit_table_plookup(const element& input); @@ -276,7 +278,7 @@ template class element { std::array limb_max; // tracks the maximum limb size represented in each element_table entry }; - template > + template > struct eight_bit_fixed_base_table { enum CurveType { BN254, SECP256K1, SECP256R1 }; eight_bit_fixed_base_table(const CurveType input_curve_type, bool use_endo) @@ -294,7 +296,7 @@ template class element { bool use_endomorphism; }; - template > + template > static std::pair, four_bit_table_plookup<>> create_endo_pair_four_bit_table_plookup( const element& input) { @@ -373,7 +375,7 @@ template class element { * * Uses ROM tables to efficiently access lookup table **/ - template > + template > struct lookup_table_plookup { static constexpr size_t table_size = (1ULL << (length)); lookup_table_plookup() {} @@ -390,14 +392,17 @@ template class element { std::array limb_max; }; - using twin_lookup_table = typename std:: - conditional, lookup_table_base<2>>::type; + using twin_lookup_table = typename std::conditional, + lookup_table_base<2>>::type; - using triple_lookup_table = typename std:: - conditional, lookup_table_base<3>>::type; + using triple_lookup_table = typename std::conditional, + lookup_table_base<3>>::type; - using quad_lookup_table = typename std:: - conditional, lookup_table_base<4>>::type; + using quad_lookup_table = typename std::conditional, + lookup_table_base<4>>::type; /** * Creates a pair of 4-bit lookup tables, the former corresponding to 4 input points, @@ -410,7 +415,7 @@ template class element { quad_lookup_table endo_table; uint256_t beta_val = barretenberg::field::cube_root_of_unity(); Fq beta(barretenberg::fr(beta_val.slice(0, 136)), barretenberg::fr(beta_val.slice(136, 256)), false); - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { for (size_t i = 0; i < 8; ++i) { endo_table.element_table[i + 8].x = base_table[7 - i].x * beta; endo_table.element_table[i + 8].y = base_table[7 - i].y; @@ -435,7 +440,7 @@ template class element { * Creates a pair of 5-bit lookup tables, the former corresponding to 5 input points, * the latter corresponding to the endomorphism equivalent of the 5 input points (e.g. x -> \beta * x, y -> -y) **/ - template > + template > static std::pair, lookup_table_plookup<5, X>> create_endo_pair_five_lookup_table( const std::array& inputs) { @@ -443,7 +448,7 @@ template class element { lookup_table_plookup<5> endo_table; uint256_t beta_val = barretenberg::field::cube_root_of_unity(); Fq beta(barretenberg::fr(beta_val.slice(0, 136)), barretenberg::fr(beta_val.slice(136, 256)), false); - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { for (size_t i = 0; i < 16; ++i) { endo_table.element_table[i + 16].x = base_table[15 - i].x * beta; endo_table.element_table[i + 16].y = base_table[15 - i].y; @@ -462,7 +467,7 @@ template class element { * * UltraPlonk version **/ - template > + template > struct batch_lookup_table_plookup { batch_lookup_table_plookup(const std::vector& points) { @@ -882,7 +887,7 @@ template class element { bool has_singleton; }; - using batch_lookup_table = typename std::conditional, batch_lookup_table_base>::type; }; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp index 9176076a56f4..1c034e658e7e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup.test.cpp @@ -5,7 +5,7 @@ #include "../biggroup/biggroup.hpp" #include "../bool/bool.hpp" #include "../field/field.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/stdlib/primitives/curves/secp256r1.hpp" @@ -68,7 +68,7 @@ template class stdlib_biggroup : public testing::Test { uint64_t after = composer.get_num_gates(); if (i == num_repetitions - 1) { std::cout << "num gates per add = " << after - before << std::endl; - benchmark_info(GET_COMPOSER_NAME_STRING(Composer), "Biggroup", "ADD", "Gate Count", after - before); + benchmark_info(Composer::NAME_STRING, "Biggroup", "ADD", "Gate Count", after - before); } affine_element c_expected(element(input_a) + element(input_b)); @@ -882,7 +882,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, multiple_montgomery_ladder) HEAVY_TYPED_TEST(stdlib_biggroup, compute_naf) { // ULTRATODO: make this work for secp curves - if constexpr (TypeParam::Curve::type == CurveType::BN254) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::BN254) { size_t num_repetitions = 1; for (size_t i = 0; i < num_repetitions; i++) { TestFixture::test_compute_naf(); @@ -895,7 +895,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, compute_naf) /* These tests only work for Ultra Circuit Constructor */ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_batch_mul) { - if constexpr (TypeParam::Curve::Composer::type == ComposerType::PLOOKUP) { + if constexpr (TypeParam::Curve::Composer::type == proof_system::ComposerType::PLOOKUP) { TestFixture::test_compute_wnaf(); } else { GTEST_SKIP(); @@ -906,7 +906,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_batch_mul) case where Fr is a bigfield. */ HEAVY_TYPED_TEST(stdlib_biggroup, compute_wnaf) { - if constexpr (TypeParam::Curve::Composer::type != ComposerType::PLOOKUP && TypeParam::use_bigfield) { + if constexpr (TypeParam::Curve::Composer::type != proof_system::ComposerType::PLOOKUP && TypeParam::use_bigfield) { GTEST_SKIP(); } else { TestFixture::test_compute_wnaf(); @@ -943,7 +943,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_batch_4) /* The following tests are specific to BN254 and don't work when Fr is a bigfield */ HEAVY_TYPED_TEST(stdlib_biggroup, bn254_endo_batch_mul) { - if constexpr (TypeParam::Curve::type == CurveType::BN254 && !TypeParam::use_bigfield) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::BN254 && !TypeParam::use_bigfield) { TestFixture::test_bn254_endo_batch_mul(); } else { GTEST_SKIP(); @@ -951,7 +951,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, bn254_endo_batch_mul) } HEAVY_TYPED_TEST(stdlib_biggroup, mixed_mul_bn254_endo) { - if constexpr (TypeParam::Curve::type == CurveType::BN254 && !TypeParam::use_bigfield) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::BN254 && !TypeParam::use_bigfield) { TestFixture::test_mixed_mul_bn254_endo(); } else { GTEST_SKIP(); @@ -961,7 +961,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, mixed_mul_bn254_endo) /* The following tests are specific to SECP256k1 */ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_secp256k1) { - if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::SECP256K1) { TestFixture::test_wnaf_secp256k1(); } else { GTEST_SKIP(); @@ -969,7 +969,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_secp256k1) } HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_8bit_secp256k1) { - if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::SECP256K1) { TestFixture::test_wnaf_8bit_secp256k1(); } else { GTEST_SKIP(); @@ -977,7 +977,7 @@ HEAVY_TYPED_TEST(stdlib_biggroup, wnaf_8bit_secp256k1) } HEAVY_TYPED_TEST(stdlib_biggroup, ecdsa_mul_secp256k1) { - if constexpr (TypeParam::Curve::type == CurveType::SECP256K1) { + if constexpr (TypeParam::Curve::type == proof_system::CurveType::SECP256K1) { TestFixture::test_ecdsa_mul_secp256k1(); } else { GTEST_SKIP(); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp index bff1805db3ca..c6749aea6b39 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_impl.hpp @@ -4,7 +4,7 @@ #include "barretenberg/numeric/uintx/uintx.hpp" #include -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "../bit_array/bit_array.hpp" // #include "../field/field.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp index a0fd3571c8a1..a603d5cb9934 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/biggroup_nafs.hpp @@ -243,7 +243,7 @@ typename element::secp256k1_wnaf_pair element::compu // Compute and constrain skews field_t negative_skew = witness_t(ctx, is_negative ? 0 : skew); field_t positive_skew = witness_t(ctx, is_negative ? skew : 0); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { ctx->create_new_range_constraint(negative_skew.witness_index, 1, "biggroup_nafs"); ctx->create_new_range_constraint(positive_skew.witness_index, 1, "biggroup_nafs"); ctx->create_new_range_constraint((negative_skew + positive_skew).witness_index, 1, "biggroup_nafs"); @@ -384,7 +384,7 @@ std::vector> element::compute_wnaf(const Fr& scalar) offset_entry = (1ULL << (WNAF_SIZE - 1)) - 1 - (wnaf_values[i] & 0xffffff); } field_t entry(witness_t(ctx, offset_entry)); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { ctx->create_new_range_constraint(entry.witness_index, 1ULL << (WNAF_SIZE), "biggroup_nafs"); } else { ctx->create_range_constraint(entry.witness_index, WNAF_SIZE, "biggroup_nafs"); @@ -394,7 +394,7 @@ std::vector> element::compute_wnaf(const Fr& scalar) // add skew wnaf_entries.emplace_back(witness_t(ctx, skew)); - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { ctx->create_new_range_constraint(wnaf_entries[wnaf_entries.size() - 1].witness_index, 1, "biggroup_nafs"); } else { ctx->create_range_constraint(wnaf_entries[wnaf_entries.size() - 1].witness_index, 1, "biggroup_nafs"); @@ -507,7 +507,7 @@ std::vector> element::compute_naf(const Fr& scalar, cons bit.context = ctx; bit.witness_index = witness_t(ctx, true).witness_index; // flip sign bit.witness_bool = true; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { ctx->create_new_range_constraint( bit.witness_index, 1, "biggroup_nafs: compute_naf extracted too many bits in non-next_entry case"); } else { @@ -519,7 +519,7 @@ std::vector> element::compute_naf(const Fr& scalar, cons bool_t bit(ctx, false); bit.witness_index = witness_t(ctx, false).witness_index; // don't flip sign bit.witness_bool = false; - if constexpr (C::type == ComposerType::PLOOKUP) { + if constexpr (C::type == proof_system::ComposerType::PLOOKUP) { ctx->create_new_range_constraint( bit.witness_index, 1, "biggroup_nafs: compute_naf extracted too many bits in next_entry case"); } else { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.cpp index b8f9dbc3434e..a6e3ee7e2d24 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.cpp @@ -1,5 +1,5 @@ #include "bit_array.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp index a3e6846b9b24..40dbf049064d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../uint/uint.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp index 29ca9133d2ac..f44ef48de714 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bit_array/bit_array.test.cpp @@ -1,7 +1,7 @@ #include "bit_array.hpp" #include #include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp index 30e83c42a7ba..a106f811c550 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.cpp @@ -1,5 +1,5 @@ #include "bool.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.hpp index 86e98acf9eec..4550342c21b4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../witness/witness.hpp" namespace proof_system::plonk::stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp index 37cde2d4652e..bcfa48d78a50 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/bool/bool.test.cpp @@ -1,6 +1,6 @@ #include "bool.hpp" #include -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.cpp" #define STDLIB_TYPE_ALIASES \ diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp index d63356bc19c1..82a642a985c2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.cpp @@ -2,7 +2,7 @@ #include -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; @@ -129,7 +129,7 @@ template byte_array::byte_array(const field_t y_lo = (-validator) + (s_lo + shift); field_t y_overlap; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { // carve out the 2 high bits from (y_lo + shifted_high_limb) and instantiate as y_overlap const uint256_t y_lo_value = y_lo.get_value() + shifted_high_limb.get_value(); const uint256_t y_overlap_value = y_lo_value >> 128; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp index ccc992fa8ba8..e1414986da90 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.hpp @@ -1,6 +1,6 @@ #pragma once #include "../bool/bool.hpp" -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" #include "../safe_uint/safe_uint.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp index 4e00a32f96ff..9c3faaf0fcc8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/byte_array/byte_array.test.cpp @@ -1,5 +1,6 @@ -#include "byte_array.hpp" #include + +#include "byte_array.hpp" #include "barretenberg/stdlib/primitives/bool/bool.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" @@ -8,18 +9,18 @@ namespace test_stdlib_byte_array { using namespace barretenberg; -using namespace plonk; +using namespace proof_system::plonk::stdlib; #define STDLIB_TYPE_ALIASES \ using Composer = TypeParam; \ - using witness_ct = stdlib::witness_t; \ - using byte_array_ct = stdlib::byte_array; \ - using field_ct = stdlib::field_t; \ - using bool_ct = stdlib::bool_t; + using witness_ct = witness_t; \ + using byte_array_ct = byte_array; \ + using field_ct = field_t; \ + using bool_ct = bool_t; template class ByteArrayTest : public ::testing::Test {}; -template using byte_array_ct = stdlib::byte_array; +template using byte_array_ct = byte_array; using ComposerTypes = ::testing::Types; \ + template class stdlib_type; \ + template class stdlib_type; + +#define INSTANTIATE_STDLIB_TYPE_VA(stdlib_type, ...) \ + template class stdlib_type; \ + template class stdlib_type; \ + template class stdlib_type; + +#define INSTANTIATE_STDLIB_BASIC_TYPE(stdlib_type) \ + template class stdlib_type; \ + template class stdlib_type; + +#define INSTANTIATE_STDLIB_BASIC_TYPE_VA(stdlib_type, ...) \ + template class stdlib_type; \ + template class stdlib_type; + +#define INSTANTIATE_STDLIB_ULTRA_METHOD(stdlib_method) template stdlib_method(proof_system::UltraCircuitConstructor); + +#define INSTANTIATE_STDLIB_ULTRA_TYPE(stdlib_type) template class stdlib_type; + +#define INSTANTIATE_STDLIB_ULTRA_TYPE_VA(stdlib_type, ...) \ + template class stdlib_type; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp new file mode 100644 index 000000000000..53f8b43e7d7e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp @@ -0,0 +1,52 @@ +/** + * @brief Defines particular composer and circuit constructor types expected to be used for proof or circuit +construction in stdlib and contains macros for explicit instantiation. + * + * @details This file is designed to be included in header files to instruct the compiler that these classes exist and + * their instantiation will eventually take place. Given it has no dependencies, it causes no additional compilation or + * propagation. + */ +#pragma once + +namespace proof_system::honk { +namespace flavor { +class Standard; +class Ultra; +} // namespace flavor +} // namespace proof_system::honk + +namespace proof_system { +class StandardCircuitConstructor; +class TurboCircuitConstructor; +class UltraCircuitConstructor; +} // namespace proof_system + +#define EXTERN_STDLIB_TYPE(stdlib_type) \ + extern template class stdlib_type; \ + extern template class stdlib_type; \ + extern template class stdlib_type; + +#define EXTERN_STDLIB_METHOD(stdlib_method) \ + extern template stdlib_method(proof_system::StandardCircuitConstructor); \ + extern template stdlib_method(proof_system::TurboCircuitConstructor); \ + extern template stdlib_method(proof_system::UltraCircuitConstructor); + +#define EXTERN_STDLIB_TYPE_VA(stdlib_type, ...) \ + extern template class stdlib_type; \ + extern template class stdlib_type; \ + extern template class stdlib_type; + +#define EXTERN_STDLIB_BASIC_TYPE(stdlib_type) \ + extern template class stdlib_type; \ + extern template class stdlib_type; + +#define EXTERN_STDLIB_BASIC_TYPE_VA(stdlib_type, ...) \ + extern template class stdlib_type; \ + extern template class stdlib_type; + +#define EXTERN_STDLIB_ULTRA_TYPE(stdlib_type) extern template class stdlib_type; + +#define EXTERN_STDLIB_ULTRA_TYPE_VA(stdlib_type, ...) \ + extern template class stdlib_type; + +#define EXTERN_STDLIB_ULTRA_METHOD(stdlib_method) extern template stdlib_method(proof_system::UltraCircuitConstructor); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp deleted file mode 100644 index c1522e0ac8f0..000000000000 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/** - * @brief Contains all the headers required to adequately compile the types defined in composers_fwd.hpp and instantiate - * templates. - */ -#pragma once -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/honk/composer/standard_honk_composer.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "barretenberg/honk/composer/ultra_honk_composer.hpp" -#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" -#include "barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp" -#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" - -#define INSTANTIATE_STDLIB_METHOD(stdlib_method) \ - template stdlib_method(proof_system::StandardCircuitConstructor); \ - template stdlib_method(proof_system::TurboCircuitConstructor); \ - template stdlib_method(proof_system::UltraCircuitConstructor); \ - template stdlib_method(plonk::StandardPlonkComposer); \ - template stdlib_method(honk::StandardHonkComposer); \ - template stdlib_method(plonk::TurboPlonkComposer); \ - template stdlib_method(plonk::UltraPlonkComposer); \ - template stdlib_method(honk::UltraHonkComposer); - -#define INSTANTIATE_STDLIB_TYPE(stdlib_type) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; - -#define INSTANTIATE_STDLIB_TYPE_VA(stdlib_type, ...) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; - -#define INSTANTIATE_STDLIB_BASIC_TYPE(stdlib_type) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; - -#define INSTANTIATE_STDLIB_BASIC_TYPE_VA(stdlib_type, ...) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; - -#define INSTANTIATE_STDLIB_ULTRA_METHOD(stdlib_method) \ - template stdlib_method(proof_system::UltraCircuitConstructor); \ - template stdlib_method(plonk::UltraPlonkComposer); \ - template stdlib_method(honk::UltraHonkComposer); - -#define INSTANTIATE_STDLIB_ULTRA_TYPE(stdlib_type) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; - -#define INSTANTIATE_STDLIB_ULTRA_TYPE_VA(stdlib_type, ...) \ - template class stdlib_type; \ - template class stdlib_type; \ - template class stdlib_type; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp deleted file mode 100644 index 1fb6e8d38920..000000000000 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/composers/composers_fwd.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @brief Defines particular composer and circuit constructor types expected to be used for proof or circuit -construction in stdlib and contains macros for explicit instantiation. - * - * @details This file is designed to be included in header files to instruct the compiler that these classes exist and - * their instantiation will eventually take place. Given it has no dependencies, it causes no additional compilation or - * propagation. - */ -#pragma once - -namespace proof_system::plonk { -class StandardPlonkComposer; -class TurboPlonkComposer; -class UltraPlonkComposer; - -} // namespace proof_system::plonk - -namespace proof_system::honk { -namespace flavor { -class Standard; -class Ultra; -} // namespace flavor -template class StandardHonkComposer_; -using StandardHonkComposer = StandardHonkComposer_; -template class UltraHonkComposer_; -using UltraHonkComposer = UltraHonkComposer_; -} // namespace proof_system::honk - -namespace proof_system { -class StandardCircuitConstructor; -class TurboCircuitConstructor; -class UltraCircuitConstructor; -} // namespace proof_system - -#define EXTERN_STDLIB_TYPE(stdlib_type) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_METHOD(stdlib_method) \ - extern template stdlib_method(proof_system::StandardCircuitConstructor); \ - extern template stdlib_method(proof_system::TurboCircuitConstructor); \ - extern template stdlib_method(proof_system::UltraCircuitConstructor); \ - extern template stdlib_method(plonk::StandardPlonkComposer); \ - extern template stdlib_method(honk::StandardHonkComposer); \ - extern template stdlib_method(plonk::TurboPlonkComposer); \ - extern template stdlib_method(plonk::UltraPlonkComposer); \ - extern template stdlib_method(honk::UltraHonkComposer); - -#define EXTERN_STDLIB_TYPE_VA(stdlib_type, ...) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_BASIC_TYPE(stdlib_type) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_BASIC_TYPE_VA(stdlib_type, ...) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_ULTRA_TYPE(stdlib_type) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_ULTRA_TYPE_VA(stdlib_type, ...) \ - extern template class stdlib_type; \ - extern template class stdlib_type; \ - extern template class stdlib_type; - -#define EXTERN_STDLIB_ULTRA_METHOD(stdlib_method) \ - extern template stdlib_method(proof_system::UltraCircuitConstructor); \ - extern template stdlib_method(plonk::UltraPlonkComposer); \ - extern template stdlib_method(honk::UltraHonkComposer); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/bn254.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/bn254.hpp index 4fc46e4e41e8..4919ff490fc5 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/bn254.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/curves/bn254.hpp @@ -7,25 +7,30 @@ namespace proof_system::plonk { namespace stdlib { -template struct bn254 { +template struct bn254 { static constexpr proof_system::CurveType type = proof_system::CurveType::BN254; - typedef barretenberg::fq fq; - typedef barretenberg::fr fr; - typedef barretenberg::g1 g1; + // NOTE: Naming in flux here; maybe name should reflect "native" somehow? + using BaseField = curve::BN254::BaseField; + using fq = BaseField; + using ScalarField = curve::BN254::ScalarField; + using fr = ScalarField; + using Group = curve::BN254::Group; + using g1 = Group; - typedef ComposerType Composer; - typedef witness_t witness_ct; - typedef public_witness_t public_witness_ct; - typedef field_t fr_ct; - typedef byte_array byte_array_ct; - typedef bool_t bool_ct; - typedef stdlib::uint32 uint32_ct; + using Builder = CircuitBuilder; + using Composer = CircuitBuilder; + typedef witness_t witness_ct; + typedef public_witness_t public_witness_ct; + typedef field_t fr_ct; + typedef byte_array byte_array_ct; + typedef bool_t bool_ct; + typedef stdlib::uint32 uint32_ct; - typedef bigfield fq_ct; - typedef bigfield bigfr_ct; - typedef element g1_ct; - typedef element g1_bigfr_ct; + typedef bigfield fq_ct; + typedef bigfield bigfr_ct; + typedef element g1_ct; + typedef element g1_bigfr_ct; }; // namespace bn254 } // namespace stdlib diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp index 2543e5d16c90..7b1a91b53441 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/array.test.cpp @@ -3,7 +3,7 @@ #include "array.hpp" #include #include -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #include "barretenberg/numeric/random/engine.hpp" namespace test_stdlib_array { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp index 2f2bfd3efa8d..7455b7c9aada 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.cpp @@ -1,7 +1,7 @@ #include "field.hpp" #include #include "../bool/bool.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" using namespace proof_system; @@ -739,7 +739,7 @@ void field_t::create_range_constraint(const size_t num_bits, st if (is_constant()) { ASSERT(uint256_t(get_value()).get_msb() < num_bits); } else { - if constexpr (ComposerContext::type == ComposerType::PLOOKUP) { + if constexpr (ComposerContext::type == proof_system::ComposerType::PLOOKUP) { context->decompose_into_default_range( normalize().get_witness_index(), num_bits, @@ -984,7 +984,7 @@ field_t field_t::accumulate(const std::vector< * * If num elements is not a multiple of 3, the final gate will be padded with zero_idx wires **/ - if constexpr (ComposerContext::type == ComposerType::PLOOKUP) { + if constexpr (ComposerContext::type == proof_system::ComposerType::PLOOKUP) { ComposerContext* ctx = nullptr; std::vector accumulator; field_t constant_term = 0; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp index 2e78f7856f6c..fed2471ffc45 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../witness/witness.hpp" #include "barretenberg/common/assert.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp index 2bbe6bb7ff4f..078a2ff53543 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp @@ -6,7 +6,7 @@ #include #include "barretenberg/numeric/random/engine.hpp" #include "barretenberg/common/streams.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp index e30da4dc843d..a47ca1aa9e88 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/group/group.test.cpp @@ -12,7 +12,8 @@ namespace stdlib_group_tests { using namespace barretenberg; -using namespace plonk; +using namespace proof_system::plonk; + namespace { auto& engine = numeric::random::get_debug_engine(); } diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp index d8a3e0ca9035..0b700e8ba5db 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.cpp @@ -1,5 +1,5 @@ #include "logic.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "../plookup/plookup.hpp" #include "barretenberg/common/assert.hpp" #include "barretenberg/numeric/uint256/uint256.hpp" @@ -52,7 +52,7 @@ field_t logic::create_logic_constraint( field_pt b_witness = field_pt::from_witness_index(ctx, ctx->put_constant_variable(b_native)); return create_logic_constraint(a, b_witness, num_bits, is_xor_gate, get_chunk); } - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { Composer* ctx = a.get_context(); const size_t num_chunks = (num_bits / 32) + ((num_bits % 32 == 0) ? 0 : 1); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.hpp index 1ec450de009c..dc97d81f7e14 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" #include "barretenberg/stdlib/primitives/witness/witness.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp index d29b29b9459d..9130a4b973a4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/logic/logic.test.cpp @@ -1,10 +1,11 @@ +#include + #include "../bool/bool.hpp" -#include "barretenberg/numeric/uint256/uint256.hpp" -#include "barretenberg/proof_system/types/composer_type.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "logic.hpp" -#include "../composers/composers.hpp" -#include #include "barretenberg/numeric/random/engine.hpp" +#include "barretenberg/numeric/uint256/uint256.hpp" +#include "barretenberg/proof_system/types/composer_type.hpp" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" @@ -126,7 +127,7 @@ TYPED_TEST(LogicTest, DifferentWitnessSameResult) STDLIB_TYPE_ALIASES auto composer = Composer(); - if (Composer::type == ComposerType::PLOOKUP) { + if (Composer::type == proof_system::ComposerType::PLOOKUP) { uint256_t a = 3758096391; uint256_t b = 2147483649; field_ct x = witness_ct(&composer, uint256_t(a)); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp index 66937a23bafa..7df6d118711f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.cpp @@ -1,6 +1,6 @@ #include "dynamic_array.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "../bool/bool.hpp" namespace proof_system::plonk { @@ -25,7 +25,7 @@ DynamicArray::DynamicArray(Composer* composer, const size_t maximum_si , _max_size(maximum_size) , _length(0) { - static_assert(Composer::type == ComposerType::PLOOKUP); + static_assert(Composer::type == proof_system::ComposerType::PLOOKUP); ASSERT(_context != nullptr); _inner_table = ram_table(_context, maximum_size); // Initialize the ram table with all zeroes diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp index b3435522bf05..829142f6b5db 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.hpp @@ -1,6 +1,6 @@ #pragma once #include "ram_table.hpp" -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" namespace proof_system::plonk { namespace stdlib { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp index 44beaa9b719d..92c95d818aad 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/dynamic_array.test.cpp @@ -5,7 +5,7 @@ #include "barretenberg/numeric/random/engine.hpp" #include "../bool/bool.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" namespace test_stdlib_dynamic_array { using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp index f68089e229b9..020b81cbd352 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.cpp @@ -1,6 +1,6 @@ #include "ram_table.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" namespace proof_system::plonk { namespace stdlib { @@ -13,7 +13,7 @@ namespace stdlib { */ template ram_table::ram_table(Composer* composer, const size_t table_size) { - static_assert(Composer::type == ComposerType::PLOOKUP); + static_assert(Composer::type == proof_system::ComposerType::PLOOKUP); _context = composer; _length = table_size; _index_initialized.resize(table_size); @@ -35,7 +35,7 @@ template ram_table::ram_table(Composer* composer, */ template ram_table::ram_table(const std::vector& table_entries) { - static_assert(Composer::type == ComposerType::PLOOKUP); + static_assert(Composer::type == proof_system::ComposerType::PLOOKUP); // get the composer _context for (const auto& entry : table_entries) { if (entry.get_context() != nullptr) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.hpp index b3526c452cb7..8bdc472a6ce2 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp index a98c83a1b093..5af8a84c4313 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/ram_table.test.cpp @@ -1,10 +1,8 @@ -#include "ram_table.hpp" - #include +#include "ram_table.hpp" #include "barretenberg/numeric/random/engine.hpp" - -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" namespace test_stdlib_ram_table { @@ -26,13 +24,13 @@ TEST(ram_table, ram_table_init_read_consistency) std::vector table_values; const size_t table_size = 10; for (size_t i = 0; i < table_size; ++i) { - table_values.emplace_back(witness_ct(&composer, fr::random_element())); + table_values.emplace_back(witness_ct(&composer, barretenberg::fr::random_element())); } ram_table_ct table(table_values); field_ct result(0); - fr expected(0); + barretenberg::fr expected(0); for (size_t i = 0; i < 10; ++i) { field_ct index(witness_ct(&composer, (uint64_t)i)); @@ -58,7 +56,7 @@ TEST(ram_table, ram_table_read_write_consistency) Composer composer; const size_t table_size = 10; - std::vector table_values(table_size); + std::vector table_values(table_size); ram_table_ct table(&composer, table_size); @@ -66,12 +64,12 @@ TEST(ram_table, ram_table_read_write_consistency) table.write(i, 0); } field_ct result(0); - fr expected(0); + barretenberg::fr expected(0); const auto update = [&]() { for (size_t i = 0; i < table_size / 2; ++i) { - table_values[2 * i] = fr::random_element(); - table_values[2 * i + 1] = fr::random_element(); + table_values[2 * i] = barretenberg::fr::random_element(); + table_values[2 * i + 1] = barretenberg::fr::random_element(); // init with both constant and variable values table.write(2 * i, table_values[2 * i]); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp index 53ed2a80f414..bd8f699ea57f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.cpp @@ -1,6 +1,6 @@ #include "rom_table.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; @@ -9,7 +9,7 @@ namespace stdlib { template rom_table::rom_table(const std::vector& table_entries) { - static_assert(Composer::type == ComposerType::PLOOKUP); + static_assert(Composer::type == proof_system::ComposerType::PLOOKUP); // get the composer context for (const auto& entry : table_entries) { if (entry.get_context() != nullptr) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.hpp index b539b0a750f0..56b953d68c99 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp index 88de9fcbb00f..f697ede8d99d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/rom_table.test.cpp @@ -1,10 +1,9 @@ -#include "rom_table.hpp" #include +#include "rom_table.hpp" #include "barretenberg/numeric/random/engine.hpp" - -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" namespace test_stdlib_rom_array { using namespace barretenberg; @@ -27,13 +26,13 @@ TEST(rom_table, rom_table_read_write_consistency) std::vector table_values; const size_t table_size = 10; for (size_t i = 0; i < table_size; ++i) { - table_values.emplace_back(witness_ct(&composer, fr::random_element())); + table_values.emplace_back(witness_ct(&composer, barretenberg::fr::random_element())); } rom_table_ct table(table_values); field_ct result(0); - fr expected(0); + barretenberg::fr expected(0); for (size_t i = 0; i < 10; ++i) { field_ct index(witness_ct(&composer, (uint64_t)i)); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp index e8aaff2af48d..ad56a4f2241f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.cpp @@ -1,6 +1,6 @@ #include "twin_rom_table.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; @@ -10,7 +10,7 @@ namespace stdlib { template twin_rom_table::twin_rom_table(const std::vector>& table_entries) { - static_assert(Composer::type == ComposerType::PLOOKUP); + static_assert(Composer::type == proof_system::ComposerType::PLOOKUP); // get the composer context for (const auto& entry : table_entries) { if (entry[0].get_context() != nullptr) { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.hpp index c07e67dc4299..ceb639931182 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/memory/twin_rom_table.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp index 62d0d1bb6b3b..da8e4acdc341 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.cpp @@ -1,6 +1,6 @@ #include "packed_byte_array.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp index a8e452f02b8d..d081d5af1925 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.hpp @@ -1,5 +1,5 @@ #pragma once -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" #include "../bool/bool.hpp" #include "../byte_array/byte_array.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp index 5c16d0b59d17..238a016ebc9d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/packed_byte_array/packed_byte_array.test.cpp @@ -3,7 +3,7 @@ #include "packed_byte_array.hpp" #include "barretenberg/stdlib/primitives/byte_array/byte_array.hpp" #include "barretenberg/numeric/random/engine.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" #pragma GCC diagnostic ignored "-Wunused-local-typedefs" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp index 27761a2fd0ee..2816fde8d623 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.cpp @@ -1,7 +1,7 @@ #include "./plookup.hpp" #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" #include "barretenberg/proof_system/plookup_tables/types.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" namespace proof_system::plonk { class UltraPlonkComposer; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp index 778f76b7ac12..cc4633cbd203 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.hpp @@ -2,7 +2,7 @@ #include #include #include "barretenberg/proof_system/plookup_tables/plookup_tables.hpp" -#include "barretenberg/stdlib/primitives/composers/composers_fwd.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders_fwd.hpp" #include "barretenberg/proof_system/plookup_tables/types.hpp" #include "barretenberg/stdlib/primitives/field/field.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp index f564c80b7a4c..bbaad6cafb9c 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/plookup/plookup.test.cpp @@ -8,7 +8,7 @@ #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" #include "barretenberg/stdlib/primitives/uint/uint.hpp" #include "barretenberg/stdlib/primitives/curves/secp256k1.hpp" -#include "barretenberg/stdlib/primitives/composers/composers.hpp" +#include "barretenberg/stdlib/primitives/circuit_builders/circuit_builders.hpp" namespace test_stdlib_plookups { using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp index 344ffe3d02b4..ce07f16a27f8 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.cpp @@ -1,6 +1,6 @@ #include "safe_uint.hpp" #include "../bool/bool.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" namespace proof_system::plonk { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp index 213eee5c963b..adc668574777 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include "../composers/composers_fwd.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "../witness/witness.hpp" #include "../bool/bool.hpp" #include "barretenberg/common/assert.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp index b237006da29f..ad0da41a2a18 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/safe_uint/safe_uint.test.cpp @@ -24,7 +24,8 @@ auto& engine = numeric::random::get_debug_engine(); namespace test_stdlib_safe_uint { using namespace barretenberg; -using namespace plonk; +using namespace proof_system::plonk; + template void ignore_unused(T&) {} // use to ignore unused variables in lambdas template class SafeUintTest : public ::testing::Test {}; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp index bcc347ad5b3f..26b10b520ea4 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/arithmetic.cpp @@ -1,4 +1,4 @@ -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/comparison.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/comparison.cpp index 374df85af57a..ff6473d8eb53 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/comparison.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/comparison.cpp @@ -1,4 +1,4 @@ -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp index 39662dd8c53d..e9f3d8e6be0f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/logic.cpp @@ -1,4 +1,4 @@ -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp index 182492dbf025..befd21c39277 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/arithmetic.cpp @@ -1,4 +1,4 @@ -#include "../../composers/composers.hpp" +#include "../../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/comparison.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/comparison.cpp index 7e83eab6033f..14ec78a5e829 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/comparison.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/comparison.cpp @@ -1,4 +1,4 @@ -#include "../../composers/composers.hpp" +#include "../../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/logic.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/logic.cpp index 6dea194335b9..d2c89e307302 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/logic.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/logic.cpp @@ -1,4 +1,4 @@ -#include "../../composers/composers.hpp" +#include "../../circuit_builders/circuit_builders.hpp" #include "uint.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.cpp index e626d348f95d..a60cc0393fb6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.cpp @@ -1,5 +1,5 @@ #include "uint.hpp" -#include "../../composers/composers.hpp" +#include "../../circuit_builders/circuit_builders.hpp" using namespace barretenberg; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp index 14eecbaf5e97..6b41f6c4ceee 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/plookup/uint.hpp @@ -1,7 +1,7 @@ #pragma once #include "../../bool/bool.hpp" #include "../../byte_array/byte_array.hpp" -#include "../../composers/composers_fwd.hpp" +#include "../../circuit_builders/circuit_builders_fwd.hpp" #include "../../field/field.hpp" #include "../../plookup/plookup.hpp" diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.cpp index 66866da1b7b8..f93d031c7f48 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.cpp @@ -1,5 +1,5 @@ #include "uint.hpp" -#include "../composers/composers.hpp" +#include "../circuit_builders/circuit_builders.hpp" using namespace barretenberg; using namespace proof_system; @@ -16,7 +16,7 @@ std::vector uint::constrain_accumulators(Composer* c const size_t num_bits, std::string const& msg) const { - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { // TODO: manage higher bit ranges const auto sequence = plookup_read::get_lookup_accumulators( plookup::MultiTableId::UINT32_XOR, @@ -317,7 +317,7 @@ template bool_t uintget_variable(right_idx)) - uint256_t(context->get_variable(left_idx)) * uint256_t(4); - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { uint256_t lo_bit = quad & 1; uint256_t hi_bit = (quad & 2) >> 1; // difference in quads = 0, 1, 2, 3 = delta diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp index 7658a010dfaf..2a9c690a95ac 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.hpp @@ -1,7 +1,7 @@ #pragma once #include "../bool/bool.hpp" #include "../byte_array/byte_array.hpp" -#include "../composers/composers_fwd.hpp" +#include "../circuit_builders/circuit_builders_fwd.hpp" #include "../field/field.hpp" #include "../plookup/plookup.hpp" @@ -189,19 +189,19 @@ template inline std::ostream& operator<<(std::ostream& } template -using uint8 = typename std::conditional, uint>::type; template -using uint16 = typename std::conditional, uint>::type; template -using uint32 = typename std::conditional, uint>::type; template -using uint64 = typename std::conditional, uint>::type; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp index 6f1e3646b0fc..70d8398f9e38 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/uint/uint.test.cpp @@ -75,7 +75,7 @@ uint_native rotate(uint_native value, size_t rotation) : value; } template class stdlib_uint : public testing::Test { - typedef typename std::conditional, stdlib::uint>::type uint_ct; typedef stdlib::bool_t bool_ct; @@ -1923,10 +1923,10 @@ TYPED_TEST(stdlib_uint, test_at) // There was one plookup-specific test in the ./plookup/uint_plookup.test.cpp TEST(stdlib_uint32, test_accumulators_plookup_uint32) { - using uint32_ct = proof_system::plonk::stdlib::uint32; - using witness_ct = proof_system::plonk::stdlib::witness_t; + using uint32_ct = proof_system::plonk::stdlib::uint32; + using witness_ct = proof_system::plonk::stdlib::witness_t; - plonk::UltraPlonkComposer composer = proof_system::plonk::UltraPlonkComposer(); + proof_system::UltraCircuitConstructor composer; uint32_t a_val = engine.get_random_uint32(); uint32_t b_val = engine.get_random_uint32(); @@ -1943,7 +1943,7 @@ TEST(stdlib_uint32, test_accumulators_plookup_uint32) EXPECT_EQ(result, expected); } - printf("composer gates = %zu\n", composer.get_num_gates()); + info("composer gates = ", composer.get_num_gates()); bool proof_result = composer.check_circuit(); EXPECT_EQ(proof_result, true); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp index 87e55977d0b0..626e6c0b9334 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.hpp @@ -16,17 +16,14 @@ #include "../../primitives/witness/witness.hpp" #include "../../primitives/bool/bool.hpp" -#include "../verification_key//verification_key.hpp" -namespace proof_system::plonk { -namespace stdlib { -namespace recursion { +namespace proof_system::plonk::stdlib::recursion { template class Transcript { public: using field_pt = field_t; using witness_pt = witness_t; using fq_pt = bigfield; using group_pt = element; - using Key = proof_system::plonk::stdlib::recursion::verification_key>; + using Key = verification_key>; Transcript(Composer* in_context, const transcript::Manifest input_manifest) : context(in_context) @@ -259,7 +256,7 @@ template class Transcript { field_pt borrow = field_pt::from_witness(context, need_borrow); // directly call `create_new_range_constraint` to avoid creating an arithmetic gate - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { context->create_new_range_constraint(borrow.get_witness_index(), 1, "borrow"); } else { context->create_range_constraint(borrow.get_witness_index(), 1, "borrow"); @@ -277,7 +274,7 @@ template class Transcript { }; field_pt base_hash; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { base_hash = stdlib::pedersen_plookup_commitment::compress(std::vector{ T0 }, 0); } else { base_hash = stdlib::pedersen_commitment::compress(std::vector{ T0 }, 0); @@ -296,7 +293,7 @@ template class Transcript { for (size_t i = 2; i < num_challenges; i += 2) { // TODO(@zac-williamson) make this a Poseidon hash not a Pedersen hash field_pt hash_output; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { hash_output = stdlib::pedersen_plookup_commitment::compress( std::vector{ (base_hash + field_pt(i / 2)).normalize() }, 0); } else { @@ -429,6 +426,4 @@ template class Transcript { size_t current_round = 0; }; -} // namespace recursion -} // namespace stdlib -} // namespace proof_system::plonk +} // namespace proof_system::plonk::stdlib::recursion diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp index 6158a158593f..48d15bb3f12b 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/transcript/transcript.test.cpp @@ -1,22 +1,23 @@ -#include "transcript.hpp" #include +#include "transcript.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" - #include "barretenberg/transcript/transcript.hpp" -using namespace proof_system::plonk; +namespace proof_system::plonk::stdlib::recursion { -// ULTRATODO: Add tests for other composers too (make tests modular?) +// TODO(Cody): Testing only one circuit type. +using Builder = StandardCircuitConstructor; -typedef stdlib::field_t field_t; -typedef stdlib::bool_t bool_t; -typedef stdlib::uint uint32; -typedef stdlib::witness_t witness_t; -typedef stdlib::byte_array byte_array; -typedef stdlib::bigfield fq_t; -typedef stdlib::element group_t; +using field_t = stdlib::field_t; +using bool_t = stdlib::bool_t; +using uint32 = stdlib::uint; +using witness_t = stdlib::witness_t; +using byte_array = stdlib::byte_array; +using fq_t = stdlib::bigfield; +using group_t = stdlib::element; +using transcript_ct = Transcript; namespace { transcript::Manifest create_manifest(const size_t num_public_inputs) @@ -127,11 +128,9 @@ transcript::Transcript get_test_base_transcript(const TestData& data) return transcript; } -plonk::stdlib::recursion::Transcript get_circuit_transcript( - plonk::TurboPlonkComposer* context, const TestData& data) +transcript_ct get_circuit_transcript(Builder* context, const TestData& data) { - plonk::stdlib::recursion::Transcript transcript(context, - create_manifest(data.num_public_inputs)); + transcript_ct transcript(context, create_manifest(data.num_public_inputs)); uint256_t circuit_size_value = uint256_t(4) + (uint256_t(3) << 8) + (uint256_t(2) << 16) + (uint256_t(1) << 24); field_t circuit_size(stdlib::witness_t(context, barretenberg::fr(circuit_size_value))); field_t public_input_size(stdlib::witness_t(context, barretenberg::fr(data.num_public_inputs))); @@ -145,33 +144,19 @@ plonk::stdlib::recursion::Transcript get_circuit_tran public_inputs.push_back(witness_t(context, data.public_input_elements[i])); } transcript.add_field_element_vector("public_inputs", public_inputs); - transcript.add_group_element( - "W_1", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[0])); - transcript.add_group_element( - "W_2", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[1])); - transcript.add_group_element( - "W_3", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[2])); + transcript.add_group_element("W_1", transcript_ct::convert_g1(context, data.g1_elements[0])); + transcript.add_group_element("W_2", transcript_ct::convert_g1(context, data.g1_elements[1])); + transcript.add_group_element("W_3", transcript_ct::convert_g1(context, data.g1_elements[2])); transcript.apply_fiat_shamir("beta"); - transcript.add_group_element( - "Z_PERM", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[3])); + transcript.add_group_element("Z_PERM", transcript_ct::convert_g1(context, data.g1_elements[3])); transcript.apply_fiat_shamir("alpha"); - transcript.add_group_element( - "T_1", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[4])); - transcript.add_group_element( - "T_2", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[5])); - transcript.add_group_element( - "T_3", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[6])); + transcript.add_group_element("T_1", transcript_ct::convert_g1(context, data.g1_elements[4])); + transcript.add_group_element("T_2", transcript_ct::convert_g1(context, data.g1_elements[5])); + transcript.add_group_element("T_3", transcript_ct::convert_g1(context, data.g1_elements[6])); transcript.apply_fiat_shamir("z"); @@ -187,12 +172,8 @@ plonk::stdlib::recursion::Transcript get_circuit_tran transcript.apply_fiat_shamir("nu"); - transcript.add_group_element( - "PI_Z", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[7])); - transcript.add_group_element( - "PI_Z_OMEGA", - plonk::stdlib::recursion::Transcript::convert_g1(context, data.g1_elements[8])); + transcript.add_group_element("PI_Z", transcript_ct::convert_g1(context, data.g1_elements[7])); + transcript.add_group_element("PI_Z_OMEGA", transcript_ct::convert_g1(context, data.g1_elements[8])); transcript.apply_fiat_shamir("separator"); return transcript; @@ -203,10 +184,9 @@ TEST(stdlib_transcript, validate_transcript) TestData data = get_test_data(); transcript::Transcript normal_transcript = get_test_base_transcript(data); - plonk::TurboPlonkComposer composer = proof_system::plonk::TurboPlonkComposer(); + Builder builder; - plonk::stdlib::recursion::Transcript recursive_transcript = - get_circuit_transcript(&composer, data); + transcript_ct recursive_transcript = get_circuit_transcript(&builder, data); const auto check_challenge = [&normal_transcript, &recursive_transcript](const std::string& challenge_name, const size_t challenge_idx = 0) { @@ -289,13 +269,9 @@ TEST(stdlib_transcript, validate_transcript) check_group_element("PI_Z"); check_group_element("PI_Z_OMEGA"); - printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_prover(); - - auto verifier = composer.create_verifier(); - - plonk::proof proof = prover.construct_proof(); + info("builder gates = ", builder.get_num_gates()); - bool result = verifier.verify_proof(proof); + auto result = builder.check_circuit(); EXPECT_EQ(result, true); } +} // namespace proof_system::plonk::stdlib::recursion \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.hpp index 3d05b572a647..154a51cb77e6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.hpp @@ -58,7 +58,7 @@ template struct PedersenPreimage } preimage_data.push_back(field_pt::accumulate(work_element)); } - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { return pedersen_plookup_commitment::compress_with_relaxed_range_constraints(preimage_data, hash_index); } else { @@ -145,7 +145,7 @@ template struct PedersenPreimage field_pt borrow = field_pt::from_witness(context, need_borrow); // directly call `create_new_range_constraint` to avoid creating an arithmetic gate - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { context->create_new_range_constraint(borrow.get_witness_index(), 1, "borrow"); } else { context->create_range_constraint(borrow.get_witness_index(), 1, "borrow"); @@ -334,7 +334,7 @@ template struct verification_key { const auto circuit_key_compressed = compress(); bool found = false; // if we're using Plookup, use a ROM table to index the keys - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { field_t key_index(witness_t(context, 0)); std::vector> compressed_keys; for (size_t i = 0; i < keys_in_set.size(); ++i) { @@ -422,7 +422,7 @@ template struct verification_key { write(preimage_data, key->domain.root); barretenberg::fr compressed_key; - if constexpr (Composer::type == ComposerType::PLOOKUP) { + if constexpr (Composer::type == proof_system::ComposerType::PLOOKUP) { compressed_key = from_buffer( crypto::pedersen_commitment::lookup::compress_native(preimage_data, hash_index)); } else { diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp index 5f7cb9a8bf13..c02314925ecf 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp @@ -1,9 +1,11 @@ +#include "verification_key.hpp" + #include "barretenberg/common/test.hpp" #include "barretenberg/plonk/proof_system/verification_key/verification_key.hpp" -#include "barretenberg/plonk/composer/standard_plonk_composer.hpp" -#include "barretenberg/plonk/composer/turbo_plonk_composer.hpp" -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" -#include "verification_key.hpp" +#include "barretenberg/proof_system/circuit_constructors/standard_circuit_constructor.hpp" +#include "barretenberg/proof_system/circuit_constructors/turbo_circuit_constructor.hpp" +#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp" +#include "barretenberg/srs/factories/file_crs_factory.hpp" namespace { auto& engine = numeric::random::get_debug_engine(); @@ -19,17 +21,15 @@ using namespace proof_system::plonk; */ template class VerificationKeyFixture : public testing::Test { public: - using Curve = stdlib::bn254; - using RecursVk = plonk::stdlib::recursion::verification_key; + using Curve = proof_system::plonk::stdlib::bn254; + using RecursVk = proof_system::plonk::stdlib::recursion::verification_key; static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); } - static Composer init_composer() { return Composer(barretenberg::srs::get_crs_factory()); } - /** * @brief generate a random vk data for use in tests * - * @return verification_key_data randomly generated + * @return verification_key_data randomly generatedv */ static verification_key_data rand_vk_data() { @@ -45,17 +45,15 @@ template class VerificationKeyFixture : public testing::Test } }; -// Each test will run for all composer types -using ComposerTypes = testing::Types; +using ComposerTypes = testing::Types; TYPED_TEST_SUITE(VerificationKeyFixture, ComposerTypes); TYPED_TEST(VerificationKeyFixture, vk_data_vs_recursion_compress_native) { using RecursVk = typename TestFixture::RecursVk; - auto composer = TestFixture::init_composer(); + TypeParam builder; verification_key_data vk_data = TestFixture::rand_vk_data(); verification_key_data vk_data_copy = vk_data; @@ -64,7 +62,7 @@ TYPED_TEST(VerificationKeyFixture, vk_data_vs_recursion_compress_native) auto file_verifier = file_crs->get_verifier_crs(); auto native_vk = std::make_shared(std::move(vk_data_copy), file_verifier); - auto recurs_vk = RecursVk::from_witness(&composer, native_vk); + auto recurs_vk = RecursVk::from_witness(&builder, native_vk); EXPECT_EQ(vk_data.compress_native(0), RecursVk::compress_native(native_vk, 0)); // EXPECT_EQ(vk_data.compress_native(15), RecursVk::compress_native(native_vk, 15)); @@ -76,7 +74,7 @@ TYPED_TEST(VerificationKeyFixture, vk_data_vs_recursion_compress_native) TYPED_TEST(VerificationKeyFixture, compress_vs_compress_native) { using RecursVk = typename TestFixture::RecursVk; - auto composer = TestFixture::init_composer(); + TypeParam builder; verification_key_data vk_data = TestFixture::rand_vk_data(); @@ -84,7 +82,7 @@ TYPED_TEST(VerificationKeyFixture, compress_vs_compress_native) auto file_verifier = file_crs->get_verifier_crs(); auto native_vk = std::make_shared(std::move(vk_data), file_verifier); - auto recurs_vk = RecursVk::from_witness(&composer, native_vk); + auto recurs_vk = RecursVk::from_witness(&builder, native_vk); EXPECT_EQ(recurs_vk->compress(0).get_value(), RecursVk::compress_native(native_vk, 0)); // EXPECT_EQ(recurs_vk->compress(15).get_value(), RecursVk::compress_native(native_vk, 15)); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp index 244aa0950ca4..dbe0fed979ed 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.hpp @@ -1,33 +1,31 @@ #pragma once -#include "../../primitives/bigfield/bigfield.hpp" -#include "../../primitives/biggroup/biggroup.hpp" -#include "../../primitives/bool/bool.hpp" -#include "../../primitives/field/field.hpp" - -#include "../transcript/transcript.hpp" -#include "../aggregation_state/aggregation_state.hpp" - -#include "barretenberg/plonk/proof_system/utils/kate_verification.hpp" -#include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp" - -#include "barretenberg/polynomials/polynomial_arithmetic.hpp" - #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/bn254/pairing.hpp" +#include "barretenberg/plonk/flavor/flavor.hpp" +#include "barretenberg/plonk/proof_system/types/proof.hpp" +#include "barretenberg/plonk/proof_system/utils/kate_verification.hpp" +#include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp" +#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" +#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" +#include "barretenberg/stdlib/primitives/field/field.hpp" +#include "barretenberg/stdlib/recursion/transcript/transcript.hpp" +#include "barretenberg/stdlib/recursion/aggregation_state/aggregation_state.hpp" +#include "barretenberg/stdlib/recursion/verifier/program_settings.hpp" namespace proof_system::plonk { namespace stdlib { namespace recursion { -template struct lagrange_evaluations { - field_t l_start; - field_t l_end; - field_t vanishing_poly; +template struct lagrange_evaluations { + field_t l_start; + field_t l_end; + field_t vanishing_poly; }; template -void populate_kate_element_map(typename Curve::Composer* ctx, +void populate_kate_element_map(typename Curve::Builder* ctx, typename Transcript::Key* key, const Transcript& transcript, std::map& kate_g1_elements, @@ -112,9 +110,9 @@ void populate_kate_element_map(typename Curve::Composer* ctx, } template -lagrange_evaluations get_lagrange_evaluations( +lagrange_evaluations get_lagrange_evaluations( const typename Curve::fr_ct& z, - const evaluation_domain& domain, + const evaluation_domain& domain, const size_t num_roots_cut_out_of_vanishing_polynomial = 4) { // compute Z_H*(z), l_start(z), l_{end}(z) @@ -127,9 +125,9 @@ lagrange_evaluations get_lagrange_evaluations( // typedef typename Curve::fr_ct fr_ct; - typedef typename Curve::Composer Composer; + typedef typename Curve::Builder Builder; - fr_ct z_pow = z.pow(field_t(domain.size)); + fr_ct z_pow = z.pow(field_t(domain.size)); fr_ct numerator = z_pow - fr_ct(1); // compute modified vanishing polynomial Z_H*(z) @@ -138,7 +136,7 @@ lagrange_evaluations get_lagrange_evaluations( // (z - w^{n-1})(z - w^{n-2})...(z - w^{n - k}) // fr_ct denominators_vanishing_poly = fr_ct(1); - lagrange_evaluations result; + lagrange_evaluations result; fr_ct work_root = domain.root_inverse; for (size_t i = 0; i < num_roots_cut_out_of_vanishing_polynomial; ++i) { @@ -176,17 +174,17 @@ lagrange_evaluations get_lagrange_evaluations( * which includes detailed comments. */ template -aggregation_state verify_proof(typename Curve::Composer* context, +aggregation_state verify_proof(typename Curve::Builder* context, std::shared_ptr> key, const transcript::Manifest& manifest, const plonk::proof& proof, const aggregation_state previous_output = aggregation_state()) { - using Composer = typename Curve::Composer; + using Builder = typename Curve::Builder; key->program_width = program_settings::program_width; - Transcript transcript = Transcript(context, proof.proof_data, manifest); + Transcript transcript = Transcript(context, proof.proof_data, manifest); return verify_proof_(context, key, transcript, previous_output); } @@ -196,15 +194,15 @@ aggregation_state verify_proof(typename Curve::Composer* context, * which includes detailed comments. */ template -aggregation_state verify_proof_(typename Curve::Composer* context, +aggregation_state verify_proof_(typename Curve::Builder* context, std::shared_ptr> key, - Transcript& transcript, + Transcript& transcript, const aggregation_state previous_output = aggregation_state()) { using fr_ct = typename Curve::fr_ct; using fq_ct = typename Curve::fq_ct; using g1_ct = typename Curve::g1_ct; - using Composer = typename Curve::Composer; + using Builder = typename Curve::Builder; key->program_width = program_settings::program_width; @@ -233,7 +231,7 @@ aggregation_state verify_proof_(typename Curve::Composer* context, key->z_pow_n = zeta.pow(key->domain.domain); - lagrange_evaluations lagrange_evals = get_lagrange_evaluations(zeta, key->domain); + lagrange_evaluations lagrange_evals = get_lagrange_evaluations(zeta, key->domain); // reconstruct evaluation of quotient polynomial from prover messages @@ -250,14 +248,14 @@ aggregation_state verify_proof_(typename Curve::Composer* context, fr_ct batch_opening_scalar; - populate_kate_element_map, program_settings>(context, - key.get(), - transcript, - kate_g1_elements, - kate_fr_elements_at_zeta, - kate_fr_elements_at_zeta_large, - kate_fr_elements_at_zeta_omega, - batch_opening_scalar); + populate_kate_element_map, program_settings>(context, + key.get(), + transcript, + kate_g1_elements, + kate_fr_elements_at_zeta, + kate_fr_elements_at_zeta_large, + kate_fr_elements_at_zeta_omega, + batch_opening_scalar); std::vector double_opening_scalars; std::vector double_opening_elements; @@ -415,6 +413,23 @@ aggregation_state verify_proof_(typename Curve::Composer* context, return result; } +template +aggregation_state> verify_proof( + typename Flavor::CircuitConstructor* context, + std::shared_ptr>> key, + const plonk::proof& proof, + const aggregation_state> previous_output = + aggregation_state>()) +{ + // TODO(Cody): Be sure this is kosher + const auto manifest = + Flavor::create_manifest(static_cast(key->num_public_inputs.get_value().from_montgomery_form().data[0])); + return verify_proof< + bn254, + recursion::recursive_ultra_verifier_settings>>( + context, key, manifest, proof, previous_output); +} + } // namespace recursion } // namespace stdlib } // namespace proof_system::plonk diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp index bffd6a114eee..d80af95e6657 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier.test.cpp @@ -1,56 +1,88 @@ #include "verifier.hpp" +#include "program_settings.hpp" + #include "barretenberg/common/test.hpp" -#include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" -#include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/bn254/pairing.hpp" -#include "../../hash/blake3s/blake3s.hpp" -#include "../../hash/pedersen/pedersen.hpp" -#include "program_settings.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" +#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" +#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" +#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/primitives/curves/bn254.hpp" +#include "barretenberg/transcript/transcript.hpp" -using namespace proof_system::plonk; +namespace proof_system::plonk::stdlib { template class stdlib_verifier : public testing::Test { - using InnerComposer = proof_system::plonk::UltraPlonkComposer; - - typedef stdlib::bn254 inner_curve; - typedef stdlib::bn254 outer_curve; - typedef proof_system::plonk::stdlib::recursion::verification_key verification_key_pt; - typedef proof_system::plonk::stdlib::recursion::recursive_ultra_verifier_settings recursive_settings; - typedef proof_system::plonk::stdlib::recursion::recursive_ultra_to_standard_verifier_settings - ultra_to_standard_recursive_settings; - typedef inner_curve::fr_ct fr_ct; - typedef inner_curve::public_witness_ct public_witness_ct; - typedef inner_curve::witness_ct witness_ct; + + using InnerComposer = proof_system::plonk::UltraPlonkComposerHelper; + using InnerBuilder = typename InnerComposer::CircuitConstructor; + + using OuterBuilder = typename OuterComposer::CircuitConstructor; + + using inner_curve = bn254; + using outer_curve = bn254; + + using verification_key_pt = recursion::verification_key; + using recursive_settings = recursion::recursive_ultra_verifier_settings; + using ultra_to_standard_recursive_settings = recursion::recursive_ultra_to_standard_verifier_settings; + + using inner_scalar_field_ct = inner_curve::fr_ct; + using inner_ground_field_ct = inner_curve::fq_ct; + using public_witness_ct = inner_curve::public_witness_ct; + using witness_ct = inner_curve::witness_ct; + using byte_array_ct = inner_curve::byte_array_ct; + + using inner_scalar_field = typename inner_curve::ScalarField; + using outer_scalar_field = typename outer_curve::BaseField; + using pairing_target_field = barretenberg::fq12; + + // These constexpr definitions are to allow for the following: An Ultra Pedersen hash evaluates to a + // different value from the Turbo/Standard versions of the Pedersen hash. Therefore, the fiat-shamir + // challenges generated by the prover and verifier _could_ accidentally be different if an ultra proof is + // generated using ultra-pedersen challenges, but is being verified within a non-ultra circuit which uses + // non-ultra-pedersen challenges. We need the prover and verifier hashes to be the same. The solution is to + // select the relevant prover and verifier types (whose settings use the same hash for fiat-shamir), + // depending on the Inner-Outer combo. It's a bit clunky, but the alternative is to have a template argument + // for the hashtype, and that would pervade the entire UltraPlonkComposer, which would be horrendous. + static constexpr bool is_ultra_to_ultra = + std::is_same_v; + using ProverOfInnerCircuit = + std::conditional_t; + using VerifierOfInnerProof = + std::conditional_t; + using RecursiveSettings = + std::conditional_t; struct circuit_outputs { - stdlib::recursion::aggregation_state aggregation_state; + recursion::aggregation_state aggregation_state; std::shared_ptr verification_key; }; - static void create_inner_circuit(InnerComposer& composer, const std::vector& public_inputs) + static void create_inner_circuit(InnerBuilder& builder, const std::vector& public_inputs) { - fr_ct a(public_witness_ct(&composer, public_inputs[0])); - fr_ct b(public_witness_ct(&composer, public_inputs[1])); - fr_ct c(public_witness_ct(&composer, public_inputs[2])); + inner_scalar_field_ct a(public_witness_ct(&builder, public_inputs[0])); + inner_scalar_field_ct b(public_witness_ct(&builder, public_inputs[1])); + inner_scalar_field_ct c(public_witness_ct(&builder, public_inputs[2])); for (size_t i = 0; i < 32; ++i) { a = (a * b) + b + a; a = a.madd(b, c); } - plonk::stdlib::pedersen_commitment::compress(a, b); - typename inner_curve::byte_array_ct to_hash(&composer, "nonsense test data"); - stdlib::blake3s(to_hash); + pedersen_commitment::compress(a, b); + byte_array_ct to_hash(&builder, "nonsense test data"); + blake3s(to_hash); - barretenberg::fr bigfield_data = fr::random_element(); - barretenberg::fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; - barretenberg::fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; + inner_scalar_field bigfield_data = fr::random_element(); + inner_scalar_field bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; + inner_scalar_field bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - typename inner_curve::fq_ct big_a(fr_ct(witness_ct(&composer, bigfield_data_a.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - typename inner_curve::fq_ct big_b(fr_ct(witness_ct(&composer, bigfield_data_b.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); + inner_ground_field_ct big_a(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); + inner_ground_field_ct big_b(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); big_a* big_b; }; @@ -58,13 +90,13 @@ template class stdlib_verifier : public testing::Test { /** * Test is included because UltraPlonkComposer used to fail for circuits which didn't lookup any tables. */ - static void create_inner_circuit_no_tables(InnerComposer& composer, - const std::vector& public_inputs) + static void create_inner_circuit_no_tables(InnerBuilder& builder, + const std::vector& public_inputs) { // A nice Pythagorean triples circuit example: "I know a & b s.t. a^2 + b^2 = c^2". - fr_ct a(witness_ct(&composer, public_inputs[0])); - fr_ct b(witness_ct(&composer, public_inputs[1])); - fr_ct c(witness_ct(&composer, public_inputs[2])); + inner_scalar_field_ct a(witness_ct(&builder, public_inputs[0])); + inner_scalar_field_ct b(witness_ct(&builder, public_inputs[1])); + inner_scalar_field_ct c(witness_ct(&builder, public_inputs[2])); auto a_sq = a * a; auto b_sq = b * b; @@ -75,65 +107,48 @@ template class stdlib_verifier : public testing::Test { c_sq.set_public(); }; - static void create_alternate_inner_circuit(InnerComposer& composer, - const std::vector& public_inputs) + static void create_alternate_inner_circuit(InnerBuilder& builder, + const std::vector& public_inputs) { - fr_ct a(public_witness_ct(&composer, public_inputs[0])); - fr_ct b(public_witness_ct(&composer, public_inputs[1])); - fr_ct c(public_witness_ct(&composer, public_inputs[2])); + inner_scalar_field_ct a(public_witness_ct(&builder, public_inputs[0])); + inner_scalar_field_ct b(public_witness_ct(&builder, public_inputs[1])); + inner_scalar_field_ct c(public_witness_ct(&builder, public_inputs[2])); for (size_t i = 0; i < 32; ++i) { a = (a * b) + b + a; a = c.madd(b, a); } - plonk::stdlib::pedersen_commitment::compress(a, a); - inner_curve::byte_array_ct to_hash(&composer, "different nonsense test data"); - stdlib::blake3s(to_hash); - - barretenberg::fr bigfield_data = fr::random_element(); - barretenberg::fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; - barretenberg::fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - - inner_curve::bn254::fq_ct big_a(fr_ct(witness_ct(&composer, bigfield_data_a.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - inner_curve::bn254::fq_ct big_b(fr_ct(witness_ct(&composer, bigfield_data_b.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); + pedersen_commitment::compress(a, a); + byte_array_ct to_hash(&builder, "different nonsense test data"); + blake3s(to_hash); + + inner_scalar_field bigfield_data = fr::random_element(); + inner_scalar_field bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; + inner_scalar_field bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; + + inner_ground_field_ct big_a(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); + inner_ground_field_ct big_b(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); ((big_a * big_b) + big_a) * big_b; } - static circuit_outputs create_outer_circuit(InnerComposer& inner_composer, OuterComposer& outer_composer) + static circuit_outputs create_outer_circuit(InnerBuilder& inner_circuit, OuterBuilder& outer_builder) { - // These constexpr definitions are to allow for the following: - // An Ultra Pedersen hash evaluates to a different value from the Turbo/Standard versions of the Pedersen hash. - // Therefore, the fiat-shamir challenges generated by the prover and verifier _could_ accidentally be different - // if an ultra proof is generated using ultra-pedersen challenges, but is being verified within a non-ultra - // circuit which uses non-ultra-pedersen challenges. We need the prover and verifier hashes to be the same. The - // solution is to select the relevant prover and verifier types (whose settings use the same hash for - // fiat-shamir), depending on the Inner-Outer combo. It's a bit clunky, but the alternative is to have a - // template argument for the hashtype, and that would pervade the entire UltraPlonkComposer, which would be - // horrendous. - constexpr bool is_ultra_to_ultra = std::is_same::value; - typedef typename std::conditional::type - ProverOfInnerCircuit; - typedef typename std::conditional::type - VerifierOfInnerProof; - typedef - typename std::conditional::type - RecursiveSettings; - info("Creating ultra (inner) prover..."); ProverOfInnerCircuit prover; + InnerComposer inner_composer; if constexpr (is_ultra_to_ultra) { - prover = inner_composer.create_prover(); + prover = inner_composer.create_prover(inner_circuit); } else { - prover = inner_composer.create_ultra_to_standard_prover(); + prover = inner_composer.create_ultra_to_standard_prover(inner_circuit); } info("Computing verification key..."); - const auto verification_key_native = inner_composer.compute_verification_key(); + const auto verification_key_native = inner_composer.compute_verification_key(inner_circuit); // Convert the verification key's elements into _circuit_ types, using the OUTER composer. std::shared_ptr verification_key = - verification_key_pt::from_witness(&outer_composer, verification_key_native); + verification_key_pt::from_witness(&outer_builder, verification_key_native); info("Constructing the ultra (inner) proof ..."); plonk::proof proof_to_recursively_verify = prover.construct_proof(); @@ -144,9 +159,9 @@ template class stdlib_verifier : public testing::Test { VerifierOfInnerProof native_verifier; if constexpr (is_ultra_to_ultra) { - native_verifier = inner_composer.create_verifier(); + native_verifier = inner_composer.create_verifier(inner_circuit); } else { - native_verifier = inner_composer.create_ultra_to_standard_verifier(); + native_verifier = inner_composer.create_ultra_to_standard_verifier(inner_circuit); } info("Verifying the ultra (inner) proof natively..."); @@ -157,63 +172,50 @@ template class stdlib_verifier : public testing::Test { transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); - info("Verifying the ultra (inner) proof with CIRCUIT TYPES (i.e. within a standard plonk arithmetic circuit):"); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, proof_to_recursively_verify); + auto output = recursion::verify_proof( + &outer_builder, verification_key, recursive_manifest, proof_to_recursively_verify); return { output, verification_key }; }; - static circuit_outputs create_double_outer_circuit(InnerComposer& inner_composer_a, - InnerComposer& inner_composer_b, - OuterComposer& outer_composer) + static circuit_outputs create_double_outer_circuit(InnerBuilder& inner_circuit_a, + InnerBuilder& inner_circuit_b, + OuterBuilder& outer_circuit) { - // See create_outer_circuit for explanation of these constexpr definitions. - constexpr bool is_ultra_to_ultra = std::is_same::value; - typedef typename std::conditional::type - ProverOfInnerCircuit; - typedef - typename std::conditional::type - RecursiveSettings; - ProverOfInnerCircuit prover; + InnerComposer inner_composer_a; if constexpr (is_ultra_to_ultra) { - prover = inner_composer_a.create_prover(); + prover = inner_composer_a.create_prover(inner_circuit_a); } else { - prover = inner_composer_a.create_ultra_to_standard_prover(); + prover = inner_composer_a.create_ultra_to_standard_prover(inner_circuit_a); } - const auto verification_key_native = inner_composer_a.compute_verification_key(); + const auto verification_key_native = inner_composer_a.compute_verification_key(inner_circuit_a); std::shared_ptr verification_key = - verification_key_pt::from_witness(&outer_composer, verification_key_native); + verification_key_pt::from_witness(&outer_circuit, verification_key_native); plonk::proof proof_to_recursively_verify_a = prover.construct_proof(); transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); - stdlib::recursion::aggregation_state previous_output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, proof_to_recursively_verify_a); + auto previous_output = recursion::verify_proof( + &outer_circuit, verification_key, recursive_manifest, proof_to_recursively_verify_a); + InnerComposer inner_composer_b; if constexpr (is_ultra_to_ultra) { - prover = inner_composer_b.create_prover(); + prover = inner_composer_b.create_prover(inner_circuit_b); } else { - prover = inner_composer_b.create_ultra_to_standard_prover(); + prover = inner_composer_b.create_ultra_to_standard_prover(inner_circuit_b); } - const auto verification_key_b_raw = inner_composer_b.compute_verification_key(); + const auto verification_key_b_raw = inner_composer_b.compute_verification_key(inner_circuit_b); std::shared_ptr verification_key_b = - verification_key_pt::from_witness(&outer_composer, verification_key_b_raw); + verification_key_pt::from_witness(&outer_circuit, verification_key_b_raw); plonk::proof proof_to_recursively_verify_b = prover.construct_proof(); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof(&outer_composer, - verification_key_b, - recursive_manifest, - proof_to_recursively_verify_b, - previous_output); + auto output = proof_system::plonk::stdlib::recursion::verify_proof( + &outer_circuit, verification_key_b, recursive_manifest, proof_to_recursively_verify_b, previous_output); verification_key_b->compress(); verification_key->compress(); @@ -221,43 +223,36 @@ template class stdlib_verifier : public testing::Test { } // creates a cicuit that verifies either a proof from composer a, or from composer b - static circuit_outputs create_outer_circuit_with_variable_inner_circuit(InnerComposer& inner_composer_a, - InnerComposer& inner_composer_b, - OuterComposer& outer_composer, + static circuit_outputs create_outer_circuit_with_variable_inner_circuit(InnerBuilder& inner_circuit_a, + InnerBuilder& inner_circuit_b, + OuterBuilder& outer_circuit, const bool proof_type, const bool create_failing_proof = false, const bool use_constant_key = false) { - // See create_outer_circuit for explanation of these constexpr definitions. - constexpr bool is_ultra_to_ultra = std::is_same::value; - typedef typename std::conditional::type - ProverOfInnerCircuit; - typedef - typename std::conditional::type - RecursiveSettings; - ProverOfInnerCircuit prover_a; ProverOfInnerCircuit prover_b; + InnerComposer inner_composer_a; + InnerComposer inner_composer_b; if constexpr (is_ultra_to_ultra) { - prover_a = inner_composer_a.create_prover(); - prover_b = inner_composer_b.create_prover(); + prover_a = inner_composer_a.create_prover(inner_circuit_a); + prover_b = inner_composer_b.create_prover(inner_circuit_b); } else { - prover_a = inner_composer_a.create_ultra_to_standard_prover(); - prover_b = inner_composer_b.create_ultra_to_standard_prover(); + prover_a = inner_composer_a.create_ultra_to_standard_prover(inner_circuit_a); + prover_b = inner_composer_b.create_ultra_to_standard_prover(inner_circuit_b); } - const auto verification_key_raw_a = inner_composer_a.compute_verification_key(); - const auto verification_key_raw_b = inner_composer_b.compute_verification_key(); + const auto verification_key_raw_a = inner_composer_a.compute_verification_key(inner_circuit_a); + const auto verification_key_raw_b = inner_composer_b.compute_verification_key(inner_circuit_b); std::shared_ptr verification_key; if (use_constant_key) { - verification_key = proof_type - ? verification_key_pt::from_constants(&outer_composer, verification_key_raw_a) - : verification_key_pt::from_constants(&outer_composer, verification_key_raw_b); + verification_key = proof_type ? verification_key_pt::from_constants(&outer_circuit, verification_key_raw_a) + : verification_key_pt::from_constants(&outer_circuit, verification_key_raw_b); } else { - verification_key = proof_type ? verification_key_pt::from_witness(&outer_composer, verification_key_raw_a) - : verification_key_pt::from_witness(&outer_composer, verification_key_raw_b); + verification_key = proof_type ? verification_key_pt::from_witness(&outer_circuit, verification_key_raw_a) + : verification_key_pt::from_witness(&outer_circuit, verification_key_raw_b); } if (!use_constant_key) { @@ -272,9 +267,9 @@ template class stdlib_verifier : public testing::Test { transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover_a.key->num_public_inputs); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, recursive_proof); + proof_system::plonk::stdlib::recursion::aggregation_state output = + proof_system::plonk::stdlib::recursion::verify_proof( + &outer_circuit, verification_key, recursive_manifest, recursive_proof); return { output, verification_key }; } @@ -283,159 +278,155 @@ template class stdlib_verifier : public testing::Test { * @brief Check the correctness of the recursive proof public inputs * * @details Circuit constructors have no notion of SRS and any proof-related stuff except for the existence of - * recursive proof-specific public inputs, so we can't check the recursive proof fully in check_circuit. So we use - * this additional function to check that the recursive proof points work. + * recursive proof-specific public inputs, so we can't check the recursive proof fully in check_circuit. So we + * use this additional function to check that the recursive proof points work. * * @return boolean result */ - static bool check_recursive_proof_public_inputs(OuterComposer& composer, + + static bool check_recursive_proof_public_inputs(OuterBuilder& builder, const barretenberg::pairing::miller_lines* lines) { - if (composer.contains_recursive_proof && composer.recursive_proof_public_input_indices.size() == 16) { - const auto& inputs = composer.circuit_constructor.public_inputs; + if (builder.contains_recursive_proof && builder.recursive_proof_public_input_indices.size() == 16) { + const auto& inputs = builder.public_inputs; const auto recover_fq_from_public_inputs = - [&inputs, &composer](const size_t idx0, const size_t idx1, const size_t idx2, const size_t idx3) { - const uint256_t l0 = composer.circuit_constructor.get_variable(inputs[idx0]); - const uint256_t l1 = composer.circuit_constructor.get_variable(inputs[idx1]); - const uint256_t l2 = composer.circuit_constructor.get_variable(inputs[idx2]); - const uint256_t l3 = composer.circuit_constructor.get_variable(inputs[idx3]); + [&inputs, &builder](const size_t idx0, const size_t idx1, const size_t idx2, const size_t idx3) { + const uint256_t l0 = builder.get_variable(inputs[idx0]); + const uint256_t l1 = builder.get_variable(inputs[idx1]); + const uint256_t l2 = builder.get_variable(inputs[idx2]); + const uint256_t l3 = builder.get_variable(inputs[idx3]); const uint256_t limb = l0 + (l1 << NUM_LIMB_BITS_IN_FIELD_SIMULATION) + (l2 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 2)) + (l3 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 3)); - return barretenberg::fq(limb); + return outer_scalar_field(limb); }; - const auto x0 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[0], - composer.recursive_proof_public_input_indices[1], - composer.recursive_proof_public_input_indices[2], - composer.recursive_proof_public_input_indices[3]); - const auto y0 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[4], - composer.recursive_proof_public_input_indices[5], - composer.recursive_proof_public_input_indices[6], - composer.recursive_proof_public_input_indices[7]); - const auto x1 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[8], - composer.recursive_proof_public_input_indices[9], - composer.recursive_proof_public_input_indices[10], - composer.recursive_proof_public_input_indices[11]); - const auto y1 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[12], - composer.recursive_proof_public_input_indices[13], - composer.recursive_proof_public_input_indices[14], - composer.recursive_proof_public_input_indices[15]); + const auto x0 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[0], + builder.recursive_proof_public_input_indices[1], + builder.recursive_proof_public_input_indices[2], + builder.recursive_proof_public_input_indices[3]); + const auto y0 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[4], + builder.recursive_proof_public_input_indices[5], + builder.recursive_proof_public_input_indices[6], + builder.recursive_proof_public_input_indices[7]); + const auto x1 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[8], + builder.recursive_proof_public_input_indices[9], + builder.recursive_proof_public_input_indices[10], + builder.recursive_proof_public_input_indices[11]); + const auto y1 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[12], + builder.recursive_proof_public_input_indices[13], + builder.recursive_proof_public_input_indices[14], + builder.recursive_proof_public_input_indices[15]); g1::affine_element P_affine[2]{ { x0, y0 }, { x1, y1 }, }; - barretenberg::fq12 result = + pairing_target_field result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P_affine, lines, 2); - return (result == barretenberg::fq12::one()); + return (result == pairing_target_field::one()); } return true; } - public: - static void test_recursive_proof_composition() + static void check_pairing(const circuit_outputs& circuit_output) { - InnerComposer inner_composer = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - create_inner_circuit(inner_composer, inner_inputs); - - auto circuit_output = create_outer_circuit(inner_composer, outer_composer); - + auto g2_lines = barretenberg::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); - - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs[0]); - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs[1]); + P[0].x = outer_scalar_field(circuit_output.aggregation_state.P0.x.get_value().lo); + P[0].y = outer_scalar_field(circuit_output.aggregation_state.P0.y.get_value().lo); + P[1].x = outer_scalar_field(circuit_output.aggregation_state.P1.x.get_value().lo); + P[1].y = outer_scalar_field(circuit_output.aggregation_state.P1.y.get_value().lo); + pairing_target_field inner_proof_result = + barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P, g2_lines, 2); + EXPECT_EQ(inner_proof_result, pairing_target_field::one()); + } - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); + static void check_recursive_verification_circuit(OuterBuilder& outer_circuit, bool expected_result) + { + info("number of gates in recursive verification circuit = ", outer_circuit.get_num_gates()); + bool result = outer_circuit.check_circuit(); + EXPECT_EQ(result, expected_result); + auto g2_lines = barretenberg::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); + EXPECT_EQ(check_recursive_proof_public_inputs(outer_circuit, g2_lines), true); + } - circuit_output.aggregation_state.assign_object_to_proof_outputs(); + public: + static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); } - EXPECT_EQ(outer_composer.failed(), false); + static void test_inner_circuit() + { + InnerBuilder builder; + std::vector inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - bool result = outer_composer.check_circuit(); + create_inner_circuit(builder, inputs); + bool result = builder.check_circuit(); EXPECT_EQ(result, true); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); } - static void test_recursive_proof_composition_ultra_no_tables() + static void test_recursive_proof_composition() { - InnerComposer inner_composer = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - - std::vector inner_inputs{ 3, 4, 5 }; + InnerBuilder inner_circuit; + OuterBuilder outer_circuit; - create_inner_circuit_no_tables(inner_composer, inner_inputs); + std::vector inner_public_inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = create_outer_circuit(inner_composer, outer_composer); + create_inner_circuit(inner_circuit, inner_public_inputs); - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); + auto circuit_output = create_outer_circuit(inner_circuit, outer_circuit); + EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_public_inputs[0]); + EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_public_inputs[1]); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + circuit_output.aggregation_state.assign_object_to_proof_outputs(); + EXPECT_EQ(outer_circuit.failed(), false); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); + } - circuit_output.aggregation_state.assign_object_to_proof_outputs(); + static void test_recursive_proof_composition_ultra_no_tables() + { + InnerBuilder inner_circuit; + OuterBuilder outer_circuit; - EXPECT_EQ(outer_composer.failed(), false); + std::vector inner_public_inputs{ 3, 4, 5 }; - info("composer gates = ", outer_composer.get_num_gates()); + create_inner_circuit_no_tables(inner_circuit, inner_public_inputs); - bool result = outer_composer.check_circuit(); + auto circuit_output = create_outer_circuit(inner_circuit, outer_circuit); - EXPECT_EQ(result, true); + circuit_output.aggregation_state.assign_object_to_proof_outputs(); + EXPECT_EQ(outer_circuit.failed(), false); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } static void test_double_verification() { - if constexpr (std::is_same::value) - return; // We only care about running this test for turbo and ultra outer circuits, since in practice the - // only circuits which verify >1 proof are ultra or turbo circuits. Standard uses so many gates - // (16m) that it's a waste of time testing it. - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; - OuterComposer mid_composer_a = OuterComposer("../srs_db/ignition"); - OuterComposer mid_composer_b = OuterComposer("../srs_db/ignition"); + OuterBuilder mid_circuit_a; + OuterBuilder mid_circuit_b; - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); + OuterBuilder outer_circuit; - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + std::vector inner_inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - create_inner_circuit(inner_composer_a, inner_inputs); - create_inner_circuit(inner_composer_b, inner_inputs); + create_inner_circuit(inner_circuit_a, inner_inputs); + create_inner_circuit(inner_circuit_b, inner_inputs); - auto circuit_output_a = create_outer_circuit(inner_composer_a, mid_composer_a); + auto circuit_output_a = create_outer_circuit(inner_circuit_a, mid_circuit_a); uint256_t a0 = circuit_output_a.aggregation_state.P0.x.binary_basis_limbs[1].element.get_value(); uint256_t a1 = circuit_output_a.aggregation_state.P0.y.binary_basis_limbs[1].element.get_value(); @@ -449,246 +440,143 @@ template class stdlib_verifier : public testing::Test { circuit_output_a.aggregation_state.assign_object_to_proof_outputs(); - auto circuit_output_b = create_outer_circuit(inner_composer_b, mid_composer_b); + auto circuit_output_b = create_outer_circuit(inner_circuit_b, mid_circuit_b); circuit_output_b.aggregation_state.assign_object_to_proof_outputs(); - auto circuit_output = create_double_outer_circuit(mid_composer_a, mid_composer_b, outer_composer); - + auto circuit_output = create_double_outer_circuit(mid_circuit_a, mid_circuit_b, outer_circuit); circuit_output.aggregation_state.assign_object_to_proof_outputs(); - - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); - EXPECT_EQ(circuit_output_a.aggregation_state.public_inputs[0].get_value(), inner_inputs[0]); EXPECT_EQ(circuit_output_a.aggregation_state.public_inputs[1].get_value(), inner_inputs[1]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } - // verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the two - // variable circuits + // verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the + // two variable circuits static void test_recursive_proof_composition_with_variable_verification_key_a() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = - create_outer_circuit_with_variable_inner_circuit(inner_composer_a, inner_composer_b, outer_composer, true); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = + create_outer_circuit_with_variable_inner_circuit(inner_circuit_a, inner_circuit_b, outer_circuit, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } - // verifies a proof of a circuit that verifies one of two proofs. Test 'b' uses a proof over the second of the two - // variable circuits + // verifies a proof of a circuit that verifies one of two proofs. Test 'b' uses a proof over the second of the + // two variable circuits static void test_recursive_proof_composition_with_variable_verification_key_b() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); - auto circuit_output = - create_outer_circuit_with_variable_inner_circuit(inner_composer_a, inner_composer_b, outer_composer, false); - g1::affine_element P[2]; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + + auto circuit_output = + create_outer_circuit_with_variable_inner_circuit(inner_circuit_a, inner_circuit_b, outer_circuit, false); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_b[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_b[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_b[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } static void test_recursive_proof_composition_with_variable_verification_key_failure_case() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = create_outer_circuit_with_variable_inner_circuit( - inner_composer_a, inner_composer_b, outer_composer, true, true); - - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = create_outer_circuit_with_variable_inner_circuit( + inner_circuit_a, inner_circuit_b, outer_circuit, true, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, false); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, false); } static void test_recursive_proof_composition_with_constant_verification_key() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = create_outer_circuit_with_variable_inner_circuit( - inner_composer_a, inner_composer_b, outer_composer, true, false, true); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = create_outer_circuit_with_variable_inner_circuit( + inner_circuit_a, inner_circuit_b, outer_circuit, true, false, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); - } - - static void test_inner_circuit() - { - if constexpr (!std::is_same::value) - return; // We only want to run this test once (since it's not actually dependent on the typed test - // parameter; which is the outer composer). We've only made it a typed test so that it can be - // included in this test suite. So to avoid running this test identically 3 times, we escape all but - // 1 permutation. - - InnerComposer inner_composer = InnerComposer("../srs_db/ignition"); - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - create_inner_circuit(inner_composer, inner_inputs); - - auto prover = inner_composer.create_prover(); - auto verifier = inner_composer.create_verifier(); - auto proof = prover.construct_proof(); - auto verified = verifier.verify_proof(proof); - EXPECT_EQ(verified, true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } }; -typedef testing::Types - OuterComposerTypes; +typedef testing:: + Types + OuterComposerTypes; TYPED_TEST_SUITE(stdlib_verifier, OuterComposerTypes); +HEAVY_TYPED_TEST(stdlib_verifier, test_inner_circuit) +{ + TestFixture::test_inner_circuit(); +} + HEAVY_TYPED_TEST(stdlib_verifier, recursive_proof_composition) { TestFixture::test_recursive_proof_composition(); @@ -696,20 +584,19 @@ HEAVY_TYPED_TEST(stdlib_verifier, recursive_proof_composition) HEAVY_TYPED_TEST(stdlib_verifier, recursive_proof_composition_ultra_no_tables) { - if constexpr (TypeParam::type == ComposerType::PLOOKUP) { + if constexpr (std::same_as) { TestFixture::test_recursive_proof_composition_ultra_no_tables(); } else { - // no point running this if we're not in UltraPlonk GTEST_SKIP(); } }; HEAVY_TYPED_TEST(stdlib_verifier, double_verification) { - if constexpr (TypeParam::type == ComposerType::PLOOKUP) { + if constexpr (std::same_as) { TestFixture::test_double_verification(); } else { - // CircleCI can't cope with non-ultraplonk version. + // Test doesn't compile-. GTEST_SKIP(); } }; @@ -734,7 +621,4 @@ HEAVY_TYPED_TEST(stdlib_verifier, recursive_proof_composition_const_verif_key) TestFixture::test_recursive_proof_composition_with_constant_verification_key(); } -HEAVY_TYPED_TEST(stdlib_verifier, test_inner_circuit) -{ - TestFixture::test_inner_circuit(); -} +} // namespace proof_system::plonk::stdlib \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier_turbo.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier_turbo.test.cpp index e8349f8eb999..3a92aa233f02 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier_turbo.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/verifier/verifier_turbo.test.cpp @@ -1,207 +1,202 @@ #include "verifier.hpp" +#include "program_settings.hpp" + #include "barretenberg/common/test.hpp" -#include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" -#include "barretenberg/stdlib/primitives/curves/bn254.hpp" #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/bn254/pairing.hpp" -#include "../../hash/blake3s/blake3s.hpp" -#include "../../hash/pedersen/pedersen.hpp" -#include "program_settings.hpp" +#include "barretenberg/plonk/composer/composer_helper/standard_plonk_composer_helper.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" +#include "barretenberg/plonk/proof_system/proving_key/serialize.hpp" +#include "barretenberg/stdlib/hash/blake3s/blake3s.hpp" +#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp" +#include "barretenberg/stdlib/primitives/curves/bn254.hpp" +#include "barretenberg/transcript/transcript.hpp" -using namespace proof_system::plonk; +namespace proof_system::plonk::stdlib { template class stdlib_verifier_turbo : public testing::Test { - using InnerComposer = proof_system::plonk::TurboPlonkComposer; - typedef stdlib::bn254 inner_curve; - typedef stdlib::bn254 outer_curve; - typedef proof_system::plonk::stdlib::recursion::verification_key verification_key_pt; - typedef proof_system::plonk::stdlib::recursion::recursive_turbo_verifier_settings recursive_settings; - typedef inner_curve::fr_ct fr_ct; - typedef inner_curve::public_witness_ct public_witness_ct; - typedef inner_curve::witness_ct witness_ct; + using InnerComposer = proof_system::plonk::TurboPlonkComposerHelper; + using InnerBuilder = typename InnerComposer::CircuitConstructor; + + using OuterBuilder = typename OuterComposer::CircuitConstructor; + + using inner_curve = bn254; + using outer_curve = bn254; + + using verification_key_pt = recursion::verification_key; + using recursive_settings = recursion::recursive_turbo_verifier_settings; + + using inner_scalar_field_ct = inner_curve::fr_ct; + using inner_ground_field_ct = inner_curve::fq_ct; + using public_witness_ct = inner_curve::public_witness_ct; + using witness_ct = inner_curve::witness_ct; + using byte_array_ct = inner_curve::byte_array_ct; + + using inner_scalar_field = typename inner_curve::ScalarField; + using outer_scalar_field = typename outer_curve::BaseField; + using pairing_target_field = barretenberg::fq12; + + using ProverOfInnerCircuit = plonk::TurboProver; + using VerifierOfInnerProof = plonk::TurboVerifier; + using RecursiveSettings = recursive_settings; struct circuit_outputs { - stdlib::recursion::aggregation_state aggregation_state; + recursion::aggregation_state aggregation_state; std::shared_ptr verification_key; }; - /** - * @brief Check the correctness of the recursive proof public inputs - * - * @details Circuit constructors have no notion of SRS and any proof-related stuff except for the existence of - * recursive proof-specific public inputs, so we can't check the recursive proof fully in check_circuit. So we use - * this additional function to check that the recursive proof points work. - * - * @return true - * @return false - */ - static bool check_recursive_proof_public_inputs(OuterComposer& composer, - const barretenberg::pairing::miller_lines* lines) + + static void create_inner_circuit(InnerBuilder& builder, const std::vector& public_inputs) { - if (composer.contains_recursive_proof && composer.recursive_proof_public_input_indices.size() == 16) { - const auto& inputs = composer.circuit_constructor.public_inputs; - const auto recover_fq_from_public_inputs = - [&inputs, &composer](const size_t idx0, const size_t idx1, const size_t idx2, const size_t idx3) { - const uint256_t l0 = composer.circuit_constructor.get_variable(inputs[idx0]); - const uint256_t l1 = composer.circuit_constructor.get_variable(inputs[idx1]); - const uint256_t l2 = composer.circuit_constructor.get_variable(inputs[idx2]); - const uint256_t l3 = composer.circuit_constructor.get_variable(inputs[idx3]); + inner_scalar_field_ct a(public_witness_ct(&builder, public_inputs[0])); + inner_scalar_field_ct b(public_witness_ct(&builder, public_inputs[1])); + inner_scalar_field_ct c(public_witness_ct(&builder, public_inputs[2])); - const uint256_t limb = l0 + (l1 << NUM_LIMB_BITS_IN_FIELD_SIMULATION) + - (l2 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 2)) + - (l3 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 3)); - return barretenberg::fq(limb); - }; + for (size_t i = 0; i < 32; ++i) { + a = (a * b) + b + a; + a = a.madd(b, c); + } + pedersen_commitment::compress(a, b); + byte_array_ct to_hash(&builder, "nonsense test data"); + blake3s(to_hash); - const auto x0 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[0], - composer.recursive_proof_public_input_indices[1], - composer.recursive_proof_public_input_indices[2], - composer.recursive_proof_public_input_indices[3]); - const auto y0 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[4], - composer.recursive_proof_public_input_indices[5], - composer.recursive_proof_public_input_indices[6], - composer.recursive_proof_public_input_indices[7]); - const auto x1 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[8], - composer.recursive_proof_public_input_indices[9], - composer.recursive_proof_public_input_indices[10], - composer.recursive_proof_public_input_indices[11]); - const auto y1 = recover_fq_from_public_inputs(composer.recursive_proof_public_input_indices[12], - composer.recursive_proof_public_input_indices[13], - composer.recursive_proof_public_input_indices[14], - composer.recursive_proof_public_input_indices[15]); - g1::affine_element P_affine[2]{ - { x0, y0 }, - { x1, y1 }, - }; + inner_scalar_field bigfield_data = fr::random_element(); + inner_scalar_field bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; + inner_scalar_field bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - barretenberg::fq12 result = - barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P_affine, lines, 2); + inner_ground_field_ct big_a(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); + inner_ground_field_ct big_b(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); - return (result == barretenberg::fq12::one()); - } - return true; - } - static void create_inner_circuit(InnerComposer& composer, const std::vector& public_inputs) + big_a* big_b; + }; + static void create_alternate_inner_circuit(InnerBuilder& builder, + const std::vector& public_inputs) { - fr_ct a(public_witness_ct(&composer, public_inputs[0])); - fr_ct b(public_witness_ct(&composer, public_inputs[1])); - fr_ct c(public_witness_ct(&composer, public_inputs[2])); + inner_scalar_field_ct a(public_witness_ct(&builder, public_inputs[0])); + inner_scalar_field_ct b(public_witness_ct(&builder, public_inputs[1])); + inner_scalar_field_ct c(public_witness_ct(&builder, public_inputs[2])); for (size_t i = 0; i < 32; ++i) { a = (a * b) + b + a; - a = a.madd(b, c); + a = c.madd(b, a); } - plonk::stdlib::pedersen_commitment::compress(a, b); - typename inner_curve::byte_array_ct to_hash(&composer, "nonsense test data"); - stdlib::blake3s(to_hash); - - barretenberg::fr bigfield_data = fr::random_element(); - barretenberg::fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; - barretenberg::fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - - typename inner_curve::fq_ct big_a(fr_ct(witness_ct(&composer, bigfield_data_a.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - typename inner_curve::fq_ct big_b(fr_ct(witness_ct(&composer, bigfield_data_b.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - big_a* big_b; - }; + pedersen_commitment::compress(a, a); + byte_array_ct to_hash(&builder, "different nonsense test data"); + blake3s(to_hash); + + inner_scalar_field bigfield_data = fr::random_element(); + inner_scalar_field bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; + inner_scalar_field bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; + + inner_ground_field_ct big_a(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_a.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); + inner_ground_field_ct big_b(inner_scalar_field_ct(witness_ct(&builder, bigfield_data_b.to_montgomery_form())), + inner_scalar_field_ct(witness_ct(&builder, 0))); + ((big_a * big_b) + big_a) * big_b; + } - static circuit_outputs create_outer_circuit(InnerComposer& inner_composer, OuterComposer& outer_composer) + static circuit_outputs create_outer_circuit(InnerBuilder& inner_circuit, OuterBuilder& outer_builder) { - auto prover = inner_composer.create_prover(); - const auto verification_key_raw = inner_composer.compute_verification_key(); + info("Creating turbo (inner) prover..."); + ProverOfInnerCircuit prover; + InnerComposer inner_composer; + prover = inner_composer.create_prover(inner_circuit); + + info("Computing verification key..."); + const auto verification_key_native = inner_composer.compute_verification_key(inner_circuit); + // Convert the verification key's elements into _circuit_ types, using the OUTER composer. std::shared_ptr verification_key = - verification_key_pt::from_witness(&outer_composer, verification_key_raw); - plonk::proof recursive_proof = prover.construct_proof(); + verification_key_pt::from_witness(&outer_builder, verification_key_native); + + info("Constructing the turbo (inner) proof ..."); + plonk::proof proof_to_recursively_verify = prover.construct_proof(); + + { + // Native check is mainly for comparison vs circuit version of the verifier. + info("Creating a native turbo (inner) verifier..."); + VerifierOfInnerProof native_verifier; + native_verifier = inner_composer.create_verifier(inner_circuit); + + info("Verifying the turbo (inner) proof natively..."); + auto native_result = native_verifier.verify_proof(proof_to_recursively_verify); + + info("Native result: ", native_result); + } + transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, recursive_proof); + + auto output = recursion::verify_proof( + &outer_builder, verification_key, recursive_manifest, proof_to_recursively_verify); + return { output, verification_key }; }; - static circuit_outputs create_double_outer_circuit(InnerComposer& inner_composer_a, - InnerComposer& inner_composer_b, - OuterComposer& outer_composer) + static circuit_outputs create_double_outer_circuit(InnerBuilder& inner_circuit_a, + InnerBuilder& inner_circuit_b, + OuterBuilder& outer_circuit) { + ProverOfInnerCircuit prover; + InnerComposer inner_composer_a; + prover = inner_composer_a.create_prover(inner_circuit_a); - auto prover = inner_composer_a.create_prover(); - - const auto verification_key_raw = inner_composer_a.compute_verification_key(); + const auto verification_key_native = inner_composer_a.compute_verification_key(inner_circuit_a); std::shared_ptr verification_key = - verification_key_pt::from_witness(&outer_composer, verification_key_raw); - plonk::proof recursive_proof_a = prover.construct_proof(); + verification_key_pt::from_witness(&outer_circuit, verification_key_native); + + plonk::proof proof_to_recursively_verify_a = prover.construct_proof(); transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover.key->num_public_inputs); - stdlib::recursion::aggregation_state previous_output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, recursive_proof_a); + auto previous_output = recursion::verify_proof( + &outer_circuit, verification_key, recursive_manifest, proof_to_recursively_verify_a); - auto prover_b = inner_composer_b.create_prover(); + InnerComposer inner_composer_b; + prover = inner_composer_b.create_prover(inner_circuit_b); - const auto verification_key_b_raw = inner_composer_b.compute_verification_key(); + const auto verification_key_b_raw = inner_composer_b.compute_verification_key(inner_circuit_b); std::shared_ptr verification_key_b = - verification_key_pt::from_witness(&outer_composer, verification_key_b_raw); - plonk::proof recursive_proof_b = prover_b.construct_proof(); + verification_key_pt::from_witness(&outer_circuit, verification_key_b_raw); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key_b, recursive_manifest, recursive_proof_b, previous_output); + plonk::proof proof_to_recursively_verify_b = prover.construct_proof(); - return { output, verification_key }; - } - - static void create_alternate_inner_circuit(InnerComposer& composer, - const std::vector& public_inputs) - { - fr_ct a(public_witness_ct(&composer, public_inputs[0])); - fr_ct b(public_witness_ct(&composer, public_inputs[1])); - fr_ct c(public_witness_ct(&composer, public_inputs[2])); + auto output = proof_system::plonk::stdlib::recursion::verify_proof( + &outer_circuit, verification_key_b, recursive_manifest, proof_to_recursively_verify_b, previous_output); - for (size_t i = 0; i < 32; ++i) { - a = (a * b) + b + a; - a = c.madd(b, a); - } - plonk::stdlib::pedersen_commitment::compress(a, a); - inner_curve::byte_array_ct to_hash(&composer, "different nonsense test data"); - stdlib::blake3s(to_hash); - - barretenberg::fr bigfield_data = fr::random_element(); - barretenberg::fr bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 }; - barretenberg::fr bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 }; - - inner_curve::bn254::fq_ct big_a(fr_ct(witness_ct(&composer, bigfield_data_a.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - inner_curve::bn254::fq_ct big_b(fr_ct(witness_ct(&composer, bigfield_data_b.to_montgomery_form())), - fr_ct(witness_ct(&composer, 0))); - ((big_a * big_b) + big_a) * big_b; + verification_key_b->compress(); + verification_key->compress(); + return { output, verification_key }; } // creates a cicuit that verifies either a proof from composer a, or from composer b - static circuit_outputs create_outer_circuit_with_variable_inner_circuit(InnerComposer& inner_composer_a, - InnerComposer& inner_composer_b, - OuterComposer& outer_composer, + static circuit_outputs create_outer_circuit_with_variable_inner_circuit(InnerBuilder& inner_circuit_a, + InnerBuilder& inner_circuit_b, + OuterBuilder& outer_circuit, const bool proof_type, const bool create_failing_proof = false, const bool use_constant_key = false) { - auto prover_a = inner_composer_a.create_prover(); - auto prover_b = inner_composer_b.create_prover(); - const auto verification_key_raw_a = inner_composer_a.compute_verification_key(); - const auto verification_key_raw_b = inner_composer_b.compute_verification_key(); + ProverOfInnerCircuit prover_a; + ProverOfInnerCircuit prover_b; + InnerComposer inner_composer_a; + InnerComposer inner_composer_b; + prover_a = inner_composer_a.create_prover(inner_circuit_a); + prover_b = inner_composer_b.create_prover(inner_circuit_b); + + const auto verification_key_raw_a = inner_composer_a.compute_verification_key(inner_circuit_a); + const auto verification_key_raw_b = inner_composer_b.compute_verification_key(inner_circuit_b); std::shared_ptr verification_key; if (use_constant_key) { - verification_key = proof_type - ? verification_key_pt::from_constants(&outer_composer, verification_key_raw_a) - : verification_key_pt::from_constants(&outer_composer, verification_key_raw_b); + verification_key = proof_type ? verification_key_pt::from_constants(&outer_circuit, verification_key_raw_a) + : verification_key_pt::from_constants(&outer_circuit, verification_key_raw_b); } else { - verification_key = proof_type ? verification_key_pt::from_witness(&outer_composer, verification_key_raw_a) - : verification_key_pt::from_witness(&outer_composer, verification_key_raw_b); + verification_key = proof_type ? verification_key_pt::from_witness(&outer_circuit, verification_key_raw_a) + : verification_key_pt::from_witness(&outer_circuit, verification_key_raw_b); } + if (!use_constant_key) { if (create_failing_proof) { verification_key->validate_key_is_in_set({ verification_key_raw_b, verification_key_raw_b }); @@ -209,300 +204,301 @@ template class stdlib_verifier_turbo : public testing:: verification_key->validate_key_is_in_set({ verification_key_raw_a, verification_key_raw_b }); } } + plonk::proof recursive_proof = proof_type ? prover_a.construct_proof() : prover_b.construct_proof(); + transcript::Manifest recursive_manifest = InnerComposer::create_manifest(prover_a.key->num_public_inputs); - stdlib::recursion::aggregation_state output = - stdlib::recursion::verify_proof( - &outer_composer, verification_key, recursive_manifest, recursive_proof); + + proof_system::plonk::stdlib::recursion::aggregation_state output = + proof_system::plonk::stdlib::recursion::verify_proof( + &outer_circuit, verification_key, recursive_manifest, recursive_proof); + return { output, verification_key }; } - public: - static void test_recursive_proof_composition() + // /** + // * @brief Check the correctness of the recursive proof public inputs + // * + // * @details Circuit constructors have no notion of SRS and any proof-related stuff except for the existence of + // * recursive proof-specific public inputs, so we can't check the recursive proof fully in check_circuit. So we + // * use this additional function to check that the recursive proof points work. + // * + // * @return boolean result + // */ + + static bool check_recursive_proof_public_inputs(OuterBuilder& builder, + const barretenberg::pairing::miller_lines* lines) { - InnerComposer inner_composer = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + if (builder.contains_recursive_proof && builder.recursive_proof_public_input_indices.size() == 16) { + const auto& inputs = builder.public_inputs; + const auto recover_fq_from_public_inputs = + [&inputs, &builder](const size_t idx0, const size_t idx1, const size_t idx2, const size_t idx3) { + const uint256_t l0 = builder.get_variable(inputs[idx0]); + const uint256_t l1 = builder.get_variable(inputs[idx1]); + const uint256_t l2 = builder.get_variable(inputs[idx2]); + const uint256_t l3 = builder.get_variable(inputs[idx3]); + + const uint256_t limb = l0 + (l1 << NUM_LIMB_BITS_IN_FIELD_SIMULATION) + + (l2 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 2)) + + (l3 << (NUM_LIMB_BITS_IN_FIELD_SIMULATION * 3)); + return outer_scalar_field(limb); + }; - create_inner_circuit(inner_composer, inner_inputs); + const auto x0 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[0], + builder.recursive_proof_public_input_indices[1], + builder.recursive_proof_public_input_indices[2], + builder.recursive_proof_public_input_indices[3]); + const auto y0 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[4], + builder.recursive_proof_public_input_indices[5], + builder.recursive_proof_public_input_indices[6], + builder.recursive_proof_public_input_indices[7]); + const auto x1 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[8], + builder.recursive_proof_public_input_indices[9], + builder.recursive_proof_public_input_indices[10], + builder.recursive_proof_public_input_indices[11]); + const auto y1 = recover_fq_from_public_inputs(builder.recursive_proof_public_input_indices[12], + builder.recursive_proof_public_input_indices[13], + builder.recursive_proof_public_input_indices[14], + builder.recursive_proof_public_input_indices[15]); + g1::affine_element P_affine[2]{ + { x0, y0 }, + { x1, y1 }, + }; - auto circuit_output = create_outer_circuit(inner_composer, outer_composer); + pairing_target_field result = + barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P_affine, lines, 2); + return (result == pairing_target_field::one()); + } + return true; + } + + static void check_pairing(const circuit_outputs& circuit_output) + { + auto g2_lines = barretenberg::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + P[0].x = outer_scalar_field(circuit_output.aggregation_state.P0.x.get_value().lo); + P[0].y = outer_scalar_field(circuit_output.aggregation_state.P0.y.get_value().lo); + P[1].x = outer_scalar_field(circuit_output.aggregation_state.P1.x.get_value().lo); + P[1].y = outer_scalar_field(circuit_output.aggregation_state.P1.y.get_value().lo); + pairing_target_field inner_proof_result = + barretenberg::pairing::reduced_ate_pairing_batch_precomputed(P, g2_lines, 2); + EXPECT_EQ(inner_proof_result, pairing_target_field::one()); + } - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs[0]); - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs[1]); + static void check_recursive_verification_circuit(OuterBuilder& outer_circuit, bool expected_result) + { + info("number of gates in recursive verification circuit = ", outer_circuit.get_num_gates()); + bool result = outer_circuit.check_circuit(); + EXPECT_EQ(result, expected_result); + auto g2_lines = barretenberg::srs::get_crs_factory()->get_verifier_crs()->get_precomputed_g2_lines(); + EXPECT_EQ(check_recursive_proof_public_inputs(outer_circuit, g2_lines), true); + } - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); + public: + static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); } - circuit_output.aggregation_state.assign_object_to_proof_outputs(); + static void test_inner_circuit() + { + InnerBuilder builder; + std::vector inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - EXPECT_EQ(outer_composer.failed(), false); + create_inner_circuit(builder, inputs); - bool result = outer_composer.check_circuit(); + bool result = builder.check_circuit(); EXPECT_EQ(result, true); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + } + + static void test_recursive_proof_composition() + { + InnerBuilder inner_circuit; + OuterBuilder outer_circuit; + + std::vector inner_public_inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; + + create_inner_circuit(inner_circuit, inner_public_inputs); + + auto circuit_output = create_outer_circuit(inner_circuit, outer_circuit); + EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_public_inputs[0]); + EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_public_inputs[1]); + + circuit_output.aggregation_state.assign_object_to_proof_outputs(); + EXPECT_EQ(outer_circuit.failed(), false); + + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } static void test_double_verification() { - if constexpr (!(std::is_same::value || - std::is_same::value)) - return; // We only care about running this test for turbo and ultra outer circuits, since in practice the - // only circuits which verify >1 proof are ultra or turbo circuits. Standard uses so many gates - // (16m) that it's a waste of time testing it. + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); + OuterBuilder mid_circuit_a; + OuterBuilder mid_circuit_b; - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); + OuterBuilder outer_circuit; - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + std::vector inner_inputs{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - create_inner_circuit(inner_composer_a, inner_inputs); - create_inner_circuit(inner_composer_b, inner_inputs); + create_inner_circuit(inner_circuit_a, inner_inputs); + create_inner_circuit(inner_circuit_b, inner_inputs); - auto circuit_output = create_double_outer_circuit(inner_composer_a, inner_composer_b, outer_composer); + auto circuit_output_a = create_outer_circuit(inner_circuit_a, mid_circuit_a); - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + uint256_t a0 = circuit_output_a.aggregation_state.P0.x.binary_basis_limbs[1].element.get_value(); + uint256_t a1 = circuit_output_a.aggregation_state.P0.y.binary_basis_limbs[1].element.get_value(); + uint256_t a2 = circuit_output_a.aggregation_state.P1.x.binary_basis_limbs[1].element.get_value(); + uint256_t a3 = circuit_output_a.aggregation_state.P1.y.binary_basis_limbs[1].element.get_value(); - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs[0]); - EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs[1]); + ASSERT(a0.get_msb() <= 68); + ASSERT(a1.get_msb() <= 68); + ASSERT(a2.get_msb() <= 68); + ASSERT(a3.get_msb() <= 68); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); + circuit_output_a.aggregation_state.assign_object_to_proof_outputs(); - printf("composer gates = %zu\n", outer_composer.get_num_gates()); + auto circuit_output_b = create_outer_circuit(inner_circuit_b, mid_circuit_b); - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + circuit_output_b.aggregation_state.assign_object_to_proof_outputs(); + + auto circuit_output = create_double_outer_circuit(mid_circuit_a, mid_circuit_b, outer_circuit); + circuit_output.aggregation_state.assign_object_to_proof_outputs(); + EXPECT_EQ(circuit_output_a.aggregation_state.public_inputs[0].get_value(), inner_inputs[0]); + EXPECT_EQ(circuit_output_a.aggregation_state.public_inputs[1].get_value(), inner_inputs[1]); + + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } - // verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the two - // variable circuits + // verifies a proof of a circuit that verifies one of two proofs. Test 'a' uses a proof over the first of the + // two variable circuits static void test_recursive_proof_composition_with_variable_verification_key_a() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = - create_outer_circuit_with_variable_inner_circuit(inner_composer_a, inner_composer_b, outer_composer, true); - - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = + create_outer_circuit_with_variable_inner_circuit(inner_circuit_a, inner_circuit_b, outer_circuit, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } - // verifies a proof of a circuit that verifies one of two proofs. Test 'b' uses a proof over the second of the two - // variable circuits + // verifies a proof of a circuit that verifies one of two proofs. Test 'b' uses a proof over the second of the + // two variable circuits static void test_recursive_proof_composition_with_variable_verification_key_b() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); - auto circuit_output = - create_outer_circuit_with_variable_inner_circuit(inner_composer_a, inner_composer_b, outer_composer, false); - g1::affine_element P[2]; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + + auto circuit_output = + create_outer_circuit_with_variable_inner_circuit(inner_circuit_a, inner_circuit_b, outer_circuit, false); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_b[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_b[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_b[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } static void test_recursive_proof_composition_with_variable_verification_key_failure_case() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = create_outer_circuit_with_variable_inner_circuit( - inner_composer_a, inner_composer_b, outer_composer, true, true); - - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = create_outer_circuit_with_variable_inner_circuit( + inner_circuit_a, inner_circuit_b, outer_circuit, true, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, false); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, false); } static void test_recursive_proof_composition_with_constant_verification_key() { - InnerComposer inner_composer_a = InnerComposer("../srs_db/ignition"); - InnerComposer inner_composer_b = InnerComposer("../srs_db/ignition"); - OuterComposer outer_composer = OuterComposer("../srs_db/ignition"); - std::vector inner_inputs_a{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - std::vector inner_inputs_b{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; + InnerBuilder inner_circuit_a; + InnerBuilder inner_circuit_b; + OuterBuilder outer_circuit; - create_inner_circuit(inner_composer_a, inner_inputs_a); - create_alternate_inner_circuit(inner_composer_b, inner_inputs_b); + std::vector inner_inputs_a{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - auto circuit_output = create_outer_circuit_with_variable_inner_circuit( - inner_composer_a, inner_composer_b, outer_composer, true, false, true); + std::vector inner_inputs_b{ inner_scalar_field::random_element(), + inner_scalar_field::random_element(), + inner_scalar_field::random_element() }; - g1::affine_element P[2]; - P[0].x = barretenberg::fq(circuit_output.aggregation_state.P0.x.get_value().lo); - P[0].y = barretenberg::fq(circuit_output.aggregation_state.P0.y.get_value().lo); - P[1].x = barretenberg::fq(circuit_output.aggregation_state.P1.x.get_value().lo); - P[1].y = barretenberg::fq(circuit_output.aggregation_state.P1.y.get_value().lo); - barretenberg::fq12 inner_proof_result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - P, circuit_output.verification_key->reference_string->get_precomputed_g2_lines(), 2); + create_inner_circuit(inner_circuit_a, inner_inputs_a); + create_alternate_inner_circuit(inner_circuit_b, inner_inputs_b); + auto circuit_output = create_outer_circuit_with_variable_inner_circuit( + inner_circuit_a, inner_circuit_b, outer_circuit, true, false, true); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[0].get_value(), inner_inputs_a[0]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[1].get_value(), inner_inputs_a[1]); EXPECT_EQ(circuit_output.aggregation_state.public_inputs[2].get_value(), inner_inputs_a[2]); - EXPECT_EQ(inner_proof_result, barretenberg::fq12::one()); - - printf("composer gates = %zu\n", outer_composer.get_num_gates()); - - bool result = outer_composer.check_circuit(); - EXPECT_EQ(result, true); - EXPECT_EQ(check_recursive_proof_public_inputs( - outer_composer, - outer_composer.composer_helper.crs_factory_->get_verifier_crs()->get_precomputed_g2_lines()), - true); - } - - static void test_inner_circuit() - { - if constexpr (!std::is_same::value) - return; // We only want to run this test once (since it's not actually dependent on the typed test - // parameter; which is the outer composer). We've only made it a typed test so that it can be - // included in this test suite. So to avoid running this test identically 3 times, we escape all but - // 1 permutation. - - InnerComposer inner_composer = InnerComposer("../srs_db/ignition"); - std::vector inner_inputs{ barretenberg::fr::random_element(), - barretenberg::fr::random_element(), - barretenberg::fr::random_element() }; - - create_inner_circuit(inner_composer, inner_inputs); - - auto prover = inner_composer.create_prover(); - auto verifier = inner_composer.create_verifier(); - auto proof = prover.construct_proof(); - auto verified = verifier.verify_proof(proof); - EXPECT_EQ(verified, true); + check_pairing(circuit_output); + check_recursive_verification_circuit(outer_circuit, true); } }; -typedef testing::Types OuterComposerTypes; +typedef testing::Types OuterComposerTypes; TYPED_TEST_SUITE(stdlib_verifier_turbo, OuterComposerTypes); +HEAVY_TYPED_TEST(stdlib_verifier_turbo, test_inner_circuit) +{ + TestFixture::test_inner_circuit(); +} + HEAVY_TYPED_TEST(stdlib_verifier_turbo, recursive_proof_composition) { TestFixture::test_recursive_proof_composition(); @@ -510,7 +506,12 @@ HEAVY_TYPED_TEST(stdlib_verifier_turbo, recursive_proof_composition) HEAVY_TYPED_TEST(stdlib_verifier_turbo, double_verification) { - TestFixture::test_double_verification(); + if constexpr (std::same_as) { + TestFixture::test_double_verification(); + } else { + // Test doesn't compile. + GTEST_SKIP(); + } }; HEAVY_TYPED_TEST(stdlib_verifier_turbo, recursive_proof_composition_with_variable_verification_key_a) @@ -533,7 +534,4 @@ HEAVY_TYPED_TEST(stdlib_verifier_turbo, recursive_proof_composition_const_verif_ TestFixture::test_recursive_proof_composition_with_constant_verification_key(); } -HEAVY_TYPED_TEST(stdlib_verifier_turbo, test_inner_circuit) -{ - TestFixture::test_inner_circuit(); -} +} // namespace proof_system::plonk::stdlib \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/types/turbo.hpp b/barretenberg/cpp/src/barretenberg/stdlib/types/turbo.hpp index 8f9af0ee654a..de5124f1a988 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/types/turbo.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/types/turbo.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/plonk/composer/turbo_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/turbo_plonk_composer_helper.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/plonk/proof_system/types/prover_settings.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" @@ -22,45 +22,47 @@ namespace proof_system::plonk::stdlib::types { using namespace proof_system::plonk; -typedef plonk::TurboComposer Composer; +using Builder = proof_system::TurboCircuitConstructor; -typedef plonk::TurboProver Prover; +using Composer = plonk::TurboPlonkComposerHelper; -typedef plonk::TurboVerifier Verifier; +using Prover = plonk::TurboProver; + +using Verifier = plonk::TurboVerifier; using settings = plonk::turbo_settings; using kate_commitment_scheme = plonk::KateCommitmentScheme; -typedef stdlib::witness_t witness_ct; -typedef stdlib::public_witness_t public_witness_ct; -typedef stdlib::bool_t bool_ct; -typedef stdlib::byte_array byte_array_ct; -typedef stdlib::packed_byte_array packed_byte_array_ct; -typedef stdlib::field_t field_ct; -typedef stdlib::safe_uint_t suint_ct; -typedef stdlib::uint8 uint8_ct; -typedef stdlib::uint16 uint16_ct; -typedef stdlib::uint32 uint32_ct; -typedef stdlib::uint64 uint64_ct; -typedef stdlib::bit_array bit_array_ct; -typedef stdlib::bigfield fq_ct; -typedef stdlib::element biggroup_ct; -typedef stdlib::point point_ct; -typedef stdlib::pedersen_commitment pedersen_commitment; -typedef stdlib::group group_ct; -typedef stdlib::bn254 bn254; -typedef stdlib::secp256k1 secp256k1_ct; +using witness_ct = stdlib::witness_t; +using public_witness_ct = stdlib::public_witness_t; +using bool_ct = stdlib::bool_t; +using byte_array_ct = stdlib::byte_array; +using packed_byte_array_ct = stdlib::packed_byte_array; +using field_ct = stdlib::field_t; +using suint_ct = stdlib::safe_uint_t; +using uint8_ct = stdlib::uint8; +using uint16_ct = stdlib::uint16; +using uint32_ct = stdlib::uint32; +using uint64_ct = stdlib::uint64; +using bit_array_ct = stdlib::bit_array; +using fq_ct = stdlib::bigfield; +using biggroup_ct = stdlib::element; +using point_ct = stdlib::point; +using pedersen_commitment = stdlib::pedersen_commitment; +using group_ct = stdlib::group; +using bn254 = stdlib::bn254; +using secp256k1_ct = stdlib::secp256k1; namespace merkle_tree { using namespace stdlib::merkle_tree; -typedef stdlib::merkle_tree::hash_path hash_path; +using hash_path = stdlib::merkle_tree::hash_path; } // namespace merkle_tree namespace schnorr { -typedef stdlib::schnorr::signature_bits signature_bits; +using signature_bits = stdlib::schnorr::signature_bits; } // namespace schnorr -typedef recursion::recursive_turbo_verifier_settings recursive_inner_verifier_settings; +using recursive_inner_verifier_settings = recursion::recursive_turbo_verifier_settings; } // namespace proof_system::plonk::stdlib::types diff --git a/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp b/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp index 848050278f7a..611581ec908e 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/types/ultra.hpp @@ -1,5 +1,5 @@ #pragma once -#include "barretenberg/plonk/composer/ultra_plonk_composer.hpp" +#include "barretenberg/plonk/composer/composer_helper/ultra_plonk_composer_helper.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/plonk/proof_system/types/prover_settings.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" @@ -23,48 +23,48 @@ namespace proof_system::plonk::stdlib::types { using namespace proof_system::plonk; -typedef plonk::UltraPlonkComposer Composer; +using Builder = proof_system::UltraCircuitConstructor; +using Composer = plonk::UltraPlonkComposerHelper; -typedef plonk::UltraProver Prover; - -typedef plonk::UltraVerifier Verifier; +// TODO(Cody): These might be wrong depending on desired F-S hash. +using Prover = plonk::UltraProver; +using Verifier = plonk::UltraVerifier; using settings = plonk::ultra_settings; using kate_commitment_scheme = plonk::KateCommitmentScheme; - -typedef stdlib::witness_t witness_ct; -typedef stdlib::public_witness_t public_witness_ct; -typedef stdlib::bool_t bool_ct; -typedef stdlib::byte_array byte_array_ct; -typedef stdlib::packed_byte_array packed_byte_array_ct; -typedef stdlib::field_t field_ct; -typedef stdlib::safe_uint_t suint_ct; -typedef stdlib::uint8 uint8_ct; -typedef stdlib::uint16 uint16_ct; -typedef stdlib::uint32 uint32_ct; -typedef stdlib::uint64 uint64_ct; -typedef stdlib::bit_array bit_array_ct; -typedef stdlib::bigfield fq_ct; -typedef stdlib::element biggroup_ct; -typedef stdlib::point point_ct; -typedef stdlib::pedersen_commitment pedersen_commitment; -typedef stdlib::group group_ct; -typedef stdlib::bn254 bn254; -typedef stdlib::secp256k1 secp256k1_ct; +using witness_ct = stdlib::witness_t; +using public_witness_ct = stdlib::public_witness_t; +using bool_ct = stdlib::bool_t; +using byte_array_ct = stdlib::byte_array; +using packed_byte_array_ct = stdlib::packed_byte_array; +using field_ct = stdlib::field_t; +using suint_ct = stdlib::safe_uint_t; +using uint8_ct = stdlib::uint8; +using uint16_ct = stdlib::uint16; +using uint32_ct = stdlib::uint32; +using uint64_ct = stdlib::uint64; +using bit_array_ct = stdlib::bit_array; +using fq_ct = stdlib::bigfield; +using biggroup_ct = stdlib::element; +using point_ct = stdlib::point; +using pedersen_commitment = stdlib::pedersen_commitment; +using group_ct = stdlib::group; +using bn254 = stdlib::bn254; +using secp256k1_ct = stdlib::secp256k1; namespace merkle_tree { using namespace stdlib::merkle_tree; -typedef stdlib::merkle_tree::hash_path hash_path; +using hash_path = stdlib::merkle_tree::hash_path; } // namespace merkle_tree namespace schnorr { -typedef stdlib::schnorr::signature_bits signature_bits; +using signature_bits = stdlib::schnorr::signature_bits; } // namespace schnorr // Ultra-composer specific types -typedef stdlib::rom_table rom_table_ct; +using rom_table_ct = stdlib::rom_table; -typedef recursion::recursive_ultra_verifier_settings recursive_inner_verifier_settings; +using recursive_inner_verifier_settings = recursion::recursive_ultra_verifier_settings; } // namespace proof_system::plonk::stdlib::types