diff --git a/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp b/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp index ff957c6b9b..586a82b03d 100644 --- a/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp +++ b/cpp/src/barretenberg/dsl/acir_format/acir_format.test.cpp @@ -105,10 +105,10 @@ TEST(acir_format, test_logic_gate_from_noir_circuit) std::cout << "made composer" << std::endl; - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); EXPECT_EQ(verifier.verify_proof(proof), true); } @@ -174,10 +174,10 @@ TEST(acir_format, test_schnorr_verify_pass) 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_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); EXPECT_EQ(verifier.verify_proof(proof), true); } @@ -243,10 +243,10 @@ TEST(acir_format, test_schnorr_verify_small_range) 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_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); EXPECT_EQ(verifier.verify_proof(proof), true); } \ No newline at end of file diff --git a/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp b/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp index 21585f6df4..bbcb24c42c 100644 --- a/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp +++ b/cpp/src/barretenberg/dsl/acir_proofs/acir_proofs.cpp @@ -117,7 +117,7 @@ size_t new_proof(void* pippenger, create_circuit_with_witness(composer, constraint_system, witness); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto heapProver = new stdlib::types::Prover(std::move(prover)); auto& proof_data = heapProver->construct_proof().proof_data; @@ -144,7 +144,7 @@ bool verify_proof( create_circuit(composer, constraint_system); plonk::proof pp = { std::vector(proof, proof + length) }; - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); verified = verifier.verify_proof(pp); #ifndef __wasm__ diff --git a/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp b/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp index e5371b8bd0..b7dfb6f48d 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/compute_circuit_data.hpp @@ -229,20 +229,20 @@ circuit_data get_circuit_data(std::string const& name, Timer timer; if (!mock) { - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; data.num_gates = composer.get_num_gates(); info(name, ": Circuit size: ", data.num_gates); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } else { - auto prover = mock_proof_composer.create_prover(); + auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); data.padding_proof = proof.proof_data; data.num_gates = mock_proof_composer.get_num_gates(); info(name, ": Mock circuit size: ", data.num_gates); - auto verifier = mock_proof_composer.create_verifier(); + auto verifier = mock_proof_composer.create_ultra_with_keccak_verifier(); info(name, ": Padding verified: ", verifier.verify_proof(proof)); } info(name, ": Padding proof computed in ", timer.toString(), "s"); diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp index 8dd542fdf6..b86ae164a1 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/create_proof.hpp @@ -20,7 +20,7 @@ inline std::vector create_proof(join_split_tx const& tx, info("Join-split circuit logic failed: ", composer.err()); } - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); return proof.proof_data; diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp index 44567b5b26..bacb9868c8 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.cpp @@ -79,12 +79,12 @@ stdlib::types::Prover new_join_split_prover(join_split_tx const& tx, bool mock) if (!mock) { info("composer gates: ", composer.get_num_gates()); - return composer.create_prover(); + return composer.create_ultra_with_keccak_prover(); } else { Composer mock_proof_composer(proving_key, nullptr); join_split_example::proofs::mock::mock_circuit(mock_proof_composer, composer.get_public_inputs()); info("mock composer gates: ", mock_proof_composer.get_num_gates()); - return mock_proof_composer.create_prover(); + return mock_proof_composer.create_ultra_with_keccak_prover(); } } diff --git a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp index 0249baff3d..fc3e4a1426 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/join_split/join_split.test.cpp @@ -98,14 +98,14 @@ TYPED_TEST(join_split, deposit) BenchmarkInfoCollator benchmark_collator; Timer timer; - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_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(); + auto verifier = composer.create_ultra_with_keccak_verifier(); bool verified = verifier.verify_proof(proof); ASSERT_TRUE(verified); diff --git a/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp index 16004e9787..2188725010 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/mock/mock_circuit.test.cpp @@ -20,14 +20,14 @@ TEST(mock_circuit_tests, test_simple_circuit) Composer composer = Composer("../srs_db/ignition"); mock_circuit(composer, public_inputs); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); plonk::proof proof = prover.construct_proof(); std::cout << "gates: " << composer.get_num_gates() << std::endl; std::cout << "proof size: " << proof.proof_data.size() << std::endl; std::cout << "public inputs size: " << composer.public_inputs.size() << std::endl; - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); bool result = verifier.verify_proof(proof); EXPECT_TRUE(result); diff --git a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp index e243b35fb8..f3410308bd 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp +++ b/cpp/src/barretenberg/join_split_example/proofs/notes/circuit/value/value_note.test.cpp @@ -30,11 +30,11 @@ TEST(value_note, commits) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); EXPECT_FALSE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -64,11 +64,11 @@ TEST(value_note, commits_with_0_value) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); EXPECT_FALSE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -96,11 +96,11 @@ TEST(value_note, commit_with_oversized_asset_id_fails) auto result = circuit_note.commitment; result.assert_equal(expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); EXPECT_TRUE(composer.failed()); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); diff --git a/cpp/src/barretenberg/join_split_example/proofs/verify.hpp b/cpp/src/barretenberg/join_split_example/proofs/verify.hpp index e87a3e0bee..9daf7e4795 100644 --- a/cpp/src/barretenberg/join_split_example/proofs/verify.hpp +++ b/cpp/src/barretenberg/join_split_example/proofs/verify.hpp @@ -90,12 +90,12 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } else { - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } } else { - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } @@ -108,12 +108,12 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } else { - auto prover = mock_proof_composer.create_prover(); + auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } } else { - auto prover = mock_proof_composer.create_prover(); + auto prover = mock_proof_composer.create_ultra_with_keccak_prover(); auto proof = prover.construct_proof(); result.proof_data = proof.proof_data; } @@ -126,11 +126,11 @@ auto verify_internal(Composer& composer, Tx& tx, CircuitData const& cd, char con auto verifier = composer.create_ultra_to_standard_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } else { - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } } else { - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); result.verified = verifier.verify_proof({ result.proof_data }); } diff --git a/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp b/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp index 597b2ddea0..8782f6ab61 100644 --- a/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp +++ b/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp @@ -890,6 +890,50 @@ UltraToStandardProver UltraComposer::create_ultra_to_standard_prover() return output_state; } +/** + * @brief Uses slightly different settings from the UltraProver. + */ +UltraWithKeccakProver UltraComposer::create_ultra_with_keccak_prover() +{ + compute_proving_key(); + compute_witness(); + + UltraWithKeccakProver output_state(circuit_proving_key, create_manifest(public_inputs.size())); + + std::unique_ptr> permutation_widget = + std::make_unique>(circuit_proving_key.get()); + + std::unique_ptr> plookup_widget = + std::make_unique>(circuit_proving_key.get()); + + std::unique_ptr> arithmetic_widget = + std::make_unique>(circuit_proving_key.get()); + + std::unique_ptr> sort_widget = + std::make_unique>(circuit_proving_key.get()); + + std::unique_ptr> elliptic_widget = + std::make_unique>(circuit_proving_key.get()); + + std::unique_ptr> auxiliary_widget = + std::make_unique>(circuit_proving_key.get()); + + output_state.random_widgets.emplace_back(std::move(permutation_widget)); + output_state.random_widgets.emplace_back(std::move(plookup_widget)); + + output_state.transition_widgets.emplace_back(std::move(arithmetic_widget)); + output_state.transition_widgets.emplace_back(std::move(sort_widget)); + output_state.transition_widgets.emplace_back(std::move(elliptic_widget)); + output_state.transition_widgets.emplace_back(std::move(auxiliary_widget)); + + std::unique_ptr> kate_commitment_scheme = + std::make_unique>(); + + output_state.commitment_scheme = std::move(kate_commitment_scheme); + + return output_state; +} + UltraVerifier UltraComposer::create_verifier() { compute_verification_key(); @@ -918,6 +962,20 @@ UltraToStandardVerifier UltraComposer::create_ultra_to_standard_verifier() return output_state; } +UltraWithKeccakVerifier UltraComposer::create_ultra_with_keccak_verifier() +{ + compute_verification_key(); + + UltraWithKeccakVerifier output_state(circuit_verification_key, create_manifest(public_inputs.size())); + + std::unique_ptr> kate_commitment_scheme = + std::make_unique>(); + + output_state.commitment_scheme = std::move(kate_commitment_scheme); + + return output_state; +} + void UltraComposer::initialize_precomputed_table( const plookup::BasicTableId id, bool (*generator)(std::vector&, std ::vector&, std::vector&), diff --git a/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp b/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp index 6cdc969423..b3157639fd 100644 --- a/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp +++ b/cpp/src/barretenberg/plonk/composer/ultra_composer.hpp @@ -160,6 +160,9 @@ class UltraComposer : public ComposerBase { UltraToStandardProver create_ultra_to_standard_prover(); UltraToStandardVerifier create_ultra_to_standard_verifier(); + UltraWithKeccakProver create_ultra_with_keccak_prover(); + UltraWithKeccakVerifier create_ultra_with_keccak_verifier(); + void create_add_gate(const add_triple& in) override; void create_big_add_gate(const add_quad& in, const bool use_next_gate_w_4 = false); diff --git a/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp b/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp index 8219f9183c..eef80fa56c 100644 --- a/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp +++ b/cpp/src/barretenberg/plonk/composer/ultra_composer.test.cpp @@ -10,7 +10,7 @@ using namespace barretenberg; using namespace proof_system; -namespace proof_system::plonk { +namespace proof_system::plonk::test_ultra_composer { namespace { auto& engine = numeric::random::get_debug_engine(); @@ -27,7 +27,39 @@ std::vector add_variables(UltraComposer& composer, std::vector var } return res; } -TEST(ultra_composer, create_gates_from_plookup_accumulators) + +template class ultra_composer : public ::testing::Test { + public: + void prove_and_verify(UltraComposer& composer, bool expected_result) + { + if constexpr (T::use_keccak) { + auto prover = composer.create_ultra_with_keccak_prover(); + auto verifier = composer.create_ultra_with_keccak_verifier(); + auto proof = prover.construct_proof(); + bool verified = verifier.verify_proof(proof); + EXPECT_EQ(verified, expected_result); + } else { + auto prover = composer.create_prover(); + auto verifier = composer.create_verifier(); + auto proof = prover.construct_proof(); + bool verified = verifier.verify_proof(proof); + EXPECT_EQ(verified, expected_result); + } + }; +}; + +struct UseKeccak32Bytes { + static constexpr bool use_keccak = true; +}; + +struct UsePlookupPedersen16Bytes { + static constexpr bool use_keccak = false; +}; + +using BooleanTypes = ::testing::Types; +TYPED_TEST_SUITE(ultra_composer, BooleanTypes); + +TYPED_TEST(ultra_composer, create_gates_from_plookup_accumulators) { UltraComposer composer = UltraComposer(); @@ -106,16 +138,10 @@ TEST(ultra_composer, create_gates_from_plookup_accumulators) EXPECT_EQ(composer.get_variable(lookup_witnesses_hi[ColumnIdx::C3][i]), expected_y[i + num_lookups_lo]); } - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - auto proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, test_no_lookup_proof) +TYPED_TEST(ultra_composer, test_no_lookup_proof) { UltraComposer composer = UltraComposer(); @@ -133,17 +159,10 @@ TEST(ultra_composer, test_no_lookup_proof) } } - auto prover = composer.create_prover(); - - auto verifier = composer.create_verifier(); - - auto proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, test_elliptic_gate) +TYPED_TEST(ultra_composer, test_elliptic_gate) { typedef grumpkin::g1::affine_element affine_element; typedef grumpkin::g1::element element; @@ -180,17 +199,10 @@ TEST(ultra_composer, test_elliptic_gate) gate = ecc_add_gate{ x1, y1, x2, y2, x3, y3, beta.sqr(), -1 }; composer.create_ecc_add_gate(gate); - auto prover = composer.create_prover(); - - auto verifier = composer.create_verifier(); - - auto proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, non_trivial_tag_permutation) +TYPED_TEST(ultra_composer, non_trivial_tag_permutation) { UltraComposer composer = UltraComposer(); fr a = fr::random_element(); @@ -215,15 +227,11 @@ TEST(ultra_composer, non_trivial_tag_permutation) // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, non_trivial_tag_permutation_and_cycles) + +TYPED_TEST(ultra_composer, non_trivial_tag_permutation_and_cycles) { UltraComposer composer = UltraComposer(); fr a = fr::random_element(); @@ -257,17 +265,11 @@ TEST(ultra_composer, non_trivial_tag_permutation_and_cycles) // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); // composer.create_add_gate({ a_idx, b_idx, composer.zero_idx, fr::one(), fr::neg_one(), fr::zero(), fr::zero() }); - auto prover = composer.create_prover(); - - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, bad_tag_permutation) +TYPED_TEST(ultra_composer, bad_tag_permutation) { UltraComposer composer = UltraComposer(); fr a = fr::random_element(); @@ -288,16 +290,12 @@ TEST(ultra_composer, bad_tag_permutation) composer.assign_tag(b_idx, 1); composer.assign_tag(c_idx, 2); composer.assign_tag(d_idx, 2); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } // same as above but with turbocomposer to check reason of failue is really tag mismatch -TEST(ultra_composer, bad_tag_turbo_permutation) +TYPED_TEST(ultra_composer, bad_tag_turbo_permutation) { UltraComposer composer = UltraComposer(); fr a = fr::random_element(); @@ -317,13 +315,10 @@ TEST(ultra_composer, bad_tag_turbo_permutation) auto prover = composer.create_prover(); auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, sort_widget) +TYPED_TEST(ultra_composer, sort_widget) { UltraComposer composer = UltraComposer(); fr a = fr::one(); @@ -336,16 +331,11 @@ TEST(ultra_composer, sort_widget) auto c_idx = composer.add_variable(c); auto d_idx = composer.add_variable(d); composer.create_sort_constraint({ a_idx, b_idx, c_idx, d_idx }); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, sort_with_edges_gate) +TYPED_TEST(ultra_composer, sort_with_edges_gate) { fr a = fr::one(); @@ -368,13 +358,8 @@ TEST(ultra_composer, sort_with_edges_gate) auto g_idx = composer.add_variable(g); auto h_idx = composer.add_variable(h); composer.create_sort_constraint_with_edges({ a_idx, b_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, a, h); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } { @@ -407,13 +392,8 @@ TEST(ultra_composer, sort_with_edges_gate) auto g_idx = composer.add_variable(g); auto h_idx = composer.add_variable(h); composer.create_sort_constraint_with_edges({ a_idx, b_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, b, h); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } { UltraComposer composer = UltraComposer(); @@ -426,26 +406,16 @@ TEST(ultra_composer, sort_with_edges_gate) auto h_idx = composer.add_variable(h); auto b2_idx = composer.add_variable(fr(15)); composer.create_sort_constraint_with_edges({ a_idx, b2_idx, c_idx, d_idx, e_idx, f_idx, g_idx, h_idx }, b, h); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } { UltraComposer composer = UltraComposer(); auto idx = add_variables(composer, { 1, 2, 5, 6, 7, 10, 11, 13, 16, 17, 20, 22, 22, 25, 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); composer.create_sort_constraint_with_edges(idx, 1, 45); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } { UltraComposer composer = UltraComposer(); @@ -453,16 +423,12 @@ TEST(ultra_composer, sort_with_edges_gate) 26, 29, 29, 32, 32, 33, 35, 38, 39, 39, 42, 42, 43, 45 }); composer.create_sort_constraint_with_edges(idx, 1, 29); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } } -TEST(ultra_composer, range_constraint) +TYPED_TEST(ultra_composer, range_constraint) { { UltraComposer composer = UltraComposer(); @@ -488,13 +454,8 @@ TEST(ultra_composer, range_constraint) } // auto ind = {a_idx,b_idx,c_idx,d_idx,e_idx,f_idx,g_idx,h_idx}; composer.create_dummy_constraints(indices); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } { UltraComposer composer = UltraComposer(); @@ -503,13 +464,8 @@ TEST(ultra_composer, range_constraint) composer.create_new_range_constraint(indices[i], 8); } composer.create_sort_constraint(indices); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } { UltraComposer composer = UltraComposer(); @@ -519,13 +475,8 @@ TEST(ultra_composer, range_constraint) composer.create_new_range_constraint(indices[i], 128); } composer.create_dummy_constraints(indices); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } { UltraComposer composer = UltraComposer(); @@ -551,17 +502,12 @@ TEST(ultra_composer, range_constraint) composer.create_new_range_constraint(indices[i], 79); } composer.create_dummy_constraints(indices); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } } -TEST(ultra_composer, range_with_gates) +TYPED_TEST(ultra_composer, range_with_gates) { UltraComposer composer = UltraComposer(); @@ -574,15 +520,11 @@ TEST(ultra_composer, range_with_gates) composer.create_add_gate({ idx[2], idx[3], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -7 }); composer.create_add_gate({ idx[4], idx[5], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -11 }); composer.create_add_gate({ idx[6], idx[7], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -15 }); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, range_with_gates_where_range_is_not_a_power_of_two) +TYPED_TEST(ultra_composer, range_with_gates_where_range_is_not_a_power_of_two) { UltraComposer composer = UltraComposer(); auto idx = add_variables(composer, { 1, 2, 3, 4, 5, 6, 7, 8 }); @@ -594,15 +536,11 @@ TEST(ultra_composer, range_with_gates_where_range_is_not_a_power_of_two) composer.create_add_gate({ idx[2], idx[3], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -7 }); composer.create_add_gate({ idx[4], idx[5], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -11 }); composer.create_add_gate({ idx[6], idx[7], composer.zero_idx, fr::one(), fr::one(), fr::zero(), -15 }); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, sort_widget_complex) +TYPED_TEST(ultra_composer, sort_widget_complex) { { @@ -628,16 +566,11 @@ TEST(ultra_composer, sort_widget_complex) for (size_t i = 0; i < a.size(); i++) ind.emplace_back(composer.add_variable(a[i])); composer.create_sort_constraint(ind); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); // instance, prover.reference_string.SRS_T2); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } } -TEST(ultra_composer, sort_widget_neg) +TYPED_TEST(ultra_composer, sort_widget_neg) { UltraComposer composer = UltraComposer(); fr a = fr::one(); @@ -650,15 +583,11 @@ TEST(ultra_composer, sort_widget_neg) auto c_idx = composer.add_variable(c); auto d_idx = composer.add_variable(d); composer.create_sort_constraint({ a_idx, b_idx, c_idx, d_idx }); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, false); + TestFixture::prove_and_verify(composer, /*expected_result=*/false); } -TEST(ultra_composer, composed_range_constraint) + +TYPED_TEST(ultra_composer, composed_range_constraint) { UltraComposer composer = UltraComposer(); auto c = fr::random_element(); @@ -667,16 +596,11 @@ TEST(ultra_composer, composed_range_constraint) auto a_idx = composer.add_variable(fr(e)); composer.create_add_gate({ a_idx, composer.zero_idx, composer.zero_idx, 1, 0, 0, -fr(e) }); composer.decompose_into_default_range(a_idx, 134); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, non_native_field_multiplication) +TYPED_TEST(ultra_composer, non_native_field_multiplication) { UltraComposer composer = UltraComposer(); @@ -728,16 +652,10 @@ TEST(ultra_composer, non_native_field_multiplication) const auto [lo_1_idx, hi_1_idx] = composer.evaluate_non_native_field_multiplication(inputs); composer.range_constrain_two_limbs(lo_1_idx, hi_1_idx, 70, 70); - auto prover = composer.create_prover(); - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, rom) +TYPED_TEST(ultra_composer, rom) { UltraComposer composer = UltraComposer(); @@ -774,18 +692,10 @@ TEST(ultra_composer, rom) 0, }); - auto prover = composer.create_prover(); - info("composer.num_gates after constructing prover: ", composer.num_gates); - - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -TEST(ultra_composer, ram) +TYPED_TEST(ultra_composer, ram) { UltraComposer composer = UltraComposer(); @@ -845,15 +755,7 @@ TEST(ultra_composer, ram) }, false); - auto prover = composer.create_prover(); - std::cout << "prover num_gates = " << composer.num_gates << std::endl; - - auto verifier = composer.create_verifier(); - - proof proof = prover.construct_proof(); - - bool result = verifier.verify_proof(proof); - EXPECT_EQ(result, true); + TestFixture::prove_and_verify(composer, /*expected_result=*/true); } -} // namespace proof_system::plonk +} // namespace proof_system::plonk::test_ultra_composer diff --git a/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.cpp b/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.cpp index 9e1d5a9d02..f084d8ad34 100644 --- a/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.cpp +++ b/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.cpp @@ -392,4 +392,5 @@ template class KateCommitmentScheme; template class KateCommitmentScheme; template class KateCommitmentScheme; template class KateCommitmentScheme; +template class KateCommitmentScheme; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp b/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp index 653340dbdf..741193d0d8 100644 --- a/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp @@ -43,5 +43,6 @@ extern template class KateCommitmentScheme; extern template class KateCommitmentScheme; extern template class KateCommitmentScheme; extern template class KateCommitmentScheme; +extern template class KateCommitmentScheme; } // namespace proof_system::plonk \ No newline at end of file diff --git a/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp b/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp index 5e91ef8ae4..b7730585e1 100644 --- a/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp +++ b/cpp/src/barretenberg/plonk/proof_system/prover/prover.cpp @@ -1,5 +1,6 @@ #include "prover.hpp" #include "../public_inputs/public_inputs.hpp" +#include "barretenberg/plonk/proof_system/types/prover_settings.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include #include "barretenberg/ecc/curves/bn254/scalar_multiplication/scalar_multiplication.hpp" @@ -639,5 +640,6 @@ template class ProverBase; template class ProverBase; template class ProverBase; template class ProverBase; +template class ProverBase; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp b/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp index d0476608e2..6b817e5c19 100644 --- a/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/prover/prover.hpp @@ -109,5 +109,6 @@ typedef ProverBase UltraProver; // TODO(Mike): maybe just return // need separate cases for ultra vs ultra_to_standard...??? // TODO(Cody): Make this into an issue? typedef ProverBase UltraToStandardProver; +typedef ProverBase UltraWithKeccakProver; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp b/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp index b4b9d5d753..39c98c2784 100644 --- a/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/types/program_settings.hpp @@ -187,4 +187,20 @@ class ultra_to_standard_verifier_settings : public ultra_verifier_settings { static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; }; +// This is neededed for the Noir backend. The ultra verifier contract uses 32-byte challenges generated with Keccak256. +class ultra_with_keccak_verifier_settings : public ultra_verifier_settings { + public: + typedef VerifierPlookupArithmeticWidget + PlookupArithmeticWidget; + typedef VerifierGenPermSortWidget GenPermSortWidget; + typedef VerifierTurboLogicWidget TurboLogicWidget; + typedef VerifierPermutationWidget PermutationWidget; + typedef VerifierPlookupWidget PlookupWidget; + typedef VerifierEllipticWidget EllipticWidget; + typedef VerifierPlookupAuxiliaryWidget + PlookupAuxiliaryWidget; + + static constexpr size_t num_challenge_bytes = 32; + static constexpr transcript::HashType hash_type = transcript::HashType::Keccak256; +}; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp b/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp index fd439df766..3fa0e35d38 100644 --- a/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/types/prover_settings.hpp @@ -57,4 +57,12 @@ class ultra_to_standard_settings : public ultra_settings { static constexpr transcript::HashType hash_type = transcript::HashType::PedersenBlake3s; }; +// Only needed because ultra-to-standard recursion requires us to use a Pedersen hash which is common to both Ultra & +// Standard plonk i.e. the non-ultra version. +class ultra_with_keccak_settings : public ultra_settings { + public: + static constexpr size_t num_challenge_bytes = 32; + static constexpr transcript::HashType hash_type = transcript::HashType::Keccak256; +}; + } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.cpp b/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.cpp index 2a4681df5f..bee400fd36 100644 --- a/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.cpp +++ b/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.cpp @@ -241,5 +241,6 @@ template class VerifierBase; template class VerifierBase; template class VerifierBase; template class VerifierBase; +template class VerifierBase; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.hpp b/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.hpp index 151117ba10..951cef26d6 100644 --- a/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.hpp +++ b/cpp/src/barretenberg/plonk/proof_system/verifier/verifier.hpp @@ -32,10 +32,11 @@ extern template class VerifierBase; extern template class VerifierBase; extern template class VerifierBase; extern template class VerifierBase; +extern template class VerifierBase; typedef VerifierBase Verifier; typedef VerifierBase TurboVerifier; typedef VerifierBase UltraVerifier; typedef VerifierBase UltraToStandardVerifier; - +typedef VerifierBase UltraWithKeccakVerifier; } // namespace proof_system::plonk diff --git a/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp b/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp index aa4457a72e..53062b79fe 100644 --- a/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp +++ b/cpp/src/barretenberg/stdlib/encryption/schnorr/schnorr.test.cpp @@ -33,10 +33,10 @@ auto run_scalar_mul_test = [](grumpkin::fr scalar_mont, bool expect_verify) { EXPECT_EQ(output.y.get_value(), expected.y); }; - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -152,10 +152,10 @@ TEST(stdlib_schnorr, convert_field_into_wnaf) field_ct input(&composer, scalar); convert_field_into_wnaf(&composer, input); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -208,9 +208,9 @@ TEST(stdlib_schnorr, verify_signature) byte_array_ct message(&composer, message_string); stdlib::schnorr::verify_signature(message, pub_key, sig); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -252,10 +252,10 @@ TEST(stdlib_schnorr, verify_signature_failure) byte_array_ct message(&composer, message_string); stdlib::schnorr::verify_signature(message, pub_key2_ct, sig); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -291,9 +291,9 @@ TEST(stdlib_schnorr, signature_verification_result) bool_ct signature_result = stdlib::schnorr::signature_verification_result(message, pub_key, sig); EXPECT_EQ(signature_result.witness_bool, true); - plonk::stdlib::types::Prover prover = composer.create_prover(); + plonk::stdlib::types::Prover prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - plonk::stdlib::types::Verifier verifier = composer.create_verifier(); + plonk::stdlib::types::Verifier verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -335,9 +335,9 @@ TEST(stdlib_schnorr, signature_verification_result_failure) bool_ct signature_result = stdlib::schnorr::signature_verification_result(message, pub_key2_ct, sig); EXPECT_EQ(signature_result.witness_bool, false); - plonk::stdlib::types::Prover prover = composer.create_prover(); + plonk::stdlib::types::Prover prover = composer.create_ultra_with_keccak_prover(); info("composer gates = %zu\n", composer.get_num_gates()); - plonk::stdlib::types::Verifier verifier = composer.create_verifier(); + plonk::stdlib::types::Verifier verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); bool verification_result = verifier.verify_proof(proof); EXPECT_EQ(verification_result, true); diff --git a/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp b/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp index b61cbc305d..4b5fc2910d 100644 --- a/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp +++ b/cpp/src/barretenberg/stdlib/hash/blake2s/blake2s.test.cpp @@ -26,10 +26,10 @@ TEST(stdlib_blake2s, test_single_block) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); auto proof = prover.construct_proof(); @@ -50,10 +50,10 @@ TEST(stdlib_blake2s, test_single_block_plookup) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); std::cout << "prover gates = " << prover.circuit_size << std::endl; printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); auto proof = prover.construct_proof(); @@ -74,10 +74,10 @@ TEST(stdlib_blake2s, test_double_block) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); auto proof = prover.construct_proof(); @@ -98,10 +98,10 @@ TEST(stdlib_blake2s, test_double_block_plookup) EXPECT_EQ(output.get_value(), expected); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); std::cout << "prover gates = " << prover.circuit_size << std::endl; printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); auto proof = prover.construct_proof(); diff --git a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp index 1c5947c669..4e79f1fb43 100644 --- a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp +++ b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.bench.cpp @@ -47,7 +47,7 @@ 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(); + provers[idx] = composers[idx].create_ultra_with_keccak_prover(); 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()); } @@ -58,7 +58,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_ultra_with_keccak_verifier(); } } BENCHMARK(construct_instances_bench)->DenseRange(START_BYTES, MAX_BYTES, BYTES_PER_CHUNK); diff --git a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp index 9379e2382a..4ac0307275 100644 --- a/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp +++ b/cpp/src/barretenberg/stdlib/hash/sha256/sha256.test.cpp @@ -222,9 +222,9 @@ TEST(stdlib_sha256, test_55_bytes) EXPECT_EQ(output[7].get_value(), fr(0x93791fc7ULL)); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -252,9 +252,9 @@ TEST(stdlib_sha256, test_NIST_vector_one_packed_byte_array) EXPECT_EQ(uint256_t(output[7].get_value()).data[0], (uint64_t)0xF20015ADU); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -317,9 +317,9 @@ TEST(stdlib_sha256, test_NIST_vector_two) EXPECT_EQ(output[7].get_value(), 0x19DB06C1ULL); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); printf("constructing proof \n"); plonk::proof proof = prover.construct_proof(); printf("constructed proof \n"); @@ -349,9 +349,9 @@ TEST(stdlib_sha256, test_NIST_vector_three) EXPECT_EQ(output[7].get_value(), 0x8ffe732bULL); printf("composer gates = %zu\n", composer.get_num_gates()); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -379,10 +379,10 @@ TEST(stdlib_sha256, test_NIST_vector_four) EXPECT_EQ(output[6].get_value(), 0xbd56c61cULL); EXPECT_EQ(output[7].get_value(), 0xcccd9504ULL); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); diff --git a/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp b/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp index 1fb8f216f6..477e1406cf 100644 --- a/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp +++ b/cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp @@ -32,10 +32,10 @@ TEST(stdlib_merkle_tree, test_check_membership) bool_ct is_member_ = check_membership(root, create_witness_hash_path(composer, db.get_hash_path(1)), field_ct(1), seven); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -66,9 +66,9 @@ TEST(stdlib_merkle_tree, test_batch_update_membership) field_ct start_idx = field_ct(witness_ct(&composer, fr(4))); batch_update_membership(new_root, old_root, old_hash_path_1, values, start_idx); batch_update_membership(new_root, old_root, old_hash_path_2, values, start_idx); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); @@ -85,10 +85,10 @@ TEST(stdlib_merkle_tree, test_assert_check_membership) assert_check_membership(root, create_witness_hash_path(composer, db.get_hash_path(0)), field_ct(0), zero); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -108,10 +108,10 @@ TEST(stdlib_merkle_tree, test_assert_check_membership_fail) assert_check_membership(root, create_witness_hash_path(composer, db.get_hash_path(0)), field_ct(1), zero); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -140,10 +140,10 @@ TEST(stdlib_merkle_tree, test_update_members) update_membership(new_root, new_value, old_root, old_path, old_value, zero); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -169,10 +169,10 @@ TEST(stdlib_merkle_tree, test_update_members) update_membership(new_root, new_value, old_root, new_path, old_value, zero); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -197,10 +197,10 @@ TEST(stdlib_merkle_tree, test_tree) assert_check_tree(root, values); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); @@ -266,9 +266,9 @@ TEST(stdlib_merkle_tree, test_update_memberships) update_memberships(old_root_ct, new_roots_ct, new_values_ct, old_values_ct, old_hash_paths_ct, old_indices_ct); - auto prover = composer.create_prover(); + auto prover = composer.create_ultra_with_keccak_prover(); printf("composer gates = %zu\n", composer.get_num_gates()); - auto verifier = composer.create_verifier(); + auto verifier = composer.create_ultra_with_keccak_verifier(); plonk::proof proof = prover.construct_proof(); bool result = verifier.verify_proof(proof); EXPECT_EQ(result, true); diff --git a/cpp/src/barretenberg/stdlib/types/types.hpp b/cpp/src/barretenberg/stdlib/types/types.hpp index 706b160800..6a1db12f6e 100644 --- a/cpp/src/barretenberg/stdlib/types/types.hpp +++ b/cpp/src/barretenberg/stdlib/types/types.hpp @@ -3,6 +3,7 @@ #include "barretenberg/plonk/composer/standard_composer.hpp" #include "barretenberg/plonk/composer/turbo_composer.hpp" #include "barretenberg/plonk/composer/ultra_composer.hpp" +#include "barretenberg/plonk/proof_system/prover/prover.hpp" #include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp" #include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp" #include "barretenberg/stdlib/primitives/bit_array/bit_array.hpp" @@ -39,25 +40,13 @@ typedef std::conditional_t< typedef std::conditional_t< SYSTEM_COMPOSER == proof_system::STANDARD, plonk::Prover, - std::conditional_t> + std::conditional_t> Prover; typedef std::conditional_t< SYSTEM_COMPOSER == proof_system::STANDARD, plonk::Verifier, - std::conditional_t> - Verifier; - -typedef std::conditional_t< - SYSTEM_COMPOSER == proof_system::STANDARD, - plonk::Prover, - std::conditional_t> - Prover; - -typedef std::conditional_t< - SYSTEM_COMPOSER == proof_system::STANDARD, - plonk::Verifier, - std::conditional_t> + std::conditional_t> Verifier; typedef stdlib::witness_t witness_ct;