From 2dc4d77256f17db8f389c83c783cc5d37842fcee Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 20 Jun 2023 22:10:13 +0000 Subject: [PATCH 01/28] Use circuit constructor. --- circuits/cpp/barretenberg | 2 +- .../cpp/src/aztec3/circuits/abis/.test.cpp | 2 +- .../cpp/src/aztec3/circuits/apps/.test.cpp | 2 +- .../basic_contract_deployment/init.hpp | 2 +- .../circuits/apps/test_apps/escrow/.test.cpp | 18 +++++++++--------- .../circuits/apps/test_apps/escrow/init.hpp | 2 +- .../private_to_private_function_call/.test.cpp | 6 +++--- .../private_to_private_function_call/init.hpp | 2 +- .../aztec3/circuits/kernel/private/.test.cpp | 4 ++-- .../aztec3/circuits/kernel/private/c_bind.cpp | 2 +- .../aztec3/circuits/kernel/private/init.hpp | 2 +- .../aztec3/circuits/kernel/private/utils.cpp | 2 +- .../aztec3/circuits/kernel/public/.test.cpp | 12 ++++++------ .../aztec3/circuits/kernel/public/c_bind.cpp | 2 +- .../src/aztec3/circuits/kernel/public/init.hpp | 2 +- .../circuits/mock/mock_kernel_circuit.hpp | 2 +- .../cpp/src/aztec3/circuits/recursion/init.hpp | 2 +- .../src/aztec3/circuits/rollup/base/c_bind.cpp | 2 +- .../src/aztec3/circuits/rollup/root/c_bind.cpp | 2 +- .../src/aztec3/utils/types/circuit_types.hpp | 2 +- 20 files changed, 36 insertions(+), 36 deletions(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index 0838474e6746..61b2c6c74458 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 0838474e67469a6d91d6595d1ee23e1dea53863c +Subproject commit 61b2c6c74458a970858f125c0c6b27f548cd37f6 diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 5fe2e078a1bf..9acc0e7c71da 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -9,7 +9,7 @@ namespace { // Composer -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; // Types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index 8f60b0eed1c1..53f23b6828c5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -25,7 +25,7 @@ namespace { // Composer -using C = plonk::UltraPlonkComposer; +using C = UltraCircuitConstructor; // Types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp index d24db87213d5..c37d5b038a29 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp @@ -14,7 +14,7 @@ namespace aztec3::circuits::apps::test_apps::basic_contract_deployment { // Composer -using C = plonk::UltraPlonkComposer; +using C = UltraCircuitConstructor; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp index bc2e12a1785e..936532a74aae 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp @@ -56,9 +56,9 @@ TEST_F(escrow_tests, circuit_deposit) // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.circuit_constructor.failed()); - info("err: ", composer.circuit_constructor.err()); - info("n: ", composer.circuit_constructor.num_gates); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } TEST_F(escrow_tests, circuit_transfer) @@ -81,9 +81,9 @@ TEST_F(escrow_tests, circuit_transfer) // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.circuit_constructor.failed()); - info("err: ", composer.circuit_constructor.err()); - info("n: ", composer.circuit_constructor.num_gates); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } TEST_F(escrow_tests, circuit_withdraw) @@ -105,9 +105,9 @@ TEST_F(escrow_tests, circuit_withdraw) // info("witness: ", composer.witness); // info("constant variables: ", composer.constant_variables); // info("variables: ", composer.variables); - info("failed?: ", composer.circuit_constructor.failed()); - info("err: ", composer.circuit_constructor.err()); - info("n: ", composer.circuit_constructor.num_gates); + info("failed?: ", composer.failed()); + info("err: ", composer.err()); + info("n: ", composer.num_gates); } } // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index 757b8e5e49e6..6b6770333c86 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -14,7 +14,7 @@ namespace aztec3::circuits::apps::test_apps::escrow { // Composer -using C = plonk::UltraPlonkComposer; +using C = UltraCircuitConstructor; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp index 2b6c64252e30..cb0bcc9ba723 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp @@ -54,9 +54,9 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function // info("witness: ", fn1_composer.witness); // info("constant variables: ", fn1_composer.constant_variables); // info("variables: ", fn1_composer.variables); - info("failed?: ", fn1_composer.circuit_constructor.failed()); - info("err: ", fn1_composer.circuit_constructor.err()); - info("n: ", fn1_composer.circuit_constructor.num_gates); + info("failed?: ", fn1_composer.failed()); + info("err: ", fn1_composer.err()); + info("n: ", fn1_composer.num_gates); } } // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index 26712cc998e5..dfe210ff6e48 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { // Composer -using C = plonk::UltraPlonkComposer; +using C = UltraCircuitConstructor; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 6823c5cb4279..2f2a227b1729 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -53,7 +53,7 @@ TEST_F(private_kernel_tests, basic) auto const& public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs, true); // Check the private kernel circuit - EXPECT_TRUE(private_kernel_composer.circuit_constructor.check_circuit()); + EXPECT_TRUE(private_kernel_composer.check_circuit()); } /** @@ -96,7 +96,7 @@ TEST_F(private_kernel_tests, circuit_cbinds) std::vector private_constructor_call_vec; write(private_constructor_call_vec, private_inputs.private_call); - uint8_t const* proof_data_buf = nullptr; + // uint8_t const* proof_data_buf = nullptr; uint8_t const* public_inputs_buf = nullptr; size_t public_inputs_size = 0; // info("Simulating to generate public inputs..."); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index ac466ca254e4..87692ffb4edd 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -9,7 +9,7 @@ #include namespace { -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::PreviousKernelData; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp index a9328737d0c7..0f775c600b44 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp @@ -9,7 +9,7 @@ namespace aztec3::circuits::kernel::private_kernel { -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index f67d54013737..026f4e554b02 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -113,7 +113,7 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) PreviousKernelData const init_previous_kernel{}; auto crs_factory = barretenberg::srs::get_crs_factory(); - Composer mock_kernel_composer = Composer(crs_factory); + Composer mock_kernel_composer; auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs); NT::Proof const mock_kernel_proof = diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index c96e9c021bb9..602c15759934 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -361,12 +361,12 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat .bytecode_hash = 1234567, }; - CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { - .private_data_tree_root = 1000, - .contract_tree_root = 2000, - .l1_to_l2_messages_tree_root = 3000, - .private_kernel_vk_tree_root = 4000, - } }; + // CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { + // .private_data_tree_root = 1000, + // .contract_tree_root = 2000, + // .l1_to_l2_messages_tree_root = 3000, + // .private_kernel_vk_tree_root = 4000, + // } }; CombinedConstantData const end_constants = { .historic_tree_roots = diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index 1e822e170fa4..7690aab9d97f 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -12,7 +12,7 @@ #include namespace { -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::KernelCircuitPublicInputs; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index 9c89a76aabda..41dcaeafddbe 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -10,7 +10,7 @@ namespace aztec3::circuits::kernel::public_kernel { -using Composer = plonk::UltraPlonkComposer; +using Composer = proof_system::UltraCircuitConstructor; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index 27945263e0f4..9816622c526a 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -43,7 +43,7 @@ KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, // We still add dummy witness indices in the recursive proof indices just so that we don't trigger an assertion in // while setting recursion elements as public inputs. These dummy indices would not be used as we're setting // contains_recursive_proof to be false. - composer.circuit_constructor.contains_recursive_proof = false; + composer.contains_recursive_proof = false; plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); return public_inputs.template to_native_type(); diff --git a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp index 6731110b6cfe..c01805ef6098 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp @@ -7,7 +7,7 @@ namespace aztec3::circuits::recursion { // Composer -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; // Generic types: using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 15fca05480c4..00ef77a54a49 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -11,7 +11,7 @@ #include namespace { -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 70da1ca64e38..2f71e4e52f49 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -9,7 +9,7 @@ #include namespace { -using Composer = plonk::UltraPlonkComposer; +using Composer = UltraCircuitConstructor; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index eb2a3042d9b2..c66db57e001c 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -43,7 +43,7 @@ template struct CircuitTypes { using AggregationObject = stdlib::recursion::aggregation_state; using recursive_inner_verifier_settings = - std::conditional_t, + std::conditional_t, stdlib::recursion::recursive_turbo_verifier_settings, stdlib::recursion::recursive_ultra_verifier_settings>; using VK = stdlib::recursion::verification_key; From 0d186afca5bb601014ea5add5e4bb40bf662302c Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 21 Jun 2023 04:02:18 +0000 Subject: [PATCH 02/28] Undo hack to stop exposing manifest. --- circuits/cpp/barretenberg | 2 +- .../kernel/private/private_kernel_circuit.cpp | 21 ++++++------------- .../aztec3/circuits/recursion/aggregator.hpp | 9 ++++---- .../src/aztec3/utils/types/circuit_types.hpp | 5 +---- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index 61b2c6c74458..0493ef0a4c27 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 61b2c6c74458a970858f125c0c6b27f548cd37f6 +Subproject commit 0493ef0a4c275b66aa3c72bb4a626619bff8b09e diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index bb76a7fdfa5c..d4fe59b78890 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -27,22 +27,16 @@ using aztec3::circuits::silo_nullifier; // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // private_call.call_stack_item.public_inputs! -CT::AggregationObject verify_proofs(Composer& composer, - PrivateKernelInputsInner const& private_inputs, - size_t const& num_private_call_public_inputs, - size_t const& num_private_kernel_public_inputs) +CT::AggregationObject verify_proofs(Composer& composer, PrivateKernelInputsInner const& private_inputs) { // compute P0, P1 for private function proof - CT::AggregationObject aggregation_object = Aggregator::aggregate( - &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, num_private_call_public_inputs); + CT::AggregationObject aggregation_object = + Aggregator::aggregate(&composer, private_inputs.private_call.vk, private_inputs.private_call.proof); // computes P0, P1 for previous kernel proof // AND accumulates all of it in P0_agg, P1_agg - Aggregator::aggregate(&composer, - private_inputs.previous_kernel.vk, - private_inputs.previous_kernel.proof, - num_private_kernel_public_inputs, - aggregation_object); + Aggregator::aggregate( + &composer, private_inputs.previous_kernel.vk, private_inputs.previous_kernel.proof, aggregation_object); return aggregation_object; } @@ -334,10 +328,7 @@ KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, update_end_values(private_inputs, public_inputs); - auto aggregation_object = verify_proofs(composer, - private_inputs, - _private_inputs.private_call.vk->num_public_inputs, - _private_inputs.previous_kernel.vk->num_public_inputs); + auto aggregation_object = verify_proofs(composer, private_inputs); // TODO: kernel vk membership check! diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index 53e3ea525324..5e01d9976307 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -1,6 +1,8 @@ #pragma once #include "init.hpp" +#include "barretenberg/plonk/flavor/flavor.hpp" + namespace aztec3::circuits::recursion { class Aggregator { @@ -9,13 +11,10 @@ class Aggregator { Composer* composer, const std::shared_ptr& vk, const NT::Proof& proof, - const size_t& num_public_inputs, const CT::AggregationObject& previous_aggregation_output = CT::AggregationObject()) { - const Manifest recursive_manifest = Composer::create_manifest(num_public_inputs); - - CT::AggregationObject result = verify_proof( - composer, vk, recursive_manifest, proof, previous_aggregation_output); + CT::AggregationObject result = + verify_proof(composer, vk, proof, previous_aggregation_output); return result; } diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index c66db57e001c..cf2fb4371238 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -42,10 +42,7 @@ template struct CircuitTypes { using ecdsa_signature = stdlib::ecdsa::signature; using AggregationObject = stdlib::recursion::aggregation_state; - using recursive_inner_verifier_settings = - std::conditional_t, - stdlib::recursion::recursive_turbo_verifier_settings, - stdlib::recursion::recursive_ultra_verifier_settings>; + using recursive_inner_verifier_settings = stdlib::recursion::recursive_ultra_verifier_settings; using VK = stdlib::recursion::verification_key; // Notice: no CircuitType for a Proof: we only ever handle native; the verify_proof() function swallows the // 'circuit-type-ness' of the proof. From 350ab82820ab64a10c45cdc37f590479e860264e Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 21 Jun 2023 04:12:52 +0000 Subject: [PATCH 03/28] Update Bb --- circuits/cpp/barretenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index 0493ef0a4c27..efb41193977a 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 0493ef0a4c275b66aa3c72bb4a626619bff8b09e +Subproject commit efb41193977ae6c8f55b3a21cde55b7a68aa4be7 From ea69fc5c204095a7ce1b35d3cd418b608baea956 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 21 Jun 2023 04:24:46 +0000 Subject: [PATCH 04/28] Update Bb --- circuits/cpp/barretenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index efb41193977a..daec1bc7ad4d 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit efb41193977ae6c8f55b3a21cde55b7a68aa4be7 +Subproject commit daec1bc7ad4d63094278a8fccb6a2feddf78552f From 64c8ba700b75df07a8452a6f2eae3d23cf7625a6 Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 21 Jun 2023 13:59:46 +0000 Subject: [PATCH 05/28] Bump Bb (need Mont conversion) --- circuits/cpp/barretenberg | 2 +- circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index daec1bc7ad4d..b053b7921c1b 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit daec1bc7ad4d63094278a8fccb6a2feddf78552f +Subproject commit b053b7921c1bcf2c9574ca59294356e366f69a99 diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 2f2a227b1729..5b26c060c9e3 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -49,7 +49,7 @@ TEST_F(private_kernel_tests, basic) false, deposit, { amount, asset_id, memo }, encrypted_logs_hash, encrypted_log_preimages_length, true); // Execute and prove the first kernel iteration - Composer private_kernel_composer("../barretenberg/cpp/srs_db/ignition"); + Composer private_kernel_composer; auto const& public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs, true); // Check the private kernel circuit From d488fc4f59e28d4ab0d1a43086f522020b2a1c2f Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 04:11:12 +0000 Subject: [PATCH 06/28] Using builder and CircuitType --- .vscode/settings.json | 1 + circuits/cpp/barretenberg | 2 +- circuits/cpp/src/aztec3/circuits/abis/.test.cpp | 2 +- circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp | 2 +- circuits/cpp/src/aztec3/circuits/apps/.test.cpp | 2 +- .../circuits/apps/test_apps/basic_contract_deployment/init.hpp | 2 +- circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp | 2 +- .../apps/test_apps/private_to_private_function_call/init.hpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp | 2 +- circuits/cpp/src/aztec3/circuits/recursion/init.hpp | 2 +- circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp | 2 +- circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp | 2 +- 16 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e4568cdcb29d..d60bf21d980e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -165,6 +165,7 @@ "testMate.cpp.test.workingDirectory": "${workspaceFolder}/circuits/cpp/build", // Filter all binaries that are not tests "testMate.cpp.test.executables": "${workspaceFolder}/circuits/cpp/build/bin/*{test,Test,TEST}*", + "cmake.configureOnOpen": true, // End C++/Circuits settings /////////////////////////////////////// } diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index b053b7921c1b..9db5fcb17f11 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit b053b7921c1bcf2c9574ca59294356e366f69a99 +Subproject commit 9db5fcb17f118838c0574bebce93f4655d6dbccd diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 9acc0e7c71da..2599e6351f64 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -9,7 +9,7 @@ namespace { // Composer -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; // Types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index 909b543badcc..b86311e8f787 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -117,7 +117,7 @@ TEST(abi_tests, hash_vk) { // Initialize some random VK data NT::VKData vk_data; - vk_data.composer_type = engine.get_random_uint32(); + vk_data.circuit_type = engine.get_random_uint32(); vk_data.circuit_size = static_cast(1) << (engine.get_random_uint8() >> 3); // must be a power of two vk_data.num_public_inputs = engine.get_random_uint32(); vk_data.commitments["test1"] = g1::element::random_element(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index 53f23b6828c5..9bf9eab8d71b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -25,7 +25,7 @@ namespace { // Composer -using C = UltraCircuitConstructor; +using C = UltraCircuitBuilder; // Types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp index c37d5b038a29..e960a9f3671d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp @@ -14,7 +14,7 @@ namespace aztec3::circuits::apps::test_apps::basic_contract_deployment { // Composer -using C = UltraCircuitConstructor; +using C = UltraCircuitBuilder; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index 6b6770333c86..fbd0bbb2d2f6 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -14,7 +14,7 @@ namespace aztec3::circuits::apps::test_apps::escrow { // Composer -using C = UltraCircuitConstructor; +using C = UltraCircuitBuilder; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index dfe210ff6e48..ebd912a307b0 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { // Composer -using C = UltraCircuitConstructor; +using C = UltraCircuitBuilder; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index 87692ffb4edd..ae81049c6a81 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -9,7 +9,7 @@ #include namespace { -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::PreviousKernelData; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp index 0f775c600b44..bf634d50eb71 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp @@ -9,7 +9,7 @@ namespace aztec3::circuits::kernel::private_kernel { -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index 026f4e554b02..2a81d464323d 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -91,7 +91,7 @@ std::shared_ptr fake_vk() { std::map commitments; commitments["FAKE"] = *new NT::bn254_point(NT::fq(0), NT::fq(0)); - NT::VKData vk_data = { .composer_type = proof_system::ComposerType::TURBO, + NT::VKData vk_data = { .circuit_type = static_cast(proof_system::CircuitType::TURBO), .circuit_size = 2048, .num_public_inputs = 116, .commitments = commitments, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index 7690aab9d97f..9586857bcabe 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -12,7 +12,7 @@ #include namespace { -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::KernelCircuitPublicInputs; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index 41dcaeafddbe..2e236fd14cf1 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -10,7 +10,7 @@ namespace aztec3::circuits::kernel::public_kernel { -using Composer = proof_system::UltraCircuitConstructor; +using Composer = proof_system::UltraCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp index c01805ef6098..be6d819cb5c8 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp @@ -7,7 +7,7 @@ namespace aztec3::circuits::recursion { // Composer -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; // Generic types: using CT = aztec3::utils::types::CircuitTypes; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 00ef77a54a49..63e32b6c731d 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -11,7 +11,7 @@ #include namespace { -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 2f71e4e52f49..7c0e6c087044 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -9,7 +9,7 @@ #include namespace { -using Composer = UltraCircuitConstructor; +using Composer = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; From ded2a64d02a87a08014c3f24088e44de494c4112 Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 15:35:15 +0000 Subject: [PATCH 07/28] Fix some things break others. --- yarn-project/circuits.js/src/cbind/circuits.gen.ts | 14 +++++++------- .../kernel/__snapshots__/index.test.ts.snap | 10 +++++----- .../rollup/__snapshots__/base_rollup.test.ts.snap | 4 ++-- .../rollup/__snapshots__/root_rollup.test.ts.snap | 4 ++-- yarn-project/circuits.js/src/structs/shared.ts | 5 ++--- .../circuits.js/src/structs/verification_key.ts | 8 ++++---- yarn-project/circuits.js/src/tests/factories.ts | 4 ++-- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 04141331c407..1a9979261568 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -748,7 +748,7 @@ export function fromKernelCircuitPublicInputs(o: KernelCircuitPublicInputs): Msg } interface MsgpackVerificationKeyData { - composer_type: number; + circuit_type: number; circuit_size: number; num_public_inputs: number; commitments: Record; @@ -757,8 +757,8 @@ interface MsgpackVerificationKeyData { } export function toVerificationKeyData(o: MsgpackVerificationKeyData): VerificationKeyData { - if (o.composer_type === undefined) { - throw new Error('Expected composer_type in VerificationKeyData deserialization'); + if (o.circuit_type === undefined) { + throw new Error('Expected circuit_type in VerificationKeyData deserialization'); } if (o.circuit_size === undefined) { throw new Error('Expected circuit_size in VerificationKeyData deserialization'); @@ -776,7 +776,7 @@ export function toVerificationKeyData(o: MsgpackVerificationKeyData): Verificati throw new Error('Expected recursive_proof_public_input_indices in VerificationKeyData deserialization'); } return new VerificationKeyData( - o.composer_type, + o.circuit_type, o.circuit_size, o.num_public_inputs, mapValues(o.commitments, (v: MsgpackG1AffineElement) => toG1AffineElement(v)), @@ -786,8 +786,8 @@ export function toVerificationKeyData(o: MsgpackVerificationKeyData): Verificati } export function fromVerificationKeyData(o: VerificationKeyData): MsgpackVerificationKeyData { - if (o.composerType === undefined) { - throw new Error('Expected composerType in VerificationKeyData serialization'); + if (o.circuitType === undefined) { + throw new Error('Expected CircuitType in VerificationKeyData serialization'); } if (o.circuitSize === undefined) { throw new Error('Expected circuitSize in VerificationKeyData serialization'); @@ -805,7 +805,7 @@ export function fromVerificationKeyData(o: VerificationKeyData): MsgpackVerifica throw new Error('Expected recursiveProofPublicInputIndices in VerificationKeyData serialization'); } return { - composer_type: o.composerType, + circuit_type: o.circuitType, circuit_size: o.circuitSize, num_public_inputs: o.numPublicInputs, commitments: mapValues(o.commitments, (v: G1AffineElement) => fromG1AffineElement(v)), diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index c17109b918ae..e40a554ed65a 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -250,7 +250,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -471,7 +471,7 @@ is_execution_request: 0 proof: [ 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -640,7 +640,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -840,7 +840,7 @@ is_execution_request: 0 proof: [ 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -1144,7 +1144,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap index 221dae3dcd0c..7036a9a9b935 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap @@ -136,7 +136,7 @@ is_private: 1 proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ @@ -281,7 +281,7 @@ is_private: 1 proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ] vk: -key.composer_type: 0 +key.circuit_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap index 5eeab7ec5d22..120fe335b945 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap @@ -66,7 +66,7 @@ end_public_data_tree_root: calldata_hash: [ 0x901 0x902 ] proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ] -vk: key.composer_type: 0 +vk: key.circuit_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ @@ -144,7 +144,7 @@ end_public_data_tree_root: calldata_hash: [ 0x1901 0x1902 ] proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ] -vk: key.composer_type: 0 +vk: key.circuit_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/shared.ts b/yarn-project/circuits.js/src/structs/shared.ts index 9f19fe113ebc..749e016414ba 100644 --- a/yarn-project/circuits.js/src/structs/shared.ts +++ b/yarn-project/circuits.js/src/structs/shared.ts @@ -97,11 +97,10 @@ export class EcdsaSignature { /** * Composer prover type. */ -export enum ComposerType { +export enum CircuitType { STANDARD = 0, TURBO = 1, - PLOOKUP = 2, - STANDARD_HONK = 3, + ULTRA = 2 } /** diff --git a/yarn-project/circuits.js/src/structs/verification_key.ts b/yarn-project/circuits.js/src/structs/verification_key.ts index 20a5a91af5fb..803331cb23e4 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.ts @@ -1,7 +1,7 @@ import { BufferReader } from '@aztec/foundation/serialize'; import { serializeToBuffer } from '../utils/serialize.js'; import { Fq } from './index.js'; -import { ComposerType } from './shared.js'; +import { CircuitType } from './shared.js'; import times from 'lodash.times'; /** @@ -81,7 +81,7 @@ export class VerificationKey { /** * Composer prover type we're using. */ - public composerType: ComposerType, + public circuitType: CircuitType, /** * The number of gates in this circuit. */ @@ -110,7 +110,7 @@ export class VerificationKey { */ toBuffer() { return serializeToBuffer( - this.composerType, + this.circuitType, this.circuitSize, this.numPublicInputs, new CommitmentMap(this.commitments), @@ -142,7 +142,7 @@ export class VerificationKey { */ static makeFake(): VerificationKey { return new VerificationKey( - ComposerType.TURBO, + CircuitType.TURBO, 2048, 116, { diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 48490b78d796..5bb9d40b03ad 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -15,7 +15,7 @@ import { CombinedAccumulatedData, CombinedConstantData, CombinedHistoricTreeRoots, - ComposerType, + CircuitType, ConstantBaseRollupData, ContractDeploymentData, ContractStorageRead, @@ -377,7 +377,7 @@ export function makeMembershipWitness(size: N, start: number): */ export function makeVerificationKey(): VerificationKey { return new VerificationKey( - ComposerType.STANDARD, + CircuitType.STANDARD, 101, // arbitrary 102, // arbitrary { From 2224d0f5bb9753b0d270b2c29ac77aa39912c16e Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 15:53:11 +0000 Subject: [PATCH 08/28] Satisfy prettier? --- yarn-project/circuits.js/src/structs/shared.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/circuits.js/src/structs/shared.ts b/yarn-project/circuits.js/src/structs/shared.ts index 749e016414ba..b2147bdd9ab9 100644 --- a/yarn-project/circuits.js/src/structs/shared.ts +++ b/yarn-project/circuits.js/src/structs/shared.ts @@ -100,7 +100,7 @@ export class EcdsaSignature { export enum CircuitType { STANDARD = 0, TURBO = 1, - ULTRA = 2 + ULTRA = 2, } /** From aa6f850cfc6adccbe6c118bf2e79ad7ccbd6defd Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 16:52:14 +0000 Subject: [PATCH 09/28] Composer ~> Builder --- .../cpp/src/aztec3/circuits/abis/.test.cpp | 10 +- .../cpp/src/aztec3/circuits/abis/README.md | 2 +- .../src/aztec3/circuits/abis/call_context.hpp | 14 +- .../aztec3/circuits/abis/call_stack_item.hpp | 6 +- .../abis/combined_accumulated_data.hpp | 13 +- .../circuits/abis/combined_constant_data.hpp | 10 +- .../abis/combined_historic_tree_roots.hpp | 12 +- .../abis/contract_deployment_data.hpp | 15 +- .../circuits/abis/contract_storage_read.hpp | 10 +- .../abis/contract_storage_update_request.hpp | 12 +- .../aztec3/circuits/abis/function_data.hpp | 10 +- .../circuits/abis/function_leaf_preimage.hpp | 10 +- .../abis/kernel_circuit_public_inputs.hpp | 14 +- .../circuits/abis/membership_witness.hpp | 4 +- .../circuits/abis/new_contract_data.hpp | 14 +- .../abis/optionally_revealed_data.hpp | 13 +- .../circuits/abis/previous_kernel_data.hpp | 6 +- .../abis/private_circuit_public_inputs.hpp | 55 ++-- .../abis/private_historic_tree_roots.hpp | 11 +- .../call_context_reconciliation_data.hpp | 6 +- .../circuits/abis/private_kernel/globals.hpp | 4 +- .../abis/private_kernel/private_call_data.hpp | 8 +- .../private_kernel_inputs_init.hpp | 5 +- .../private_kernel_inputs_inner.hpp | 5 +- .../abis/public_circuit_public_inputs.hpp | 6 +- .../aztec3/circuits/abis/public_data_read.hpp | 10 +- .../abis/public_data_update_request.hpp | 11 +- .../abis/public_kernel/public_call_data.hpp | 6 +- .../public_kernel/public_kernel_inputs.hpp | 4 +- .../src/aztec3/circuits/abis/tx_context.hpp | 12 +- .../src/aztec3/circuits/abis/tx_request.hpp | 4 +- .../cpp/src/aztec3/circuits/apps/.test.cpp | 4 +- .../cpp/src/aztec3/circuits/apps/contract.hpp | 2 +- .../apps/function_execution_context.hpp | 44 +-- .../apps/notes/default_private_note/note.hpp | 16 +- .../apps/notes/default_private_note/note.tpp | 55 ++-- .../default_private_note/note_preimage.hpp | 8 +- .../nullifier_preimage.hpp | 6 +- .../default_singleton_private_note/note.hpp | 16 +- .../default_singleton_private_note/note.tpp | 54 ++-- .../note_preimage.hpp | 8 +- .../nullifier_preimage.hpp | 6 +- .../circuits/apps/notes/note_interface.hpp | 6 +- .../aztec3/circuits/apps/opcodes/opcodes.hpp | 20 +- .../aztec3/circuits/apps/opcodes/opcodes.tpp | 26 +- .../aztec3/circuits/apps/oracle_wrapper.hpp | 16 +- .../circuits/apps/private_state.test.cpp | 4 +- .../apps/state_vars/field_state_var.hpp | 16 +- .../apps/state_vars/mapping_state_var.hpp | 16 +- .../apps/state_vars/mapping_state_var.tpp | 12 +- .../apps/state_vars/state_var_base.hpp | 14 +- .../apps/state_vars/state_var_base.tpp | 8 +- .../apps/state_vars/utxo_set_state_var.hpp | 14 +- .../apps/state_vars/utxo_set_state_var.tpp | 14 +- .../apps/state_vars/utxo_state_var.hpp | 14 +- .../apps/state_vars/utxo_state_var.tpp | 18 +- .../basic_contract_deployment/init.hpp | 4 +- .../circuits/apps/test_apps/escrow/init.hpp | 4 +- .../private_to_private_function_call/init.hpp | 4 +- .../src/aztec3/circuits/apps/utxo_datum.hpp | 6 +- circuits/cpp/src/aztec3/circuits/hash.hpp | 4 +- .../aztec3/circuits/kernel/private/.test.cpp | 4 +- .../aztec3/circuits/kernel/private/c_bind.cpp | 8 +- .../aztec3/circuits/kernel/private/common.cpp | 12 +- .../aztec3/circuits/kernel/private/common.hpp | 10 +- .../aztec3/circuits/kernel/private/init.hpp | 8 +- .../native_private_kernel_circuit_init.cpp | 10 +- .../native_private_kernel_circuit_init.hpp | 4 +- ...ative_private_kernel_circuit_init.test.cpp | 54 ++-- .../native_private_kernel_circuit_inner.cpp | 12 +- .../native_private_kernel_circuit_inner.hpp | 4 +- ...tive_private_kernel_circuit_inner.test.cpp | 47 ++- ...native_private_kernel_circuit_ordering.cpp | 6 +- ...native_private_kernel_circuit_ordering.hpp | 4 +- ...e_private_kernel_circuit_ordering.test.cpp | 10 +- .../kernel/private/private_kernel_circuit.cpp | 30 +- .../kernel/private/private_kernel_circuit.hpp | 2 +- .../kernel/private/testing_harness.cpp | 2 +- .../kernel/private/testing_harness.hpp | 4 +- .../aztec3/circuits/kernel/private/utils.cpp | 2 +- .../aztec3/circuits/kernel/public/.test.cpp | 274 +++++++++--------- .../aztec3/circuits/kernel/public/c_bind.cpp | 6 +- .../aztec3/circuits/kernel/public/common.cpp | 2 +- .../aztec3/circuits/kernel/public/common.hpp | 40 +-- .../aztec3/circuits/kernel/public/init.hpp | 6 +- ...kernel_circuit_private_previous_kernel.cpp | 6 +- ...kernel_circuit_private_previous_kernel.hpp | 4 +- ..._kernel_circuit_public_previous_kernel.cpp | 6 +- ..._kernel_circuit_public_previous_kernel.hpp | 4 +- .../src/aztec3/circuits/mock/mock_circuit.hpp | 4 +- .../circuits/mock/mock_kernel_circuit.hpp | 10 +- .../aztec3/circuits/recursion/aggregator.hpp | 2 +- .../src/aztec3/circuits/recursion/init.hpp | 6 +- .../src/aztec3/circuits/rollup/base/.test.cpp | 46 ++- .../aztec3/circuits/rollup/base/c_bind.cpp | 6 +- .../src/aztec3/circuits/rollup/base/init.hpp | 2 +- .../base/native_base_rollup_circuit.cpp | 30 +- .../base/native_base_rollup_circuit.hpp | 2 +- .../circuits/rollup/components/components.cpp | 8 +- .../circuits/rollup/components/components.hpp | 10 +- .../circuits/rollup/components/init.hpp | 2 +- .../aztec3/circuits/rollup/merge/.test.cpp | 26 +- .../aztec3/circuits/rollup/merge/c_bind.cpp | 4 +- .../src/aztec3/circuits/rollup/merge/init.hpp | 2 +- .../merge/native_merge_rollup_circuit.cpp | 2 +- .../merge/native_merge_rollup_circuit.hpp | 2 +- .../src/aztec3/circuits/rollup/root/.test.cpp | 4 +- .../aztec3/circuits/rollup/root/c_bind.cpp | 6 +- .../src/aztec3/circuits/rollup/root/init.hpp | 2 +- .../root/native_root_rollup_circuit.cpp | 2 +- .../root/native_root_rollup_circuit.hpp | 2 +- .../circuits/rollup/test_utils/init.hpp | 2 +- .../circuits/rollup/test_utils/utils.cpp | 8 +- .../circuits/rollup/test_utils/utils.hpp | 6 +- circuits/cpp/src/aztec3/utils/array.hpp | 8 +- .../cpp/src/aztec3/utils/dummy_composer.hpp | 4 +- .../aztec3/utils/msgpack_derived_equals.hpp | 2 +- .../src/aztec3/utils/types/circuit_types.hpp | 54 ++-- .../cpp/src/aztec3/utils/types/convert.hpp | 174 +++++------ 119 files changed, 881 insertions(+), 899 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 2599e6351f64..23c9101a4460 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -8,11 +8,11 @@ #include namespace { -// Composer -using Composer = UltraCircuitBuilder; +// Builder +using Builder = UltraCircuitBuilder; // Types -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; } // namespace @@ -74,7 +74,7 @@ TEST(abi_tests, native_to_circuit_function_data) info("function data: ", native_function_data); - Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); + Builder composer = Builder("../barretenberg/cpp/srs_db/ignition"); FunctionData const circuit_function_data = native_function_data.to_circuit_type(composer); info("function data: ", circuit_function_data); @@ -105,7 +105,7 @@ TEST(abi_tests, native_to_circuit_call_context) info("call context: ", native_call_context); - Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); + Builder composer = Builder("../barretenberg/cpp/srs_db/ignition"); CallContext const circuit_call_context = native_call_context.to_circuit_type(composer); info("call context: ", circuit_call_context); diff --git a/circuits/cpp/src/aztec3/circuits/abis/README.md b/circuits/cpp/src/aztec3/circuits/abis/README.md index 26acdf5f58fc..192d66c0c10c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/README.md +++ b/circuits/cpp/src/aztec3/circuits/abis/README.md @@ -6,4 +6,4 @@ Contains all ABIs for use by: - Kernel circuits - Rollup circuits -All ABIs are generalised by an `NCT` template parameter (meaning `NativeOrCircuitTypes`). `NCT` can be either `aztec3::utils::types::NativeTypes` or `aztec3::utils::types::CircuitTypes` for some `Composer`. The idea being, there's a single implementation of every struct/class for native and circuit types. NativeType structs can be switched to CircuitType with the `to_circuit_type()` method. +All ABIs are generalised by an `NCT` template parameter (meaning `NativeOrCircuitTypes`). `NCT` can be either `aztec3::utils::types::NativeTypes` or `aztec3::utils::types::CircuitTypes` for some `Builder`. The idea being, there's a single implementation of every struct/class for native and circuit types. NativeType structs can be switched to CircuitType with the `to_circuit_type()` method. diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp index 1a40181b8210..1b166064ff06 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp @@ -40,14 +40,14 @@ template struct CallContext { return utils::msgpack_derived_equals(*this, other); }; - template CallContext> to_circuit_type(Composer& composer) const + template CallContext> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - CallContext> call_context = { + CallContext> call_context = { to_ct(msg_sender), to_ct(storage_contract_address), to_ct(portal_contract_address), to_ct(is_delegate_call), to_ct(is_static_call), to_ct(is_contract_deployment), @@ -56,10 +56,10 @@ template struct CallContext { return call_context; }; - template CallContext to_native_type() const + template CallContext to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; CallContext call_context = { to_nt(msg_sender), to_nt(storage_contract_address), to_nt(portal_contract_address), @@ -79,9 +79,9 @@ template struct CallContext { return NCT::compress(inputs, GeneratorIndex::CALL_CONTEXT); } - template void assert_is_zero() + template void assert_is_zero() { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); msg_sender.to_field().assert_is_zero(); storage_contract_address.to_field().assert_is_zero(); diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp index 3cb84b30ed0b..3725a5073792 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp @@ -49,15 +49,15 @@ template typename PrivatePublic> struct CallStac return utils::msgpack_derived_equals(*this, other); }; - template - CallStackItem, PrivatePublic> to_circuit_type(Composer& composer) const + template + CallStackItem, PrivatePublic> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - CallStackItem, PrivatePublic> call_stack_item = { + CallStackItem, PrivatePublic> call_stack_item = { to_ct(contract_address), function_data.to_circuit_type(composer), public_inputs.to_circuit_type(composer), diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp index d226b624a95b..41c212282da3 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp @@ -83,10 +83,9 @@ template struct CombinedAccumulatedData { public_data_reads == other.public_data_reads; }; - template - CombinedAccumulatedData> to_circuit_type(Composer& composer) const + template CombinedAccumulatedData> to_circuit_type(Builder& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); // Capture the composer: @@ -124,11 +123,11 @@ template struct CombinedAccumulatedData { return acc_data; }; - template CombinedAccumulatedData to_native_type() const + template CombinedAccumulatedData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; CombinedAccumulatedData acc_data = { typename NativeTypes::AggregationObject{ diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp index 39ebb0bf1cd0..7bc5a74a021d 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp @@ -30,11 +30,11 @@ template struct CombinedConstantData { return historic_tree_roots == other.historic_tree_roots && tx_context == other.tx_context; } - template CombinedConstantData> to_circuit_type(Composer& composer) const + template CombinedConstantData> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); - CombinedConstantData> constant_data = { + CombinedConstantData> constant_data = { historic_tree_roots.to_circuit_type(composer), tx_context.to_circuit_type(composer), }; @@ -42,11 +42,11 @@ template struct CombinedConstantData { return constant_data; }; - template CombinedConstantData to_native_type() const + template CombinedConstantData to_native_type() const { - static_assert(std::is_same, NCT>::value); + static_assert(std::is_same, NCT>::value); - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; CombinedConstantData constant_data = { to_native_type(historic_tree_roots), diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp index 0f4152ae59d4..c4115f26d9d9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp @@ -27,25 +27,25 @@ template struct CombinedHistoricTreeRoots { return private_historic_tree_roots == other.private_historic_tree_roots; }; - template - CombinedHistoricTreeRoots> to_circuit_type(Composer& composer) const + template + CombinedHistoricTreeRoots> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - CombinedHistoricTreeRoots> data = { + CombinedHistoricTreeRoots> data = { to_circuit_type(private_historic_tree_roots), }; return data; }; - template CombinedHistoricTreeRoots to_native_type() const + template CombinedHistoricTreeRoots to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_native_type = [&](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_native_type = [&](T& e) { return e.template to_native_type(); }; CombinedHistoricTreeRoots data = { to_native_type(private_historic_tree_roots), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp index a77116acf329..52b421158ba4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp @@ -36,15 +36,14 @@ template struct ContractDeploymentData { portal_contract_address == other.portal_contract_address; }; - template - ContractDeploymentData> to_circuit_type(Composer& composer) const + template ContractDeploymentData> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractDeploymentData> data = { + ContractDeploymentData> data = { to_ct(deployer_public_key), to_ct(constructor_vk_hash), to_ct(function_tree_root), to_ct(contract_address_salt), to_ct(portal_contract_address), }; @@ -52,10 +51,10 @@ template struct ContractDeploymentData { return data; }; - template ContractDeploymentData to_native_type() const + template ContractDeploymentData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; ContractDeploymentData call_context = { to_nt(deployer_public_key), to_nt(constructor_vk_hash), to_nt(function_tree_root), @@ -65,9 +64,9 @@ template struct ContractDeploymentData { return call_context; }; - template void assert_is_zero() + template void assert_is_zero() { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); deployer_public_key[0].assert_is_zero(); deployer_public_key[1].assert_is_zero(); diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp index 3a13701fb820..af910654d8ff 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp @@ -23,14 +23,14 @@ template struct ContractStorageRead { MSGPACK_FIELDS(storage_slot, current_value); bool operator==(ContractStorageRead const&) const = default; - template ContractStorageRead> to_circuit_type(Composer& composer) const + template ContractStorageRead> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractStorageRead> contract_storage_read = { + ContractStorageRead> contract_storage_read = { to_ct(storage_slot), to_ct(current_value), }; @@ -38,11 +38,11 @@ template struct ContractStorageRead { return contract_storage_read; }; - template ContractStorageRead to_native_type() const + template ContractStorageRead to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; ContractStorageRead contract_storage_read = { to_nt(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp index 73109e138861..1ff0d2bba946 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp @@ -23,15 +23,15 @@ template struct ContractStorageUpdateRequest { // for serialization, update with new fields MSGPACK_FIELDS(storage_slot, old_value, new_value); bool operator==(ContractStorageUpdateRequest const&) const = default; - template - ContractStorageUpdateRequest> to_circuit_type(Composer& composer) const + template + ContractStorageUpdateRequest> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractStorageUpdateRequest> update_request = { + ContractStorageUpdateRequest> update_request = { to_ct(storage_slot), to_ct(old_value), to_ct(new_value), @@ -40,11 +40,11 @@ template struct ContractStorageUpdateRequest { return update_request; }; - template ContractStorageUpdateRequest to_native_type() const + template ContractStorageUpdateRequest to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; ContractStorageUpdateRequest update_request = { to_nt(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp index 6e6d939856ad..a01b85709636 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp @@ -29,14 +29,14 @@ template struct FunctionData { is_constructor == other.is_constructor; }; - template FunctionData> to_circuit_type(Composer& composer) const + template FunctionData> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - FunctionData> function_data = { + FunctionData> function_data = { to_ct(function_selector), to_ct(is_private), to_ct(is_constructor), @@ -45,10 +45,10 @@ template struct FunctionData { return function_data; }; - template FunctionData to_native_type() const + template FunctionData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; FunctionData function_data = { to_nt(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp index f5297667941e..c15d185e835f 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp @@ -42,14 +42,14 @@ template struct FunctionLeafPreimage { vk_hash == other.vk_hash && acir_hash == other.acir_hash; }; - template FunctionLeafPreimage> to_circuit_type(Composer& composer) const + template FunctionLeafPreimage> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - FunctionLeafPreimage> preimage = { + FunctionLeafPreimage> preimage = { to_ct(function_selector), to_ct(is_private), to_ct(vk_hash), @@ -59,10 +59,10 @@ template struct FunctionLeafPreimage { return preimage; }; - template FunctionLeafPreimage to_native_type() const + template FunctionLeafPreimage to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; FunctionLeafPreimage preimage = { to_nt(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp index 76b4878d5985..6293066f7dd9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp @@ -31,15 +31,15 @@ template struct KernelCircuitPublicInputs { return end == other.end && constants == other.constants && is_private == other.is_private; }; - template - KernelCircuitPublicInputs> to_circuit_type(Composer& composer) const + template + KernelCircuitPublicInputs> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - KernelCircuitPublicInputs> private_inputs = { + KernelCircuitPublicInputs> private_inputs = { end.to_circuit_type(composer), constants.to_circuit_type(composer), @@ -49,11 +49,11 @@ template struct KernelCircuitPublicInputs { return private_inputs; }; - template KernelCircuitPublicInputs to_native_type() const + template KernelCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; KernelCircuitPublicInputs pis = { to_native_type(end), diff --git a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp index 67e9b423e307..27e9656fab6e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp @@ -24,14 +24,14 @@ template struct MembershipWitness { return leaf_index == other.leaf_index && sibling_path == other.sibling_path; }; - template MembershipWitness, N> to_circuit_type(Composer& composer) const + template MembershipWitness, N> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - MembershipWitness, N> witness = { + MembershipWitness, N> witness = { to_ct(leaf_index), map(sibling_path, to_ct), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp index c37d6c265e11..e341df852113 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp @@ -30,24 +30,24 @@ template struct NewContractData { return utils::msgpack_derived_equals(*this, other); }; - template NewContractData> to_circuit_type(Composer& composer) const + template NewContractData> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - NewContractData> new_contract_data = { to_ct(contract_address), - to_ct(portal_contract_address), - to_ct(function_tree_root) }; + NewContractData> new_contract_data = { to_ct(contract_address), + to_ct(portal_contract_address), + to_ct(function_tree_root) }; return new_contract_data; }; - template NewContractData to_native_type() const + template NewContractData to_native_type() const { - static_assert(std::is_same, NCT>::value); + static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; NewContractData new_contract_data = { to_nt(contract_address), to_nt(portal_contract_address), diff --git a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp index 8ae52a767e57..9e91597bf0ab 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp @@ -45,15 +45,14 @@ template struct OptionallyRevealedData { called_from_l1 == other.called_from_l1 && called_from_public_l2 == other.called_from_public_l2; }; - template - OptionallyRevealedData> to_circuit_type(Composer& composer) const + template OptionallyRevealedData> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - OptionallyRevealedData> data = { + OptionallyRevealedData> data = { to_ct(call_stack_item_hash), function_data.to_circuit_type(composer), to_ct(vk_hash), @@ -67,11 +66,11 @@ template struct OptionallyRevealedData { return data; }; - template OptionallyRevealedData to_native_type() const + template OptionallyRevealedData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; OptionallyRevealedData data = { to_nt(call_stack_item_hash), to_native_type(function_data), to_nt(vk_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp index fb40a0650aef..1fd5194d2d6b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp @@ -39,15 +39,15 @@ template struct PreviousKernelData { }; // WARNING: the `proof` does NOT get converted! - template PreviousKernelData> to_circuit_type(Composer& composer) const + template PreviousKernelData> to_circuit_type(Builder& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PreviousKernelData> data = { + PreviousKernelData> data = { public_inputs.to_circuit_type(composer), proof, // Notice: not converted! Stays as native. CT::VK::from_witness(&composer, vk), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index 417054917d35..6b868ca13f43 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -70,8 +70,8 @@ template class PrivateCircuitPublicInputs { contract_deployment_data == other.contract_deployment_data; }; - template - PrivateCircuitPublicInputs> to_circuit_type(Composer& composer) const + template + PrivateCircuitPublicInputs> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -79,7 +79,7 @@ template class PrivateCircuitPublicInputs { auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PrivateCircuitPublicInputs> pis = { + PrivateCircuitPublicInputs> pis = { to_circuit_type(call_context), to_ct(args_hash), @@ -111,11 +111,11 @@ template class PrivateCircuitPublicInputs { return pis; }; - template PrivateCircuitPublicInputs to_native_type() const + template PrivateCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; PrivateCircuitPublicInputs pis = { to_native_type(call_context), @@ -409,9 +409,9 @@ template class OptionalPrivateCircuitPublicInputs { } } - template void make_unused_inputs_zero(Composer& composer) + template void make_unused_inputs_zero(Builder& composer) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); make_unused_element_zero(composer, call_context); @@ -443,7 +443,7 @@ template class OptionalPrivateCircuitPublicInputs { all_elements_populated = true; } - template void set_public(Composer& composer) + template void set_public(Builder& composer) { static_assert(!(std::is_same::value)); @@ -479,8 +479,8 @@ template class OptionalPrivateCircuitPublicInputs { (*contract_deployment_data).set_public(); } - template - OptionalPrivateCircuitPublicInputs> to_circuit_type(Composer& composer) const + template + OptionalPrivateCircuitPublicInputs> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -490,7 +490,7 @@ template class OptionalPrivateCircuitPublicInputs { return e ? std::make_optional((*e).to_circuit_type(composer)) : std::nullopt; }; - OptionalPrivateCircuitPublicInputs> pis = { + OptionalPrivateCircuitPublicInputs> pis = { to_circuit_type(call_context), to_ct(args_hash), @@ -522,12 +522,12 @@ template class OptionalPrivateCircuitPublicInputs { return pis; }; - template OptionalPrivateCircuitPublicInputs to_native_type() const + template OptionalPrivateCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; auto to_native_type = [](const std::optional& e) { - return e ? std::make_optional((*e).template to_native_type()) : std::nullopt; + return e ? std::make_optional((*e).template to_native_type()) : std::nullopt; }; // auto to_native_type = [&](T& e) { return e.to_native_type(); }; @@ -663,38 +663,37 @@ template class OptionalPrivateCircuitPublicInputs { vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } - template - void make_unused_array_elements_zero(Composer& composer, std::array, SIZE>& arr) + template + void make_unused_array_elements_zero(Builder& composer, std::array, SIZE>& arr) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); for (std::optional& e : arr) { make_unused_element_zero(composer, e); } } - template - void make_unused_element_zero(Composer& composer, std::optional& element) + template void make_unused_element_zero(Builder& composer, std::optional& element) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); if (!element) { element = - T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` + T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` fr(*element).assert_is_zero(); } } // ABIStruct is a template for any of the structs in the abis/ dir. E.g. ExecutedCallback, CallbackStackItem. - template class ABIStruct> - void make_unused_element_zero(Composer& composer, std::optional>>& element) + template class ABIStruct> + void make_unused_element_zero(Builder& composer, std::optional>>& element) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); if (!element) { element = ABIStruct().to_circuit_type( composer); // convert the nullopt value to a circuit witness value of `0` - (*element).template assert_is_zero(); + (*element).template assert_is_zero(); } } diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp index a1048a68f152..7e6aa75d7bc0 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp @@ -37,15 +37,14 @@ template struct PrivateHistoricTreeRoots { private_kernel_vk_tree_root == other.private_kernel_vk_tree_root; }; - template - PrivateHistoricTreeRoots> to_circuit_type(Composer& composer) const + template PrivateHistoricTreeRoots> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PrivateHistoricTreeRoots> data = { + PrivateHistoricTreeRoots> data = { to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root), to_ct(l1_to_l2_messages_tree_root), to_ct(private_kernel_vk_tree_root), }; @@ -53,10 +52,10 @@ template struct PrivateHistoricTreeRoots { return data; }; - template PrivateHistoricTreeRoots to_native_type() const + template PrivateHistoricTreeRoots to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PrivateHistoricTreeRoots data = { to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp index 68b6bc041e87..e50064fb024a 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp @@ -33,8 +33,8 @@ // std::array, NEW_L2_TO_L1_MSGS_LENGTH> l1_call_contexts; // std::array l1_counterparts; // TODO: this is probably wrong. -// template -// CallContextReconciliationData> to_circuit_type(Composer& composer) const +// template +// CallContextReconciliationData> to_circuit_type(Builder& composer) const // { // static_assert((std::is_same::value)); @@ -42,7 +42,7 @@ // auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; -// CallContextReconciliationData> data = { +// CallContextReconciliationData> data = { // map(private_call_contexts, to_circuit_type), to_ct(private_counterparts), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp index 8edb04939535..c49423ebdd19 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp @@ -19,14 +19,14 @@ template struct Globals { boolean operator==(Globals const& other) const { return min_timestamp == other.min_timestamp; }; - template Globals> to_circuit_type(Composer& composer) const + template Globals> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - Globals> global_data = { to_ct(min_timestamp) }; + Globals> global_data = { to_ct(min_timestamp) }; return global_data; }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp index 7611fa1c82d5..a7c6ccaaf1e9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp @@ -55,16 +55,16 @@ template struct PrivateCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PrivateCallData> to_circuit_type(Composer& composer) const + template PrivateCallData> to_circuit_type(Builder& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PrivateCallData> data = { + PrivateCallData> data = { to_circuit_type(call_stack_item), map(private_call_stack_preimages, to_circuit_type), @@ -76,7 +76,7 @@ template struct PrivateCallData { to_circuit_type(function_leaf_membership_witness), to_circuit_type(contract_leaf_membership_witness), - aztec3::utils::types::to_ct>( + aztec3::utils::types::to_ct>( composer, read_request_membership_witnesses), to_ct(portal_contract_address), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp index 6f6db83d8fbc..1c57817a6368 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp @@ -24,12 +24,11 @@ template struct PrivateKernelInputsInit { return tx_request == other.tx_request && private_call == other.private_call; }; - template - PrivateKernelInputsInit> to_circuit_type(Composer& composer) const + template PrivateKernelInputsInit> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); - PrivateKernelInputsInit> private_inputs = { + PrivateKernelInputsInit> private_inputs = { // TODO to_ct(signature), tx_request.to_circuit_type(composer), private_call.to_circuit_type(composer), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp index f29ab8bbc371..d884c06ee82b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp @@ -26,12 +26,11 @@ template struct PrivateKernelInputsInner { return previous_kernel == other.previous_kernel && private_call == other.private_call; }; - template - PrivateKernelInputsInner> to_circuit_type(Composer& composer) const + template PrivateKernelInputsInner> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); - PrivateKernelInputsInner> private_inputs = { + PrivateKernelInputsInner> private_inputs = { previous_kernel.to_circuit_type(composer), private_call.to_circuit_type(composer), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp index d939ad51aee7..d85532329668 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp @@ -70,8 +70,8 @@ template struct PublicCircuitPublicInputs { return msgpack_derived_equals(*this, other); } - template - PublicCircuitPublicInputs> to_circuit_type(Composer& composer) const + template + PublicCircuitPublicInputs> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -79,7 +79,7 @@ template struct PublicCircuitPublicInputs { auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PublicCircuitPublicInputs> pis = { + PublicCircuitPublicInputs> pis = { .call_context = to_circuit_type(call_context), .args_hash = to_ct(args_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp index f8c1830bd5f9..d9b7b7ee70e7 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp @@ -23,14 +23,14 @@ template struct PublicDataRead { MSGPACK_FIELDS(leaf_index, value); bool operator==(PublicDataRead const&) const = default; - template PublicDataRead> to_circuit_type(Composer& composer) const + template PublicDataRead> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PublicDataRead> read = { + PublicDataRead> read = { to_ct(leaf_index), to_ct(value), }; @@ -38,11 +38,11 @@ template struct PublicDataRead { return read; }; - template PublicDataRead to_native_type() const + template PublicDataRead to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PublicDataRead read = { to_nt(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp index 866291ff53b4..3bc12400f733 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp @@ -24,15 +24,14 @@ template struct PublicDataUpdateRequest { MSGPACK_FIELDS(leaf_index, old_value, new_value); bool operator==(PublicDataUpdateRequest const&) const = default; - template - PublicDataUpdateRequest> to_circuit_type(Composer& composer) const + template PublicDataUpdateRequest> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PublicDataUpdateRequest> update_request = { + PublicDataUpdateRequest> update_request = { to_ct(leaf_index), to_ct(old_value), to_ct(new_value), @@ -41,11 +40,11 @@ template struct PublicDataUpdateRequest { return update_request; }; - template PublicDataUpdateRequest to_native_type() const + template PublicDataUpdateRequest to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PublicDataUpdateRequest update_request = { to_nt(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp index d242b7f2a69e..976c7334f37c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp @@ -43,16 +43,16 @@ template struct PublicCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PublicCallData> to_circuit_type(Composer& composer) const + template PublicCallData> to_circuit_type(Builder& composer) const { - // typedef CircuitTypes CT; + // typedef CircuitTypes CT; static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PublicCallData> data = { + PublicCallData> data = { call_stack_item.to_circuit_type(composer), map(public_call_stack_preimages, to_circuit_type), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp index f4a50dd7e485..21409b871e36 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp @@ -28,11 +28,11 @@ template struct PublicKernelInputs { return previous_kernel == other.previous_kernel && public_call == other.public_call; }; - template PublicKernelInputs> to_circuit_type(Composer& composer) const + template PublicKernelInputs> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); - PublicKernelInputs> public_kernel_inputs = { + PublicKernelInputs> public_kernel_inputs = { previous_kernel.to_circuit_type(composer), public_call.to_circuit_type(composer), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp index 329528b1fa4a..e63166ce14b9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp @@ -33,7 +33,7 @@ template struct TxContext { contract_deployment_data == other.contract_deployment_data; }; - template TxContext> to_circuit_type(Composer& composer) const + template TxContext> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -41,7 +41,7 @@ template struct TxContext { auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - TxContext> tx_context = { + TxContext> tx_context = { to_ct(is_fee_payment_tx), to_ct(is_rebate_payment_tx), to_ct(is_contract_deployment_tx), @@ -51,11 +51,11 @@ template struct TxContext { return tx_context; }; - template TxContext to_native_type() const + template TxContext to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; TxContext tx_context = { to_nt(is_fee_payment_tx), diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp index d9b74a4a9ff1..7765c00dae6b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp @@ -30,7 +30,7 @@ template struct TxRequest { tx_context == other.tx_context; }; - template TxRequest> to_circuit_type(Composer& composer) const + template TxRequest> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -38,7 +38,7 @@ template struct TxRequest { auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - TxRequest> tx_request = { + TxRequest> tx_request = { to_ct(origin), to_circuit_type(function_data), to_ct(args_hash), diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index 9bf9eab8d71b..67a98210ee4b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -24,7 +24,7 @@ #include namespace { -// Composer +// Builder using C = UltraCircuitBuilder; // Types @@ -55,7 +55,7 @@ using aztec3::circuits::apps::notes::DefaultPrivateNote; using aztec3::circuits::apps::notes::DefaultSingletonPrivateNote; // State variables -// Get rid of ugly `Composer` template arg from our state var types: +// Get rid of ugly `Builder` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXO = UTXOStateVar; template using UTXOSet = UTXOSetStateVar; diff --git a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp index 537d9dc8ff81..cfb880a96ccb 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp @@ -12,7 +12,7 @@ using aztec3::circuits::abis::FunctionData; using NT = aztec3::utils::types::NativeTypes; -// template class FunctionExecutionContext; +// template class FunctionExecutionContext; template class Contract { using fr = typename NCT::fr; diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp index 6f90ced32977..e278b280054a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp @@ -34,34 +34,34 @@ using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using aztec3::utils::types::to_nt; -template class FunctionExecutionContext { +template class FunctionExecutionContext { using NT = NativeTypes; - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using address = typename CT::address; // We restrict only the opcodes to be able to push to the private members of the exec_ctx. // This will just help us build better separation of concerns. - friend class Opcodes; + friend class Opcodes; public: - Composer& composer; - OracleWrapperInterface& oracle; + Builder& composer; + OracleWrapperInterface& oracle; Contract* contract = nullptr; - std::array>, PRIVATE_CALL_STACK_LENGTH> + std::array>, PRIVATE_CALL_STACK_LENGTH> nested_private_call_exec_ctxs; // TODO: make this private! OptionalPrivateCircuitPublicInputs private_circuit_public_inputs{}; private: - std::vector>> new_notes; + std::vector>> new_notes; std::vector new_commitments; // Nullifier preimages can be got from the corresponding Note that they nullify. - std::vector>> nullified_notes; + std::vector>> nullified_notes; std::vector new_nullifiers; PrivateCircuitPublicInputs final_private_circuit_public_inputs{}; @@ -69,7 +69,7 @@ template class FunctionExecutionContext { bool is_finalised = false; public: - FunctionExecutionContext(Composer& composer, OracleWrapperInterface& oracle) + FunctionExecutionContext(Builder& composer, OracleWrapperInterface& oracle) : composer(composer) , oracle(oracle) , private_circuit_public_inputs(OptionalPrivateCircuitPublicInputs::create()) @@ -89,13 +89,13 @@ template class FunctionExecutionContext { // TODO: consider making this a debug-only method. // Not a reference, because we won't want to allow unsafe access. Hmmm, except it's a vector of pointers, so one can // still modify the pointers... But at least the original vector isn't being pushed-to or deleted-from. - std::vector>> get_new_notes() { return new_notes; } + std::vector>> get_new_notes() { return new_notes; } std::vector get_new_nullifiers() { return new_nullifiers; } - void push_new_note(NoteInterface* const note_ptr) { new_notes.push_back(note_ptr); } + void push_new_note(NoteInterface* const note_ptr) { new_notes.push_back(note_ptr); } - void push_newly_nullified_note(NoteInterface* note_ptr) { nullified_notes.push_back(note_ptr); } + void push_newly_nullified_note(NoteInterface* note_ptr) { nullified_notes.push_back(note_ptr); } PrivateCircuitPublicInputs get_final_private_circuit_public_inputs() { @@ -157,7 +157,7 @@ template class FunctionExecutionContext { std::array call( address const& f_contract_address, std::string const& f_name, - std::function&, std::vector)> f, + std::function&, std::vector)> f, std::vector const& args) { // Convert function name to bytes and use the first 4 bytes as the function encoding, for now: @@ -193,25 +193,25 @@ template class FunctionExecutionContext { NativeOracle f_oracle(oracle.native_oracle.db, f_contract_address.get_value(), - f_function_data_ct.template to_native_type(), - f_call_context_ct.template to_native_type(), + f_function_data_ct.template to_native_type(), + f_call_context_ct.template to_native_type(), oracle.get_msg_sender_private_key() .get_value() // TODO: consider whether a nested function should even be able to // access a private key, given that the call is now coming from a // contract (which cannot own a secret), rather than a human. ); - Composer f_composer = Composer("../barretenberg/cpp/srs_db/ignition"); + Builder f_composer = Builder("../barretenberg/cpp/srs_db/ignition"); - OracleWrapperInterface f_oracle_wrapper(f_composer, f_oracle); + OracleWrapperInterface f_oracle_wrapper(f_composer, f_oracle); // We need an exec_ctx reference which won't go out of scope, so we store a shared_ptr to the newly-created // exec_ctx in `this` exec_ctx. - auto f_exec_ctx = std::make_shared>(f_composer, f_oracle_wrapper); + auto f_exec_ctx = std::make_shared>(f_composer, f_oracle_wrapper); array_push(nested_private_call_exec_ctxs, f_exec_ctx); - auto native_args = to_nt(args); + auto native_args = to_nt(args); // This calls the function `f`, passing the arguments shown. // The f_exec_ctx will be populated with all the information about that function's execution. @@ -242,7 +242,7 @@ template class FunctionExecutionContext { auto call_stack_item_hash = f_call_stack_item_ct.hash(); - array_push(private_circuit_public_inputs.private_call_stack, call_stack_item_hash); + array_push(private_circuit_public_inputs.private_call_stack, call_stack_item_hash); // The return values are implicitly constrained by being returned as circuit types from this method, for // further use in the circuit. Note: ALL elements of the return_values array MUST be constrained, even if @@ -294,7 +294,7 @@ template class FunctionExecutionContext { // This is almost a visitor pattern. Call methods on each note. The note will choose what to do. for (size_t i = 0; i < new_notes.size(); ++i) { - NoteInterface& note = *new_notes[i]; + NoteInterface& note = *new_notes[i]; if (note.needs_nonce()) { const bool next_nullifier_available = new_nullifiers_copy.size() > used_nullifiers_count; @@ -322,7 +322,7 @@ template class FunctionExecutionContext { private_circuit_public_inputs.set_nullifiers(new_nullifiers); private_circuit_public_inputs.set_public(composer); final_private_circuit_public_inputs = - private_circuit_public_inputs.remove_optionality().template to_native_type(); + private_circuit_public_inputs.remove_optionality().template to_native_type(); is_finalised = true; } }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp index c4c8a81e4bb4..1da0b8655502 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp @@ -9,7 +9,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { -template class StateVar; +template class StateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { @@ -19,19 +19,19 @@ using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; -template class DefaultPrivateNote : public NoteInterface { +template class DefaultPrivateNote : public NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; using boolean = typename CT::boolean; - using NotePreimage = DefaultPrivateNotePreimage, ValueType>; - using NullifierPreimage = DefaultPrivateNoteNullifierPreimage>; + using NotePreimage = DefaultPrivateNotePreimage, ValueType>; + using NullifierPreimage = DefaultPrivateNoteNullifierPreimage>; - StateVar* state_var; + StateVar* state_var; private: std::optional commitment; @@ -42,7 +42,7 @@ template class DefaultPrivateNote : publ std::optional nullifier_preimage; public: - DefaultPrivateNote(StateVar* state_var, NotePreimage note_preimage) + DefaultPrivateNote(StateVar* state_var, NotePreimage note_preimage) : state_var(state_var), note_preimage(note_preimage){}; ~DefaultPrivateNote() override = default; @@ -77,7 +77,7 @@ template class DefaultPrivateNote : publ // return *partial_commitment; // }; - void constrain_against_advice(NoteInterface const& advice_note) override; + void constrain_against_advice(NoteInterface const& advice_note) override; bool needs_nonce() override; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp index 15826362d3ab..03dc64c7d1f8 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp @@ -26,35 +26,35 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template void DefaultPrivateNote::remove() +template void DefaultPrivateNote::remove() { - Opcodes::UTXO_NULL(state_var, *this); + Opcodes::UTXO_NULL(state_var, *this); } -template auto& DefaultPrivateNote::get_oracle() +template auto& DefaultPrivateNote::get_oracle() { return state_var->exec_ctx->oracle; } -template bool DefaultPrivateNote::is_partial_preimage() const +template bool DefaultPrivateNote::is_partial_preimage() const { const auto& [value, owner, creator_address, memo, salt, nonce, _] = note_preimage; return (!value || !owner || !creator_address || !memo || !salt || !nonce); } -template bool DefaultPrivateNote::is_partial_storage_slot() const +template bool DefaultPrivateNote::is_partial_storage_slot() const { return state_var->is_partial_slot; } -template bool DefaultPrivateNote::is_partial() const +template bool DefaultPrivateNote::is_partial() const { return is_partial_preimage() || is_partial_storage_slot(); } -template -typename CircuitTypes::fr DefaultPrivateNote::compute_commitment() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_commitment() { if (commitment.has_value()) { return *commitment; @@ -108,8 +108,8 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_com return *commitment; } -template -typename CircuitTypes::grumpkin_point DefaultPrivateNote::compute_partial_commitment() +template +typename CircuitTypes::grumpkin_point DefaultPrivateNote::compute_partial_commitment() { if (partial_commitment.has_value()) { info( @@ -161,8 +161,8 @@ typename CircuitTypes::grumpkin_point DefaultPrivateNote: return *partial_commitment; } -template -typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier() { if (is_partial()) { throw_or_abort("Can't nullify a partial note."); @@ -177,7 +177,7 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nul fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); nullifier = - DefaultPrivateNote::compute_nullifier(*commitment, owner_private_key, note_preimage.is_dummy); + DefaultPrivateNote::compute_nullifier(*commitment, owner_private_key, note_preimage.is_dummy); nullifier_preimage = { *commitment, owner_private_key, @@ -186,20 +186,21 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nul return *nullifier; }; -template -typename CircuitTypes::fr DefaultPrivateNote::compute_dummy_nullifier() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); fr const dummy_commitment = oracle.generate_random_element(); fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; - return DefaultPrivateNote::compute_nullifier(dummy_commitment, owner_private_key, is_dummy_commitment); + return DefaultPrivateNote::compute_nullifier(dummy_commitment, owner_private_key, is_dummy_commitment); }; -template -typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier( - fr const& commitment, fr const& owner_private_key, boolean const& is_dummy_commitment) +template +typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier(fr const& commitment, + fr const& owner_private_key, + boolean const& is_dummy_commitment) { /** * Hashing the private key in this way enables the following use case: @@ -236,11 +237,11 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nul return fr(blake_result); }; -template -void DefaultPrivateNote::constrain_against_advice(NoteInterface const& advice_note) +template +void DefaultPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const auto& advice_note_ref = dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { @@ -259,20 +260,20 @@ void DefaultPrivateNote::constrain_against_advice(NoteInterface bool DefaultPrivateNote::needs_nonce() +template bool DefaultPrivateNote::needs_nonce() { return !note_preimage.nonce; } -template -void DefaultPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) +template +void DefaultPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) { ASSERT(!note_preimage.nonce); note_preimage.nonce = nonce; }; -template -typename CircuitTypes::fr DefaultPrivateNote::generate_nonce() +template +typename CircuitTypes::fr DefaultPrivateNote::generate_nonce() { ASSERT(!note_preimage.nonce); note_preimage.nonce = compute_dummy_nullifier(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index a520e8e4b852..549c538dec25 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -31,7 +31,7 @@ template struct DefaultPrivateNotePreimage { bool operator==(DefaultPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Composer& composer) const + template auto to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -60,7 +60,7 @@ template struct DefaultPrivateNotePreimage { // When this method is called, this class must be templated over native types. We can avoid templating over the // circuit types (for the return values) (in order to make the calling syntax cleaner) with the below `decltype` // deduction of the _circuit_ version of template type `V`. - DefaultPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { + DefaultPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { circuit_value, to_ct(owner), to_ct(creator_address), to_ct(memo), to_ct(salt), to_ct(nonce), to_ct(is_dummy), }; @@ -68,11 +68,11 @@ template struct DefaultPrivateNotePreimage { return preimage; }; - template auto to_native_type() const + template auto to_native_type() const { static_assert(!std::is_same::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; // See `to_circuit_type()` for explanation of this code. const bool has_to_native_type = requires(V v) { v.to_native_type(); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp index fdc9658b4587..4e54498de030 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp @@ -21,15 +21,15 @@ template struct DefaultPrivateNoteNullifierPreimage { bool operator==(DefaultPrivateNoteNullifierPreimage const&) const = default; - template - DefaultPrivateNoteNullifierPreimage> to_circuit_type(Composer& composer) const + template + DefaultPrivateNoteNullifierPreimage> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - DefaultPrivateNoteNullifierPreimage> preimage = { + DefaultPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), to_ct(owner_private_key), to_ct(is_dummy), diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp index a3f231f13075..3edefba7d6a5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp @@ -9,7 +9,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { -template class StateVar; +template class StateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { @@ -19,19 +19,19 @@ using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; -template class DefaultSingletonPrivateNote : public NoteInterface { +template class DefaultSingletonPrivateNote : public NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; using boolean = typename CT::boolean; - using NotePreimage = DefaultSingletonPrivateNotePreimage, ValueType>; - using NullifierPreimage = DefaultSingletonPrivateNoteNullifierPreimage>; + using NotePreimage = DefaultSingletonPrivateNotePreimage, ValueType>; + using NullifierPreimage = DefaultSingletonPrivateNoteNullifierPreimage>; - StateVar* state_var; + StateVar* state_var; private: std::optional commitment; @@ -41,7 +41,7 @@ template class DefaultSingletonPrivateNo std::optional nullifier_preimage; public: - DefaultSingletonPrivateNote(StateVar* state_var, NotePreimage note_preimage) + DefaultSingletonPrivateNote(StateVar* state_var, NotePreimage note_preimage) : state_var(state_var), note_preimage(note_preimage){}; ~DefaultSingletonPrivateNote() override = default; @@ -66,7 +66,7 @@ template class DefaultSingletonPrivateNo return compute_nullifier(); }; - void constrain_against_advice(NoteInterface const& advice_note) override; + void constrain_against_advice(NoteInterface const& advice_note) override; bool needs_nonce() override; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp index 6d7c4173037a..f89ccd82070c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp @@ -26,35 +26,35 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template void DefaultSingletonPrivateNote::remove() +template void DefaultSingletonPrivateNote::remove() { - Opcodes::UTXO_NULL(state_var, *this); + Opcodes::UTXO_NULL(state_var, *this); } -template auto& DefaultSingletonPrivateNote::get_oracle() +template auto& DefaultSingletonPrivateNote::get_oracle() { return state_var->exec_ctx->oracle; } -template bool DefaultSingletonPrivateNote::is_partial_preimage() const +template bool DefaultSingletonPrivateNote::is_partial_preimage() const { const auto& [value, owner, salt, nonce] = note_preimage; return (!value || !owner || !salt || !nonce); } -template bool DefaultSingletonPrivateNote::is_partial_storage_slot() const +template bool DefaultSingletonPrivateNote::is_partial_storage_slot() const { return state_var->is_partial_slot; } -template bool DefaultSingletonPrivateNote::is_partial() const +template bool DefaultSingletonPrivateNote::is_partial() const { return is_partial_preimage() || is_partial_storage_slot(); } -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_commitment() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_commitment() { if (commitment.has_value()) { return *commitment; @@ -98,8 +98,8 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co return *commitment; } -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier() { if (is_partial()) { throw_or_abort("Can't nullify a partial note."); @@ -113,7 +113,7 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); - nullifier = DefaultSingletonPrivateNote::compute_nullifier(*commitment, owner_private_key); + nullifier = DefaultSingletonPrivateNote::compute_nullifier(*commitment, owner_private_key); nullifier_preimage = { *commitment, owner_private_key, @@ -121,20 +121,20 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co return *nullifier; }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_dummy_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); fr const dummy_commitment = oracle.generate_random_element(); fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; - return DefaultSingletonPrivateNote::compute_nullifier( + return DefaultSingletonPrivateNote::compute_nullifier( dummy_commitment, owner_private_key, is_dummy_commitment); }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier( +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier( fr const& commitment, fr const& owner_private_key, boolean const& is_dummy_commitment) { /** @@ -172,11 +172,11 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::co return fr(blake_result); }; -template -void DefaultSingletonPrivateNote::constrain_against_advice(NoteInterface const& advice_note) +template +void DefaultSingletonPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const auto& advice_note_ref = dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { @@ -193,28 +193,28 @@ void DefaultSingletonPrivateNote::constrain_against_advice(NoteInte assert_equal(this_preimage.nonce, advice_preimage.nonce); } -template bool DefaultSingletonPrivateNote::needs_nonce() +template bool DefaultSingletonPrivateNote::needs_nonce() { return !note_preimage.nonce; } -template -void DefaultSingletonPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) +template +void DefaultSingletonPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) { ASSERT(!note_preimage.nonce); note_preimage.nonce = nonce; }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::generate_nonce() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::generate_nonce() { ASSERT(!note_preimage.nonce); note_preimage.nonce = compute_dummy_nullifier(); return *(note_preimage.nonce); }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::get_initialisation_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::get_initialisation_nullifier() { auto& oracle = get_oracle(); @@ -234,7 +234,7 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::ge const fr compressed_storage_slot_point = CT::compress(hash_inputs, GeneratorIndex::INITIALISATION_NULLIFIER); // For now, we piggy-back on the regular nullifier function. - return DefaultSingletonPrivateNote::compute_nullifier( + return DefaultSingletonPrivateNote::compute_nullifier( compressed_storage_slot_point, owner_private_key, is_dummy); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp index 3e84dbb5f24d..810e8a5d7910 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp @@ -27,7 +27,7 @@ template struct DefaultSingletonPrivateNotePreimage { bool operator==(DefaultSingletonPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Composer& composer) const + template auto to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); @@ -56,7 +56,7 @@ template struct DefaultSingletonPrivateNotePreimage { // When this method is called, this class must be templated over native types. We can avoid templating over the // circuit types (for the return values) (in order to make the calling syntax cleaner) with the below `decltype` // deduction of the _circuit_ version of template type `V`. - DefaultSingletonPrivateNotePreimage, typename decltype(circuit_value)::value_type> + DefaultSingletonPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { circuit_value, to_ct(owner), @@ -67,11 +67,11 @@ template struct DefaultSingletonPrivateNotePreimage { return preimage; }; - template auto to_native_type() const + template auto to_native_type() const { static_assert(!std::is_same::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; // See `to_circuit_type()` for explanation of this code. const bool has_to_native_type = requires(V v) { v.to_native_type(); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp index 0e7765e2c456..c70a342ac148 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp @@ -21,15 +21,15 @@ template struct DefaultSingletonPrivateNoteNullifierPreimage { bool operator==(DefaultSingletonPrivateNoteNullifierPreimage const&) const = default; - template - DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Composer& composer) const + template + DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Builder& composer) const { static_assert((std::is_same::value)); // Capture the composer: auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - DefaultSingletonPrivateNoteNullifierPreimage> preimage = { + DefaultSingletonPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), to_ct(owner_private_key), to_ct(is_dummy), diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp index beddc7167100..58cda9e8a322 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp @@ -13,9 +13,9 @@ using aztec3::utils::types::CircuitTypes; * It's essentially a visitor pattern. The Opcodes and UTXOStateVar types can call all of these * methods on any Note, and the Note must choose whether to compute something, or whether to throw, for each method. */ -template class NoteInterface { +template class NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; @@ -40,7 +40,7 @@ template class NoteInterface { virtual fr get_initialisation_nullifier() = 0; - virtual void constrain_against_advice(NoteInterface const& advice_note) = 0; + virtual void constrain_against_advice(NoteInterface const& advice_note) = 0; virtual bool needs_nonce() = 0; diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp index 55c4aeacfa30..59e715f1d0f4 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp @@ -6,9 +6,9 @@ #include namespace aztec3::circuits::apps::state_vars { -template class StateVar; -template class UTXOStateVar; -template class UTXOSetStateVar; +template class StateVar; +template class UTXOStateVar; +template class UTXOSetStateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::opcodes { @@ -31,9 +31,9 @@ using plonk::stdlib::witness_t; * * TODO: Any oracle access or exec_ctx access should go through this class? */ -template class Opcodes { +template class Opcodes { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using address = typename CT::address; /** @@ -43,7 +43,7 @@ template class Opcodes { * - Validate the data */ template - static Note UTXO_SLOAD(UTXOStateVar* utxo_state_var, typename Note::NotePreimage const& advice); + static Note UTXO_SLOAD(UTXOStateVar* utxo_state_var, typename Note::NotePreimage const& advice); /** * @brief @@ -51,26 +51,26 @@ template class Opcodes { * - Generate constraints to prove each datum's existence in the tree * - Validate the data */ - template static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, + template static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, size_t const& num_notes, typename Note::NotePreimage const& advice); /** * @brief Compute and push a new nullifier to the public inputs of this exec_ctx. */ - template static void UTXO_NULL(StateVar* state_var, Note& note_to_nullify); + template static void UTXO_NULL(StateVar* state_var, Note& note_to_nullify); /** * @brief Compute and push a new commitment to the public inputs of this exec_ctx, BUT ALSO compute and produce an * initialisation nullifier, to prevent this note from being initialised again in the future. */ - template static void UTXO_INIT(StateVar* state_var, Note& note_to_initialise); + template static void UTXO_INIT(StateVar* state_var, Note& note_to_initialise); /** * @brief Compute and push a new commitment to the public inputs of this exec_ctx. */ template - static void UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage); + static void UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage); }; } // namespace aztec3::circuits::apps::opcodes diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp index f3716aefd4e0..9c49b7ea1b9b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp @@ -26,9 +26,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template template -Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, - typename Note::NotePreimage const& advice) +template template +Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, + typename Note::NotePreimage const& advice) { auto& oracle = utxo_state_var->exec_ctx->oracle; @@ -59,10 +59,10 @@ Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, return new_note; }; -template template -std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, - size_t const& num_notes, - typename Note::NotePreimage const& advice) +template template +std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, + size_t const& num_notes, + typename Note::NotePreimage const& advice) { auto& oracle = utxo_set_state_var->exec_ctx->oracle; @@ -103,8 +103,8 @@ std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* return new_notes; }; -template template -void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nullify) +template template +void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nullify) { typename CT::fr const nullifier = note_to_nullify.get_nullifier(); @@ -117,8 +117,8 @@ void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_n exec_ctx->nullified_notes.push_back(nullified_note_ptr); }; -template template -void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_initialise) +template template +void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_initialise) { typename CT::fr const init_nullifier = note_to_initialise.get_initialisation_nullifier(); @@ -134,8 +134,8 @@ void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_i exec_ctx->new_notes.push_back(init_note_ptr); }; -template template -void Opcodes::UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage) +template template +void Opcodes::UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage) { auto& exec_ctx = state_var->exec_ctx; diff --git a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp index 3377c6580e53..9157ce8eec76 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp @@ -25,19 +25,19 @@ using aztec3::utils::types::CircuitTypes; * could provide two different witnesses for a single thing). The Native oracle will throw if you try a double-query of * certain information. */ -template class OracleWrapperInterface { - using CT = CircuitTypes; +template class OracleWrapperInterface { + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; public: - Composer& composer; + Builder& composer; NativeOracle& native_oracle; // Initialise from Native. // Used when initialising for a user's first call. - OracleWrapperInterface(Composer& composer, NativeOracle& native_oracle) + OracleWrapperInterface(Builder& composer, NativeOracle& native_oracle) : composer(composer), native_oracle(native_oracle){}; fr& get_msg_sender_private_key() @@ -86,9 +86,9 @@ template class OracleWrapperInterface { template auto get_utxo_sload_datum(grumpkin_point const& storage_slot_point, NotePreimage const& advice) { - auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); + auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); - auto native_advice = advice.template to_native_type(); + auto native_advice = advice.template to_native_type(); auto native_utxo_sload_datum = native_oracle.get_utxo_sload_datum(native_storage_slot_point, native_advice); @@ -99,9 +99,9 @@ template class OracleWrapperInterface { size_t const& num_notes, NotePreimage const& advice) { - auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); + auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); - auto native_advice = advice.template to_native_type(); + auto native_advice = advice.template to_native_type(); auto native_utxo_sload_data = native_oracle.get_utxo_sload_data(native_storage_slot_point, num_notes, native_advice); diff --git a/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp index b304d32b2719..4584d1d145ec 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp @@ -8,8 +8,8 @@ // namespace aztec3::circuits::apps { // namespace { -// using Composer = aztec3::utils::types:plonk::stdlib::types::Composer; -// using CT = aztec3::utils::types::CircuitTypes; +// using Builder = aztec3::utils::types:plonk::stdlib::types::Builder; +// using CT = aztec3::utils::types::CircuitTypes; // using NT = aztec3::utils::types::NativeTypes; // // using plonk::stdlib::pedersen; // } // namespace diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp index 00fc50a71416..02a0b0aa3587 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp @@ -11,9 +11,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; // TODO: we can probably generalise this to be a PrimitiveStateVar for any stdlib primitive. -template class FieldStateVar : public StateVar { +template class FieldStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -29,22 +29,22 @@ template class FieldStateVar : public StateVar { FieldStateVar() = default; // Instantiate a top-level var: - FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, fr const& start_slot) - : StateVar(exec_ctx, state_var_name, start_slot){}; + FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, fr const& start_slot) + : StateVar(exec_ctx, state_var_name, start_slot){}; // Instantiate a var nested within a container: - FieldStateVar(FunctionExecutionContext* exec_ctx, + FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; - bool operator==(FieldStateVar const&) const = default; + bool operator==(FieldStateVar const&) const = default; }; -template inline std::ostream& operator<<(std::ostream& os, FieldStateVar const& v) +template inline std::ostream& operator<<(std::ostream& os, FieldStateVar const& v) { return os << v.value; } diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp index a387c720142b..b8e76a52a281 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -24,9 +24,9 @@ using aztec3::utils::types::NativeTypes; * more easily (it was difficult enough to get working). You'll notice, therefore, that there's no Key template type; * only a value template type (`V`). Adding a Key template type could be a future enhancement. */ -template class MappingStateVar : public StateVar { +template class MappingStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -37,22 +37,22 @@ template class MappingStateVar : public StateVar MappingStateVar() = default; // Instantiate a top-level mapping: - MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a nested mapping (within some other container). // Note: we assume this is called by some other StateVar, and the params have been computed correctly. // TODO: we could specify a set of `friend` classes which may access this method, to make this assumption more // explicit. - MappingStateVar(FunctionExecutionContext* exec_ctx, + MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; - bool operator==(MappingStateVar const&) const = default; + bool operator==(MappingStateVar const&) const = default; V& operator[](std::optional const& key) { return this->at(key); }; V& operator[](std::string const& question_mark) diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp index 06419fdb1674..7f1f9d85076d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp @@ -36,8 +36,8 @@ using aztec3::utils::types::NativeTypes; // start_slot_point becomes: prev_start_slot_point + k1 * B // at(k2).slot = new_start_slot_point + k2 * C -template -std::tuple MappingStateVar::compute_slot_point_at_mapping_key( +template +std::tuple MappingStateVar::compute_slot_point_at_mapping_key( NT::fr const& start_slot, size_t level_of_container_nesting, std::optional const& key) { bool const is_partial_slot = false; @@ -66,8 +66,8 @@ std::tuple MappingStateVar::comp return std::make_tuple(NativeTypes::commit(input_pairs), is_partial_slot); } -template -std::tuple::grumpkin_point, bool> MappingStateVar:: +template +std::tuple::grumpkin_point, bool> MappingStateVar:: compute_slot_point_at_mapping_key(std::optional const& key) { bool is_partial_slot = false; @@ -101,7 +101,7 @@ std::tuple::grumpkin_point, bool> MappingStateVa return std::make_tuple(CT::commit(input_pairs), is_partial_slot); } -template V& MappingStateVar::at(std::optional const& key) +template V& MappingStateVar::at(std::optional const& key) { // First calculate natively and check to see if we've already calculated this state's slot and stored it in the // cache, so we don't create unnecessary circuit gates: @@ -115,7 +115,7 @@ template V& MappingStateVar::at(std bool is_partial_slot = false; NativeTypes::grumpkin_point native_new_slot_point; - std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( + std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( this->start_slot.get_value(), this->level_of_container_nesting, native_key); NativeTypes::fr const native_lookup = native_new_slot_point.x; diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp index 718de6c3f705..0bead2a69c3d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp @@ -5,7 +5,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -20,15 +20,15 @@ using aztec3::utils::types::NativeTypes; * slots, and generating constraints for those slot derivations, in a protocol-consistent way, regardless of the app * being written. */ -template class StateVar { +template class StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; // The execution context of the function currently being executed. - FunctionExecutionContext* exec_ctx; + FunctionExecutionContext* exec_ctx; // Must match the name of a state which has been declared to the `Contract`. std::string state_var_name; @@ -57,11 +57,11 @@ template class StateVar { StateVar() = default; // Instantiate a top-level state: - StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name); + StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name); // Instantiate a state nested within a container: StateVar( - FunctionExecutionContext* exec_ctx, + FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, // the parent always calculates the storage_slot_point of its child. size_t level_of_container_nesting, // the parent always calculates the level of nesting of its child. @@ -72,7 +72,7 @@ template class StateVar { , level_of_container_nesting(level_of_container_nesting) , is_partial_slot(is_partial_slot){}; - bool operator==(StateVar const&) const = default; + bool operator==(StateVar const&) const = default; StateVar operator=(StateVar const& other) { diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp index dfbd18e1bbf4..b920e2ca8a4e 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp @@ -15,8 +15,8 @@ namespace aztec3::circuits::apps::state_vars { using aztec3::utils::types::CircuitTypes; using crypto::generators::generator_index_t; -template -StateVar::StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) +template +StateVar::StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) : exec_ctx(exec_ctx), state_var_name(state_var_name) { // NOLINTBEGIN(cppcoreguidelines-prefer-member-initializer) @@ -26,12 +26,12 @@ StateVar::StateVar(FunctionExecutionContext* exec_ctx, std:: // NOLINTEND(cppcoreguidelines-prefer-member-initializer) } -template typename CircuitTypes::grumpkin_point StateVar::compute_slot_point() +template typename CircuitTypes::grumpkin_point StateVar::compute_slot_point() { ASSERT(level_of_container_nesting == 0); return CT::commit({ start_slot }, { StorageSlotGeneratorIndex::BASE_SLOT }); } -// template class PrivateStateVar; +// template class PrivateStateVar; }; // namespace aztec3::circuits::apps::state_vars diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp index f74b60f57c93..69121dba555f 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -25,9 +25,9 @@ using aztec3::utils::types::NativeTypes; * designed. The Note type must implement the NoteInterface. TODO: maybe explicitly have this class act on the * NoteInterface type, rather than a template type. */ -template class UTXOSetStateVar : public StateVar { +template class UTXOSetStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -37,16 +37,16 @@ template class UTXOSetStateVar : public State UTXOSetStateVar() = default; // Instantiate a top-level var: - UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a var nested within a container: - UTXOSetStateVar(FunctionExecutionContext* exec_ctx, + UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; /** diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp index 0864cb2d2246..4f289777f2e8 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp @@ -11,17 +11,17 @@ using aztec3::circuits::apps::opcodes::Opcodes; namespace aztec3::circuits::apps::state_vars { -template -std::vector UTXOSetStateVar::get(size_t const& num_notes, - typename Note::NotePreimage const& advice) +template +std::vector UTXOSetStateVar::get(size_t const& num_notes, + typename Note::NotePreimage const& advice) { - return Opcodes::template UTXO_SLOAD(this, num_notes, advice); + return Opcodes::template UTXO_SLOAD(this, num_notes, advice); }; -template -void UTXOSetStateVar::insert(typename Note::NotePreimage new_note_preimage) +template +void UTXOSetStateVar::insert(typename Note::NotePreimage new_note_preimage) { - return Opcodes::template UTXO_SSTORE(this, new_note_preimage); + return Opcodes::template UTXO_SSTORE(this, new_note_preimage); }; } // namespace aztec3::circuits::apps::state_vars \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp index 456de1c9a81b..4e18980a8c21 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -26,9 +26,9 @@ using aztec3::utils::types::NativeTypes; * designed. The Note type must implement the NoteInterface. TODO: maybe explicitly have this class act on the * NoteInterface type, rather than a template type. */ -template class UTXOStateVar : public StateVar { +template class UTXOStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -39,16 +39,16 @@ template class UTXOStateVar : public StateVar UTXOStateVar() = default; // Instantiate a top-level var: - UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a var nested within a container: - UTXOStateVar(FunctionExecutionContext* exec_ctx, + UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; /** diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp index 10f963091278..5f7081546683 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp @@ -11,23 +11,23 @@ using aztec3::circuits::apps::opcodes::Opcodes; namespace aztec3::circuits::apps::state_vars { -template -Note UTXOStateVar::get(typename Note::NotePreimage const& advice) +template +Note UTXOStateVar::get(typename Note::NotePreimage const& advice) { - return Opcodes::template UTXO_SLOAD(this, advice); + return Opcodes::template UTXO_SLOAD(this, advice); }; -template -void UTXOStateVar::initialise(typename Note::NotePreimage new_note_preimage) +template +void UTXOStateVar::initialise(typename Note::NotePreimage new_note_preimage) { Note new_note{ this, new_note_preimage }; - Opcodes::template UTXO_INIT(this, new_note); + Opcodes::template UTXO_INIT(this, new_note); }; -template -void UTXOStateVar::insert(typename Note::NotePreimage new_note_preimage) +template +void UTXOStateVar::insert(typename Note::NotePreimage new_note_preimage) { - Opcodes::template UTXO_SSTORE(this, new_note_preimage); + Opcodes::template UTXO_SSTORE(this, new_note_preimage); }; } // namespace aztec3::circuits::apps::state_vars \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp index e960a9f3671d..4b193f601d7d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::apps::test_apps::basic_contract_deployment { -// Composer +// Builder using C = UltraCircuitBuilder; // Native and circuit types @@ -34,7 +34,7 @@ using aztec3::utils::types::to_ct; using apps::state_vars::MappingStateVar; using apps::state_vars::UTXOSetStateVar; -// Get rid of ugly `Composer` template arg from our state var types: +// Get rid of ugly `Builder` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXOSet = UTXOSetStateVar; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index fbd0bbb2d2f6..30d5da1dbbcb 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::apps::test_apps::escrow { -// Composer +// Builder using C = UltraCircuitBuilder; // Native and circuit types @@ -34,7 +34,7 @@ using aztec3::utils::types::to_ct; using apps::state_vars::MappingStateVar; using apps::state_vars::UTXOSetStateVar; -// Get rid of ugly `Composer` template arg from our state var types: +// Get rid of ugly `Builder` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXOSet = UTXOSetStateVar; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index ebd912a307b0..7f2e42a70a47 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -12,7 +12,7 @@ namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { -// Composer +// Builder using C = UltraCircuitBuilder; // Native and circuit types @@ -32,7 +32,7 @@ using aztec3::utils::types::to_ct; // StateVars using apps::state_vars::UTXOStateVar; -// Get rid of ugly `Composer` template arg from our state var types: +// Get rid of ugly `Builder` template arg from our state var types: template using UTXO = UTXOStateVar; using Note = apps::notes::DefaultSingletonPrivateNote; diff --git a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp index ce924ce7b73c..5f58c93bd3f5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp @@ -12,7 +12,7 @@ using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; /** - * @tparam NCT - NativeTypes or CircuitTypes + * @tparam NCT - NativeTypes or CircuitTypes * @tparam NotePreimage */ template struct UTXOSLoadDatum { @@ -28,7 +28,7 @@ template struct UTXOSLoadDatum { uint32 leaf_index; fr historic_private_data_tree_root = 0; - template auto to_circuit_type(Composer& composer) const + template auto to_circuit_type(Builder& composer) const { static_assert(std::is_same::value); @@ -37,7 +37,7 @@ template struct UTXOSLoadDatum { auto preimage_ct = preimage.to_circuit_type(composer); - UTXOSLoadDatum, decltype(preimage_ct)> datum = { + UTXOSLoadDatum, decltype(preimage_ct)> datum = { to_ct(commitment), to_ct(contract_address), preimage_ct, to_ct(sibling_path), to_ct(leaf_index), to_ct(historic_private_data_tree_root), }; diff --git a/circuits/cpp/src/aztec3/circuits/hash.hpp b/circuits/cpp/src/aztec3/circuits/hash.hpp index c87dc5c3cb9e..7b796fd308e4 100644 --- a/circuits/cpp/src/aztec3/circuits/hash.hpp +++ b/circuits/cpp/src/aztec3/circuits/hash.hpp @@ -183,8 +183,8 @@ std::array get_sibling_path(MerkleTree& tree, size_t leaf_index, size_t c return sibling_path; } -template -void check_membership(Composer& composer, +template +void check_membership(Builder& composer, typename NCT::fr const& value, typename NCT::fr const& index, std::array const& sibling_path, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 5b26c060c9e3..7f3127004547 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -49,7 +49,7 @@ TEST_F(private_kernel_tests, basic) false, deposit, { amount, asset_id, memo }, encrypted_logs_hash, encrypted_log_preimages_length, true); // Execute and prove the first kernel iteration - Composer private_kernel_composer; + Builder private_kernel_composer; auto const& public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs, true); // Check the private kernel circuit @@ -70,7 +70,7 @@ TEST_F(private_kernel_tests, circuit_cbinds) // first run actual simulation to get public inputs auto const& private_inputs = do_private_call_get_kernel_inputs_init( true, constructor, { arg0, arg1, arg2 }, encrypted_logs_hash, encrypted_log_preimages_length, true); - DummyComposer composer = DummyComposer("private_kernel_tests__circuit_create_proof_cbinds"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__circuit_create_proof_cbinds"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); // serialize expected public inputs for later comparison diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index ae81049c6a81..2bb000f603eb 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -9,9 +9,9 @@ #include namespace { -using Composer = UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::abis::TxRequest; using aztec3::circuits::abis::private_kernel::PrivateCallData; @@ -63,7 +63,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyComposer composer = DummyComposer("private_kernel__sim_init"); + DummyBuilder composer = DummyBuilder("private_kernel__sim_init"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); @@ -94,7 +94,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyComposer composer = DummyComposer("private_kernel__sim_inner"); + DummyBuilder composer = DummyBuilder("private_kernel__sim_inner"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index ea3eef29577d..b06d39e835c6 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -13,7 +13,7 @@ #include "aztec3/utils/array.hpp" #include "aztec3/utils/dummy_composer.hpp" -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::ContractDeploymentData; using aztec3::circuits::abis::ContractLeafPreimage; @@ -25,13 +25,13 @@ using aztec3::circuits::abis::NewContractData; using aztec3::utils::array_push; using aztec3::utils::is_array_empty; using aztec3::utils::push_array_to_array; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using aztec3::circuits::abis::private_kernel::PrivateCallData; namespace aztec3::circuits::kernel::private_kernel { -void common_validate_call_stack(DummyComposer& composer, PrivateCallData const& private_call) +void common_validate_call_stack(DummyBuilder& composer, PrivateCallData const& private_call) { const auto& stack = private_call.call_stack_item.public_inputs.private_call_stack; const auto& preimages = private_call.private_call_stack_preimages; @@ -64,7 +64,7 @@ void common_validate_call_stack(DummyComposer& composer, PrivateCallData con * @param historic_private_data_tree_root This is a reference to the historic root which all * read requests are checked against here. */ -void common_validate_read_requests(DummyComposer& composer, +void common_validate_read_requests(DummyBuilder& composer, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, @@ -104,7 +104,7 @@ void common_validate_read_requests(DummyComposer& composer, } } -void common_update_end_values(DummyComposer& composer, +void common_update_end_values(DummyBuilder& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs) { @@ -201,7 +201,7 @@ void common_update_end_values(DummyComposer& composer, } } -void common_contract_logic(DummyComposer& composer, +void common_contract_logic(DummyBuilder& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp index 912aad1c15e5..f7539607882e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp @@ -14,7 +14,7 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::ContractDeploymentData; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::MembershipWitness; @@ -23,20 +23,20 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; // TODO(suyash): Add comments to these as well as other functions in PKC-init. -void common_validate_call_stack(DummyComposer& composer, PrivateCallData const& private_call); +void common_validate_call_stack(DummyBuilder& composer, PrivateCallData const& private_call); -void common_validate_read_requests(DummyComposer& composer, +void common_validate_read_requests(DummyBuilder& composer, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, NT::fr const& historic_private_data_tree_root); -void common_update_end_values(DummyComposer& composer, +void common_update_end_values(DummyBuilder& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs); -void common_contract_logic(DummyComposer& composer, +void common_contract_logic(DummyBuilder& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp index bf634d50eb71..143eb0b1d687 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp @@ -9,19 +9,19 @@ namespace aztec3::circuits::kernel::private_kernel { -using Composer = UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; // Generic: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using DB = oracle::FakeDB; using oracle::NativeOracle; -using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; +using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; -using FunctionExecutionContext = aztec3::circuits::apps::FunctionExecutionContext; +using FunctionExecutionContext = aztec3::circuits::apps::FunctionExecutionContext; } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp index c6b631dac9e1..056e640f44f5 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp @@ -22,7 +22,7 @@ namespace aztec3::circuits::kernel::private_kernel { // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Composer& composer, +// CT::AggregationObject verify_proofs(Builder& composer, // PrivateKernelInputsInit const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) @@ -67,7 +67,7 @@ void initialise_end_values(PrivateKernelInputsInit const& private_inputs, public_inputs.constants = constants; } -void validate_this_private_call_against_tx_request(DummyComposer& composer, +void validate_this_private_call_against_tx_request(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs) { // TODO(mike): this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' @@ -93,7 +93,7 @@ void validate_this_private_call_against_tx_request(DummyComposer& composer, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); }; -void validate_inputs(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs) +void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; @@ -123,7 +123,7 @@ void validate_inputs(DummyComposer& composer, PrivateKernelInputsInit const& CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); } -void update_end_values(DummyComposer& composer, +void update_end_values(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -149,7 +149,7 @@ void update_end_values(DummyComposer& composer, // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyComposer& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs) { // We'll be pushing data to this during execution of this circuit. diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp index c9d86e0a397e..2fa45b417383 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp @@ -11,9 +11,9 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; // using abis::private_kernel::PublicInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyComposer& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp index 7d342ad3708a..285567194f80 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp @@ -56,7 +56,7 @@ TEST_F(native_private_kernel_init_tests, deposit) auto const& private_inputs = do_private_call_get_kernel_inputs_init( false, deposit, standard_test_args(), encrypted_logs_hash, encrypted_log_preimages_length); - DummyComposer composer = DummyComposer("private_kernel_tests__native_deposit"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__native_deposit"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_TRUE(validate_no_new_deployed_contract(public_inputs)); @@ -90,7 +90,7 @@ TEST_F(native_private_kernel_init_tests, deposit) TEST_F(native_private_kernel_init_tests, basic_contract_deployment) { auto const& private_inputs = do_private_call_get_kernel_inputs_init(true, constructor, standard_test_args()); - DummyComposer composer = DummyComposer("private_kernel_tests__native_basic_contract_deployment"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__native_basic_contract_deployment"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_TRUE(validate_deployed_contract_address(private_inputs, public_inputs)); @@ -119,8 +119,8 @@ TEST_F(native_private_kernel_init_tests, DISABLED_contract_deployment_call_stack // Randomise the second item in the private call stack (i.e. hash of the private call item). private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[1] = NT::fr::random_element(); - DummyComposer composer = - DummyComposer("private_kernel_tests__contract_deployment_call_stack_item_hash_mismatch_fails"); + DummyBuilder composer = + DummyBuilder("private_kernel_tests__contract_deployment_call_stack_item_hash_mismatch_fails"); native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_EQ(composer.failed(), true); @@ -135,8 +135,8 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_construct // Pollute the constructor vk hash in the tx_request. private_inputs.tx_request.tx_context.contract_deployment_data.constructor_vk_hash = NT::fr::random_element(); - DummyComposer composer = - DummyComposer("private_kernel_tests__contract_deployment_incorrect_constructor_vk_hash_fails"); + DummyBuilder composer = + DummyBuilder("private_kernel_tests__contract_deployment_incorrect_constructor_vk_hash_fails"); native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_EQ(composer.failed(), true); @@ -154,8 +154,7 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_contract_ private_inputs.tx_request.origin = random_address; private_inputs.private_call.call_stack_item.contract_address = random_address; - DummyComposer composer = - DummyComposer("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_EQ(composer.failed(), true); @@ -174,7 +173,7 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_contract_address_mi private_inputs.private_call.call_stack_item.contract_address = random_contract_address; // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -191,7 +190,7 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_function_data_misma private_inputs.tx_request.function_data.function_selector = numeric::random::get_engine().get_random_uint32(); // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -211,7 +210,7 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_args_hash_mismatch_ private_inputs.tx_request.args_hash = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -231,7 +230,7 @@ TEST_F(native_private_kernel_init_tests, private_function_is_private_false_fails private_inputs.private_call.call_stack_item.function_data.is_private = false; // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__private_function_is_private_false_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_is_private_false_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -251,7 +250,7 @@ TEST_F(native_private_kernel_init_tests, private_function_static_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_static_call = true; // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__private_function_static_call_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_static_call_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -268,7 +267,7 @@ TEST_F(native_private_kernel_init_tests, private_function_delegate_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__private_function_delegate_call_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_delegate_call_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -286,8 +285,8 @@ TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_cont NT::fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_storage_contract_address_fails"); + DummyBuilder composer = + DummyBuilder("private_kernel_tests__private_function_incorrect_storage_contract_address_fails"); native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks @@ -312,7 +311,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_request"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_request"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -340,7 +339,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -368,7 +367,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -406,7 +405,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_root_mismatch"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_root_mismatch"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -432,7 +431,7 @@ TEST_F(native_private_kernel_init_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_no_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_no_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -461,7 +460,7 @@ TEST_F(native_private_kernel_init_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_one_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_one_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -490,7 +489,7 @@ TEST_F(native_private_kernel_init_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_two_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_two_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -520,7 +519,7 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_max_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -558,8 +557,7 @@ TEST_F(native_private_kernel_init_tests, native_one_transient_read_requests_work read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_init_tests__native_one_transient_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_one_transient_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -590,8 +588,8 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_ read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_init_tests__native_max_read_requests_one_transient_works"); + DummyBuilder composer = + DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_one_transient_works"); auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp index ce799bdba995..9960180808a9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp @@ -16,14 +16,14 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; using aztec3::utils::array_length; using aztec3::utils::array_pop; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // using plonk::stdlib::merkle_tree:: // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Composer& composer, +// CT::AggregationObject verify_proofs(Builder& composer, // PrivateInputs const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) @@ -41,7 +41,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // return aggregation_object; // } -void validate_this_private_call_hash(DummyComposer& composer, +void validate_this_private_call_hash(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -56,7 +56,7 @@ void validate_this_private_call_hash(DummyComposer& composer, CircuitErrorCode::PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); }; -void validate_contract_tree_root(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs) +void validate_contract_tree_root(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) { auto const& purported_contract_tree_root = private_inputs.private_call.call_stack_item.public_inputs.historic_contract_tree_root; @@ -69,7 +69,7 @@ void validate_contract_tree_root(DummyComposer& composer, PrivateKernelInputsInn CircuitErrorCode::PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH); } -void validate_inputs(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs) +void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; @@ -98,7 +98,7 @@ void validate_inputs(DummyComposer& composer, PrivateKernelInputsInner const // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyComposer& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) { // We'll be pushing data to this during execution of this circuit. diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp index c9dbd8fa7d93..e832b6981ac9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp @@ -10,9 +10,9 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyComposer& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp index fb68a4f50458..07c73b53d2e2 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp @@ -54,8 +54,7 @@ TEST_F(native_private_kernel_inner_tests, private_function_zero_storage_contract private_inputs.private_call.call_stack_item.hash(); // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_zero_storage_contract_address_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_zero_storage_contract_address_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -74,7 +73,7 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_tr .contract_tree_root = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = DummyComposer("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -95,8 +94,7 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -115,8 +113,8 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); + DummyBuilder composer = + DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -136,8 +134,7 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -156,8 +153,8 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); + DummyBuilder composer = + DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -177,8 +174,7 @@ TEST_F(native_private_kernel_inner_tests, DISABLED_private_function_incorrect_ca private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[0] = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyComposer composer = - DummyComposer("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); + DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks @@ -192,7 +188,7 @@ TEST_F(native_private_kernel_inner_tests, DISABLED_private_function_incorrect_ca TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregating_too_many_commitments) { // Negative test to check if push_array_to_array fails if two many commitments are merged together - DummyComposer composer = DummyComposer("should_fail_if_aggregating_too_many_commitments"); + DummyBuilder composer = DummyBuilder("should_fail_if_aggregating_too_many_commitments"); PrivateKernelInputsInner private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); @@ -242,7 +238,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_request"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_request"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -269,7 +265,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -296,7 +292,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -333,7 +329,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_root_mismatch"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_root_mismatch"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -356,7 +352,7 @@ TEST_F(native_private_kernel_inner_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_no_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_no_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -384,7 +380,7 @@ TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_one_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_one_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -412,7 +408,7 @@ TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_two_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_two_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -441,7 +437,7 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_max_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -471,8 +467,7 @@ TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_wor read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); + DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); @@ -505,8 +500,8 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_inner_tests__native_max_read_requests_one_transient_works"); + DummyBuilder composer = + DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_one_transient_works"); auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp index 78946339927e..da0e7f22b82f 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp @@ -13,14 +13,14 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // TODO(jeanmon): the following code will be optimized based on hints regarding matching // a read request and commitment, i.e., we get pairs i,j such that read_requests[i] == new_commitments[j] // Relevant task: https://github.com/AztecProtocol/aztec-packages/issues/892 -void chop_pending_commitments(DummyComposer& composer, +void chop_pending_commitments(DummyBuilder& composer, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, @@ -53,7 +53,7 @@ void chop_pending_commitments(DummyComposer& composer, utils::array_rearrange(new_commitments); } -KernelCircuitPublicInputs native_private_kernel_circuit_ordering(DummyComposer& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_ordering(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) { // We'll be pushing data to this during execution of this circuit. diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp index 5108f3d7c7e0..d44c1179b2cb 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp @@ -10,9 +10,9 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_private_kernel_circuit_ordering( - DummyComposer& composer, PrivateKernelInputsInner const& private_inputs); + DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp index 02364ef41662..8dbc6baf06b8 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp @@ -48,8 +48,8 @@ TEST_F(native_private_kernel_ordering_tests, native_one_read_request_choping_com private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_ordering_tests__native_one_read_request_choping_commitment_works"); + DummyBuilder composer = + DummyBuilder("native_private_kernel_ordering_tests__native_one_read_request_choping_commitment_works"); auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); auto failure = composer.get_first_failure(); @@ -85,8 +85,8 @@ TEST_F(native_private_kernel_ordering_tests, native_read_requests_choping_commit private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = - DummyComposer("native_private_kernel_ordering_tests__native_read_requests_choping_commitment_works"); + DummyBuilder composer = + DummyBuilder("native_private_kernel_ordering_tests__native_read_requests_choping_commitment_works"); auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); auto failure = composer.get_first_failure(); @@ -127,7 +127,7 @@ TEST_F(native_private_kernel_ordering_tests, native_read_request_unknown_fails) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyComposer composer = DummyComposer("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); + DummyBuilder composer = DummyBuilder("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); auto failure = composer.get_first_failure(); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index d4fe59b78890..9a376c22308a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -27,7 +27,7 @@ using aztec3::circuits::silo_nullifier; // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // private_call.call_stack_item.public_inputs! -CT::AggregationObject verify_proofs(Composer& composer, PrivateKernelInputsInner const& private_inputs) +CT::AggregationObject verify_proofs(Builder& composer, PrivateKernelInputsInner const& private_inputs) { // compute P0, P1 for private function proof CT::AggregationObject aggregation_object = @@ -92,8 +92,8 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne const auto& is_static_call = private_call_public_inputs.call_context.is_static_call; // No state changes are allowed for static calls: - is_static_call.must_imply(is_array_empty(new_commitments) == true); - is_static_call.must_imply(is_array_empty(new_nullifiers) == true); + is_static_call.must_imply(is_array_empty(new_commitments) == true); + is_static_call.must_imply(is_array_empty(new_nullifiers) == true); // TODO: name change (just contract_address) const auto& storage_contract_address = private_call_public_inputs.call_context.storage_contract_address; @@ -135,7 +135,7 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne // push the contract address nullifier to nullifier vector CT::fr const conditional_contract_address_nullifier = CT::fr::conditional_assign(is_contract_deployment, contract_address_nullifier, CT::fr(0)); - array_push(public_inputs.end.new_nullifiers, conditional_contract_address_nullifier); + array_push(public_inputs.end.new_nullifiers, conditional_contract_address_nullifier); // Add new contract data if its a contract deployment function auto const new_contract_data = NewContractData{ @@ -144,8 +144,8 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne .function_tree_root = contract_deployment_data.function_tree_root, }; - array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, - new_contract_data); + array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, + new_contract_data); } { // commitments, nullifiers, and contracts @@ -161,14 +161,14 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne } // Add new commitments/etc to AggregatedData - push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); - push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); + push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); + push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); } { // call stacks // copy the private function circuit's callstack into the AggregatedData const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; - push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); + push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); } // { @@ -193,7 +193,7 @@ void validate_this_private_call_hash(PrivateKernelInputsInner const& private const auto& start = private_inputs.previous_kernel.public_inputs.end; // TODO: this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' tx, // and the 'gas rebate' tx). - const auto this_private_call_hash = array_pop(start.private_call_stack); + const auto this_private_call_hash = array_pop(start.private_call_stack); const auto calculated_this_private_call_hash = private_inputs.private_call.call_stack_item.hash(); this_private_call_hash.assert_equal(calculated_this_private_call_hash, "this private_call_hash does not reconcile"); @@ -243,9 +243,9 @@ void validate_inputs(PrivateKernelInputsInner const& private_inputs, bool fi // These lengths are calculated by counting entries until a non-zero one is encountered // True array length is constant which is a property we need for circuit inputs, // but we want to know "length" in terms of how many nonzero entries have been inserted - CT::fr const start_private_call_stack_length = array_length(start.private_call_stack); - CT::fr const start_public_call_stack_length = array_length(start.public_call_stack); - CT::fr const start_new_l2_to_l1_msgs_length = array_length(start.new_l2_to_l1_msgs); + CT::fr const start_private_call_stack_length = array_length(start.private_call_stack); + CT::fr const start_public_call_stack_length = array_length(start.public_call_stack); + CT::fr const start_new_l2_to_l1_msgs_length = array_length(start.new_l2_to_l1_msgs); // Recall: we can't do traditional `if` statements in a circuit; all code paths are always executed. The below is // some syntactic sugar, which seeks readability similar to an `if` statement. @@ -306,7 +306,7 @@ void validate_inputs(PrivateKernelInputsInner const& private_inputs, bool fi // TODO: decide what to return. // TODO: is there a way to identify whether an input has not been used by ths circuit? This would help us more-safely // ensure we're constraining everything. -KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, +KernelCircuitPublicInputs private_kernel_circuit(Builder& composer, PrivateKernelInputsInner const& _private_inputs, bool first_iteration) { @@ -336,7 +336,7 @@ KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, public_inputs.set_public(); - return public_inputs.to_native_type(); + return public_inputs.to_native_type(); }; } // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp index 1f006c8ea3fd..a35865f68545 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp @@ -10,7 +10,7 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, +KernelCircuitPublicInputs private_kernel_circuit(Builder& composer, PrivateKernelInputsInner const& private_inputs, bool first_iteration); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp index dade8da54e3b..66fe8732d997 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp @@ -228,7 +228,7 @@ std::pair, ContractDeploymentData> create_private_call_d // Create a private circuit/call using composer, oracles, execution context // Generate its proof and public inputs for submission with a TX request //*************************************************************************** - Composer private_circuit_composer = Composer("../barretenberg/cpp/srs_db/ignition"); + Builder private_circuit_composer = Builder("../barretenberg/cpp/srs_db/ignition"); DB dummy_db; NativeOracle oracle = diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp index 24288935d92d..493adf6378a2 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp @@ -28,14 +28,14 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::utils::zero_array; // A type representing any private circuit function // (for now it works for deposit and constructor) using private_function = std::function( - FunctionExecutionContext&, std::vector const&)>; + FunctionExecutionContext&, std::vector const&)>; } // namespace diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index 2a81d464323d..17f5a98564ff 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -113,7 +113,7 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) PreviousKernelData const init_previous_kernel{}; auto crs_factory = barretenberg::srs::get_crs_factory(); - Composer mock_kernel_composer; + Builder mock_kernel_composer; auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs); NT::Proof const mock_kernel_proof = diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index 602c15759934..321b093d2237 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -28,7 +28,7 @@ #include namespace { -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::CallContext; @@ -472,8 +472,7 @@ void validate_private_data_propagation(const PublicKernelInputs& inputs, TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__only_valid_public_data_reads_should_be_propagated"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__only_valid_public_data_reads_should_be_propagated"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // modify the contract storage reads so only 2 are valid and only those should be propagated @@ -494,9 +493,9 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyBuilder.failed()); ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); @@ -516,7 +515,7 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__only_valid_update_requests_should_be_propagated"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__only_valid_update_requests_should_be_propagated"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // modify the contract storage update requests so only 2 are valid and only those should be propagated @@ -539,9 +538,9 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyBuilder.failed()); ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); @@ -563,90 +562,89 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) TEST(public_kernel_tests, constructor_should_fail) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__constructor_should_fail"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__constructor_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.is_constructor = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); } TEST(public_kernel_tests, constructor_should_fail_2) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__constructor_should_fail_2"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__constructor_should_fail_2"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.public_inputs.call_context.is_contract_deployment = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); } TEST(public_kernel_tests, no_bytecode_hash_should_fail) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__no_bytecode_hash_should_fail"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__no_bytecode_hash_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.bytecode_hash = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); } TEST(public_kernel_tests, contract_address_must_be_valid) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__contract_address_must_be_valid"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__contract_address_must_be_valid"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.contract_address = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); } TEST(public_kernel_tests, function_selector_must_be_valid) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__function_selector_must_be_valid"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__function_selector_must_be_valid"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.function_selector = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); } TEST(public_kernel_tests, private_call_should_fail) { - DummyComposer dummyComposer = DummyComposer("public_kernel_tests__private_call_should_fail"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__private_call_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.is_private = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); } TEST(public_kernel_tests, inconsistent_call_hash_should_fail) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyComposer dummyComposer = - DummyComposer(format("public_kernel_tests__inconsistent_call_hash_should_fail-", i)); + DummyBuilder dummyBuilder = DummyBuilder(format("public_kernel_tests__inconsistent_call_hash_should_fail-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // change a value of something in the call stack pre-image inputs.public_call.public_call_stack_preimages[i].public_inputs.args_hash++; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_MISMATCH); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_MISMATCH); } } TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_calls) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyComposer dummyComposer = DummyComposer( - format("public_kernel_tests__incorrect_storage_contract_address_fails_for_regular_calls-", i)); + DummyBuilder dummyBuilder = + DummyBuilder(format("public_kernel_tests__incorrect_storage_contract_address_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // change the storage contract address so it does not equal the contract address @@ -654,9 +652,9 @@ TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_c NT::fr(inputs.public_call.public_call_stack_preimages[i].contract_address) + 1; inputs.public_call.public_call_stack_preimages[i].public_inputs.call_context.storage_contract_address = new_contract_address; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); } } @@ -664,24 +662,24 @@ TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_c TEST(public_kernel_tests, incorrect_msg_sender_fails_for_regular_calls) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyComposer dummyComposer = - DummyComposer(format("public_kernel_tests__incorrect_msg_sender_fails_for_regular_calls-", i)); + DummyBuilder dummyBuilder = + DummyBuilder(format("public_kernel_tests__incorrect_msg_sender_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // set the msg sender to be the address of the called contract, which is wrong const auto new_msg_sender = inputs.public_call.public_call_stack_preimages[i].contract_address; // change the storage contract address so it does not equal the contract address inputs.public_call.public_call_stack_preimages[i].public_inputs.call_context.msg_sender = new_msg_sender; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); } } TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -713,14 +711,14 @@ TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_ } inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -744,16 +742,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call) { - DummyComposer dummyComposer = DummyComposer( - "public_kernel_tests__public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -775,16 +773,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contr inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -808,16 +806,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contra inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); } TEST(public_kernel_tests, public_kernel_circuit_only_checks_non_empty_call_stacks) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_only_checks_non_empty_call_stacks"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_only_checks_non_empty_call_stacks"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -847,86 +845,86 @@ TEST(public_kernel_tests, public_kernel_circuit_only_checks_non_empty_call_stack // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, public_kernel_circuit_with_private_previous_kernel_should_succeed) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_with_private_previous_kernel_should_succeed"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_with_private_previous_kernel_should_succeed"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_previous_private_kernel) { - DummyComposer dummyComposer = DummyComposer( - "public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_private_kernel"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_private_kernel"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); // test that the prior set of private kernel public inputs were copied to the outputs validate_private_data_propagation(inputs, public_inputs); validate_public_kernel_outputs_correctly_propagated(inputs, public_inputs); - ASSERT_FALSE(dummyComposer.failed()); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, private_previous_kernel_non_empty_private_call_stack_should_fail) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__private_previous_kernel_non_empty_private_call_stack_should_fail"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__private_previous_kernel_non_empty_private_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.end.private_call_stack[0] = 1; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); } TEST(public_kernel_tests, private_previous_kernel_empty_public_call_stack_should_fail) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__private_previous_kernel_empty_public_call_stack_should_fail"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__private_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.end.public_call_stack = zero_array(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); } TEST(public_kernel_tests, private_previous_kernel_non_private_previous_kernel_should_fail) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__private_previous_kernel_non_private_previous_kernel_should_fail"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__private_previous_kernel_non_private_previous_kernel_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.is_private = false; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); } TEST(public_kernel_tests, previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call) { - DummyComposer dummyComposer = DummyComposer( + DummyBuilder dummyBuilder = DummyBuilder( "public_kernel_tests__previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // the function call has contract storage update requests so setting it to static should fail inputs.public_call.call_stack_item.public_inputs.call_context.is_static_call = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); ASSERT_EQ( - dummyComposer.get_first_failure().code, + dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); } TEST(public_kernel_tests, previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call) { - DummyComposer dummyComposer = DummyComposer( + DummyBuilder dummyBuilder = DummyBuilder( "public_kernel_tests__previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); @@ -934,47 +932,47 @@ TEST(public_kernel_tests, previous_private_kernel_fails_if_incorrect_storage_con // delegate call inputs.public_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); } TEST(public_kernel_tests, public_kernel_circuit_with_public_previous_kernel_should_succeed) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_kernel_circuit_with_public_previous_kernel_should_succeed"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_kernel_circuit_with_public_previous_kernel_should_succeed"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(false); - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_FALSE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, public_previous_kernel_empty_public_call_stack_should_fail) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_previous_kernel_empty_public_call_stack_should_fail"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); inputs.previous_kernel.public_inputs.end.public_call_stack = zero_array(); - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); } TEST(public_kernel_tests, public_previous_kernel_private_previous_kernel_should_fail) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__public_previous_kernel_private_previous_kernel_should_fail"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__public_previous_kernel_private_previous_kernel_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); inputs.previous_kernel.public_inputs.is_private = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); } TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_previous_public_kernel) { - DummyComposer dummyComposer = - DummyComposer("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_public_kernel"); + DummyBuilder dummyBuilder = + DummyBuilder("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_public_kernel"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // setup 2 previous data writes on the public inputs @@ -1026,7 +1024,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre initial_l2_to_l1_messages[0] = fr(1); inputs.previous_kernel.public_inputs.end.new_l2_to_l1_msgs = initial_l2_to_l1_messages; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); // test that the prior set of private kernel public inputs were copied to the outputs validate_private_data_propagation(inputs, public_inputs); @@ -1097,28 +1095,28 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre expected_new_messages, public_inputs.end.new_l2_to_l1_msgs)); - ASSERT_FALSE(dummyComposer.failed()); + ASSERT_FALSE(dummyBuilder.failed()); } TEST(public_kernel_tests, previous_public_kernel_fails_if_contract_storage_update_requests_on_static_call) { - DummyComposer dummyComposer = DummyComposer( + DummyBuilder dummyBuilder = DummyBuilder( "public_kernel_tests__previous_public_kernel_fails_if_contract_storage_update_requests_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has contract storage update requests so setting it to static should fail inputs.public_call.call_stack_item.public_inputs.call_context.is_static_call = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); ASSERT_EQ( - dummyComposer.get_first_failure().code, + dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); } TEST(public_kernel_tests, previous_public_kernel_fails_if_incorrect_storage_contract_on_delegate_call) { - DummyComposer dummyComposer = DummyComposer( + DummyBuilder dummyBuilder = DummyBuilder( "public_kernel_tests__previous_public_kernel_fails_if_incorrect_storage_contract_on_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); @@ -1126,15 +1124,15 @@ TEST(public_kernel_tests, previous_public_kernel_fails_if_incorrect_storage_cont // delegate call inputs.public_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); } TEST(public_kernel_tests, public_kernel_fails_creating_new_commitments_on_static_call) { - DummyComposer dummyComposer = DummyComposer("public_kernel_fails_creating_new_commitments_on_static_call"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_fails_creating_new_commitments_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has the contract address and storage contract address equal and so it should fail for a @@ -1150,15 +1148,15 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_commitments_on_static get_call_stack_item_hash(inputs.public_call.call_stack_item); // Update call stack hash - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); } TEST(public_kernel_tests, public_kernel_fails_creating_new_nullifiers_on_static_call) { - DummyComposer dummyComposer = DummyComposer("public_kernel_fails_creating_new_nullifiers_on_static_call"); + DummyBuilder dummyBuilder = DummyBuilder("public_kernel_fails_creating_new_nullifiers_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has the contract address and storage contract address equal and so it should fail for a @@ -1176,9 +1174,9 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_nullifiers_on_static_ get_call_stack_item_hash(inputs.public_call.call_stack_item); // Update call stack hash - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); - ASSERT_TRUE(dummyComposer.failed()); - ASSERT_EQ(dummyComposer.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + ASSERT_TRUE(dummyBuilder.failed()); + ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index 9586857bcabe..99a23548b212 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -12,9 +12,9 @@ #include namespace { -using Composer = UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_private_previous_kernel; @@ -48,7 +48,7 @@ WASM_EXPORT size_t public_kernel__init_verification_key(uint8_t const* pk_buf, u } CBIND(public_kernel__sim, [](PublicKernelInputs public_kernel_inputs) { - DummyComposer composer = DummyComposer("public_kernel__sim"); + DummyBuilder composer = DummyBuilder("public_kernel__sim"); KernelCircuitPublicInputs const result = public_kernel_inputs.previous_kernel.public_inputs.is_private ? native_public_kernel_circuit_private_previous_kernel(composer, public_kernel_inputs) diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp index 6a4219b4930d..bcf1bcc056dd 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp @@ -40,7 +40,7 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_this_public_call_hash(DummyComposer& composer, +void validate_this_public_call_hash(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs) { diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index ab463dd36af7..74ab65c92527 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -18,7 +18,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PublicDataRead; using aztec3::circuits::abis::PublicDataUpdateRequest; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::check_membership; using aztec3::circuits::compute_public_data_tree_index; using aztec3::circuits::compute_public_data_tree_value; @@ -37,7 +37,7 @@ namespace aztec3::circuits::kernel::public_kernel { * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_stack(DummyComposer& composer, KernelInput const& public_kernel_inputs) +void common_validate_call_stack(DummyBuilder& composer, KernelInput const& public_kernel_inputs) { // Ensures that the stack of pre-images corresponds to the call stack auto& stack = public_kernel_inputs.public_call.call_stack_item.public_inputs.public_call_stack; @@ -130,7 +130,7 @@ void common_validate_call_stack(DummyComposer& composer, KernelInput const& publ * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_context(DummyComposer& composer, KernelInput const& public_kernel_inputs) +void common_validate_call_context(DummyBuilder& composer, KernelInput const& public_kernel_inputs) { const auto& call_stack_item = public_kernel_inputs.public_call.call_stack_item; const auto is_delegate_call = call_stack_item.public_inputs.call_context.is_delegate_call; @@ -157,7 +157,7 @@ void common_validate_call_context(DummyComposer& composer, KernelInput const& pu * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_kernel_execution(DummyComposer& composer, KernelInput const& public_kernel_inputs) +void common_validate_kernel_execution(DummyBuilder& composer, KernelInput const& public_kernel_inputs) { common_validate_call_context(composer, public_kernel_inputs); common_validate_call_stack(composer, public_kernel_inputs); @@ -170,7 +170,7 @@ void common_validate_kernel_execution(DummyComposer& composer, KernelInput const * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_inputs(DummyComposer& composer, KernelInput const& public_kernel_inputs) +void common_validate_inputs(DummyBuilder& composer, KernelInput const& public_kernel_inputs) { // Validates commons inputs for all type of kernel inputs const auto& this_call_stack_item = public_kernel_inputs.public_call.call_stack_item; @@ -194,8 +194,8 @@ void common_validate_inputs(DummyComposer& composer, KernelInput const& public_k CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); } -template -void perform_static_call_checks(Composer& composer, KernelInput const& public_kernel_inputs) +template +void perform_static_call_checks(Builder& composer, KernelInput const& public_kernel_inputs) { // If the call is a static call, there should be no new commitments or nullifiers. const auto& public_call_public_inputs = public_kernel_inputs.public_call.call_stack_item.public_inputs; @@ -220,8 +220,8 @@ void perform_static_call_checks(Composer& composer, KernelInput const& public_ke * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_public_data_update_requests(Composer& composer, +template +void propagate_valid_public_data_update_requests(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -248,8 +248,8 @@ void propagate_valid_public_data_update_requests(Composer& composer, * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_public_data_reads(Composer& composer, +template +void propagate_valid_public_data_reads(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -276,8 +276,8 @@ void propagate_valid_public_data_reads(Composer& composer, * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_commitments(Composer& composer, +template +void propagate_new_commitments(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -305,8 +305,8 @@ void propagate_new_commitments(Composer& composer, * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_nullifiers(Composer& composer, +template +void propagate_new_nullifiers(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -333,8 +333,8 @@ void propagate_new_nullifiers(Composer& composer, * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_l2_to_l1_messages(Composer& composer, +template +void propagate_new_l2_to_l1_messages(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -397,8 +397,8 @@ template void accumulate_unencrypted_logs(PublicKernelInputs c * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void common_update_public_end_values(Composer& composer, +template +void common_update_public_end_values(Builder& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -435,7 +435,7 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param public_inputs The circuit outputs */ -void validate_this_public_call_hash(DummyComposer& composer, +void validate_this_public_call_hash(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index 2e236fd14cf1..e2eb3f7a3480 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -10,18 +10,18 @@ namespace aztec3::circuits::kernel::public_kernel { -using Composer = proof_system::UltraCircuitBuilder; +using Builder = proof_system::UltraCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; // Generic: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using DB = oracle::FakeDB; using oracle::NativeOracle; -using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; +using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp index 5d3f722b8185..9f3b70a61533 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp @@ -17,7 +17,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) { composer.do_assert(array_length(public_kernel_inputs.previous_kernel.public_inputs.end.private_call_stack) == 0, "Private call stack must be empty", @@ -35,7 +35,7 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_initialise_end_values; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; /** * @brief Entry point for the native public kernel circuit with a private previous kernel @@ -44,7 +44,7 @@ using DummyComposer = aztec3::utils::DummyComposer; * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) + DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp index 8cfba2fb8998..a9b47c4b98fb 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp @@ -11,8 +11,8 @@ namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); + DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp index 8422dab13ede..3e018229b388 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp @@ -15,7 +15,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) { const auto& previous_kernel = public_kernel_inputs.previous_kernel.public_inputs; composer.do_assert(previous_kernel.is_private == false, @@ -30,7 +30,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; /** * @brief Entry point for the native public kernel circuit with a public previous kernel @@ -39,7 +39,7 @@ using DummyComposer = aztec3::utils::DummyComposer; * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) + DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp index 317b06d12b08..208e693c9877 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp @@ -11,8 +11,8 @@ namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); + DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp index 5c9c433fdce0..4767a6ed8891 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp @@ -6,13 +6,13 @@ namespace aztec3::circuits::mock { using namespace plonk::stdlib; -template void mock_circuit(Composer& composer, std::vector const& public_inputs_) +template void mock_circuit(Builder& composer, std::vector const& public_inputs_) { const auto public_inputs = map(public_inputs_, [&](auto& i) { return field_t(witness_t(&composer, i)); }); for (auto& p : public_inputs) { p.set_public(); } - plonk::stdlib::pedersen::compress(field_t(witness_t(&composer, 1)), field_t(witness_t(&composer, 1))); + plonk::stdlib::pedersen::compress(field_t(witness_t(&composer, 1)), field_t(witness_t(&composer, 1))); } } // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index 9816622c526a..be1ea87e359c 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -17,11 +17,11 @@ using aztec3::utils::types::CircuitTypes; using plonk::stdlib::pedersen_commitment; using plonk::stdlib::witness_t; -template -KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, +template +KernelCircuitPublicInputs mock_kernel_circuit(Builder& composer, KernelCircuitPublicInputs const& _public_inputs) { - typedef CircuitTypes CT; + typedef CircuitTypes CT; typedef typename CT::fr fr; auto public_inputs = _public_inputs.to_circuit_type(composer); @@ -45,8 +45,8 @@ KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, // contains_recursive_proof to be false. composer.contains_recursive_proof = false; - plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); - return public_inputs.template to_native_type(); + plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); + return public_inputs.template to_native_type(); } } // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index 5e01d9976307..7da818cb7d75 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -8,7 +8,7 @@ namespace aztec3::circuits::recursion { class Aggregator { public: static CT::AggregationObject aggregate( - Composer* composer, + Builder* composer, const std::shared_ptr& vk, const NT::Proof& proof, const CT::AggregationObject& previous_aggregation_output = CT::AggregationObject()) diff --git a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp index be6d819cb5c8..427d25f502da 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp @@ -6,11 +6,11 @@ #include namespace aztec3::circuits::recursion { -// Composer -using Composer = UltraCircuitBuilder; +// Builder +using Builder = UltraCircuitBuilder; // Generic types: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 03a77d811831..3303632e3221 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -50,7 +50,7 @@ using aztec3::circuits::abis::NewContractData; using aztec3::circuits::rollup::test_utils::utils::make_public_data_update_request; using aztec3::circuits::rollup::test_utils::utils::make_public_read; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; } // namespace namespace aztec3::circuits::rollup::base::native_base_rollup_circuit { @@ -124,7 +124,7 @@ class base_rollup_tests : public ::testing::Test { TEST_F(base_rollup_tests, native_no_new_contract_leafs) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_no_new_contract_leafs"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_no_new_contract_leafs"); // When there are no contract deployments. The contract tree should be inserting 0 leafs, (not empty leafs); // Initially, the start_contract_tree_snapshot is empty (leaf is 0. hash it up). // Get sibling path of index 0 leaf (for circuit to check membership via sibling path) @@ -153,7 +153,7 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) TEST_F(base_rollup_tests, native_contract_leaf_inserted) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_contract_leaf_inserted"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted"); // When there is a contract deployment, the contract tree should be inserting 1 leaf. // The remaining leafs should be 0 leafs, (not empty leafs); @@ -195,8 +195,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted) TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tree) { - DummyComposer composer = - DummyComposer("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); // Same as before except our start_contract_snapshot_tree is not empty std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; @@ -247,7 +246,7 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr TEST_F(base_rollup_tests, native_new_commitments_tree) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_new_commitments_tree"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_commitments_tree"); // Create 4 new mock commitments. Add them to kernel data. // Then get sibling path so we can verify insert them into the tree. @@ -320,7 +319,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) /** * RUN */ - DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_empty"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_empty"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -353,7 +352,7 @@ void nullifier_insertion_test(std::array n } auto end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyComposer composer = DummyComposer("base_rollup_tests__nullifier_insertion_test"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__nullifier_insertion_test"); std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; for (uint8_t i = 0; i < 2; i++) { std::array kernel_nullifiers; @@ -401,7 +400,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) } auto expected_end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_sparse"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_sparse"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values_explicit(empty_inputs, nullifiers, initial_values); @@ -430,7 +429,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) TEST_F(base_rollup_tests, native_nullifier_tree_regression) { // Regression test caught when testing the typescript nullifier tree implementation - DummyComposer composer = DummyComposer("base_rollup_tests__native_nullifier_tree_regression"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_nullifier_tree_regression"); // This test runs after some data has already been inserted into the tree // This test will pre-populate the tree with 24 values (0 item + 23 more) simulating that a rollup inserting two @@ -508,7 +507,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) * DESCRIPTION */ - DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_double_spend"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_double_spend"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::array const new_nullifiers = { 11, 0, 11, 0, 0, 0, 0, 0 }; @@ -525,7 +524,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_empty_block_calldata_hash"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); @@ -572,7 +571,7 @@ TEST_F(base_rollup_tests, native_calldata_hash) std::array const expected_hash = components::compute_kernels_calldata_hash(kernel_data); - DummyComposer composer = DummyComposer("base_rollup_tests__native_calldata_hash"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_calldata_hash"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); @@ -591,8 +590,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati // WRITE a negative test that will fail the inclusion proof // Test membership works for empty trees - DummyComposer composer = - DummyComposer("base_rollup_tests__native_compute_membership_historic_private_data_negative"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_compute_membership_historic_private_data_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -619,8 +617,8 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negative) { // Test membership works for empty trees - DummyComposer composer = - DummyComposer("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); + DummyBuilder composer = + DummyBuilder("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -646,7 +644,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat TEST_F(base_rollup_tests, native_constants_dont_change) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_constants_dont_change"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_constants_dont_change"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); @@ -658,7 +656,7 @@ TEST_F(base_rollup_tests, native_constants_dont_change) TEST_F(base_rollup_tests, native_aggregate) { // TODO(rahul): Fix this when aggregation works - DummyComposer composer = DummyComposer("base_rollup_tests__native_aggregate"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_aggregate"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); @@ -669,7 +667,7 @@ TEST_F(base_rollup_tests, native_aggregate) TEST_F(base_rollup_tests, native_subtree_height_is_0) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_subtree_height_is_0"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_subtree_height_is_0"); BaseRollupInputs const inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); @@ -687,7 +685,7 @@ TEST_F(base_rollup_tests, native_cbind_0) TEST_F(base_rollup_tests, native_single_public_state_read) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_single_public_state_read"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_single_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -716,7 +714,7 @@ TEST_F(base_rollup_tests, native_single_public_state_read) TEST_F(base_rollup_tests, native_single_public_state_write) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_single_public_state_write"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_single_public_state_write"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -747,7 +745,7 @@ TEST_F(base_rollup_tests, native_single_public_state_write) TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_multiple_public_state_read_writes"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_multiple_public_state_read_writes"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -788,7 +786,7 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) TEST_F(base_rollup_tests, native_invalid_public_state_read) { - DummyComposer composer = DummyComposer("base_rollup_tests__native_invalid_public_state_read"); + DummyBuilder composer = DummyBuilder("base_rollup_tests__native_invalid_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 63e32b6c731d..ae1d9ca037dd 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -11,9 +11,9 @@ #include namespace { -using Composer = UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; @@ -51,7 +51,7 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, size_t* base_rollup_public_inputs_size_out, uint8_t const** base_or_merge_rollup_public_inputs_buf) { - DummyComposer composer = DummyComposer("base_rollup__sim"); + DummyBuilder composer = DummyBuilder("base_rollup__sim"); // TODO accept proving key and use that to initialize composers // this info is just to prevent error for unused pk_buf // TODO do we want to accept it or just get it from our factory? diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp index 272e9548eed8..f9c437775ca0 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -25,7 +25,7 @@ using NT = aztec3::utils::types::NativeTypes; using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index 399441563c4e..3d7609944759 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -94,7 +94,7 @@ NT::fr calculate_contract_subtree(std::vector contract_leaves) return contracts_tree.root(); } -NT::fr calculate_commitments_subtree(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) +NT::fr calculate_commitments_subtree(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_DEPTH); @@ -122,7 +122,7 @@ NT::fr calculate_commitments_subtree(DummyComposer& composer, BaseRollupInputs c * @param constantBaseRollupData * @param baseRollupInputs */ -void perform_historical_private_data_tree_membership_checks(DummyComposer& composer, +void perform_historical_private_data_tree_membership_checks(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { // For each of the historic_private_data_tree_membership_checks, we need to do an inclusion proof @@ -145,7 +145,7 @@ void perform_historical_private_data_tree_membership_checks(DummyComposer& compo } } -void perform_historical_contract_data_tree_membership_checks(DummyComposer& composer, +void perform_historical_contract_data_tree_membership_checks(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_contract_tree_roots_snapshot.root; @@ -166,7 +166,7 @@ void perform_historical_contract_data_tree_membership_checks(DummyComposer& comp } } -void perform_historical_l1_to_l2_message_tree_membership_checks(DummyComposer& composer, +void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_l1_to_l2_msg_tree_roots_snapshot.root; @@ -205,7 +205,7 @@ NT::fr create_nullifier_subtree( * * @returns The end nullifier tree root */ -AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyComposer& composer, +AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { // LADIES AND GENTLEMEN The P L A N ( is simple ) @@ -303,12 +303,12 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC }; // perform membership check for the low nullifier against the original root - check_membership(composer, - original_low_nullifier.hash(), - witness.leaf_index, - witness.sibling_path, - current_nullifier_tree_root, - "low nullifier membership check"); + check_membership(composer, + original_low_nullifier.hash(), + witness.leaf_index, + witness.sibling_path, + current_nullifier_tree_root, + "low nullifier membership check"); // Calculate the new value of the low_nullifier_leaf auto const updated_low_nullifier = @@ -365,7 +365,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC } fr insert_public_data_update_requests( - DummyComposer& composer, + DummyBuilder& composer, fr tree_root, std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& public_data_update_requests, @@ -396,7 +396,7 @@ fr insert_public_data_update_requests( } void validate_public_data_reads( - DummyComposer& composer, + DummyBuilder& composer, fr tree_root, std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const& public_data_reads, size_t witnesses_offset, @@ -419,7 +419,7 @@ void validate_public_data_reads( } }; -fr validate_and_process_public_state(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) +fr validate_and_process_public_state(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { // Process public data reads and public data update requests for left input validate_public_data_reads(composer, @@ -453,7 +453,7 @@ fr validate_and_process_public_state(DummyComposer& composer, BaseRollupInputs c return end_public_data_tree_root; } -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) { // Verify the previous kernel proofs for (size_t i = 0; i < 2; i++) { diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp index 6bfafc339346..6b3dabcebdaa 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp @@ -12,6 +12,6 @@ namespace aztec3::circuits::rollup::native_base_rollup { -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs); +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs); } // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp index 54d6aca27640..a87183253078 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp @@ -50,7 +50,7 @@ AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_both_input_proofs_of_same_rollup_type(DummyComposer& composer, +void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { @@ -66,7 +66,7 @@ void assert_both_input_proofs_of_same_rollup_type(DummyComposer& composer, * @param right - The public inputs of the right rollup (base or merge) * @return NT::fr - The height of the rollup subtrees */ -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyComposer& composer, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { @@ -82,7 +82,7 @@ NT::fr assert_both_input_proofs_of_same_height_and_return(DummyComposer& compose * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_equal_constants(DummyComposer& composer, +void assert_equal_constants(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { @@ -239,7 +239,7 @@ std::array compute_calldata_hash(std::array, // asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they // follow on from one-another). Ensures that right uses the tres that was updated by left. -void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer, +void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp index 31f1015c048a..fc5e30c513a5 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp @@ -11,23 +11,23 @@ namespace aztec3::circuits::rollup::components { NT::fr calculate_empty_tree_root(size_t depth); std::array compute_kernels_calldata_hash(std::array, 2> kernel_data); std::array compute_calldata_hash(std::array, 2> previous_rollup_data); -void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer, +void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_both_input_proofs_of_same_rollup_type(DummyComposer& composer, +void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyComposer& composer, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_equal_constants(DummyComposer& composer, +void assert_equal_constants(DummyBuilder& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyComposer& composer, +template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuilder& composer, AppendOnlySnapshot snapshot, std::array siblingPath, NT::fr emptySubtreeRoot, diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp index 464cf017717c..36d64ea2e59e 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp @@ -25,6 +25,6 @@ using NT = aztec3::utils::types::NativeTypes; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using AppendOnlySnapshot = abis::AppendOnlyTreeSnapshot; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; } // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index 3b4904bbb35a..a157a9ef2055 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -11,7 +11,7 @@ namespace { using aztec3::circuits::rollup::merge::MergeRollupInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_merge_rollup_inputs; @@ -69,7 +69,7 @@ class merge_rollup_tests : public ::testing::Test { TEST_F(merge_rollup_tests, native_different_rollup_type_fails) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_different_rollup_type_fails"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_different_rollup_type_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -83,7 +83,7 @@ TEST_F(merge_rollup_tests, native_different_rollup_type_fails) TEST_F(merge_rollup_tests, native_different_rollup_height_fails) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_different_rollup_height_fails"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_different_rollup_height_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -97,7 +97,7 @@ TEST_F(merge_rollup_tests, native_different_rollup_height_fails) TEST_F(merge_rollup_tests, native_constants_different_failure) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_constants_different_failure"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_constants_different_failure"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -111,7 +111,7 @@ TEST_F(merge_rollup_tests, native_constants_different_failure) TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) { - DummyComposer composerA = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); + DummyBuilder composerA = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -129,7 +129,7 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) ASSERT_EQ(composerA.get_first_failure().message, "input proofs have different private data tree snapshots"); // do the same for nullifier tree - DummyComposer composerB = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); + DummyBuilder composerB = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); auto inputB = inputs; inputB.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = { @@ -143,7 +143,7 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) ASSERT_EQ(composerB.get_first_failure().message, "input proofs have different nullifier tree snapshots"); // do the same for contract tree - DummyComposer composerC = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); + DummyBuilder composerC = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); auto inputC = inputs; inputC.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -158,7 +158,7 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_rollup_fields_are_set_correctly"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_rollup_fields_are_set_correctly"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -185,7 +185,7 @@ TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) TEST_F(merge_rollup_tests, native_start_and_end_snapshots) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_start_and_end_snapshots"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_start_and_end_snapshots"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -217,7 +217,7 @@ TEST_F(merge_rollup_tests, native_start_and_end_snapshots) TEST_F(merge_rollup_tests, native_calldata_hash) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_calldata_hash"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); @@ -254,7 +254,7 @@ TEST_F(merge_rollup_tests, native_calldata_hash) TEST_F(merge_rollup_tests, native_constants_dont_change) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_constants_dont_change"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_constants_dont_change"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -268,7 +268,7 @@ TEST_F(merge_rollup_tests, native_constants_dont_change) TEST_F(merge_rollup_tests, native_aggregate) { // TODO: Fix this when aggregation works - DummyComposer composer = DummyComposer("merge_rollup_tests__native_aggregate"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_aggregate"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -282,7 +282,7 @@ TEST_F(merge_rollup_tests, native_aggregate) TEST_F(merge_rollup_tests, native_merge_cbind) { - DummyComposer composer = DummyComposer("merge_rollup_tests__native_merge_cbind"); + DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_merge_cbind"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index fd09dffc25a7..60941661628b 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -8,7 +8,7 @@ namespace { using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::rollup::merge::merge_rollup_circuit; @@ -21,7 +21,7 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, size_t* merge_rollup_public_inputs_size_out, uint8_t const** merge_rollup_public_inputs_buf) { - DummyComposer composer = DummyComposer("merge_rollup__sim"); + DummyBuilder composer = DummyBuilder("merge_rollup__sim"); MergeRollupInputs merge_rollup_inputs; read(merge_rollup_inputs_buf, merge_rollup_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp index 13cc7774c46a..fc7986881e02 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -17,7 +17,7 @@ namespace aztec3::circuits::rollup::merge { using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp index ea606b0da04e..bb39f5168750 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, MergeRollupInputs const& mergeRollupInputs) +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& composer, MergeRollupInputs const& mergeRollupInputs) { // TODO: Verify the previous rollup proofs // TODO: Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks. diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp index 419f0310a66a..443679f4e51d 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp @@ -3,5 +3,5 @@ #include "init.hpp" namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, MergeRollupInputs const& mergeRollupInputs); +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& composer, MergeRollupInputs const& mergeRollupInputs); } // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 9e832575aeed..88e56978b31c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -138,7 +138,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) std::vector const messages_hash_input_bytes_vec(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP * 32, 0); auto messages_hash = sha256::sha256(messages_hash_input_bytes_vec); - utils::DummyComposer composer = utils::DummyComposer("root_rollup_tests__native_check_block_hashes_empty_blocks"); + utils::DummyBuilder composer = utils::DummyBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -159,7 +159,7 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) { - utils::DummyComposer composer = utils::DummyComposer("root_rollup_tests__native_root_missing_nullifier_logic"); + utils::DummyBuilder composer = utils::DummyBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); MemoryTree data_tree = MemoryTree(PRIVATE_DATA_TREE_HEIGHT); MemoryTree contract_tree = MemoryTree(CONTRACT_TREE_HEIGHT); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 7c0e6c087044..84160d3a63e4 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -9,9 +9,9 @@ #include namespace { -using Composer = UltraCircuitBuilder; +using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; using aztec3::circuits::rollup::native_root_rollup::RootRollupInputs; using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; @@ -52,7 +52,7 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, RootRollupInputs root_rollup_inputs; read(root_rollup_inputs_buf, root_rollup_inputs); - DummyComposer composer = DummyComposer("root_rollup__sim"); + DummyBuilder composer = DummyBuilder("root_rollup__sim"); RootRollupPublicInputs const public_inputs = root_rollup_circuit(composer, root_rollup_inputs); // serialize public inputs to bytes vec diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp index 0f7e24bb5ff3..c09057ed7789 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp @@ -16,7 +16,7 @@ namespace aztec3::circuits::rollup::native_root_rollup { using NT = aztec3::utils::types::NativeTypes; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 65714897ce06..70ff84c0f1be 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -68,7 +68,7 @@ std::array compute_messages_hash(std::array; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index 4febace4c8ba..a506afa149dc 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -20,7 +20,7 @@ using ConstantRollupData = aztec3::circuits::abis::ConstantRollupData; using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; using RootRollupPublicInputs = aztec3::circuits::abis::RootRollupPublicInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -238,7 +238,7 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne std::move(kernel_data), private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); } -std::array, 2> get_previous_rollup_data(DummyComposer& composer, +std::array, 2> get_previous_rollup_data(DummyBuilder& composer, std::array kernel_data) { // NOTE: Still assuming that this is first and second. Don't handle more rollups atm @@ -301,13 +301,13 @@ std::array, 2> get_previous_rollup_data(DummyComposer& co return { previous_rollup1, previous_rollup2 }; } -MergeRollupInputs get_merge_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data) +MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& composer, std::array kernel_data) { MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)) }; return inputs; } -RootRollupInputs get_root_rollup_inputs(utils::DummyComposer& composer, +RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& composer, std::array kernel_data, std::array l1_to_l2_messages) { diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index aa6549f94cb5..f6911c6e2653 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -23,7 +23,7 @@ using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using MergeRollupInputs = aztec3::circuits::abis::MergeRollupInputs; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; -using DummyComposer = aztec3::utils::DummyComposer; +using DummyBuilder = aztec3::utils::DummyBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -87,11 +87,11 @@ NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector kernel_data, std::array l1_to_l2_messages); -MergeRollupInputs get_merge_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data); +MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& composer, std::array kernel_data); inline abis::PublicDataUpdateRequest make_public_data_update_request(fr leaf_index, fr old_value, fr new_value) { diff --git a/circuits/cpp/src/aztec3/utils/array.hpp b/circuits/cpp/src/aztec3/utils/array.hpp index d027ea92ba60..a8850097099b 100644 --- a/circuits/cpp/src/aztec3/utils/array.hpp +++ b/circuits/cpp/src/aztec3/utils/array.hpp @@ -103,8 +103,8 @@ template T array_pop(std::array& arr) * @tparam The size of the array * @param The array into which we want to store the value */ -template -void array_push(Composer& composer, std::array& arr, T const& value) +template +void array_push(Builder& composer, std::array& arr, T const& value) { for (size_t i = 0; i < arr.size(); ++i) { if (is_empty(arr[i])) { @@ -165,8 +165,8 @@ template NT::boolean is_array_empty(std::array -void push_array_to_array(Composer& composer, std::array const& source, std::array& target) +template +void push_array_to_array(Builder& composer, std::array const& source, std::array& target) { // Check if the `source` array is too large vs the remaining capacity of the `target` array size_t const source_size = static_cast(uint256_t(array_length(source))); diff --git a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp index 4c3c61da8d19..4a8e16f478c9 100644 --- a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp +++ b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp @@ -9,13 +9,13 @@ namespace aztec3::utils { -class DummyComposer { +class DummyBuilder { public: std::vector failure_msgs; // method that created this composer instance. Useful for logging. std::string method_name; - explicit DummyComposer(std::string method_name) : method_name(std::move(method_name)) {} + explicit DummyBuilder(std::string method_name) : method_name(std::move(method_name)) {} void do_assert(bool const& assertion, std::string const& msg, CircuitErrorCode error_code) { diff --git a/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp b/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp index 8a91090a4118..9d1fda1f6a2e 100644 --- a/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp +++ b/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp @@ -12,7 +12,7 @@ auto _compare_msgpack_tuples(const Tuple1& t1, const Tuple2& t2, std::index_sequ // Function to check equality of msgpack objects based on their values. // Normally, you should instead use operator==() = default; -// BoolLike represents a type like the boolean DSL type +// BoolLike represents a type like the boolean DSL type template BoolLike msgpack_derived_equals(const T& obj1, const T& obj2) { BoolLike are_equal; diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index cf2fb4371238..71b26693b0a0 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -9,37 +9,37 @@ using namespace proof_system::plonk; namespace aztec3::utils::types { -template struct CircuitTypes { +template struct CircuitTypes { // Basic uint types - using boolean = stdlib::bool_t; - using uint8 = stdlib::uint8; - using uint16 = stdlib::uint16; - using uint32 = stdlib::uint32; - using uint64 = stdlib::uint64; + using boolean = stdlib::bool_t; + using uint8 = stdlib::uint8; + using uint16 = stdlib::uint16; + using uint32 = stdlib::uint32; + using uint64 = stdlib::uint64; // Types related to the bn254 curve - using fr = stdlib::field_t; - using safe_fr = stdlib::safe_uint_t; - using address = stdlib::address_t; - using fq = stdlib::bigfield; + using fr = stdlib::field_t; + using safe_fr = stdlib::safe_uint_t; + using address = stdlib::address_t; + using fq = stdlib::bigfield; - using witness = stdlib::witness_t; + using witness = stdlib::witness_t; // typedef fq grumpkin_fr; // typedef fr grumpkin_fq; - using grumpkin_point = stdlib::point; // affine - using grumpkin_group = stdlib::group; + using grumpkin_point = stdlib::point; // affine + using grumpkin_group = stdlib::group; - using bn254 = stdlib::bn254; + using bn254 = stdlib::bn254; // typedef bn254::g1_ct bn254_point; - using bn254_point = stdlib::element; // affine + using bn254_point = stdlib::element; // affine - using bit_array = stdlib::bit_array; - using byte_array = stdlib::byte_array; - using packed_byte_array = stdlib::packed_byte_array; + using bit_array = stdlib::bit_array; + using byte_array = stdlib::byte_array; + using packed_byte_array = stdlib::packed_byte_array; - using schnorr_signature = stdlib::schnorr::signature_bits; - using ecdsa_signature = stdlib::ecdsa::signature; + using schnorr_signature = stdlib::schnorr::signature_bits; + using ecdsa_signature = stdlib::ecdsa::signature; using AggregationObject = stdlib::recursion::aggregation_state; using recursive_inner_verifier_settings = stdlib::recursion::recursive_ultra_verifier_settings; @@ -52,25 +52,25 @@ template struct CircuitTypes { // Define the 'circuit' version of the function `compress`, with the name `compress`: static fr compress(std::vector const& inputs, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::compress(inputs, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs, hash_index); } template static fr compress(std::array const& inputs, const size_t hash_index = 0) { std::vector const inputs_vec(std::begin(inputs), std::end(inputs)); - return plonk::stdlib::pedersen_commitment::compress(inputs_vec, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs_vec, hash_index); } static fr compress(std::vector const& inputs, std::vector const& hash_sub_indices, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::compress(inputs, hash_sub_indices, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs, hash_sub_indices, hash_index); } static fr compress(const std::vector>& input_pairs) { - return plonk::stdlib::pedersen_commitment::compress(input_pairs); + return plonk::stdlib::pedersen_commitment::compress(input_pairs); }; /** @@ -86,17 +86,17 @@ template struct CircuitTypes { static fr merkle_hash(fr left, fr right) { // use 0-generator for internal merkle hashing - return plonk::stdlib::pedersen_hash::hash_multiple({ left, right }, 0); + return plonk::stdlib::pedersen_hash::hash_multiple({ left, right }, 0); }; static grumpkin_point commit(const std::vector& inputs, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::commit(inputs, hash_index); + return plonk::stdlib::pedersen_commitment::commit(inputs, hash_index); }; static grumpkin_point commit(const std::vector>& input_pairs) { - return plonk::stdlib::pedersen_commitment::commit(input_pairs); + return plonk::stdlib::pedersen_commitment::commit(input_pairs); }; static byte_array blake2s(const byte_array& input) { return plonk::stdlib::blake2s(input); } diff --git a/circuits/cpp/src/aztec3/utils/types/convert.hpp b/circuits/cpp/src/aztec3/utils/types/convert.hpp index ecd2113fd734..b6010eb82a0c 100644 --- a/circuits/cpp/src/aztec3/utils/types/convert.hpp +++ b/circuits/cpp/src/aztec3/utils/types/convert.hpp @@ -13,107 +13,107 @@ using plonk::stdlib::witness_t; namespace { -template using CT = aztec3::utils::types::CircuitTypes; +template using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; } // namespace /// TODO: Lots of identical functions here (but for their in/out types). Can we use templates? I couldn't figure out how /// to keep the NT:: or CT:: prefixes with templates. -template typename CT::boolean to_ct(Composer& composer, typename NT::boolean const& e) +template typename CT::boolean to_ct(Builder& composer, typename NT::boolean const& e) { - return typename CT::boolean(witness_t(&composer, e)); + return typename CT::boolean(witness_t(&composer, e)); }; -template typename CT::fr to_ct(Composer& composer, typename NT::fr const& e) +template typename CT::fr to_ct(Builder& composer, typename NT::fr const& e) { - return typename CT::fr(witness_t(&composer, e)); + return typename CT::fr(witness_t(&composer, e)); }; -template typename CT::fq to_ct(Composer& composer, typename NT::fq const& e) +template typename CT::fq to_ct(Builder& composer, typename NT::fq const& e) { - return typename CT::fq(witness_t(&composer, e)); + return typename CT::fq(witness_t(&composer, e)); }; -template typename CT::address to_ct(Composer& composer, typename NT::address const& e) +template typename CT::address to_ct(Builder& composer, typename NT::address const& e) { - return typename CT::address(witness_t(&composer, e)); + return typename CT::address(witness_t(&composer, e)); }; -template typename CT::uint32 to_ct(Composer& composer, typename NT::uint32 const& e) +template typename CT::uint32 to_ct(Builder& composer, typename NT::uint32 const& e) { - return typename CT::uint32(witness_t(&composer, e)); + return typename CT::uint32(witness_t(&composer, e)); }; -template -typename CT::grumpkin_point to_ct(Composer& composer, typename NT::grumpkin_point const& e) +template +typename CT::grumpkin_point to_ct(Builder& composer, typename NT::grumpkin_point const& e) { - return plonk::stdlib::create_point_witness(composer, e, true); + return plonk::stdlib::create_point_witness(composer, e, true); }; -template -typename CT::bn254_point to_ct(Composer& composer, typename NT::bn254_point const& e) +template +typename CT::bn254_point to_ct(Builder& composer, typename NT::bn254_point const& e) { - return CT::bn254_point::from_witness(&composer, e); + return CT::bn254_point::from_witness(&composer, e); }; -template -typename CT::ecdsa_signature to_ct(Composer& composer, typename NT::ecdsa_signature const& e) +template +typename CT::ecdsa_signature to_ct(Builder& composer, typename NT::ecdsa_signature const& e) { - return CT::ecdsa_signature::template from_witness(&composer, e); + return CT::ecdsa_signature::template from_witness(&composer, e); }; -template -std::optional::boolean> to_ct(Composer& composer, std::optional const& e) +template +std::optional::boolean> to_ct(Builder& composer, std::optional const& e) { - return e ? std::make_optional::boolean>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::boolean>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::fr> to_ct(Composer& composer, std::optional const& e) +template +std::optional::fr> to_ct(Builder& composer, std::optional const& e) { - return e ? std::make_optional::fr>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::fr>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::address> to_ct(Composer& composer, std::optional const& e) +template +std::optional::address> to_ct(Builder& composer, std::optional const& e) { - return e ? std::make_optional::address>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::address>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::grumpkin_point> to_ct(Composer& composer, - std::optional const& e) +template +std::optional::grumpkin_point> to_ct(Builder& composer, + std::optional const& e) { - return e ? std::make_optional::grumpkin_point>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::grumpkin_point>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::ecdsa_signature> to_ct(Composer& composer, - std::optional const& e) +template +std::optional::ecdsa_signature> to_ct(Builder& composer, + std::optional const& e) { - return e ? std::make_optional::ecdsa_signature>(to_ct(&composer, e)) : std::nullopt; + return e ? std::make_optional::ecdsa_signature>(to_ct(&composer, e)) : std::nullopt; }; -template -std::vector::fr> to_ct(Composer& composer, std::vector const& vec) +template +std::vector::fr> to_ct(Builder& composer, std::vector const& vec) { auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; return map(vec, ref_to_ct); }; -template -std::optional::fr>> to_ct(Composer& composer, - std::optional> const& vec) +template +std::optional::fr>> to_ct(Builder& composer, + std::optional> const& vec) { auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; - return vec ? std::make_optional::fr>>(map(*vec, ref_to_ct)) : std::nullopt; + return vec ? std::make_optional::fr>>(map(*vec, ref_to_ct)) : std::nullopt; }; -template -std::array::fr, SIZE> to_ct(Composer& composer, std::array const& arr) +template +std::array::fr, SIZE> to_ct(Builder& composer, std::array const& arr) { auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; @@ -121,8 +121,8 @@ std::array::fr, SIZE> to_ct(Composer& composer, std::array }; -template std::array::fr>, SIZE> to_ct( - Composer& composer, std::array, SIZE> const& arr) +template std::array::fr>, SIZE> to_ct( + Builder& composer, std::array, SIZE> const& arr) { auto ref_to_ct = [&](std::optional const& e) { return to_ct(composer, e); }; @@ -132,8 +132,8 @@ template std::array -std::array to_ct(Composer& composer, std::array const& arr) +template +std::array to_ct(Builder& composer, std::array const& arr) { auto ref_to_ct = [&](NT_TYPE const& e) { return e.to_circuit_type(composer); }; @@ -144,8 +144,8 @@ std::array to_ct(Composer& composer, std::array co * @brief Convert from an array of any native types (NT_TYPE) to array of circuit types (CT_TYPE). * Allow array entries to be optional. */ -template -std::array, SIZE> to_ct(Composer& composer, std::array, SIZE> const& arr) +template +std::array, SIZE> to_ct(Builder& composer, std::array, SIZE> const& arr) { auto ref_to_ct = [&](std::optional const& e) { return e.to_circuit_type(composer); }; @@ -154,27 +154,27 @@ std::array, SIZE> to_ct(Composer& composer, std::array typename NT::boolean to_nt(typename CT::boolean const& e) +template typename NT::boolean to_nt(typename CT::boolean const& e) { return e.get_value(); }; -template typename NT::fr to_nt(typename CT::fr const& e) +template typename NT::fr to_nt(typename CT::fr const& e) { return e.get_value(); }; -template typename NT::fq to_nt(typename CT::fq const& e) +template typename NT::fq to_nt(typename CT::fq const& e) { return e.get_value(); }; -template typename NT::address to_nt(typename CT::address const& e) +template typename NT::address to_nt(typename CT::address const& e) { return NT::address(e.address_.get_value()); // TODO: add get_value() method to address types. }; -template typename NT::uint32 to_nt(typename CT::uint32 const& e) +template typename NT::uint32 to_nt(typename CT::uint32 const& e) { NT::uint256 const e_256 = e.get_value(); NT::uint64 const e_64 = e_256.data[0]; // TODO: check that this endianness is correct! @@ -182,17 +182,17 @@ template typename NT::uint32 to_nt(typename CT::ui return e_32; }; -template typename NT::grumpkin_point to_nt(typename CT::grumpkin_point const& e) +template typename NT::grumpkin_point to_nt(typename CT::grumpkin_point const& e) { return NT::grumpkin_point{ e.x.get_value(), e.y.get_value() }; }; -template typename NT::bn254_point to_nt(typename CT::bn254_point const& e) +template typename NT::bn254_point to_nt(typename CT::bn254_point const& e) { return e.get_value(); }; -template typename NT::ecdsa_signature to_nt(typename CT::ecdsa_signature const& e) +template typename NT::ecdsa_signature to_nt(typename CT::ecdsa_signature const& e) { std::vector r_bytes = e.r.get_value(); std::vector s_bytes = e.s.get_value(); @@ -205,71 +205,71 @@ template typename NT::ecdsa_signature to_nt(typename CT -std::optional to_nt(std::optional::boolean> const& e) +template +std::optional to_nt(std::optional::boolean> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template std::optional to_nt(std::optional::fr> const& e) +template std::optional to_nt(std::optional::fr> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::address> const& e) +template +std::optional to_nt(std::optional::address> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::grumpkin_point> const& e) +template +std::optional to_nt(std::optional::grumpkin_point> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::ecdsa_signature> const& e) +template +std::optional to_nt(std::optional::ecdsa_signature> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template std::vector to_nt(std::vector::fr> const& vec) +template std::vector to_nt(std::vector::fr> const& vec) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return map(vec, ref_to_nt); }; -template -std::optional> to_nt(std::optional::fr>> const& vec) +template +std::optional> to_nt(std::optional::fr>> const& vec) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return vec ? std::make_optional>(map(*vec, ref_to_nt)) : std::nullopt; }; -template -std::array to_nt(std::array::fr, SIZE> const& arr) +template +std::array to_nt(std::array::fr, SIZE> const& arr) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return map(arr, ref_to_nt); }; -// template +// template // std::optional> to_nt( -// std::optional::fr, SIZE>> const& arr) +// std::optional::fr, SIZE>> const& arr) // { -// auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; +// auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; // return arr ? std::make_optional>(map(arr, ref_to_nt)) : std::nullopt; // }; -template std::array, SIZE> to_nt( - std::array::fr>, SIZE> const& arr) +template std::array, SIZE> to_nt( + std::array::fr>, SIZE> const& arr) { - auto ref_to_nt = [&](std::optional::fr> const& e) { return to_nt(e); }; + auto ref_to_nt = [&](std::optional::fr> const& e) { return to_nt(e); }; return map(arr, ref_to_nt); }; From f91ece97543d1454dc611da4415f48d6c4d8ecc3 Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 23:26:42 +0000 Subject: [PATCH 10/28] composer ~> builder --- .../cpp/src/aztec3/circuits/abis/.test.cpp | 8 +- .../src/aztec3/circuits/abis/call_context.hpp | 6 +- .../aztec3/circuits/abis/call_stack_item.hpp | 10 +- .../abis/combined_accumulated_data.hpp | 8 +- .../circuits/abis/combined_constant_data.hpp | 6 +- .../abis/combined_historic_tree_roots.hpp | 7 +- .../abis/contract_deployment_data.hpp | 6 +- .../circuits/abis/contract_storage_read.hpp | 6 +- .../abis/contract_storage_update_request.hpp | 6 +- .../aztec3/circuits/abis/function_data.hpp | 6 +- .../circuits/abis/function_leaf_preimage.hpp | 6 +- .../abis/kernel_circuit_public_inputs.hpp | 11 +- .../circuits/abis/membership_witness.hpp | 6 +- .../circuits/abis/new_contract_data.hpp | 4 +- .../abis/optionally_revealed_data.hpp | 8 +- .../circuits/abis/previous_kernel_data.hpp | 10 +- .../abis/private_circuit_public_inputs.hpp | 70 +++--- .../abis/private_historic_tree_roots.hpp | 6 +- .../call_context_reconciliation_data.hpp | 8 +- .../circuits/abis/private_kernel/globals.hpp | 6 +- .../abis/private_kernel/private_call_data.hpp | 12 +- .../private_kernel_inputs_init.hpp | 6 +- .../private_kernel_inputs_inner.hpp | 6 +- .../abis/public_circuit_public_inputs.hpp | 9 +- .../aztec3/circuits/abis/public_data_read.hpp | 6 +- .../abis/public_data_update_request.hpp | 6 +- .../abis/public_kernel/public_call_data.hpp | 12 +- .../public_kernel/public_kernel_inputs.hpp | 6 +- .../src/aztec3/circuits/abis/tx_context.hpp | 10 +- .../src/aztec3/circuits/abis/tx_request.hpp | 8 +- .../cpp/src/aztec3/circuits/apps/.test.cpp | 44 ++-- .../apps/function_execution_context.hpp | 24 +-- .../default_private_note/note_preimage.hpp | 6 +- .../nullifier_preimage.hpp | 6 +- .../note_preimage.hpp | 6 +- .../nullifier_preimage.hpp | 6 +- .../aztec3/circuits/apps/oracle_wrapper.hpp | 22 +- .../basic_contract_deployment.cpp | 8 +- .../circuits/apps/test_apps/escrow/.test.cpp | 54 ++--- .../apps/test_apps/escrow/deposit.cpp | 8 +- .../apps/test_apps/escrow/transfer.cpp | 16 +- .../apps/test_apps/escrow/withdraw.cpp | 12 +- .../.test.cpp | 18 +- .../function_1_1.cpp | 8 +- .../function_2_1.cpp | 8 +- .../src/aztec3/circuits/apps/utxo_datum.hpp | 8 +- circuits/cpp/src/aztec3/circuits/hash.hpp | 8 +- .../aztec3/circuits/kernel/private/.test.cpp | 10 +- .../aztec3/circuits/kernel/private/c_bind.cpp | 12 +- .../aztec3/circuits/kernel/private/common.cpp | 80 +++---- .../aztec3/circuits/kernel/private/common.hpp | 8 +- .../native_private_kernel_circuit_init.cpp | 82 +++---- .../native_private_kernel_circuit_init.hpp | 2 +- ...ative_private_kernel_circuit_init.test.cpp | 200 +++++++++--------- .../native_private_kernel_circuit_inner.cpp | 58 ++--- .../native_private_kernel_circuit_inner.hpp | 2 +- ...tive_private_kernel_circuit_inner.test.cpp | 158 +++++++------- ...native_private_kernel_circuit_ordering.cpp | 8 +- ...native_private_kernel_circuit_ordering.hpp | 2 +- ...e_private_kernel_circuit_ordering.test.cpp | 22 +- .../kernel/private/private_kernel_circuit.cpp | 14 +- .../kernel/private/private_kernel_circuit.hpp | 2 +- .../kernel/private/testing_harness.cpp | 10 +- .../aztec3/circuits/kernel/private/utils.cpp | 6 +- .../aztec3/circuits/kernel/public/c_bind.cpp | 8 +- .../aztec3/circuits/kernel/public/common.cpp | 8 +- .../aztec3/circuits/kernel/public/common.hpp | 182 ++++++++-------- ...kernel_circuit_private_previous_kernel.cpp | 30 +-- ...kernel_circuit_private_previous_kernel.hpp | 2 +- ..._kernel_circuit_public_previous_kernel.cpp | 24 +-- ..._kernel_circuit_public_previous_kernel.hpp | 2 +- .../src/aztec3/circuits/mock/mock_circuit.hpp | 6 +- .../circuits/mock/mock_kernel_circuit.hpp | 11 +- .../aztec3/circuits/recursion/aggregator.hpp | 4 +- .../src/aztec3/circuits/rollup/base/.test.cpp | 127 ++++++----- .../aztec3/circuits/rollup/base/c_bind.cpp | 8 +- .../base/native_base_rollup_circuit.cpp | 76 +++---- .../base/native_base_rollup_circuit.hpp | 2 +- .../circuits/rollup/components/components.cpp | 50 ++--- .../circuits/rollup/components/components.hpp | 12 +- .../aztec3/circuits/rollup/merge/.test.cpp | 102 ++++----- .../aztec3/circuits/rollup/merge/c_bind.cpp | 6 +- .../merge/native_merge_rollup_circuit.cpp | 10 +- .../merge/native_merge_rollup_circuit.hpp | 2 +- .../src/aztec3/circuits/rollup/root/.test.cpp | 17 +- .../aztec3/circuits/rollup/root/c_bind.cpp | 6 +- .../root/native_root_rollup_circuit.cpp | 18 +- .../root/native_root_rollup_circuit.hpp | 2 +- .../circuits/rollup/test_utils/utils.cpp | 14 +- .../circuits/rollup/test_utils/utils.hpp | 4 +- circuits/cpp/src/aztec3/utils/array.hpp | 20 +- .../cpp/src/aztec3/utils/dummy_composer.hpp | 4 +- .../cpp/src/aztec3/utils/types/convert.hpp | 77 ++++--- 93 files changed, 1025 insertions(+), 1032 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 23c9101a4460..0bee851c6627 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -74,8 +74,8 @@ TEST(abi_tests, native_to_circuit_function_data) info("function data: ", native_function_data); - Builder composer = Builder("../barretenberg/cpp/srs_db/ignition"); - FunctionData const circuit_function_data = native_function_data.to_circuit_type(composer); + Builder builder = Builder(); + FunctionData const circuit_function_data = native_function_data.to_circuit_type(builder); info("function data: ", circuit_function_data); } @@ -105,8 +105,8 @@ TEST(abi_tests, native_to_circuit_call_context) info("call context: ", native_call_context); - Builder composer = Builder("../barretenberg/cpp/srs_db/ignition"); - CallContext const circuit_call_context = native_call_context.to_circuit_type(composer); + Builder builder = Builder(); + CallContext const circuit_call_context = native_call_context.to_circuit_type(builder); info("call context: ", circuit_call_context); } diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp index 1b166064ff06..f18abf5394f4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp @@ -40,12 +40,12 @@ template struct CallContext { return utils::msgpack_derived_equals(*this, other); }; - template CallContext> to_circuit_type(Builder& composer) const + template CallContext> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; CallContext> call_context = { to_ct(msg_sender), to_ct(storage_contract_address), to_ct(portal_contract_address), diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp index 3725a5073792..f1af212a15aa 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp @@ -50,17 +50,17 @@ template typename PrivatePublic> struct CallStac }; template - CallStackItem, PrivatePublic> to_circuit_type(Builder& composer) const + CallStackItem, PrivatePublic> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; CallStackItem, PrivatePublic> call_stack_item = { to_ct(contract_address), - function_data.to_circuit_type(composer), - public_inputs.to_circuit_type(composer), + function_data.to_circuit_type(builder), + public_inputs.to_circuit_type(builder), to_ct(is_execution_request), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp index 41c212282da3..cc362502cc57 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp @@ -83,14 +83,14 @@ template struct CombinedAccumulatedData { public_data_reads == other.public_data_reads; }; - template CombinedAccumulatedData> to_circuit_type(Builder& composer) const + template CombinedAccumulatedData> to_circuit_type(Builder& builder) const { typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; CombinedAccumulatedData acc_data = { typename CT::AggregationObject{ diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp index 7bc5a74a021d..2d5490bbec1b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp @@ -30,13 +30,13 @@ template struct CombinedConstantData { return historic_tree_roots == other.historic_tree_roots && tx_context == other.tx_context; } - template CombinedConstantData> to_circuit_type(Builder& composer) const + template CombinedConstantData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); CombinedConstantData> constant_data = { - historic_tree_roots.to_circuit_type(composer), - tx_context.to_circuit_type(composer), + historic_tree_roots.to_circuit_type(builder), + tx_context.to_circuit_type(builder), }; return constant_data; diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp index c4115f26d9d9..dd8e72194e25 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp @@ -27,13 +27,12 @@ template struct CombinedHistoricTreeRoots { return private_historic_tree_roots == other.private_historic_tree_roots; }; - template - CombinedHistoricTreeRoots> to_circuit_type(Builder& composer) const + template CombinedHistoricTreeRoots> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; CombinedHistoricTreeRoots> data = { to_circuit_type(private_historic_tree_roots), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp index 52b421158ba4..4edfaf89d860 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp @@ -36,12 +36,12 @@ template struct ContractDeploymentData { portal_contract_address == other.portal_contract_address; }; - template ContractDeploymentData> to_circuit_type(Builder& composer) const + template ContractDeploymentData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; ContractDeploymentData> data = { to_ct(deployer_public_key), to_ct(constructor_vk_hash), to_ct(function_tree_root), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp index af910654d8ff..f09bee3b6264 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp @@ -23,12 +23,12 @@ template struct ContractStorageRead { MSGPACK_FIELDS(storage_slot, current_value); bool operator==(ContractStorageRead const&) const = default; - template ContractStorageRead> to_circuit_type(Builder& composer) const + template ContractStorageRead> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; ContractStorageRead> contract_storage_read = { to_ct(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp index 1ff0d2bba946..862e5f3d4aa2 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp @@ -24,12 +24,12 @@ template struct ContractStorageUpdateRequest { MSGPACK_FIELDS(storage_slot, old_value, new_value); bool operator==(ContractStorageUpdateRequest const&) const = default; template - ContractStorageUpdateRequest> to_circuit_type(Builder& composer) const + ContractStorageUpdateRequest> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; ContractStorageUpdateRequest> update_request = { to_ct(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp index a01b85709636..0248847bfe7c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp @@ -29,12 +29,12 @@ template struct FunctionData { is_constructor == other.is_constructor; }; - template FunctionData> to_circuit_type(Builder& composer) const + template FunctionData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; FunctionData> function_data = { to_ct(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp index c15d185e835f..370bf7e81286 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp @@ -42,12 +42,12 @@ template struct FunctionLeafPreimage { vk_hash == other.vk_hash && acir_hash == other.acir_hash; }; - template FunctionLeafPreimage> to_circuit_type(Builder& composer) const + template FunctionLeafPreimage> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; FunctionLeafPreimage> preimage = { to_ct(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp index 6293066f7dd9..462f0df9265e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp @@ -31,17 +31,16 @@ template struct KernelCircuitPublicInputs { return end == other.end && constants == other.constants && is_private == other.is_private; }; - template - KernelCircuitPublicInputs> to_circuit_type(Builder& composer) const + template KernelCircuitPublicInputs> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; KernelCircuitPublicInputs> private_inputs = { - end.to_circuit_type(composer), - constants.to_circuit_type(composer), + end.to_circuit_type(builder), + constants.to_circuit_type(builder), to_ct(is_private), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp index 27e9656fab6e..fa4256e5d75d 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp @@ -24,12 +24,12 @@ template struct MembershipWitness { return leaf_index == other.leaf_index && sibling_path == other.sibling_path; }; - template MembershipWitness, N> to_circuit_type(Builder& composer) const + template MembershipWitness, N> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; MembershipWitness, N> witness = { to_ct(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp index e341df852113..462f2df45c0a 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp @@ -30,11 +30,11 @@ template struct NewContractData { return utils::msgpack_derived_equals(*this, other); }; - template NewContractData> to_circuit_type(Builder& composer) const + template NewContractData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; NewContractData> new_contract_data = { to_ct(contract_address), to_ct(portal_contract_address), diff --git a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp index 9e91597bf0ab..04dad9940f75 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp @@ -45,16 +45,16 @@ template struct OptionallyRevealedData { called_from_l1 == other.called_from_l1 && called_from_public_l2 == other.called_from_public_l2; }; - template OptionallyRevealedData> to_circuit_type(Builder& composer) const + template OptionallyRevealedData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; OptionallyRevealedData> data = { to_ct(call_stack_item_hash), - function_data.to_circuit_type(composer), + function_data.to_circuit_type(builder), to_ct(vk_hash), to_ct(portal_contract_address), to_ct(pay_fee_from_l1), diff --git a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp index 1fd5194d2d6b..5248d3a84487 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp @@ -39,18 +39,18 @@ template struct PreviousKernelData { }; // WARNING: the `proof` does NOT get converted! - template PreviousKernelData> to_circuit_type(Builder& composer) const + template PreviousKernelData> to_circuit_type(Builder& builder) const { typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; PreviousKernelData> data = { - public_inputs.to_circuit_type(composer), + public_inputs.to_circuit_type(builder), proof, // Notice: not converted! Stays as native. - CT::VK::from_witness(&composer, vk), + CT::VK::from_witness(&builder, vk), to_ct(vk_index), to_ct(vk_path), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index 6b868ca13f43..68e1a2a0748b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -71,13 +71,13 @@ template class PrivateCircuitPublicInputs { }; template - PrivateCircuitPublicInputs> to_circuit_type(Builder& composer) const + PrivateCircuitPublicInputs> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; PrivateCircuitPublicInputs> pis = { to_circuit_type(call_context), @@ -409,45 +409,45 @@ template class OptionalPrivateCircuitPublicInputs { } } - template void make_unused_inputs_zero(Builder& composer) + template void make_unused_inputs_zero(Builder& builder) { static_assert((std::is_same, NCT>::value)); - make_unused_element_zero(composer, call_context); + make_unused_element_zero(builder, call_context); - make_unused_element_zero(composer, args_hash); - make_unused_array_elements_zero(composer, return_values); + make_unused_element_zero(builder, args_hash); + make_unused_array_elements_zero(builder, return_values); - make_unused_array_elements_zero(composer, read_requests); + make_unused_array_elements_zero(builder, read_requests); - make_unused_array_elements_zero(composer, new_commitments); - make_unused_array_elements_zero(composer, new_nullifiers); + make_unused_array_elements_zero(builder, new_commitments); + make_unused_array_elements_zero(builder, new_nullifiers); - make_unused_array_elements_zero(composer, private_call_stack); - make_unused_array_elements_zero(composer, public_call_stack); - make_unused_array_elements_zero(composer, new_l2_to_l1_msgs); + make_unused_array_elements_zero(builder, private_call_stack); + make_unused_array_elements_zero(builder, public_call_stack); + make_unused_array_elements_zero(builder, new_l2_to_l1_msgs); - make_unused_array_elements_zero(composer, encrypted_logs_hash); - make_unused_array_elements_zero(composer, unencrypted_logs_hash); + make_unused_array_elements_zero(builder, encrypted_logs_hash); + make_unused_array_elements_zero(builder, unencrypted_logs_hash); - make_unused_element_zero(composer, encrypted_log_preimages_length); - make_unused_element_zero(composer, unencrypted_log_preimages_length); + make_unused_element_zero(builder, encrypted_log_preimages_length); + make_unused_element_zero(builder, unencrypted_log_preimages_length); - make_unused_element_zero(composer, historic_private_data_tree_root); - make_unused_element_zero(composer, historic_nullifier_tree_root); - make_unused_element_zero(composer, historic_contract_tree_root); - make_unused_element_zero(composer, historic_l1_to_l2_messages_tree_root); + make_unused_element_zero(builder, historic_private_data_tree_root); + make_unused_element_zero(builder, historic_nullifier_tree_root); + make_unused_element_zero(builder, historic_contract_tree_root); + make_unused_element_zero(builder, historic_l1_to_l2_messages_tree_root); - make_unused_element_zero(composer, contract_deployment_data); + make_unused_element_zero(builder, contract_deployment_data); all_elements_populated = true; } - template void set_public(Builder& composer) + template void set_public(Builder& builder) { static_assert(!(std::is_same::value)); - make_unused_inputs_zero(composer); + make_unused_inputs_zero(builder); // Optional members are guaranteed to be nonempty from here. @@ -480,14 +480,14 @@ template class OptionalPrivateCircuitPublicInputs { } template - OptionalPrivateCircuitPublicInputs> to_circuit_type(Builder& composer) const + OptionalPrivateCircuitPublicInputs> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; auto to_circuit_type = [&](auto& e) { - return e ? std::make_optional((*e).to_circuit_type(composer)) : std::nullopt; + return e ? std::make_optional((*e).to_circuit_type(builder)) : std::nullopt; }; OptionalPrivateCircuitPublicInputs> pis = { @@ -664,35 +664,35 @@ template class OptionalPrivateCircuitPublicInputs { } template - void make_unused_array_elements_zero(Builder& composer, std::array, SIZE>& arr) + void make_unused_array_elements_zero(Builder& builder, std::array, SIZE>& arr) { static_assert((std::is_same, NCT>::value)); for (std::optional& e : arr) { - make_unused_element_zero(composer, e); + make_unused_element_zero(builder, e); } } - template void make_unused_element_zero(Builder& composer, std::optional& element) + template void make_unused_element_zero(Builder& builder, std::optional& element) { static_assert((std::is_same, NCT>::value)); if (!element) { element = - T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` + T(witness_t(&builder, 0)); // convert the nullopt value to a circuit witness value of `0` fr(*element).assert_is_zero(); } } // ABIStruct is a template for any of the structs in the abis/ dir. E.g. ExecutedCallback, CallbackStackItem. template class ABIStruct> - void make_unused_element_zero(Builder& composer, std::optional>>& element) + void make_unused_element_zero(Builder& builder, std::optional>>& element) { static_assert((std::is_same, NCT>::value)); if (!element) { element = ABIStruct().to_circuit_type( - composer); // convert the nullopt value to a circuit witness value of `0` + builder); // convert the nullopt value to a circuit witness value of `0` (*element).template assert_is_zero(); } } diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp index 7e6aa75d7bc0..bbade3dd50a9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp @@ -37,12 +37,12 @@ template struct PrivateHistoricTreeRoots { private_kernel_vk_tree_root == other.private_kernel_vk_tree_root; }; - template PrivateHistoricTreeRoots> to_circuit_type(Builder& composer) const + template PrivateHistoricTreeRoots> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; PrivateHistoricTreeRoots> data = { to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp index e50064fb024a..1a527f39c745 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp @@ -34,13 +34,13 @@ // std::array l1_counterparts; // TODO: this is probably wrong. // template -// CallContextReconciliationData> to_circuit_type(Builder& composer) const +// CallContextReconciliationData> to_circuit_type(Builder& builder) const // { // static_assert((std::is_same::value)); -// // Capture the composer: -// auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; -// auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; +// // Capture the circuit builder: +// auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; +// auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; // CallContextReconciliationData> data = { diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp index c49423ebdd19..c0dddfa2d656 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp @@ -19,12 +19,12 @@ template struct Globals { boolean operator==(Globals const& other) const { return min_timestamp == other.min_timestamp; }; - template Globals> to_circuit_type(Builder& composer) const + template Globals> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; Globals> global_data = { to_ct(min_timestamp) }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp index a7c6ccaaf1e9..b9887739eb21 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp @@ -55,14 +55,14 @@ template struct PrivateCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PrivateCallData> to_circuit_type(Builder& composer) const + template PrivateCallData> to_circuit_type(Builder& builder) const { typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; PrivateCallData> data = { to_circuit_type(call_stack_item), @@ -71,13 +71,13 @@ template struct PrivateCallData { proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function // currently works. - CT::VK::from_witness(&composer, vk), + CT::VK::from_witness(&builder, vk), to_circuit_type(function_leaf_membership_witness), to_circuit_type(contract_leaf_membership_witness), aztec3::utils::types::to_ct>( - composer, read_request_membership_witnesses), + builder, read_request_membership_witnesses), to_ct(portal_contract_address), to_ct(acir_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp index 1c57817a6368..bd49b7d3fbb5 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp @@ -24,14 +24,14 @@ template struct PrivateKernelInputsInit { return tx_request == other.tx_request && private_call == other.private_call; }; - template PrivateKernelInputsInit> to_circuit_type(Builder& composer) const + template PrivateKernelInputsInit> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); PrivateKernelInputsInit> private_inputs = { // TODO to_ct(signature), - tx_request.to_circuit_type(composer), - private_call.to_circuit_type(composer), + tx_request.to_circuit_type(builder), + private_call.to_circuit_type(builder), }; return private_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp index d884c06ee82b..63ed04c36556 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp @@ -26,13 +26,13 @@ template struct PrivateKernelInputsInner { return previous_kernel == other.previous_kernel && private_call == other.private_call; }; - template PrivateKernelInputsInner> to_circuit_type(Builder& composer) const + template PrivateKernelInputsInner> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); PrivateKernelInputsInner> private_inputs = { - previous_kernel.to_circuit_type(composer), - private_call.to_circuit_type(composer), + previous_kernel.to_circuit_type(builder), + private_call.to_circuit_type(builder), }; return private_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp index d85532329668..6e1e22bbe71e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp @@ -70,14 +70,13 @@ template struct PublicCircuitPublicInputs { return msgpack_derived_equals(*this, other); } - template - PublicCircuitPublicInputs> to_circuit_type(Builder& composer) const + template PublicCircuitPublicInputs> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; PublicCircuitPublicInputs> pis = { .call_context = to_circuit_type(call_context), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp index d9b7b7ee70e7..2d76f269ede7 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp @@ -23,12 +23,12 @@ template struct PublicDataRead { MSGPACK_FIELDS(leaf_index, value); bool operator==(PublicDataRead const&) const = default; - template PublicDataRead> to_circuit_type(Builder& composer) const + template PublicDataRead> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; PublicDataRead> read = { to_ct(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp index 3bc12400f733..152cb9c8ef19 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp @@ -24,12 +24,12 @@ template struct PublicDataUpdateRequest { MSGPACK_FIELDS(leaf_index, old_value, new_value); bool operator==(PublicDataUpdateRequest const&) const = default; - template PublicDataUpdateRequest> to_circuit_type(Builder& composer) const + template PublicDataUpdateRequest> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; PublicDataUpdateRequest> update_request = { to_ct(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp index 976c7334f37c..3a69895231f5 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp @@ -43,23 +43,23 @@ template struct PublicCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PublicCallData> to_circuit_type(Builder& composer) const + template PublicCallData> to_circuit_type(Builder& builder) const { // typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; PublicCallData> data = { - call_stack_item.to_circuit_type(composer), + call_stack_item.to_circuit_type(builder), map(public_call_stack_preimages, to_circuit_type), proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function // currently works. - // CT::VK::from_witness(&composer, vk), + // CT::VK::from_witness(&builder, vk), // to_circuit_type(function_leaf_membership_witness), // to_circuit_type(contract_leaf_membership_witness), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp index 21409b871e36..38b3bbd31410 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp @@ -28,13 +28,13 @@ template struct PublicKernelInputs { return previous_kernel == other.previous_kernel && public_call == other.public_call; }; - template PublicKernelInputs> to_circuit_type(Builder& composer) const + template PublicKernelInputs> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); PublicKernelInputs> public_kernel_inputs = { - previous_kernel.to_circuit_type(composer), - public_call.to_circuit_type(composer), + previous_kernel.to_circuit_type(builder), + public_call.to_circuit_type(builder), }; return public_kernel_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp index e63166ce14b9..d6dc7ea5af6f 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp @@ -33,19 +33,19 @@ template struct TxContext { contract_deployment_data == other.contract_deployment_data; }; - template TxContext> to_circuit_type(Builder& composer) const + template TxContext> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; TxContext> tx_context = { to_ct(is_fee_payment_tx), to_ct(is_rebate_payment_tx), to_ct(is_contract_deployment_tx), - contract_deployment_data.to_circuit_type(composer), + contract_deployment_data.to_circuit_type(builder), }; return tx_context; diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp index 7765c00dae6b..1a9ff0d78815 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp @@ -30,13 +30,13 @@ template struct TxRequest { tx_context == other.tx_context; }; - template TxRequest> to_circuit_type(Builder& composer) const + template TxRequest> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; TxRequest> tx_request = { to_ct(origin), diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index 67a98210ee4b..ab4ca379df42 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -97,11 +97,11 @@ TEST_F(state_var_tests, circuit_mapping) // contains a reference to earlier-declared classes... so we'd end up with classes containing dangling references, // if all this stuff were to be declared in a setup function's scope. // We could instead store shared_ptrs in every class...? - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); // TODO: // Interestingly, if I scope the below, the debugger works, but running the test via the command line fails. This is @@ -120,7 +120,7 @@ TEST_F(state_var_tests, circuit_mapping) Mapping my_mapping(&exec_ctx, "my_mapping"); - my_mapping[5] = to_ct(composer, NT::fr(5)); + my_mapping[5] = to_ct(builder, NT::fr(5)); // info("my_mapping[5]: ", my_mapping[5]); // info("my_mapping[5].start_slot: ", my_mapping[5].start_slot); @@ -129,11 +129,11 @@ TEST_F(state_var_tests, circuit_mapping) TEST_F(state_var_tests, circuit_mapping_within_mapping) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); // { ::Contract contract("TestContract"); @@ -151,11 +151,11 @@ TEST_F(state_var_tests, circuit_mapping_within_mapping) TEST_F(state_var_tests, circuit_partial_mapping) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); // { ::Contract contract("TestContract"); @@ -173,11 +173,11 @@ TEST_F(state_var_tests, circuit_partial_mapping) TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); @@ -220,11 +220,11 @@ TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); // bool sort(NT::uint256 i, NT::uint256 j) // { @@ -282,11 +282,11 @@ TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) TEST_F(state_var_tests, circuit_initialise_utxo_of_default_singleton_private_note_fr) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); @@ -330,11 +330,11 @@ TEST_F(state_var_tests, circuit_initialise_utxo_of_default_singleton_private_not TEST_F(state_var_tests, circuit_modify_utxo_of_default_singleton_private_note_fr) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp index e278b280054a..f44ff1cbc71a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp @@ -45,7 +45,7 @@ template class FunctionExecutionContext { friend class Opcodes; public: - Builder& composer; + Builder& builder; OracleWrapperInterface& oracle; Contract* contract = nullptr; @@ -69,8 +69,8 @@ template class FunctionExecutionContext { bool is_finalised = false; public: - FunctionExecutionContext(Builder& composer, OracleWrapperInterface& oracle) - : composer(composer) + FunctionExecutionContext(Builder& builder, OracleWrapperInterface& oracle) + : builder(builder) , oracle(oracle) , private_circuit_public_inputs(OptionalPrivateCircuitPublicInputs::create()) { @@ -169,10 +169,10 @@ template class FunctionExecutionContext { fr f_encoding_ct = fr(f_encoding); // Important Note: we MUST constrain this function_selector value against a fixed selector value. Without the // below line, an attacker could pass any f_encoding as a witness. - f_encoding_ct.convert_constant_to_fixed_witness(&composer); + f_encoding_ct.convert_constant_to_fixed_witness(&builder); /// @dev The above constraining could alternatively be achieved as follows: - // fr alternative_f_encoding_ct = fr(to_ct(composer, f_encoding)); + // fr alternative_f_encoding_ct = fr(to_ct(builder, f_encoding)); // alternative_f_encoding_ct.fix_witness(); const FunctionData f_function_data_ct{ @@ -201,13 +201,13 @@ template class FunctionExecutionContext { // contract (which cannot own a secret), rather than a human. ); - Builder f_composer = Builder("../barretenberg/cpp/srs_db/ignition"); + Builder f_builder = Builder(); - OracleWrapperInterface f_oracle_wrapper(f_composer, f_oracle); + OracleWrapperInterface f_oracle_wrapper(f_builder, f_oracle); // We need an exec_ctx reference which won't go out of scope, so we store a shared_ptr to the newly-created // exec_ctx in `this` exec_ctx. - auto f_exec_ctx = std::make_shared>(f_composer, f_oracle_wrapper); + auto f_exec_ctx = std::make_shared>(f_builder, f_oracle_wrapper); array_push(nested_private_call_exec_ctxs, f_exec_ctx); @@ -217,9 +217,9 @@ template class FunctionExecutionContext { // The f_exec_ctx will be populated with all the information about that function's execution. std::apply(f, std::forward_as_tuple(*f_exec_ctx, native_args)); - // Remember: the data held in the f_exec_ctc was built with a different composer than that + // Remember: the data held in the f_exec_ctc was built with a different builder than that // of `this` exec_ctx. So we only allow ourselves to get the native types, so that we can consciously declare - // circuit types for `this` exec_ctx using `this->composer`. + // circuit types for `this` exec_ctx using `this->builder`. auto f_public_inputs_nt = f_exec_ctx->get_final_private_circuit_public_inputs(); // Since we've made a call to another function, we now need to push a call_stack_item_hash to `this` function's @@ -228,7 +228,7 @@ template class FunctionExecutionContext { // - args // - return_values // - call_context (TODO: maybe this only needs to be done in the kernel circuit). - auto f_public_inputs_ct = f_public_inputs_nt.to_circuit_type(composer); + auto f_public_inputs_ct = f_public_inputs_nt.to_circuit_type(builder); // Constrain that the arguments of the executed function match those we expect: auto args_hash_ct = compute_var_args_hash(args); @@ -320,7 +320,7 @@ template class FunctionExecutionContext { finalise_utxos(); private_circuit_public_inputs.set_commitments(new_commitments); private_circuit_public_inputs.set_nullifiers(new_nullifiers); - private_circuit_public_inputs.set_public(composer); + private_circuit_public_inputs.set_public(builder); final_private_circuit_public_inputs = private_circuit_public_inputs.remove_optionality().template to_native_type(); is_finalised = true; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index 549c538dec25..7d24e75678a1 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -31,12 +31,12 @@ template struct DefaultPrivateNotePreimage { bool operator==(DefaultPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Builder& composer) const + template auto to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; // Depending on whether the _circuit_ type version of `V` is from the stdlib, or some custom type, the // conversion method will be different. diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp index 4e54498de030..01a7a6e255bd 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp @@ -22,12 +22,12 @@ template struct DefaultPrivateNoteNullifierPreimage { bool operator==(DefaultPrivateNoteNullifierPreimage const&) const = default; template - DefaultPrivateNoteNullifierPreimage> to_circuit_type(Builder& composer) const + DefaultPrivateNoteNullifierPreimage> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; DefaultPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp index 810e8a5d7910..df512dc60404 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp @@ -27,12 +27,12 @@ template struct DefaultSingletonPrivateNotePreimage { bool operator==(DefaultSingletonPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Builder& composer) const + template auto to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; // Depending on whether the _circuit_ type version of `V` is from the stdlib, or some custom type, the // conversion method will be different. diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp index c70a342ac148..3db90a996e45 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp @@ -22,12 +22,12 @@ template struct DefaultSingletonPrivateNoteNullifierPreimage { bool operator==(DefaultSingletonPrivateNoteNullifierPreimage const&) const = default; template - DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Builder& composer) const + DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; DefaultSingletonPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), diff --git a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp index 9157ce8eec76..574f3488a174 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp @@ -20,7 +20,7 @@ using aztec3::utils::types::CircuitTypes; /** * The main purpose of this wrapper is to: * - cache values which have been already given by the oracle previously during this execution; - * - convert Native types (returned by the oracle) into circuit types, using the composer instance. + * - convert Native types (returned by the oracle) into circuit types, using the builder instance. * Note: Insecure circuits could be built if the same value is queried twice from the oracle (since a malicious prover * could provide two different witnesses for a single thing). The Native oracle will throw if you try a double-query of * certain information. @@ -32,20 +32,20 @@ template class OracleWrapperInterface { using address = typename CT::address; public: - Builder& composer; + Builder& builder; NativeOracle& native_oracle; // Initialise from Native. // Used when initialising for a user's first call. - OracleWrapperInterface(Builder& composer, NativeOracle& native_oracle) - : composer(composer), native_oracle(native_oracle){}; + OracleWrapperInterface(Builder& builder, NativeOracle& native_oracle) + : builder(builder), native_oracle(native_oracle){}; fr& get_msg_sender_private_key() { if (msg_sender_private_key) { return *msg_sender_private_key; } - msg_sender_private_key = aztec3::utils::types::to_ct(composer, native_oracle.get_msg_sender_private_key()); + msg_sender_private_key = aztec3::utils::types::to_ct(builder, native_oracle.get_msg_sender_private_key()); validate_msg_sender_private_key(); return *msg_sender_private_key; }; @@ -57,7 +57,7 @@ template class OracleWrapperInterface { if (call_context) { return *call_context; } - call_context = native_oracle.get_call_context().to_circuit_type(composer); + call_context = native_oracle.get_call_context().to_circuit_type(builder); return *call_context; }; @@ -66,7 +66,7 @@ template class OracleWrapperInterface { if (contract_deployment_data) { return *contract_deployment_data; } - contract_deployment_data = native_oracle.get_contract_deployment_data().to_circuit_type(composer); + contract_deployment_data = native_oracle.get_contract_deployment_data().to_circuit_type(builder); return *contract_deployment_data; }; @@ -76,11 +76,11 @@ template class OracleWrapperInterface { address& get_tx_origin() { return get_call_context().tx_origin; }; - fr generate_salt() const { return aztec3::utils::types::to_ct(composer, native_oracle.generate_salt()); } + fr generate_salt() const { return aztec3::utils::types::to_ct(builder, native_oracle.generate_salt()); } fr generate_random_element() const { - return aztec3::utils::types::to_ct(composer, native_oracle.generate_random_element()); + return aztec3::utils::types::to_ct(builder, native_oracle.generate_random_element()); } template @@ -92,7 +92,7 @@ template class OracleWrapperInterface { auto native_utxo_sload_datum = native_oracle.get_utxo_sload_datum(native_storage_slot_point, native_advice); - return native_utxo_sload_datum.to_circuit_type(composer); + return native_utxo_sload_datum.to_circuit_type(builder); } template auto get_utxo_sload_data(grumpkin_point const& storage_slot_point, @@ -106,7 +106,7 @@ template class OracleWrapperInterface { auto native_utxo_sload_data = native_oracle.get_utxo_sload_data(native_storage_slot_point, num_notes, native_advice); - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; return map(native_utxo_sload_data, to_circuit_type); } diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp index 8c3ff1cf57b6..2aff1c41490f 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp @@ -20,11 +20,11 @@ OptionalPrivateCircuitPublicInputs constructor(FunctionExecutionContext& exe exec_ctx.register_contract(&contract); // Convert params into circuit types: - auto& composer = exec_ctx.composer; + auto& builder = exec_ctx.builder; - CT::fr const arg0 = to_ct(composer, args[0]); - CT::fr const arg1 = to_ct(composer, args[1]); - CT::fr const arg2 = to_ct(composer, args[2]); + CT::fr const arg0 = to_ct(builder, args[0]); + CT::fr const arg1 = to_ct(builder, args[1]); + CT::fr const arg2 = to_ct(builder, args[2]); auto& oracle = exec_ctx.oracle; const CT::address msg_sender = oracle.get_msg_sender(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp index 936532a74aae..5e68463937ed 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp @@ -40,11 +40,11 @@ TEST_F(escrow_tests, circuit_deposit) // contains a reference to earlier-declared classes... so we'd end up with classes containing dangling references, // if all this stuff were to be declared in a setup function's scope. // We could instead store shared_ptrs in every class...? - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); auto amount = NT::fr(5); auto asset_id = NT::fr(1); @@ -53,21 +53,21 @@ TEST_F(escrow_tests, circuit_deposit) auto result = deposit(exec_ctx, { amount, asset_id, memo }); info("result: ", result); - // info("witness: ", composer.witness); - // info("constant variables: ", composer.constant_variables); - // info("variables: ", composer.variables); - info("failed?: ", composer.failed()); - info("err: ", composer.err()); - info("n: ", composer.num_gates); + // info("witness: ", builder.witness); + // info("constant variables: ", builder.constant_variables); + // info("variables: ", builder.variables); + info("failed?: ", builder.failed()); + info("err: ", builder.err()); + info("n: ", builder.num_gates); } TEST_F(escrow_tests, circuit_transfer) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); auto amount = NT::fr(5); auto to = NT::address(657756); @@ -78,21 +78,21 @@ TEST_F(escrow_tests, circuit_transfer) transfer(exec_ctx, amount, to, asset_id, memo, reveal_msg_sender_to_recipient, fee); - // info("witness: ", composer.witness); - // info("constant variables: ", composer.constant_variables); - // info("variables: ", composer.variables); - info("failed?: ", composer.failed()); - info("err: ", composer.err()); - info("n: ", composer.num_gates); + // info("witness: ", builder.witness); + // info("constant variables: ", builder.constant_variables); + // info("variables: ", builder.variables); + info("failed?: ", builder.failed()); + info("err: ", builder.err()); + info("n: ", builder.num_gates); } TEST_F(escrow_tests, circuit_withdraw) { - C composer = C("../barretenberg/cpp/srs_db/ignition"); + C builder = C(); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); - FunctionExecutionContext exec_ctx(composer, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); + FunctionExecutionContext exec_ctx(builder, oracle_wrapper); auto amount = NT::fr(5); auto asset_id = NT::fr(1); @@ -102,12 +102,12 @@ TEST_F(escrow_tests, circuit_withdraw) withdraw(exec_ctx, amount, asset_id, memo, l1_withdrawal_address, fee); - // info("witness: ", composer.witness); - // info("constant variables: ", composer.constant_variables); - // info("variables: ", composer.variables); - info("failed?: ", composer.failed()); - info("err: ", composer.err()); - info("n: ", composer.num_gates); + // info("witness: ", builder.witness); + // info("constant variables: ", builder.constant_variables); + // info("variables: ", builder.variables); + info("failed?: ", builder.failed()); + info("err: ", builder.err()); + info("n: ", builder.num_gates); } } // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp index 1e3c72f401a1..59d2ccb50d63 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp @@ -21,11 +21,11 @@ OptionalPrivateCircuitPublicInputs deposit(FunctionExecutionContext& exec_ct exec_ctx.register_contract(&contract); // Convert params into circuit types: - auto& composer = exec_ctx.composer; + auto& builder = exec_ctx.builder; - CT::fr amount = to_ct(composer, args[0]); - CT::fr asset_id = to_ct(composer, args[1]); - CT::fr memo = to_ct(composer, args[2]); + CT::fr amount = to_ct(builder, args[0]); + CT::fr asset_id = to_ct(builder, args[1]); + CT::fr memo = to_ct(builder, args[2]); auto& oracle = exec_ctx.oracle; const CT::address msg_sender = oracle.get_msg_sender(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp index 9cd5eb61294a..51e1a0be733c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp @@ -26,14 +26,14 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c exec_ctx.register_contract(&contract); // Convert arguments into circuit types: - auto& composer = exec_ctx.composer; - - CT::fr amount = to_ct(composer, _amount); - CT::address to = to_ct(composer, _to); - CT::fr asset_id = to_ct(composer, _asset_id); - CT::fr memo = to_ct(composer, _memo); - CT::boolean const reveal_msg_sender_to_recipient = to_ct(composer, _reveal_msg_sender_to_recipient); - CT::fr const fee = to_ct(composer, _fee); + auto& builder = exec_ctx.builder; + + CT::fr amount = to_ct(builder, _amount); + CT::address to = to_ct(builder, _to); + CT::fr asset_id = to_ct(builder, _asset_id); + CT::fr memo = to_ct(builder, _memo); + CT::boolean const reveal_msg_sender_to_recipient = to_ct(builder, _reveal_msg_sender_to_recipient); + CT::fr const fee = to_ct(builder, _fee); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp index 271bd1481b52..fdba8ab35e1e 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp @@ -25,13 +25,13 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c exec_ctx.register_contract(&contract); // Convert arguments into circuit types: - auto& composer = exec_ctx.composer; + auto& builder = exec_ctx.builder; - CT::fr const amount = to_ct(composer, _amount); - CT::fr asset_id = to_ct(composer, _asset_id); - CT::fr memo = to_ct(composer, _memo); - CT::fr const l1_withdrawal_address = to_ct(composer, _l1_withdrawal_address); - CT::fr const fee = to_ct(composer, _fee); + CT::fr const amount = to_ct(builder, _amount); + CT::fr asset_id = to_ct(builder, _asset_id); + CT::fr memo = to_ct(builder, _memo); + CT::fr const l1_withdrawal_address = to_ct(builder, _l1_withdrawal_address); + CT::fr const fee = to_ct(builder, _fee); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp index cb0bcc9ba723..ba7acefda62f 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp @@ -13,7 +13,7 @@ class private_to_private_function_call_tests : public ::testing::Test {}; TEST(private_to_private_function_call_tests, circuit_private_to_private_function_call) { - C fn1_composer = C("../barretenberg/cpp/srs_db/ignition"); + C fn1_builder = C(); DB db; const NT::address contract_address = 12345; @@ -37,9 +37,9 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function }; NativeOracle fn1_oracle = NativeOracle(db, contract_address, function_data, call_context, msg_sender_private_key); - OracleWrapper fn1_oracle_wrapper = OracleWrapper(fn1_composer, fn1_oracle); + OracleWrapper fn1_oracle_wrapper = OracleWrapper(fn1_builder, fn1_oracle); - FunctionExecutionContext fn1_exec_ctx(fn1_composer, fn1_oracle_wrapper); + FunctionExecutionContext fn1_exec_ctx(fn1_builder, fn1_oracle_wrapper); auto a = NT::fr(111); auto b = NT::fr(222); @@ -51,12 +51,12 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function info("function_1_1_public_inputs: ", function_1_1_public_inputs); - // info("witness: ", fn1_composer.witness); - // info("constant variables: ", fn1_composer.constant_variables); - // info("variables: ", fn1_composer.variables); - info("failed?: ", fn1_composer.failed()); - info("err: ", fn1_composer.err()); - info("n: ", fn1_composer.num_gates); + // info("witness: ", fn1_builder.witness); + // info("constant variables: ", fn1_builder.constant_variables); + // info("variables: ", fn1_builder.variables); + info("failed?: ", fn1_builder.failed()); + info("err: ", fn1_builder.err()); + info("n: ", fn1_builder.num_gates); } } // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp index 92c5a5ffa796..4377da64a9b5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp @@ -19,10 +19,10 @@ void function_1_1(FunctionExecutionContext& exec_ctx, std::vector const& exec_ctx.register_contract(&contract_1); // Convert arguments into circuit types: - auto& composer = exec_ctx.composer; - const auto a = to_ct(composer, _args[0]); - const auto b = to_ct(composer, _args[1]); - const auto c = to_ct(composer, _args[2]); + auto& builder = exec_ctx.builder; + const auto a = to_ct(builder, _args[0]); + const auto b = to_ct(builder, _args[1]); + const auto c = to_ct(builder, _args[2]); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp index b2ef763a06a3..ac424411667e 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp @@ -19,10 +19,10 @@ void function_2_1(FunctionExecutionContext& exec_ctx, std::vector const& exec_ctx.register_contract(&contract_2); // Convert arguments into circuit types: - auto& composer = exec_ctx.composer; - const auto a = to_ct(composer, _args[0]); - const auto b = to_ct(composer, _args[1]); - const auto c = to_ct(composer, _args[2]); + auto& builder = exec_ctx.builder; + const auto a = to_ct(builder, _args[0]); + const auto b = to_ct(builder, _args[1]); + const auto c = to_ct(builder, _args[2]); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp index 5f58c93bd3f5..bfb7e0d9978b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp @@ -28,14 +28,14 @@ template struct UTXOSLoadDatum { uint32 leaf_index; fr historic_private_data_tree_root = 0; - template auto to_circuit_type(Builder& composer) const + template auto to_circuit_type(Builder& builder) const { static_assert(std::is_same::value); - // Capture the composer: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // Capture the circuit builder: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto preimage_ct = preimage.to_circuit_type(composer); + auto preimage_ct = preimage.to_circuit_type(builder); UTXOSLoadDatum, decltype(preimage_ct)> datum = { to_ct(commitment), to_ct(contract_address), preimage_ct, diff --git a/circuits/cpp/src/aztec3/circuits/hash.hpp b/circuits/cpp/src/aztec3/circuits/hash.hpp index 7b796fd308e4..4fb1780552a3 100644 --- a/circuits/cpp/src/aztec3/circuits/hash.hpp +++ b/circuits/cpp/src/aztec3/circuits/hash.hpp @@ -184,7 +184,7 @@ std::array get_sibling_path(MerkleTree& tree, size_t leaf_index, size_t c } template -void check_membership(Builder& composer, +void check_membership(Builder& builder, typename NCT::fr const& value, typename NCT::fr const& index, std::array const& sibling_path, @@ -192,9 +192,9 @@ void check_membership(Builder& composer, std::string const& msg) { const auto calculated_root = root_from_sibling_path(value, index, sibling_path); - composer.do_assert(calculated_root == root, - std::string("Membership check failed: ") + msg, - aztec3::utils::CircuitErrorCode::MEMBERSHIP_CHECK_FAILED); + builder.do_assert(calculated_root == root, + std::string("Membership check failed: ") + msg, + aztec3::utils::CircuitErrorCode::MEMBERSHIP_CHECK_FAILED); } /** diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 7f3127004547..a134278b4618 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -49,11 +49,11 @@ TEST_F(private_kernel_tests, basic) false, deposit, { amount, asset_id, memo }, encrypted_logs_hash, encrypted_log_preimages_length, true); // Execute and prove the first kernel iteration - Builder private_kernel_composer; - auto const& public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs, true); + Builder private_kernel_builder; + auto const& public_inputs = private_kernel_circuit(private_kernel_builder, private_inputs, true); // Check the private kernel circuit - EXPECT_TRUE(private_kernel_composer.check_circuit()); + EXPECT_TRUE(private_kernel_builder.check_circuit()); } /** @@ -70,8 +70,8 @@ TEST_F(private_kernel_tests, circuit_cbinds) // first run actual simulation to get public inputs auto const& private_inputs = do_private_call_get_kernel_inputs_init( true, constructor, { arg0, arg1, arg2 }, encrypted_logs_hash, encrypted_log_preimages_length, true); - DummyBuilder composer = DummyBuilder("private_kernel_tests__circuit_create_proof_cbinds"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__circuit_create_proof_cbinds"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); // serialize expected public inputs for later comparison std::vector expected_public_inputs_vec; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index 2bb000f603eb..d471505e14ae 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -63,7 +63,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyBuilder composer = DummyBuilder("private_kernel__sim_init"); + DummyBuilder builder = DummyBuilder("private_kernel__sim_init"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); @@ -76,7 +76,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, .private_call = private_call_data, }; - auto public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + auto public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -86,7 +86,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *private_kernel_public_inputs_buf = raw_public_inputs_buf; *private_kernel_public_inputs_size_out = public_inputs_vec.size(); - return composer.alloc_and_serialize_first_failure(); + return builder.alloc_and_serialize_first_failure(); } WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_buf, @@ -94,7 +94,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyBuilder composer = DummyBuilder("private_kernel__sim_inner"); + DummyBuilder builder = DummyBuilder("private_kernel__sim_inner"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); @@ -106,7 +106,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu .private_call = private_call_data, }; - auto public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + auto public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -116,5 +116,5 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *private_kernel_public_inputs_buf = raw_public_inputs_buf; *private_kernel_public_inputs_size_out = public_inputs_vec.size(); - return composer.alloc_and_serialize_first_failure(); + return builder.alloc_and_serialize_first_failure(); } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index b06d39e835c6..64e91c8c597f 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -31,7 +31,7 @@ using aztec3::circuits::abis::private_kernel::PrivateCallData; namespace aztec3::circuits::kernel::private_kernel { -void common_validate_call_stack(DummyBuilder& composer, PrivateCallData const& private_call) +void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const& private_call) { const auto& stack = private_call.call_stack_item.public_inputs.private_call_stack; const auto& preimages = private_call.private_call_stack_preimages; @@ -42,9 +42,9 @@ void common_validate_call_stack(DummyBuilder& composer, PrivateCallData cons // Note: this assumes it's computationally infeasible to have `0` as a valid call_stack_item_hash. // Assumes `hash == 0` means "this stack item is empty". const auto calculated_hash = hash == 0 ? 0 : preimage.hash(); - composer.do_assert(hash == calculated_hash, - format("private_call_stack[", i, "] = ", hash, "; does not reconcile"), - CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); + builder.do_assert(hash == calculated_hash, + format("private_call_stack[", i, "] = ", hash, "; does not reconcile"), + CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); } } @@ -57,14 +57,14 @@ void common_validate_call_stack(DummyBuilder& composer, PrivateCallData cons * - https://discourse.aztec.network/t/to-read-or-not-to-read/178 * - https://discourse.aztec.network/t/spending-notes-which-havent-yet-been-inserted/180 * - * @param composer + * @param builder * @param read_requests the commitments being read by this private call * @param read_request_membership_witnesses used to compute the private data root * for a given request which is essentially a membership check. * @param historic_private_data_tree_root This is a reference to the historic root which all * read requests are checked against here. */ -void common_validate_read_requests(DummyBuilder& composer, +void common_validate_read_requests(DummyBuilder& builder, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, @@ -91,20 +91,20 @@ void common_validate_read_requests(DummyBuilder& composer, if (read_request != 0 && !is_transient_read) { const auto& root_for_read_request = root_from_sibling_path(leaf, witness.leaf_index, witness.sibling_path); - composer.do_assert(root_for_read_request == historic_private_data_tree_root, - format("private data root mismatch at read_request[", - rr_idx, - "] - ", - "Expected root: ", - historic_private_data_tree_root, - ", Read request gave root: ", - root_for_read_request), - CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); + builder.do_assert(root_for_read_request == historic_private_data_tree_root, + format("private data root mismatch at read_request[", + rr_idx, + "] - ", + "Expected root: ", + historic_private_data_tree_root, + ", Read request gave root: ", + root_for_read_request), + CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } } } -void common_update_end_values(DummyBuilder& composer, +void common_update_end_values(DummyBuilder& builder, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs) { @@ -117,12 +117,12 @@ void common_update_end_values(DummyBuilder& composer, if (is_static_call) { // No state changes are allowed for static calls: - composer.do_assert(is_array_empty(new_commitments) == true, - "new_commitments must be empty for static calls", - CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL); - composer.do_assert(is_array_empty(new_nullifiers) == true, - "new_nullifiers must be empty for static calls", - CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL); + builder.do_assert(is_array_empty(new_commitments) == true, + "new_commitments must be empty for static calls", + CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL); + builder.do_assert(is_array_empty(new_nullifiers) == true, + "new_nullifiers must be empty for static calls", + CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL); } const auto& storage_contract_address = private_call_public_inputs.call_context.storage_contract_address; @@ -144,16 +144,16 @@ void common_update_end_values(DummyBuilder& composer, new_nullifiers[i] == 0 ? 0 : silo_nullifier(storage_contract_address, new_nullifiers[i]); } - push_array_to_array(composer, siloed_new_commitments, public_inputs.end.new_commitments); - push_array_to_array(composer, siloed_new_nullifiers, public_inputs.end.new_nullifiers); + push_array_to_array(builder, siloed_new_commitments, public_inputs.end.new_commitments); + push_array_to_array(builder, siloed_new_nullifiers, public_inputs.end.new_nullifiers); } { // call stacks const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; - push_array_to_array(composer, this_private_call_stack, public_inputs.end.private_call_stack); + push_array_to_array(builder, this_private_call_stack, public_inputs.end.private_call_stack); const auto& this_public_call_stack = private_call_public_inputs.public_call_stack; - push_array_to_array(composer, this_public_call_stack, public_inputs.end.public_call_stack); + push_array_to_array(builder, this_public_call_stack, public_inputs.end.public_call_stack); } { // new l2 to l1 messages @@ -172,7 +172,7 @@ void common_update_end_values(DummyBuilder& composer, new_l2_to_l1_msgs[i]); } } - push_array_to_array(composer, new_l2_to_l1_msgs_to_insert, public_inputs.end.new_l2_to_l1_msgs); + push_array_to_array(builder, new_l2_to_l1_msgs_to_insert, public_inputs.end.new_l2_to_l1_msgs); } { // logs hashes @@ -201,7 +201,7 @@ void common_update_end_values(DummyBuilder& composer, } } -void common_contract_logic(DummyBuilder& composer, +void common_contract_logic(DummyBuilder& builder, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, @@ -231,27 +231,27 @@ void common_contract_logic(DummyBuilder& composer, portal_contract_address, contract_dep_data.function_tree_root }; - array_push(composer, public_inputs.end.new_contracts, native_new_contract_data); - composer.do_assert(contract_dep_data.constructor_vk_hash == private_call_vk_hash, - "constructor_vk_hash doesn't match private_call_vk_hash", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); + array_push(builder, public_inputs.end.new_contracts, native_new_contract_data); + builder.do_assert(contract_dep_data.constructor_vk_hash == private_call_vk_hash, + "constructor_vk_hash doesn't match private_call_vk_hash", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); // must imply == derived address - composer.do_assert(storage_contract_address == new_contract_address, - "contract address supplied doesn't match derived address", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + builder.do_assert(storage_contract_address == new_contract_address, + "contract address supplied doesn't match derived address", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); // compute contract address nullifier auto const blake_input = new_contract_address.to_field().to_buffer(); auto const new_contract_address_nullifier = NT::fr::serialize_from_buffer(NT::blake3s(blake_input).data()); // push the contract address nullifier to nullifier vector - array_push(composer, public_inputs.end.new_nullifiers, new_contract_address_nullifier); + array_push(builder, public_inputs.end.new_nullifiers, new_contract_address_nullifier); } else { // non-contract deployments must specify contract address being interacted with - composer.do_assert(storage_contract_address != 0, - "contract address can't be 0 for non-contract deployment related transactions", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + builder.do_assert(storage_contract_address != 0, + "contract address can't be 0 for non-contract deployment related transactions", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); /* We need to compute the root of the contract tree, starting from the function's VK: * - Compute the vk_hash (done above) @@ -281,7 +281,7 @@ void common_contract_logic(DummyBuilder& composer, auto const& purported_contract_tree_root = private_call.call_stack_item.public_inputs.historic_contract_tree_root; - composer.do_assert( + builder.do_assert( computed_contract_tree_root == purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root", CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp index f7539607882e..9a4dfdd65f4c 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp @@ -23,20 +23,20 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; // TODO(suyash): Add comments to these as well as other functions in PKC-init. -void common_validate_call_stack(DummyBuilder& composer, PrivateCallData const& private_call); +void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const& private_call); -void common_validate_read_requests(DummyBuilder& composer, +void common_validate_read_requests(DummyBuilder& builder, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, NT::fr const& historic_private_data_tree_root); -void common_update_end_values(DummyBuilder& composer, +void common_update_end_values(DummyBuilder& builder, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs); -void common_contract_logic(DummyBuilder& composer, +void common_contract_logic(DummyBuilder& builder, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp index 056e640f44f5..937516f3a32a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp @@ -22,16 +22,16 @@ namespace aztec3::circuits::kernel::private_kernel { // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Builder& composer, +// CT::AggregationObject verify_proofs(Builder& builder, // PrivateKernelInputsInit const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) // { // CT::AggregationObject aggregation_object = Aggregator::aggregate( -// &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, +// &builder, private_inputs.private_call.vk, private_inputs.private_call.proof, // num_private_call_public_inputs); -// Aggregator::aggregate(&composer, +// Aggregator::aggregate(&builder, // private_inputs.previous_kernel.vk, // private_inputs.previous_kernel.proof, // num_private_kernel_public_inputs, @@ -67,7 +67,7 @@ void initialise_end_values(PrivateKernelInputsInit const& private_inputs, public_inputs.constants = constants; } -void validate_this_private_call_against_tx_request(DummyBuilder& composer, +void validate_this_private_call_against_tx_request(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs) { // TODO(mike): this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' @@ -77,29 +77,29 @@ void validate_this_private_call_against_tx_request(DummyBuilder& composer, const auto& tx_request = private_inputs.tx_request; const auto& call_stack_item = private_inputs.private_call.call_stack_item; - composer.do_assert(tx_request.origin == call_stack_item.contract_address, - "user's intent does not match initial private call (tx_request.origin must match " - "call_stack_item.contract_address)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + builder.do_assert(tx_request.origin == call_stack_item.contract_address, + "user's intent does not match initial private call (tx_request.origin must match " + "call_stack_item.contract_address)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - composer.do_assert(tx_request.function_data.hash() == call_stack_item.function_data.hash(), - "user's intent does not match initial private call (tx_request.function_data must match " - "call_stack_item.function_data)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + builder.do_assert(tx_request.function_data.hash() == call_stack_item.function_data.hash(), + "user's intent does not match initial private call (tx_request.function_data must match " + "call_stack_item.function_data)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - composer.do_assert(tx_request.args_hash == call_stack_item.public_inputs.args_hash, - "user's intent does not match initial private call (tx_request.args must match " - "call_stack_item.public_inputs.args)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + builder.do_assert(tx_request.args_hash == call_stack_item.public_inputs.args_hash, + "user's intent does not match initial private call (tx_request.args must match " + "call_stack_item.public_inputs.args)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); }; -void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInit const& private_inputs) +void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; - composer.do_assert(this_call_stack_item.function_data.is_private == true, - "Cannot execute a non-private function with the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); + builder.do_assert(this_call_stack_item.function_data.is_private == true, + "Cannot execute a non-private function with the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); // TODO(mike): change to allow 3 initial calls on the private call stack, so a fee can be paid and a gas // rebate can be paid. @@ -109,21 +109,21 @@ void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInit const& * despite no longer needing a full `previous_kernel` */ - composer.do_assert(this_call_stack_item.public_inputs.call_context.is_delegate_call == false, - "Users cannot make a delegatecall", - CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - composer.do_assert(this_call_stack_item.public_inputs.call_context.is_static_call == false, - "Users cannot make a static call", - CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + builder.do_assert(this_call_stack_item.public_inputs.call_context.is_delegate_call == false, + "Users cannot make a delegatecall", + CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + builder.do_assert(this_call_stack_item.public_inputs.call_context.is_static_call == false, + "Users cannot make a static call", + CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); // The below also prevents delegatecall/staticcall in the base case - composer.do_assert(this_call_stack_item.public_inputs.call_context.storage_contract_address == - this_call_stack_item.contract_address, - "Storage contract address must be that of the called contract", - CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); + builder.do_assert(this_call_stack_item.public_inputs.call_context.storage_contract_address == + this_call_stack_item.contract_address, + "Storage contract address must be that of the called contract", + CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); } -void update_end_values(DummyBuilder& composer, +void update_end_values(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -138,7 +138,7 @@ void update_end_values(DummyBuilder& composer, ASSERT(public_inputs.end.unencrypted_log_preimages_length == fr(0)); // Since it's the first iteration, we need to push the the tx hash nullifier into the `new_nullifiers` array - array_push(composer, public_inputs.end.new_nullifiers, private_inputs.tx_request.hash()); + array_push(builder, public_inputs.end.new_nullifiers, private_inputs.tx_request.hash()); // Note that we do not need to nullify the transaction request nonce anymore. // Should an account want to additionally use nonces for replay protection or handling cancellations, @@ -149,7 +149,7 @@ void update_end_values(DummyBuilder& composer, // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs) { // We'll be pushing data to this during execution of this circuit. @@ -158,35 +158,35 @@ KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder // Do this before any functions can modify the inputs. initialise_end_values(private_inputs, public_inputs); - validate_inputs(composer, private_inputs); + validate_inputs(builder, private_inputs); - validate_this_private_call_against_tx_request(composer, private_inputs); + validate_this_private_call_against_tx_request(builder, private_inputs); // TODO(rahul) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/499 // Noir doesn't have hash index so it can't hash private call stack item correctly // TODO(dbanks12): may need to comment out hash check in here according to TODO above // TODO(jeanmon) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/671 - // common_validate_call_stack(composer, private_inputs.private_call); + // common_validate_call_stack(builder, private_inputs.private_call); common_validate_read_requests( - composer, + builder, private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address, private_inputs.private_call.call_stack_item.public_inputs.read_requests, private_inputs.private_call.read_request_membership_witnesses, public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root); // TODO(dbanks12): feels like update_end_values should happen after contract logic - update_end_values(composer, private_inputs, public_inputs); - common_update_end_values(composer, private_inputs.private_call, public_inputs); + update_end_values(builder, private_inputs, public_inputs); + common_update_end_values(builder, private_inputs.private_call, public_inputs); - common_contract_logic(composer, + common_contract_logic(builder, private_inputs.private_call, public_inputs, private_inputs.tx_request.tx_context.contract_deployment_data, private_inputs.tx_request.function_data); // We'll skip any verification in this native implementation, because for a Local Developer Testnet, there won't - // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(composer, + // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(builder, // private_inputs, // _private_inputs.private_call.vk->num_public_inputs, // _private_inputs.previous_kernel.vk->num_public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp index 2fa45b417383..39dea9a86752 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp @@ -13,7 +13,7 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; // using abis::private_kernel::PublicInputs; using DummyBuilder = aztec3::utils::DummyBuilder; -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp index 285567194f80..980936c8f3d3 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp @@ -56,8 +56,8 @@ TEST_F(native_private_kernel_init_tests, deposit) auto const& private_inputs = do_private_call_get_kernel_inputs_init( false, deposit, standard_test_args(), encrypted_logs_hash, encrypted_log_preimages_length); - DummyBuilder composer = DummyBuilder("private_kernel_tests__native_deposit"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__native_deposit"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); EXPECT_TRUE(validate_no_new_deployed_contract(public_inputs)); @@ -78,10 +78,10 @@ TEST_F(native_private_kernel_init_tests, deposit) auto const& expected_unencrypted_logs_hash = accumulate_sha256({ fr(0), fr(0), fr(0), fr(0) }); ASSERT_EQ(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); - // Assert that composer doesn't give any errors - ASSERT_FALSE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().message, ""); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::NO_ERROR); + // Assert that builder doesn't give any errors + ASSERT_FALSE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().message, ""); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::NO_ERROR); } /** @@ -90,8 +90,8 @@ TEST_F(native_private_kernel_init_tests, deposit) TEST_F(native_private_kernel_init_tests, basic_contract_deployment) { auto const& private_inputs = do_private_call_get_kernel_inputs_init(true, constructor, standard_test_args()); - DummyBuilder composer = DummyBuilder("private_kernel_tests__native_basic_contract_deployment"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__native_basic_contract_deployment"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); EXPECT_TRUE(validate_deployed_contract_address(private_inputs, public_inputs)); @@ -105,10 +105,10 @@ TEST_F(native_private_kernel_init_tests, basic_contract_deployment) ASSERT_EQ(public_inputs.end.encrypted_logs_hash, expected_logs_hash); ASSERT_EQ(public_inputs.end.encrypted_logs_hash, expected_logs_hash); - // Assert that composer doesn't give any errors - ASSERT_FALSE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().message, ""); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::NO_ERROR); + // Assert that builder doesn't give any errors + ASSERT_FALSE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().message, ""); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::NO_ERROR); } // TODO(suyash): Disabled until https://github.com/AztecProtocol/aztec-packages/issues/499 is resolved. @@ -119,12 +119,12 @@ TEST_F(native_private_kernel_init_tests, DISABLED_contract_deployment_call_stack // Randomise the second item in the private call stack (i.e. hash of the private call item). private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[1] = NT::fr::random_element(); - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_call_stack_item_hash_mismatch_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + native_private_kernel_circuit_initial(builder, private_inputs); - EXPECT_EQ(composer.failed(), true); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_EQ(builder.failed(), true); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); } @@ -135,13 +135,13 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_construct // Pollute the constructor vk hash in the tx_request. private_inputs.tx_request.tx_context.contract_deployment_data.constructor_vk_hash = NT::fr::random_element(); - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_incorrect_constructor_vk_hash_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + native_private_kernel_circuit_initial(builder, private_inputs); - EXPECT_EQ(composer.failed(), true); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); - EXPECT_EQ(composer.get_first_failure().message, "constructor_vk_hash doesn't match private_call_vk_hash"); + EXPECT_EQ(builder.failed(), true); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); + EXPECT_EQ(builder.get_first_failure().message, "constructor_vk_hash doesn't match private_call_vk_hash"); } TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_contract_address_fails) @@ -154,12 +154,12 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_contract_ private_inputs.tx_request.origin = random_address; private_inputs.private_call.call_stack_item.contract_address = random_address; - DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); - EXPECT_EQ(composer.failed(), true); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); - EXPECT_EQ(composer.get_first_failure().message, "contract address supplied doesn't match derived address"); + EXPECT_EQ(builder.failed(), true); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + EXPECT_EQ(builder.get_first_failure().message, "contract address supplied doesn't match derived address"); } TEST_F(native_private_kernel_init_tests, contract_deployment_contract_address_mismatch_fails) @@ -173,12 +173,12 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_contract_address_mi private_inputs.private_call.call_stack_item.contract_address = random_contract_address; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); } @@ -190,14 +190,14 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_function_data_misma private_inputs.tx_request.function_data.function_selector = numeric::random::get_engine().get_random_uint32(); // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "user's intent does not match initial private call (tx_request.function_data must match " "call_stack_item.function_data)"); } @@ -210,14 +210,14 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_args_hash_mismatch_ private_inputs.tx_request.args_hash = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "user's intent does not match initial private call (tx_request.args must match " "call_stack_item.public_inputs.args)"); } @@ -230,14 +230,14 @@ TEST_F(native_private_kernel_init_tests, private_function_is_private_false_fails private_inputs.private_call.call_stack_item.function_data.is_private = false; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_is_private_false_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_is_private_false_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "Cannot execute a non-private function with the private kernel circuit"); } @@ -250,13 +250,13 @@ TEST_F(native_private_kernel_init_tests, private_function_static_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_static_call = true; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_static_call_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_static_call_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - EXPECT_EQ(composer.get_first_failure().message, "Users cannot make a static call"); + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + EXPECT_EQ(builder.get_first_failure().message, "Users cannot make a static call"); } TEST_F(native_private_kernel_init_tests, private_function_delegate_call_fails) @@ -267,13 +267,13 @@ TEST_F(native_private_kernel_init_tests, private_function_delegate_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_delegate_call_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_delegate_call_fails"); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - EXPECT_EQ(composer.get_first_failure().message, "Users cannot make a delegatecall"); + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + EXPECT_EQ(builder.get_first_failure().message, "Users cannot make a delegatecall"); } TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_contract_address_fails) @@ -285,14 +285,14 @@ TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_cont NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_storage_contract_address_fails"); - native_private_kernel_circuit_initial(composer, private_inputs); + native_private_kernel_circuit_initial(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, "Storage contract address must be that of the called contract"); + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); + EXPECT_EQ(builder.get_first_failure().message, "Storage contract address must be that of the called contract"); } TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) @@ -311,13 +311,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_request"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_request"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -339,13 +339,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -367,13 +367,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -405,13 +405,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_read_request_root_mismatch"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_root_mismatch"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -431,16 +431,16 @@ TEST_F(native_private_kernel_init_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_no_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_no_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -460,16 +460,16 @@ TEST_F(native_private_kernel_init_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_one_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_one_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -489,16 +489,16 @@ TEST_F(native_private_kernel_init_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_two_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_two_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -519,16 +519,16 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -557,16 +557,16 @@ TEST_F(native_private_kernel_init_tests, native_one_transient_read_requests_work read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_init_tests__native_one_transient_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_one_transient_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_works) @@ -588,17 +588,17 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_ read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_one_transient_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } } // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp index 9960180808a9..53170f606c89 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp @@ -23,16 +23,16 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Builder& composer, +// CT::AggregationObject verify_proofs(Builder& builder, // PrivateInputs const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) // { // CT::AggregationObject aggregation_object = Aggregator::aggregate( -// &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, +// &builder, private_inputs.private_call.vk, private_inputs.private_call.proof, // num_private_call_public_inputs); -// Aggregator::aggregate(&composer, +// Aggregator::aggregate(&builder, // private_inputs.previous_kernel.vk, // private_inputs.previous_kernel.proof, // num_private_kernel_public_inputs, @@ -41,7 +41,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // return aggregation_object; // } -void validate_this_private_call_hash(DummyBuilder& composer, +void validate_this_private_call_hash(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -50,32 +50,32 @@ void validate_this_private_call_hash(DummyBuilder& composer, const auto popped_private_call_hash = array_pop(public_inputs.end.private_call_stack); const auto calculated_this_private_call_hash = private_inputs.private_call.call_stack_item.hash(); - composer.do_assert( + builder.do_assert( popped_private_call_hash == calculated_this_private_call_hash, "calculated private_call_hash does not match provided private_call_hash at the top of the call stack", CircuitErrorCode::PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); }; -void validate_contract_tree_root(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) +void validate_contract_tree_root(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) { auto const& purported_contract_tree_root = private_inputs.private_call.call_stack_item.public_inputs.historic_contract_tree_root; auto const& previous_kernel_contract_tree_root = private_inputs.previous_kernel.public_inputs.constants.historic_tree_roots.private_historic_tree_roots .contract_tree_root; - composer.do_assert( + builder.do_assert( purported_contract_tree_root == previous_kernel_contract_tree_root, "purported_contract_tree_root doesn't match previous_kernel_contract_tree_root", CircuitErrorCode::PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH); } -void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs) +void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; - composer.do_assert(this_call_stack_item.function_data.is_private == true, - "Cannot execute a non-private function with the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); + builder.do_assert(this_call_stack_item.function_data.is_private == true, + "Cannot execute a non-private function with the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); const auto& start = private_inputs.previous_kernel.public_inputs.end; @@ -84,21 +84,21 @@ void validate_inputs(DummyBuilder& composer, PrivateKernelInputsInner const& NT::fr const start_private_call_stack_length = array_length(start.private_call_stack); - composer.do_assert(private_inputs.previous_kernel.public_inputs.is_private == true, - "Cannot verify a non-private kernel snark in the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL); - composer.do_assert(this_call_stack_item.function_data.is_constructor == false, - "A constructor must be executed as the first tx in the recursion", - CircuitErrorCode::PRIVATE_KERNEL__CONSTRUCTOR_EXECUTED_IN_RECURSION); - composer.do_assert(start_private_call_stack_length != 0, - "Cannot execute private kernel circuit with an empty private call stack", - CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_EMPTY); + builder.do_assert(private_inputs.previous_kernel.public_inputs.is_private == true, + "Cannot verify a non-private kernel snark in the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL); + builder.do_assert(this_call_stack_item.function_data.is_constructor == false, + "A constructor must be executed as the first tx in the recursion", + CircuitErrorCode::PRIVATE_KERNEL__CONSTRUCTOR_EXECUTED_IN_RECURSION); + builder.do_assert(start_private_call_stack_length != 0, + "Cannot execute private kernel circuit with an empty private call stack", + CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_EMPTY); } // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) { // We'll be pushing data to this during execution of this circuit. @@ -107,19 +107,19 @@ KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& // Do this before any functions can modify the inputs. common_initialise_end_values(private_inputs, public_inputs); - validate_inputs(composer, private_inputs); + validate_inputs(builder, private_inputs); // TODO(jeanmon) Resuscitate after issue 499 is fixed as explained below. // Remove the array_pop below when uncommenting this validation. - // validate_this_private_call_hash(composer, private_inputs, public_inputs); + // validate_this_private_call_hash(builder, private_inputs, public_inputs); array_pop(public_inputs.end.private_call_stack); // TODO(dbanks12): may need to comment out hash check in here according to TODO above // TODO(jeanmon) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/671 - // common_validate_call_stack(composer, private_inputs.private_call); + // common_validate_call_stack(builder, private_inputs.private_call); common_validate_read_requests( - composer, + builder, private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address, private_inputs.private_call.call_stack_item.public_inputs.read_requests, private_inputs.private_call.read_request_membership_witnesses, @@ -127,20 +127,20 @@ KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& // TODO(dbanks12): feels like update_end_values should happen later - common_update_end_values(composer, private_inputs.private_call, public_inputs); + common_update_end_values(builder, private_inputs.private_call, public_inputs); // ensure that historic/purported contract tree root matches the one in previous kernel - validate_contract_tree_root(composer, private_inputs); + validate_contract_tree_root(builder, private_inputs); const auto private_call_stack_item = private_inputs.private_call.call_stack_item; - common_contract_logic(composer, + common_contract_logic(builder, private_inputs.private_call, public_inputs, private_call_stack_item.public_inputs.contract_deployment_data, private_call_stack_item.function_data); // We'll skip any verification in this native implementation, because for a Local Developer Testnet, there won't - // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(composer, + // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(builder, // private_inputs, // _private_inputs.private_call.vk->num_public_inputs, // _private_inputs.previous_kernel.vk->num_public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp index e832b6981ac9..09fd40b5c3f2 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp @@ -12,7 +12,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; using DummyBuilder = aztec3::utils::DummyBuilder; -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp index 07c73b53d2e2..c14baa8f7155 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp @@ -54,13 +54,13 @@ TEST_F(native_private_kernel_inner_tests, private_function_zero_storage_contract private_inputs.private_call.call_stack_item.hash(); // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_zero_storage_contract_address_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_zero_storage_contract_address_fails"); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + EXPECT_EQ(builder.get_first_failure().message, "contract address can't be 0 for non-contract deployment related transactions"); } @@ -73,15 +73,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_tr .contract_tree_root = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); + EXPECT_TRUE(builder.failed()); EXPECT_EQ( - composer.get_first_failure().code, + builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "purported_contract_tree_root doesn't match previous_kernel_contract_tree_root"); } @@ -94,14 +94,14 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -113,15 +113,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -134,14 +134,14 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -153,15 +153,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -174,21 +174,21 @@ TEST_F(native_private_kernel_inner_tests, DISABLED_private_function_incorrect_ca private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[0] = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder composer = DummyBuilder("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); - native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); + native_private_kernel_circuit_inner(builder, private_inputs); // Assertion checks - EXPECT_TRUE(composer.failed()); - EXPECT_EQ(composer.get_first_failure().code, + EXPECT_TRUE(builder.failed()); + EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); - EXPECT_EQ(composer.get_first_failure().message, + EXPECT_EQ(builder.get_first_failure().message, "calculated private_call_hash does not match provided private_call_hash at the top of the call stack"); } TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregating_too_many_commitments) { // Negative test to check if push_array_to_array fails if two many commitments are merged together - DummyBuilder composer = DummyBuilder("should_fail_if_aggregating_too_many_commitments"); + DummyBuilder builder = DummyBuilder("should_fail_if_aggregating_too_many_commitments"); PrivateKernelInputsInner private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); @@ -199,10 +199,10 @@ TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregat full_new_commitments[i] = i + 1; } private_inputs.previous_kernel.public_inputs.end.new_commitments = full_new_commitments; - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::ARRAY_OVERFLOW); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::ARRAY_OVERFLOW); } /** @@ -238,13 +238,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_request"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_request"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -265,13 +265,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -292,13 +292,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -329,13 +329,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_read_request_root_mismatch"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_root_mismatch"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().code, + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -352,16 +352,16 @@ TEST_F(native_private_kernel_inner_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_no_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_no_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) @@ -380,16 +380,16 @@ TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_one_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_one_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) @@ -408,16 +408,16 @@ TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_two_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_two_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) @@ -437,16 +437,16 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_works) @@ -467,16 +467,16 @@ TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_wor read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient_works) @@ -500,17 +500,17 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_one_transient_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } } // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp index da0e7f22b82f..fc03e3c7988a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp @@ -20,7 +20,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // TODO(jeanmon): the following code will be optimized based on hints regarding matching // a read request and commitment, i.e., we get pairs i,j such that read_requests[i] == new_commitments[j] // Relevant task: https://github.com/AztecProtocol/aztec-packages/issues/892 -void chop_pending_commitments(DummyBuilder& composer, +void chop_pending_commitments(DummyBuilder& builder, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, @@ -41,7 +41,7 @@ void chop_pending_commitments(DummyBuilder& composer, if (match_pos != KERNEL_NEW_COMMITMENTS_LENGTH) { new_commitments[match_pos] = fr(0); } else { - composer.do_assert( + builder.do_assert( false, format("transient read request at position [", i, "] does not match any new commitment"), CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH); @@ -53,7 +53,7 @@ void chop_pending_commitments(DummyBuilder& composer, utils::array_rearrange(new_commitments); } -KernelCircuitPublicInputs native_private_kernel_circuit_ordering(DummyBuilder& composer, +KernelCircuitPublicInputs native_private_kernel_circuit_ordering(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) { // We'll be pushing data to this during execution of this circuit. @@ -68,7 +68,7 @@ KernelCircuitPublicInputs native_private_kernel_circuit_ordering(DummyBuilde // Removing of nullified pending commitments have to happen on the list of commitments which have been accumulated // over all iterations of the private kernel. Therefore, we have to target commitments in public_inputs.end // Remark: The commitments in public_inputs.end have already been SILOED! - chop_pending_commitments(composer, + chop_pending_commitments(builder, private_inputs.private_call.call_stack_item.public_inputs.read_requests, private_inputs.private_call.read_request_membership_witnesses, public_inputs.end.new_commitments); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp index d44c1179b2cb..f180a3bfa6bd 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp @@ -13,6 +13,6 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_private_kernel_circuit_ordering( - DummyBuilder& composer, PrivateKernelInputsInner const& private_inputs); + DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp index 8dbc6baf06b8..6a389fd362bf 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp @@ -48,15 +48,15 @@ TEST_F(native_private_kernel_ordering_tests, native_one_read_request_choping_com private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("native_private_kernel_ordering_tests__native_one_read_request_choping_commitment_works"); - auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_ordering(builder, private_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 0); } @@ -85,15 +85,15 @@ TEST_F(native_private_kernel_ordering_tests, native_read_requests_choping_commit private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = + DummyBuilder builder = DummyBuilder("native_private_kernel_ordering_tests__native_read_requests_choping_commitment_works"); - auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_ordering(builder, private_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 2); ASSERT_TRUE(public_inputs.end.new_commitments[0] == fr(1285)); ASSERT_TRUE(public_inputs.end.new_commitments[1] == fr(1282)); @@ -127,10 +127,10 @@ TEST_F(native_private_kernel_ordering_tests, native_read_request_unknown_fails) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder composer = DummyBuilder("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); - auto const& public_inputs = native_private_kernel_circuit_ordering(composer, private_inputs); + DummyBuilder builder = DummyBuilder("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); + auto const& public_inputs = native_private_kernel_circuit_ordering(builder, private_inputs); - auto failure = composer.get_first_failure(); + auto failure = builder.get_first_failure(); ASSERT_EQ(failure.code, CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH); } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index 9a376c22308a..8af328b9bfed 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -27,16 +27,16 @@ using aztec3::circuits::silo_nullifier; // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // private_call.call_stack_item.public_inputs! -CT::AggregationObject verify_proofs(Builder& composer, PrivateKernelInputsInner const& private_inputs) +CT::AggregationObject verify_proofs(Builder& builder, PrivateKernelInputsInner const& private_inputs) { // compute P0, P1 for private function proof CT::AggregationObject aggregation_object = - Aggregator::aggregate(&composer, private_inputs.private_call.vk, private_inputs.private_call.proof); + Aggregator::aggregate(&builder, private_inputs.private_call.vk, private_inputs.private_call.proof); // computes P0, P1 for previous kernel proof // AND accumulates all of it in P0_agg, P1_agg Aggregator::aggregate( - &composer, private_inputs.previous_kernel.vk, private_inputs.previous_kernel.proof, aggregation_object); + &builder, private_inputs.previous_kernel.vk, private_inputs.previous_kernel.proof, aggregation_object); return aggregation_object; } @@ -306,14 +306,14 @@ void validate_inputs(PrivateKernelInputsInner const& private_inputs, bool fi // TODO: decide what to return. // TODO: is there a way to identify whether an input has not been used by ths circuit? This would help us more-safely // ensure we're constraining everything. -KernelCircuitPublicInputs private_kernel_circuit(Builder& composer, +KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, PrivateKernelInputsInner const& _private_inputs, bool first_iteration) { - const PrivateKernelInputsInner private_inputs = _private_inputs.to_circuit_type(composer); + const PrivateKernelInputsInner private_inputs = _private_inputs.to_circuit_type(builder); // We'll be pushing data to this during execution of this circuit. - KernelCircuitPublicInputs public_inputs = KernelCircuitPublicInputs{}.to_circuit_type(composer); + KernelCircuitPublicInputs public_inputs = KernelCircuitPublicInputs{}.to_circuit_type(builder); // Do this before any functions can modify the inputs. initialise_end_values(private_inputs, public_inputs); @@ -328,7 +328,7 @@ KernelCircuitPublicInputs private_kernel_circuit(Builder& composer, update_end_values(private_inputs, public_inputs); - auto aggregation_object = verify_proofs(composer, private_inputs); + auto aggregation_object = verify_proofs(builder, private_inputs); // TODO: kernel vk membership check! diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp index a35865f68545..17d10d4561a9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp @@ -10,7 +10,7 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -KernelCircuitPublicInputs private_kernel_circuit(Builder& composer, +KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, PrivateKernelInputsInner const& private_inputs, bool first_iteration); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp index 66fe8732d997..1b0b24827daf 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp @@ -217,7 +217,7 @@ std::pair, ContractDeploymentData> create_private_call_d /** * If `is_circuit` is true, we are running a real circuit test and therefore we need to generate a real proof using - * a private function composer. For the native tests, we are using a random data as public inputs of the private + * a private function builder. For the native tests, we are using a random data as public inputs of the private * function. As the native private kernel circuit doesn't validate any proofs and we don't currently test * multi-iterative kernel circuit, this should be fine. */ @@ -225,10 +225,10 @@ std::pair, ContractDeploymentData> create_private_call_d const NT::Proof private_circuit_proof = utils::get_proof_from_file(); if (is_circuit) { //*************************************************************************** - // Create a private circuit/call using composer, oracles, execution context + // Create a private circuit/call using builder, oracles, execution context // Generate its proof and public inputs for submission with a TX request //*************************************************************************** - Builder private_circuit_composer = Builder("../barretenberg/cpp/srs_db/ignition"); + Builder private_circuit_builder = Builder(); DB dummy_db; NativeOracle oracle = @@ -241,9 +241,9 @@ std::pair, ContractDeploymentData> create_private_call_d msg_sender_private_key) : NativeOracle(dummy_db, contract_address, function_data, call_context, msg_sender_private_key); - OracleWrapper oracle_wrapper = OracleWrapper(private_circuit_composer, oracle); + OracleWrapper oracle_wrapper = OracleWrapper(private_circuit_builder, oracle); - FunctionExecutionContext ctx(private_circuit_composer, oracle_wrapper); + FunctionExecutionContext ctx(private_circuit_builder, oracle_wrapper); OptionalPrivateCircuitPublicInputs const opt_private_circuit_public_inputs = func(ctx, args_vec); private_circuit_public_inputs = opt_private_circuit_public_inputs.remove_optionality(); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index 17f5a98564ff..a22535a3577d 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -113,8 +113,8 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) PreviousKernelData const init_previous_kernel{}; auto crs_factory = barretenberg::srs::get_crs_factory(); - Builder mock_kernel_composer; - auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs); + Builder mock_kernel_builder; + auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_builder, init_previous_kernel.public_inputs); NT::Proof const mock_kernel_proof = real_vk_proof ? get_proof_from_file() : NT::Proof{ .proof_data = std::vector(64, 0) }; @@ -129,7 +129,7 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) // TODO(rahul) assertions don't work in wasm and it isn't worth updating barratenberg to handle our error code // mechanism. Apparently we are getting rid of this function (dummy_previous_kernel()) soon anyway. - assert(!mock_kernel_composer.failed()); + assert(!mock_kernel_builder.failed()); return previous_kernel; } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index 99a23548b212..2fc71f4544d9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -48,10 +48,10 @@ WASM_EXPORT size_t public_kernel__init_verification_key(uint8_t const* pk_buf, u } CBIND(public_kernel__sim, [](PublicKernelInputs public_kernel_inputs) { - DummyBuilder composer = DummyBuilder("public_kernel__sim"); + DummyBuilder builder = DummyBuilder("public_kernel__sim"); KernelCircuitPublicInputs const result = public_kernel_inputs.previous_kernel.public_inputs.is_private - ? native_public_kernel_circuit_private_previous_kernel(composer, public_kernel_inputs) - : native_public_kernel_circuit_public_previous_kernel(composer, public_kernel_inputs); - return composer.result_or_error(result); + ? native_public_kernel_circuit_private_previous_kernel(builder, public_kernel_inputs) + : native_public_kernel_circuit_public_previous_kernel(builder, public_kernel_inputs); + return builder.result_or_error(result); }); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp index bcf1bcc056dd..7dfcd118be91 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp @@ -37,16 +37,16 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in /** * @brief Validates that the call stack item for this circuit iteration is at the top of the call stack - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_this_public_call_hash(DummyBuilder& composer, +void validate_this_public_call_hash(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs) { // If public call stack is empty, we bail so array_pop doesn't throw_or_abort if (array_length(public_inputs.end.public_call_stack) == 0) { - composer.do_assert( + builder.do_assert( false, "Public call stack can't be empty", CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); return; } @@ -59,7 +59,7 @@ void validate_this_public_call_hash(DummyBuilder& composer, const auto calculated_this_public_call_hash = get_call_stack_item_hash(public_kernel_inputs.public_call.call_stack_item); - composer.do_assert( + builder.do_assert( popped_public_call_hash == calculated_this_public_call_hash, format("calculated public_call_hash (", calculated_this_public_call_hash, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index 74ab65c92527..cb883ff7d741 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -33,11 +33,11 @@ namespace aztec3::circuits::kernel::public_kernel { /** * @brief Validate that all pre-images on the call stack hash to equal the accumulated data * @tparam The type of kernel input - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_stack(DummyBuilder& composer, KernelInput const& public_kernel_inputs) +void common_validate_call_stack(DummyBuilder& builder, KernelInput const& public_kernel_inputs) { // Ensures that the stack of pre-images corresponds to the call stack auto& stack = public_kernel_inputs.public_call.call_stack_item.public_inputs.public_call_stack; @@ -67,7 +67,7 @@ void common_validate_call_stack(DummyBuilder& composer, KernelInput const& publi const auto contract_being_called = preimage.contract_address; const auto calculated_hash = preimage.hash(); - composer.do_assert( + builder.do_assert( hash == calculated_hash, format( "public_call_stack[", i, "] = ", hash, "; does not reconcile with calculatedHash = ", calculated_hash), @@ -77,46 +77,46 @@ void common_validate_call_stack(DummyBuilder& composer, KernelInput const& publi // we need to consider regular vs delegate calls const auto preimage_msg_sender = preimage.public_inputs.call_context.msg_sender; const auto expected_msg_sender = is_delegate_call ? our_msg_sender : our_contract_address; - composer.do_assert(expected_msg_sender == preimage_msg_sender, - format("call_stack_msg_sender[", - i, - "] = ", - preimage_msg_sender, - " expected ", - expected_msg_sender, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); + builder.do_assert(expected_msg_sender == preimage_msg_sender, + format("call_stack_msg_sender[", + i, + "] = ", + preimage_msg_sender, + " expected ", + expected_msg_sender, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); // here we validate the storage address for each call on the stack // we need to consider regular vs delegate calls const auto preimage_storage_address = preimage.public_inputs.call_context.storage_contract_address; const auto expected_storage_address = is_delegate_call ? our_storage_address : contract_being_called; - composer.do_assert(expected_storage_address == preimage_storage_address, - format("call_stack_storage_address[", - i, - "] = ", - preimage_storage_address, - " expected ", - expected_storage_address, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); + builder.do_assert(expected_storage_address == preimage_storage_address, + format("call_stack_storage_address[", + i, + "] = ", + preimage_storage_address, + " expected ", + expected_storage_address, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); // if it is a delegate call then we check that the portal contract in the pre image is our portal contract const auto preimage_portal_address = preimage.public_inputs.call_context.portal_contract_address; const auto expected_portal_address = our_portal_contract_address; - composer.do_assert(!is_delegate_call || expected_portal_address == preimage_portal_address, - format("call_stack_portal_address[", - i, - "] = ", - preimage_portal_address, - " expected ", - expected_portal_address, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); + builder.do_assert(!is_delegate_call || expected_portal_address == preimage_portal_address, + format("call_stack_portal_address[", + i, + "] = ", + preimage_portal_address, + " expected ", + expected_portal_address, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); const auto num_contract_storage_update_requests = array_length(preimage.public_inputs.contract_storage_update_requests); - composer.do_assert( + builder.do_assert( !is_static_call || num_contract_storage_update_requests == 0, format("contract_storage_update_requests[", i, "] should be empty"), CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_CONTRACT_STORAGE_UPDATES_PROHIBITED_FOR_STATIC_CALL); @@ -126,11 +126,11 @@ void common_validate_call_stack(DummyBuilder& composer, KernelInput const& publi /** * @brief Validates the call context of the current iteration * @tparam The type of kernel input - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_context(DummyBuilder& composer, KernelInput const& public_kernel_inputs) +void common_validate_call_context(DummyBuilder& builder, KernelInput const& public_kernel_inputs) { const auto& call_stack_item = public_kernel_inputs.public_call.call_stack_item; const auto is_delegate_call = call_stack_item.public_inputs.call_context.is_delegate_call; @@ -140,11 +140,11 @@ void common_validate_call_context(DummyBuilder& composer, KernelInput const& pub const auto contract_storage_update_requests_length = array_length(call_stack_item.public_inputs.contract_storage_update_requests); - composer.do_assert(!is_delegate_call || contract_address != storage_contract_address, - std::string("call_context contract_address == storage_contract_address on delegate_call"), - CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); + builder.do_assert(!is_delegate_call || contract_address != storage_contract_address, + std::string("call_context contract_address == storage_contract_address on delegate_call"), + CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); - composer.do_assert( + builder.do_assert( !is_static_call || contract_storage_update_requests_length == 0, std::string("call_context contract storage update requests found on static call"), CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); @@ -153,49 +153,49 @@ void common_validate_call_context(DummyBuilder& composer, KernelInput const& pub /** * @brief Validates the kernel execution of the current iteration * @tparam The type of kernel input - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_kernel_execution(DummyBuilder& composer, KernelInput const& public_kernel_inputs) +void common_validate_kernel_execution(DummyBuilder& builder, KernelInput const& public_kernel_inputs) { - common_validate_call_context(composer, public_kernel_inputs); - common_validate_call_stack(composer, public_kernel_inputs); + common_validate_call_context(builder, public_kernel_inputs); + common_validate_call_stack(builder, public_kernel_inputs); }; /** * @brief Validates inputs to the kernel circuit that are common to all invocation scenarios * @tparam The type of kernel input - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_inputs(DummyBuilder& composer, KernelInput const& public_kernel_inputs) +void common_validate_inputs(DummyBuilder& builder, KernelInput const& public_kernel_inputs) { // Validates commons inputs for all type of kernel inputs const auto& this_call_stack_item = public_kernel_inputs.public_call.call_stack_item; - composer.do_assert(this_call_stack_item.public_inputs.call_context.is_contract_deployment == false, - "Contract deployment can't be a public function", - CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); - composer.do_assert(this_call_stack_item.contract_address != 0, - "Contract address must be valid", - CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); - composer.do_assert(this_call_stack_item.function_data.function_selector != 0, - "Function signature must be valid", - CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); - composer.do_assert(this_call_stack_item.function_data.is_constructor == false, - "Constructors can't be public functions", - CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); - composer.do_assert(this_call_stack_item.function_data.is_private == false, - "Cannot execute a private function with the public kernel circuit", - CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); - composer.do_assert(public_kernel_inputs.public_call.bytecode_hash != 0, - "Bytecode hash must be valid", - CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); + builder.do_assert(this_call_stack_item.public_inputs.call_context.is_contract_deployment == false, + "Contract deployment can't be a public function", + CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); + builder.do_assert(this_call_stack_item.contract_address != 0, + "Contract address must be valid", + CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); + builder.do_assert(this_call_stack_item.function_data.function_selector != 0, + "Function signature must be valid", + CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); + builder.do_assert(this_call_stack_item.function_data.is_constructor == false, + "Constructors can't be public functions", + CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); + builder.do_assert(this_call_stack_item.function_data.is_private == false, + "Cannot execute a private function with the public kernel circuit", + CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); + builder.do_assert(public_kernel_inputs.public_call.bytecode_hash != 0, + "Bytecode hash must be valid", + CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); } template -void perform_static_call_checks(Builder& composer, KernelInput const& public_kernel_inputs) +void perform_static_call_checks(Builder& builder, KernelInput const& public_kernel_inputs) { // If the call is a static call, there should be no new commitments or nullifiers. const auto& public_call_public_inputs = public_kernel_inputs.public_call.call_stack_item.public_inputs; @@ -205,12 +205,12 @@ void perform_static_call_checks(Builder& composer, KernelInput const& public_ker const auto& new_nullifiers = public_call_public_inputs.new_nullifiers; if (is_static_call) { - composer.do_assert(utils::is_array_empty(new_commitments) == true, - "perform_static_call_checks in static call new commitments must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); - composer.do_assert(utils::is_array_empty(new_nullifiers) == true, - "perform_static_call_checks in static call new nullifiers must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); + builder.do_assert(utils::is_array_empty(new_commitments) == true, + "perform_static_call_checks in static call new commitments must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); + builder.do_assert(utils::is_array_empty(new_nullifiers) == true, + "perform_static_call_checks in static call new nullifiers must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); } } @@ -221,7 +221,7 @@ void perform_static_call_checks(Builder& composer, KernelInput const& public_ker * @param circuit_outputs The circuit outputs to be populated */ template -void propagate_valid_public_data_update_requests(Builder& composer, +void propagate_valid_public_data_update_requests(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -238,7 +238,7 @@ void propagate_valid_public_data_update_requests(Builder& composer, .old_value = compute_public_data_tree_value(update_request.old_value), .new_value = compute_public_data_tree_value(update_request.new_value), }; - array_push(composer, circuit_outputs.end.public_data_update_requests, new_write); + array_push(builder, circuit_outputs.end.public_data_update_requests, new_write); } } @@ -249,7 +249,7 @@ void propagate_valid_public_data_update_requests(Builder& composer, * @param circuit_outputs The circuit outputs to be populated */ template -void propagate_valid_public_data_reads(Builder& composer, +void propagate_valid_public_data_reads(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -264,7 +264,7 @@ void propagate_valid_public_data_reads(Builder& composer, .leaf_index = compute_public_data_tree_index(contract_address, contract_storage_read.storage_slot), .value = compute_public_data_tree_value(contract_storage_read.current_value), }; - array_push(composer, circuit_outputs.end.public_data_reads, new_read); + array_push(builder, circuit_outputs.end.public_data_reads, new_read); } } @@ -272,12 +272,12 @@ void propagate_valid_public_data_reads(Builder& composer, * @brief Propagates new commitments from this iteration to the circuit output. * * @tparam The type of the kernel input - * @tparam The composer type + * @tparam The builder type * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ template -void propagate_new_commitments(Builder& composer, +void propagate_new_commitments(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -294,19 +294,19 @@ void propagate_new_commitments(Builder& composer, } } - push_array_to_array(composer, siloed_new_commitments, circuit_outputs.end.new_commitments); + push_array_to_array(builder, siloed_new_commitments, circuit_outputs.end.new_commitments); } /** * @brief Propagates new nullifiers from this iteration to the circuit output. * * @tparam The type of the kernel input - * @tparam The composer type + * @tparam The builder type * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ template -void propagate_new_nullifiers(Builder& composer, +void propagate_new_nullifiers(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -323,7 +323,7 @@ void propagate_new_nullifiers(Builder& composer, } } - push_array_to_array(composer, siloed_new_nullifiers, circuit_outputs.end.new_nullifiers); + push_array_to_array(builder, siloed_new_nullifiers, circuit_outputs.end.new_nullifiers); } /** @@ -334,7 +334,7 @@ void propagate_new_nullifiers(Builder& composer, * @param circuit_outputs The circuit outputs to be populated */ template -void propagate_new_l2_to_l1_messages(Builder& composer, +void propagate_new_l2_to_l1_messages(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -358,7 +358,7 @@ void propagate_new_l2_to_l1_messages(Builder& composer, new_l2_to_l1_msgs[i]); } } - push_array_to_array(composer, new_l2_to_l1_msgs_to_insert, circuit_outputs.end.new_l2_to_l1_msgs); + push_array_to_array(builder, new_l2_to_l1_msgs_to_insert, circuit_outputs.end.new_l2_to_l1_msgs); } /** @@ -393,12 +393,12 @@ template void accumulate_unencrypted_logs(PublicKernelInputs c /** * @brief Propagates valid (i.e. non-empty) public data reads from this iteration to the circuit output * @tparam The type of kernel input - * @tparam The current composer + * @tparam The current builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ template -void common_update_public_end_values(Builder& composer, +void common_update_public_end_values(Builder& builder, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -406,19 +406,19 @@ void common_update_public_end_values(Builder& composer, circuit_outputs.is_private = false; // If this call is a static call, certain operations are disallowed, such as creating new state. - perform_static_call_checks(composer, public_kernel_inputs); + perform_static_call_checks(builder, public_kernel_inputs); const auto& stack = public_kernel_inputs.public_call.call_stack_item.public_inputs.public_call_stack; - push_array_to_array(composer, stack, circuit_outputs.end.public_call_stack); + push_array_to_array(builder, stack, circuit_outputs.end.public_call_stack); - propagate_new_commitments(composer, public_kernel_inputs, circuit_outputs); - propagate_new_nullifiers(composer, public_kernel_inputs, circuit_outputs); + propagate_new_commitments(builder, public_kernel_inputs, circuit_outputs); + propagate_new_nullifiers(builder, public_kernel_inputs, circuit_outputs); - propagate_new_l2_to_l1_messages(composer, public_kernel_inputs, circuit_outputs); + propagate_new_l2_to_l1_messages(builder, public_kernel_inputs, circuit_outputs); - propagate_valid_public_data_update_requests(composer, public_kernel_inputs, circuit_outputs); + propagate_valid_public_data_update_requests(builder, public_kernel_inputs, circuit_outputs); - propagate_valid_public_data_reads(composer, public_kernel_inputs, circuit_outputs); + propagate_valid_public_data_reads(builder, public_kernel_inputs, circuit_outputs); } /** @@ -431,11 +431,11 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in /** * @brief Validates that the call stack item for this circuit iteration is at the top of the call stack - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param public_inputs The circuit outputs */ -void validate_this_public_call_hash(DummyBuilder& composer, +void validate_this_public_call_hash(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp index 9f3b70a61533..5c73c63b7fa7 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp @@ -14,17 +14,17 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; /** * @brief Validates the kernel circuit inputs specific to having a private previous kernel - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) { - composer.do_assert(array_length(public_kernel_inputs.previous_kernel.public_inputs.end.private_call_stack) == 0, - "Private call stack must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); - composer.do_assert(public_kernel_inputs.previous_kernel.public_inputs.is_private == true, - "Previous kernel must be private", - CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); + builder.do_assert(array_length(public_kernel_inputs.previous_kernel.public_inputs.end.private_call_stack) == 0, + "Private call stack must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); + builder.do_assert(public_kernel_inputs.previous_kernel.public_inputs.is_private == true, + "Previous kernel must be private", + CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); } } // namespace @@ -39,12 +39,12 @@ using DummyBuilder = aztec3::utils::DummyBuilder; /** * @brief Entry point for the native public kernel circuit with a private previous kernel - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) + DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; @@ -53,19 +53,19 @@ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kern common_initialise_end_values(public_kernel_inputs, public_inputs); // validate the inputs common to all invocation circumstances - common_validate_inputs(composer, public_kernel_inputs); + common_validate_inputs(builder, public_kernel_inputs); // validate the inputs unique to having a previous private kernel - validate_inputs(composer, public_kernel_inputs); + validate_inputs(builder, public_kernel_inputs); // validate the kernel execution common to all invocation circumstances - common_validate_kernel_execution(composer, public_kernel_inputs); + common_validate_kernel_execution(builder, public_kernel_inputs); // vallidate our public call hash - validate_this_public_call_hash(composer, public_kernel_inputs, public_inputs); + validate_this_public_call_hash(builder, public_kernel_inputs, public_inputs); // update the public end state of the circuit - common_update_public_end_values(composer, public_kernel_inputs, public_inputs); + common_update_public_end_values(builder, public_kernel_inputs, public_inputs); accumulate_unencrypted_logs(public_kernel_inputs, public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp index a9b47c4b98fb..9284adba36ea 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp @@ -14,5 +14,5 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs); + DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp index 3e018229b388..50c36f43cf8d 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp @@ -12,15 +12,15 @@ namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; /** * @brief Validates the kernel circuit inputs specific to having a public previous kernel - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) { const auto& previous_kernel = public_kernel_inputs.previous_kernel.public_inputs; - composer.do_assert(previous_kernel.is_private == false, - "Previous kernel must be public", - CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); + builder.do_assert(previous_kernel.is_private == false, + "Previous kernel must be public", + CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); } } // namespace @@ -34,12 +34,12 @@ using DummyBuilder = aztec3::utils::DummyBuilder; /** * @brief Entry point for the native public kernel circuit with a public previous kernel - * @param composer The circuit composer + * @param builder The circuit builder * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs) + DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; @@ -48,19 +48,19 @@ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kerne common_initialise_end_values(public_kernel_inputs, public_inputs); // validate the inputs common to all invocation circumstances - common_validate_inputs(composer, public_kernel_inputs); + common_validate_inputs(builder, public_kernel_inputs); // validate the inputs unique to having a previous public kernel - validate_inputs(composer, public_kernel_inputs); + validate_inputs(builder, public_kernel_inputs); // validate the kernel execution common to all invocation circumstances - common_validate_kernel_execution(composer, public_kernel_inputs); + common_validate_kernel_execution(builder, public_kernel_inputs); // validate our public call hash - validate_this_public_call_hash(composer, public_kernel_inputs, public_inputs); + validate_this_public_call_hash(builder, public_kernel_inputs, public_inputs); // update the public end state of the circuit - common_update_public_end_values(composer, public_kernel_inputs, public_inputs); + common_update_public_end_values(builder, public_kernel_inputs, public_inputs); accumulate_unencrypted_logs(public_kernel_inputs, public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp index 208e693c9877..3aec28994ae8 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp @@ -14,5 +14,5 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using DummyBuilder = aztec3::utils::DummyBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyBuilder& composer, PublicKernelInputs const& public_kernel_inputs); + DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp index 4767a6ed8891..a4c2b478f918 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp @@ -6,13 +6,13 @@ namespace aztec3::circuits::mock { using namespace plonk::stdlib; -template void mock_circuit(Builder& 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::compress(field_t(witness_t(&composer, 1)), field_t(witness_t(&composer, 1))); + plonk::stdlib::pedersen::compress(field_t(witness_t(&builder, 1)), field_t(witness_t(&builder, 1))); } } // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index be1ea87e359c..3848c675cabc 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -18,19 +18,18 @@ using plonk::stdlib::pedersen_commitment; using plonk::stdlib::witness_t; template -KernelCircuitPublicInputs mock_kernel_circuit(Builder& composer, - KernelCircuitPublicInputs const& _public_inputs) +KernelCircuitPublicInputs mock_kernel_circuit(Builder& builder, KernelCircuitPublicInputs const& _public_inputs) { typedef CircuitTypes CT; typedef typename CT::fr fr; - auto public_inputs = _public_inputs.to_circuit_type(composer); + auto public_inputs = _public_inputs.to_circuit_type(builder); { std::vector dummy_witness_indices; // 16 is the number of values added to `proof_witness_indices` at the end of `verify_proof`. for (size_t i = 0; i < 16; ++i) { - fr const witness = fr(witness_t(&composer, i)); + fr const witness = fr(witness_t(&builder, i)); uint32_t const witness_index = witness.get_witness_index(); dummy_witness_indices.push_back(witness_index); } @@ -43,9 +42,9 @@ KernelCircuitPublicInputs mock_kernel_circuit(Builder& composer, // We still add dummy witness indices in the recursive proof indices just so that we don't trigger an assertion in // while setting recursion elements as public inputs. These dummy indices would not be used as we're setting // contains_recursive_proof to be false. - composer.contains_recursive_proof = false; + builder.contains_recursive_proof = false; - plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); + plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&builder, 1)), fr(witness_t(&builder, 1))); return public_inputs.template to_native_type(); } diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index 7da818cb7d75..f11ac44ca039 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -8,13 +8,13 @@ namespace aztec3::circuits::recursion { class Aggregator { public: static CT::AggregationObject aggregate( - Builder* composer, + Builder* builder, const std::shared_ptr& vk, const NT::Proof& proof, const CT::AggregationObject& previous_aggregation_output = CT::AggregationObject()) { CT::AggregationObject result = - verify_proof(composer, vk, proof, previous_aggregation_output); + verify_proof(builder, vk, proof, previous_aggregation_output); return result; } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 3303632e3221..2c4f3a79e3d3 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -124,7 +124,7 @@ class base_rollup_tests : public ::testing::Test { TEST_F(base_rollup_tests, native_no_new_contract_leafs) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_no_new_contract_leafs"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_no_new_contract_leafs"); // When there are no contract deployments. The contract tree should be inserting 0 leafs, (not empty leafs); // Initially, the start_contract_tree_snapshot is empty (leaf is 0. hash it up). // Get sibling path of index 0 leaf (for circuit to check membership via sibling path) @@ -134,7 +134,7 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) auto empty_contract_tree = native_base_rollup::MerkleTree(CONTRACT_TREE_HEIGHT); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, emptyInputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, emptyInputs); AppendOnlyTreeSnapshot const expectedStartContractTreeSnapshot = { .root = empty_contract_tree.root(), @@ -147,13 +147,13 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) ASSERT_EQ(outputs.start_contract_tree_snapshot, expectedStartContractTreeSnapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expectedEndContractTreeSnapshot); ASSERT_EQ(outputs.start_contract_tree_snapshot, emptyInputs.start_contract_tree_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(emptyInputs, outputs); } TEST_F(base_rollup_tests, native_contract_leaf_inserted) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted"); // When there is a contract deployment, the contract tree should be inserting 1 leaf. // The remaining leafs should be 0 leafs, (not empty leafs); @@ -184,18 +184,18 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted) BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, expected_start_contracts_snapshot); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tree) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); // Same as before except our start_contract_snapshot_tree is not empty std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; @@ -236,17 +236,17 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr .next_available_leaf_index = 14, }; BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_new_commitments_tree) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_commitments_tree"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_commitments_tree"); // Create 4 new mock commitments. Add them to kernel data. // Then get sibling path so we can verify insert them into the tree. @@ -276,12 +276,12 @@ TEST_F(base_rollup_tests, native_new_commitments_tree) auto inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_private_data_tree_snapshot, expected_start_commitments_snapshot); ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.start_private_data_tree_snapshot); ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_end_commitments_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } @@ -319,12 +319,12 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) /** * RUN */ - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_empty"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_empty"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, empty_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, empty_inputs); /** * ASSERT @@ -337,7 +337,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) ASSERT_EQ(outputs.end_nullifier_tree_snapshot.root, outputs.start_nullifier_tree_snapshot.root); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, outputs.start_nullifier_tree_snapshot.next_available_leaf_index + 8); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } void nullifier_insertion_test(std::array new_nullifiers) @@ -352,7 +352,7 @@ void nullifier_insertion_test(std::array n } auto end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyBuilder composer = DummyBuilder("base_rollup_tests__nullifier_insertion_test"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__nullifier_insertion_test"); std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; for (uint8_t i = 0; i < 2; i++) { std::array kernel_nullifiers; @@ -364,7 +364,7 @@ void nullifier_insertion_test(std::array n BaseRollupInputs const inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); /** * ASSERT */ @@ -372,7 +372,7 @@ void nullifier_insertion_test(std::array n ASSERT_EQ(outputs.end_nullifier_tree_snapshot, end_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, outputs.start_nullifier_tree_snapshot.next_available_leaf_index + KERNEL_NEW_NULLIFIERS_LENGTH * 2); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(base_rollup_tests, native_new_nullifier_tree_all_larger) @@ -400,7 +400,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) } auto expected_end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_sparse"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_sparse"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values_explicit(empty_inputs, nullifiers, initial_values); @@ -413,7 +413,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) // Run the circuit BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); /** * ASSERT @@ -423,13 +423,13 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) // End state ASSERT_EQ(outputs.end_nullifier_tree_snapshot, expected_end_nullifier_tree_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(base_rollup_tests, native_nullifier_tree_regression) { // Regression test caught when testing the typescript nullifier tree implementation - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_nullifier_tree_regression"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_nullifier_tree_regression"); // This test runs after some data has already been inserted into the tree // This test will pre-populate the tree with 24 values (0 item + 23 more) simulating that a rollup inserting two @@ -464,7 +464,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); // Run the circuit BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); /** * ASSERT @@ -474,7 +474,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) // End state ASSERT_EQ(outputs.end_nullifier_tree_snapshot, expected_end_nullifier_tree_snapshot); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } // Another regression test with values from a failing packages test @@ -507,7 +507,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) * DESCRIPTION */ - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_double_spend"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_double_spend"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::array const new_nullifiers = { 11, 0, 11, 0, 0, 0, 0, 0 }; @@ -516,20 +516,20 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "Nullifier is not in the correct range"); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "Nullifier is not in the correct range"); } TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); std::array calldata_hash_fr = outputs.calldata_hash; auto high_buffer = calldata_hash_fr[0].to_buffer(); @@ -542,7 +542,7 @@ TEST_F(base_rollup_tests, native_empty_block_calldata_hash) } ASSERT_EQ(hash, calldata_hash); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } @@ -571,17 +571,17 @@ TEST_F(base_rollup_tests, native_calldata_hash) std::array const expected_hash = components::compute_kernels_calldata_hash(kernel_data); - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_calldata_hash"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_calldata_hash"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); // Take the two fields and stich them together to get the calldata hash. std::array const calldata_hash_fr = outputs.calldata_hash; ASSERT_EQ(expected_hash, calldata_hash_fr); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } @@ -590,7 +590,7 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati // WRITE a negative test that will fail the inclusion proof // Test membership works for empty trees - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_compute_membership_historic_private_data_negative"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_compute_membership_historic_private_data_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -608,17 +608,16 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati }; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "Membership check failed: historic private data tree roots 0"); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "Membership check failed: historic private data tree roots 0"); } TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negative) { // Test membership works for empty trees - DummyBuilder composer = - DummyBuilder("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -636,43 +635,43 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat }; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "Membership check failed: historic contract data tree roots 0"); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "Membership check failed: historic contract data tree roots 0"); } TEST_F(base_rollup_tests, native_constants_dont_change) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_constants_dont_change"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_constants_dont_change"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(inputs.constants, outputs.constants); - EXPECT_FALSE(composer.failed()); + EXPECT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_aggregate) { // TODO(rahul): Fix this when aggregation works - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_aggregate"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_aggregate"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(inputs.kernel_data[0].public_inputs.end.aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(base_rollup_tests, native_subtree_height_is_0) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_subtree_height_is_0"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_subtree_height_is_0"); BaseRollupInputs const inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.rollup_subtree_height, fr(0)); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(base_rollup_tests, native_cbind_0) @@ -685,7 +684,7 @@ TEST_F(base_rollup_tests, native_cbind_0) TEST_F(base_rollup_tests, native_single_public_state_read) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_single_public_state_read"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_single_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -703,18 +702,18 @@ TEST_F(base_rollup_tests, native_single_public_state_read) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_EQ(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_single_public_state_write) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_single_public_state_write"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_single_public_state_write"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -734,18 +733,18 @@ TEST_F(base_rollup_tests, native_single_public_state_write) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_NE(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_multiple_public_state_read_writes"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_multiple_public_state_read_writes"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -775,18 +774,18 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_NE(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_invalid_public_state_read) { - DummyBuilder composer = DummyBuilder("base_rollup_tests__native_invalid_public_state_read"); + DummyBuilder builder = DummyBuilder("base_rollup_tests__native_invalid_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -808,12 +807,12 @@ TEST_F(base_rollup_tests, native_invalid_public_state_read) inputs.start_public_data_tree_root = public_data_tree.root(); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_EQ(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_TRUE(composer.failed()); + ASSERT_TRUE(builder.failed()); run_cbind(inputs, outputs, true, false); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index ae1d9ca037dd..9919bd3cc3db 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -51,8 +51,8 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, size_t* base_rollup_public_inputs_size_out, uint8_t const** base_or_merge_rollup_public_inputs_buf) { - DummyBuilder composer = DummyBuilder("base_rollup__sim"); - // TODO accept proving key and use that to initialize composers + DummyBuilder builder = DummyBuilder("base_rollup__sim"); + // TODO accept proving key and use that to initialize builders // this info is just to prevent error for unused pk_buf // TODO do we want to accept it or just get it from our factory? // auto crs_factory = std::make_shared(); @@ -60,7 +60,7 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, BaseRollupInputs base_rollup_inputs; read(base_rollup_inputs_buf, base_rollup_inputs); - BaseOrMergeRollupPublicInputs const public_inputs = base_rollup_circuit(composer, base_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = base_rollup_circuit(builder, base_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -70,6 +70,6 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *base_or_merge_rollup_public_inputs_buf = raw_public_inputs_buf; *base_rollup_public_inputs_size_out = public_inputs_vec.size(); - return composer.alloc_and_serialize_first_failure(); + return builder.alloc_and_serialize_first_failure(); } } // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index 3d7609944759..bbc0fcce4cc0 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -94,7 +94,7 @@ NT::fr calculate_contract_subtree(std::vector contract_leaves) return contracts_tree.root(); } -NT::fr calculate_commitments_subtree(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) +NT::fr calculate_commitments_subtree(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_DEPTH); @@ -102,9 +102,9 @@ NT::fr calculate_commitments_subtree(DummyBuilder& composer, BaseRollupInputs co auto new_commitments = baseRollupInputs.kernel_data[i].public_inputs.end.new_commitments; // Our commitments size MUST be 4 to calculate our subtrees correctly - composer.do_assert(new_commitments.size() == 4, - "New commitments in kernel data must be 4", - CircuitErrorCode::BASE__INCORRECT_NUM_OF_NEW_COMMITMENTS); + builder.do_assert(new_commitments.size() == 4, + "New commitments in kernel data must be 4", + CircuitErrorCode::BASE__INCORRECT_NUM_OF_NEW_COMMITMENTS); for (size_t j = 0; j < new_commitments.size(); j++) { // todo: batch insert @@ -122,7 +122,7 @@ NT::fr calculate_commitments_subtree(DummyBuilder& composer, BaseRollupInputs co * @param constantBaseRollupData * @param baseRollupInputs */ -void perform_historical_private_data_tree_membership_checks(DummyBuilder& composer, +void perform_historical_private_data_tree_membership_checks(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { // For each of the historic_private_data_tree_membership_checks, we need to do an inclusion proof @@ -136,7 +136,7 @@ void perform_historical_private_data_tree_membership_checks(DummyBuilder& compos abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_private_data_tree_root_membership_witnesses[i]; - check_membership(composer, + check_membership(builder, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -145,7 +145,7 @@ void perform_historical_private_data_tree_membership_checks(DummyBuilder& compos } } -void perform_historical_contract_data_tree_membership_checks(DummyBuilder& composer, +void perform_historical_contract_data_tree_membership_checks(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_contract_tree_roots_snapshot.root; @@ -157,7 +157,7 @@ void perform_historical_contract_data_tree_membership_checks(DummyBuilder& compo abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_contract_tree_root_membership_witnesses[i]; - check_membership(composer, + check_membership(builder, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -166,7 +166,7 @@ void perform_historical_contract_data_tree_membership_checks(DummyBuilder& compo } } -void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& composer, +void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_l1_to_l2_msg_tree_roots_snapshot.root; @@ -178,7 +178,7 @@ void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& co abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_l1_to_l2_msg_tree_root_membership_witnesses[i]; - check_membership(composer, + check_membership(builder, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -205,7 +205,7 @@ NT::fr create_nullifier_subtree( * * @returns The end nullifier tree root */ -AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyBuilder& composer, +AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { // LADIES AND GENTLEMEN The P L A N ( is simple ) @@ -280,7 +280,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB } // if not matched, our subtree will misformed - we must reject - composer.do_assert( + builder.do_assert( matched, "Nullifier subtree is malformed", CircuitErrorCode::BASE__INVALID_NULLIFIER_SUBTREE); } else { @@ -289,9 +289,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB if (!(is_less_than_nullifier && is_next_greater_than)) { if (low_nullifier_preimage.next_index != 0 && low_nullifier_preimage.next_value != 0) { - composer.do_assert(false, - "Nullifier is not in the correct range", - CircuitErrorCode::BASE__INVALID_NULLIFIER_RANGE); + builder.do_assert(false, + "Nullifier is not in the correct range", + CircuitErrorCode::BASE__INVALID_NULLIFIER_RANGE); } } @@ -303,7 +303,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB }; // perform membership check for the low nullifier against the original root - check_membership(composer, + check_membership(builder, original_low_nullifier.hash(), witness.leaf_index, witness.sibling_path, @@ -341,7 +341,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB const auto empty_nullifier_subtree_root = components::calculate_empty_tree_root(NULLIFIER_SUBTREE_DEPTH); auto leafIndexNullifierSubtreeDepth = baseRollupInputs.start_nullifier_tree_snapshot.next_available_leaf_index >> NULLIFIER_SUBTREE_DEPTH; - check_membership(composer, + check_membership(builder, empty_nullifier_subtree_root, leafIndexNullifierSubtreeDepth, baseRollupInputs.new_nullifiers_subtree_sibling_path, @@ -365,7 +365,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB } fr insert_public_data_update_requests( - DummyBuilder& composer, + DummyBuilder& builder, fr tree_root, std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& public_data_update_requests, @@ -382,7 +382,7 @@ fr insert_public_data_update_requests( continue; } - check_membership(composer, + check_membership(builder, state_write.old_value, state_write.leaf_index, witness, @@ -396,7 +396,7 @@ fr insert_public_data_update_requests( } void validate_public_data_reads( - DummyBuilder& composer, + DummyBuilder& builder, fr tree_root, std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const& public_data_reads, size_t witnesses_offset, @@ -410,7 +410,7 @@ void validate_public_data_reads( continue; } - check_membership(composer, + check_membership(builder, public_data_read.value, public_data_read.leaf_index, witness, @@ -419,17 +419,17 @@ void validate_public_data_reads( } }; -fr validate_and_process_public_state(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) +fr validate_and_process_public_state(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { // Process public data reads and public data update requests for left input - validate_public_data_reads(composer, + validate_public_data_reads(builder, baseRollupInputs.start_public_data_tree_root, baseRollupInputs.kernel_data[0].public_inputs.end.public_data_reads, 0, baseRollupInputs.new_public_data_reads_sibling_paths); auto mid_public_data_tree_root = insert_public_data_update_requests( - composer, + builder, baseRollupInputs.start_public_data_tree_root, baseRollupInputs.kernel_data[0].public_inputs.end.public_data_update_requests, 0, @@ -437,14 +437,14 @@ fr validate_and_process_public_state(DummyBuilder& composer, BaseRollupInputs co // Process public data reads and public data update requests for right input using the resulting tree root from the // left one - validate_public_data_reads(composer, + validate_public_data_reads(builder, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_reads, KERNEL_PUBLIC_DATA_READS_LENGTH, baseRollupInputs.new_public_data_reads_sibling_paths); auto end_public_data_tree_root = insert_public_data_update_requests( - composer, + builder, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_update_requests, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, @@ -453,14 +453,14 @@ fr validate_and_process_public_state(DummyBuilder& composer, BaseRollupInputs co return end_public_data_tree_root; } -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs) +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) { // Verify the previous kernel proofs for (size_t i = 0; i < 2; i++) { NT::Proof const proof = baseRollupInputs.kernel_data[i].proof; - composer.do_assert(verify_kernel_proof(proof), - "kernel proof verification failed", - CircuitErrorCode::BASE__KERNEL_PROOF_VERIFICATION_FAILED); + builder.do_assert(verify_kernel_proof(proof), + "kernel proof verification failed", + CircuitErrorCode::BASE__KERNEL_PROOF_VERIFICATION_FAILED); } // First we compute the contract tree leaves @@ -468,12 +468,12 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRo // Check contracts and commitments subtrees NT::fr const contracts_tree_subroot = calculate_contract_subtree(contract_leaves); - NT::fr const commitments_tree_subroot = calculate_commitments_subtree(composer, baseRollupInputs); + NT::fr const commitments_tree_subroot = calculate_commitments_subtree(builder, baseRollupInputs); // Insert commitment subtrees: const auto empty_commitments_subtree_root = components::calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH); auto end_private_data_tree_snapshot = - components::insert_subtree_to_snapshot_tree(composer, + components::insert_subtree_to_snapshot_tree(builder, baseRollupInputs.start_private_data_tree_snapshot, baseRollupInputs.new_commitments_subtree_sibling_path, empty_commitments_subtree_root, @@ -484,7 +484,7 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRo // Insert contract subtrees: const auto empty_contracts_subtree_root = components::calculate_empty_tree_root(CONTRACT_SUBTREE_DEPTH); auto end_contract_tree_snapshot = - components::insert_subtree_to_snapshot_tree(composer, + components::insert_subtree_to_snapshot_tree(builder, baseRollupInputs.start_contract_tree_snapshot, baseRollupInputs.new_contracts_subtree_sibling_path, empty_contracts_subtree_root, @@ -494,18 +494,18 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRo // Insert nullifiers: AppendOnlySnapshot const end_nullifier_tree_snapshot = - check_nullifier_tree_non_membership_and_insert_to_tree(composer, baseRollupInputs); + check_nullifier_tree_non_membership_and_insert_to_tree(builder, baseRollupInputs); // Validate public public data reads and public data update requests, and update public data tree - fr const end_public_data_tree_root = validate_and_process_public_state(composer, baseRollupInputs); + fr const end_public_data_tree_root = validate_and_process_public_state(builder, baseRollupInputs); // Calculate the overall calldata hash std::array const calldata_hash = components::compute_kernels_calldata_hash(baseRollupInputs.kernel_data); // Perform membership checks that the notes provided exist within the historic trees data - perform_historical_private_data_tree_membership_checks(composer, baseRollupInputs); - perform_historical_contract_data_tree_membership_checks(composer, baseRollupInputs); - perform_historical_l1_to_l2_message_tree_membership_checks(composer, baseRollupInputs); + perform_historical_private_data_tree_membership_checks(builder, baseRollupInputs); + perform_historical_contract_data_tree_membership_checks(builder, baseRollupInputs); + perform_historical_l1_to_l2_message_tree_membership_checks(builder, baseRollupInputs); AggregationObject const aggregation_object = aggregate_proofs(baseRollupInputs); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp index 6b3dabcebdaa..9ea9dbb9a18c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp @@ -12,6 +12,6 @@ namespace aztec3::circuits::rollup::native_base_rollup { -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& composer, BaseRollupInputs const& baseRollupInputs); +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs); } // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp index a87183253078..d5be6aa0ddf5 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp @@ -50,13 +50,13 @@ AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& composer, +void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - composer.do_assert(left.rollup_type == right.rollup_type, - "input proofs are of different rollup types", - utils::CircuitErrorCode::ROLLUP_TYPE_MISMATCH); + builder.do_assert(left.rollup_type == right.rollup_type, + "input proofs are of different rollup types", + utils::CircuitErrorCode::ROLLUP_TYPE_MISMATCH); } /** @@ -66,13 +66,13 @@ void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& composer, * @param right - The public inputs of the right rollup (base or merge) * @return NT::fr - The height of the rollup subtrees */ -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& composer, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - composer.do_assert(left.rollup_subtree_height == right.rollup_subtree_height, - "input proofs are of different rollup heights", - utils::CircuitErrorCode::ROLLUP_HEIGHT_MISMATCH); + builder.do_assert(left.rollup_subtree_height == right.rollup_subtree_height, + "input proofs are of different rollup heights", + utils::CircuitErrorCode::ROLLUP_HEIGHT_MISMATCH); return left.rollup_subtree_height; } @@ -82,13 +82,13 @@ NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& composer * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_equal_constants(DummyBuilder& composer, +void assert_equal_constants(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - composer.do_assert(left.constants == right.constants, - "input proofs have different constants", - utils::CircuitErrorCode::CONSTANTS_MISMATCH); + builder.do_assert(left.constants == right.constants, + "input proofs have different constants", + utils::CircuitErrorCode::CONSTANTS_MISMATCH); } /** @@ -239,22 +239,22 @@ std::array compute_calldata_hash(std::array, // asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they // follow on from one-another). Ensures that right uses the tres that was updated by left. -void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& composer, +void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - composer.do_assert(left.end_private_data_tree_snapshot == right.start_private_data_tree_snapshot, - "input proofs have different private data tree snapshots", - utils::CircuitErrorCode::PRIVATE_DATA_TREE_SNAPSHOT_MISMATCH); - composer.do_assert(left.end_nullifier_tree_snapshot == right.start_nullifier_tree_snapshot, - "input proofs have different nullifier tree snapshots", - utils::CircuitErrorCode::NULLIFIER_TREE_SNAPSHOT_MISMATCH); - composer.do_assert(left.end_contract_tree_snapshot == right.start_contract_tree_snapshot, - "input proofs have different contract tree snapshots", - utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); - composer.do_assert(left.end_public_data_tree_root == right.start_public_data_tree_root, - "input proofs have different public data tree snapshots", - utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); + builder.do_assert(left.end_private_data_tree_snapshot == right.start_private_data_tree_snapshot, + "input proofs have different private data tree snapshots", + utils::CircuitErrorCode::PRIVATE_DATA_TREE_SNAPSHOT_MISMATCH); + builder.do_assert(left.end_nullifier_tree_snapshot == right.start_nullifier_tree_snapshot, + "input proofs have different nullifier tree snapshots", + utils::CircuitErrorCode::NULLIFIER_TREE_SNAPSHOT_MISMATCH); + builder.do_assert(left.end_contract_tree_snapshot == right.start_contract_tree_snapshot, + "input proofs have different contract tree snapshots", + utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); + builder.do_assert(left.end_public_data_tree_root == right.start_public_data_tree_root, + "input proofs have different public data tree snapshots", + utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); } } // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp index fc5e30c513a5..6a744ffb021b 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp @@ -11,23 +11,23 @@ namespace aztec3::circuits::rollup::components { NT::fr calculate_empty_tree_root(size_t depth); std::array compute_kernels_calldata_hash(std::array, 2> kernel_data); std::array compute_calldata_hash(std::array, 2> previous_rollup_data); -void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& composer, +void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& composer, +void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& composer, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_equal_constants(DummyBuilder& composer, +void assert_equal_constants(DummyBuilder& builder, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuilder& composer, +template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuilder& builder, AppendOnlySnapshot snapshot, std::array siblingPath, NT::fr emptySubtreeRoot, @@ -40,7 +40,7 @@ template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuil auto leafIndexAtDepth = snapshot.next_available_leaf_index >> subtreeDepth; // Check that the current root is correct and that there is an empty subtree at the insertion location - check_membership(composer, emptySubtreeRoot, leafIndexAtDepth, siblingPath, snapshot.root, message); + check_membership(builder, emptySubtreeRoot, leafIndexAtDepth, siblingPath, snapshot.root, message); // if index of leaf is x, index of its parent is x/2 or x >> 1. We need to find the parent `subtreeDepth` levels up. auto new_root = root_from_sibling_path(subtreeRootToInsert, leafIndexAtDepth, siblingPath); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index a157a9ef2055..ebf12d3b8898 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -69,53 +69,53 @@ class merge_rollup_tests : public ::testing::Test { TEST_F(merge_rollup_tests, native_different_rollup_type_fails) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_different_rollup_type_fails"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_different_rollup_type_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs mergeInput = get_merge_rollup_inputs(builder, kernels); mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 0; mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; - merge_rollup_circuit(composer, mergeInput); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "input proofs are of different rollup types"); + merge_rollup_circuit(builder, mergeInput); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "input proofs are of different rollup types"); } TEST_F(merge_rollup_tests, native_different_rollup_height_fails) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_different_rollup_height_fails"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_different_rollup_height_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs mergeInput = get_merge_rollup_inputs(builder, kernels); mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 0; mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; - merge_rollup_circuit(composer, mergeInput); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "input proofs are of different rollup heights"); + merge_rollup_circuit(builder, mergeInput); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "input proofs are of different rollup heights"); } TEST_F(merge_rollup_tests, native_constants_different_failure) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_constants_different_failure"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_constants_different_failure"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); - merge_rollup_circuit(composer, inputs); - ASSERT_TRUE(composer.failed()); - ASSERT_EQ(composer.get_first_failure().message, "input proofs have different constants"); + merge_rollup_circuit(builder, inputs); + ASSERT_TRUE(builder.failed()); + ASSERT_EQ(builder.get_first_failure().message, "input proofs have different constants"); } TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) { - DummyBuilder composerA = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); + DummyBuilder builderA = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs const inputs = get_merge_rollup_inputs(composerA, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(builderA, kernels); auto inputA = inputs; inputA.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -124,12 +124,12 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(composerA, inputA); - ASSERT_TRUE(composerA.failed()); - ASSERT_EQ(composerA.get_first_failure().message, "input proofs have different private data tree snapshots"); + merge_rollup_circuit(builderA, inputA); + ASSERT_TRUE(builderA.failed()); + ASSERT_EQ(builderA.get_first_failure().message, "input proofs have different private data tree snapshots"); // do the same for nullifier tree - DummyBuilder composerB = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); + DummyBuilder builderB = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); auto inputB = inputs; inputB.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = { @@ -138,12 +138,12 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) inputB.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(composerB, inputB); - ASSERT_TRUE(composerB.failed()); - ASSERT_EQ(composerB.get_first_failure().message, "input proofs have different nullifier tree snapshots"); + merge_rollup_circuit(builderB, inputB); + ASSERT_TRUE(builderB.failed()); + ASSERT_EQ(builderB.get_first_failure().message, "input proofs have different nullifier tree snapshots"); // do the same for contract tree - DummyBuilder composerC = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); + DummyBuilder builderC = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); auto inputC = inputs; inputC.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -151,19 +151,19 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) inputC.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(composerC, inputC); - ASSERT_TRUE(composerC.failed()); - ASSERT_EQ(composerC.get_first_failure().message, "input proofs have different contract tree snapshots"); + merge_rollup_circuit(builderC, inputC); + ASSERT_TRUE(builderC.failed()); + ASSERT_EQ(builderC.get_first_failure().message, "input proofs have different contract tree snapshots"); } TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_rollup_fields_are_set_correctly"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_rollup_fields_are_set_correctly"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(builder, inputs); // check that rollup type is set to merge ASSERT_EQ(outputs.rollup_type, 1); // check that rollup height is incremented @@ -177,20 +177,20 @@ TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; - outputs = merge_rollup_circuit(composer, inputs); + outputs = merge_rollup_circuit(builder, inputs); ASSERT_EQ(outputs.rollup_type, 1); ASSERT_EQ(outputs.rollup_subtree_height, 2); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(merge_rollup_tests, native_start_and_end_snapshots) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_start_and_end_snapshots"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_start_and_end_snapshots"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); // check that start and end snapshots are set correctly ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot); @@ -212,12 +212,12 @@ TEST_F(merge_rollup_tests, native_start_and_end_snapshots) ASSERT_EQ(outputs.end_public_data_tree_root, inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_root); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(merge_rollup_tests, native_calldata_hash) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_calldata_hash"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); @@ -234,9 +234,9 @@ TEST_F(merge_rollup_tests, native_calldata_hash) std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs const inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(builder, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); std::array actual_calldata_hash_fr = outputs.calldata_hash; auto high_buffer = actual_calldata_hash_fr[0].to_buffer(); @@ -249,18 +249,18 @@ TEST_F(merge_rollup_tests, native_calldata_hash) } ASSERT_EQ(expected_calldata_hash, actual_calldata_hash); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(merge_rollup_tests, native_constants_dont_change) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_constants_dont_change"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_constants_dont_change"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants, outputs.constants); ASSERT_EQ(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants, outputs.constants); } @@ -268,27 +268,27 @@ TEST_F(merge_rollup_tests, native_constants_dont_change) TEST_F(merge_rollup_tests, native_aggregate) { // TODO: Fix this when aggregation works - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_aggregate"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_aggregate"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); } TEST_F(merge_rollup_tests, native_merge_cbind) { - DummyBuilder composer = DummyBuilder("merge_rollup_tests__native_merge_cbind"); + DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_merge_cbind"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); - ASSERT_FALSE(composer.failed()); + ASSERT_FALSE(builder.failed()); BaseOrMergeRollupPublicInputs ignored_public_inputs; run_cbind(inputs, ignored_public_inputs, false); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index 60941661628b..7caf1fc1a2de 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -21,11 +21,11 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, size_t* merge_rollup_public_inputs_size_out, uint8_t const** merge_rollup_public_inputs_buf) { - DummyBuilder composer = DummyBuilder("merge_rollup__sim"); + DummyBuilder builder = DummyBuilder("merge_rollup__sim"); MergeRollupInputs merge_rollup_inputs; read(merge_rollup_inputs_buf, merge_rollup_inputs); - BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(composer, merge_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(builder, merge_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -35,6 +35,6 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *merge_rollup_public_inputs_buf = raw_public_inputs_buf; *merge_rollup_public_inputs_size_out = public_inputs_vec.size(); - return composer.alloc_and_serialize_first_failure(); + return builder.alloc_and_serialize_first_failure(); } } // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp index bb39f5168750..9eb114aa7a59 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& composer, MergeRollupInputs const& mergeRollupInputs) +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& builder, MergeRollupInputs const& mergeRollupInputs) { // TODO: Verify the previous rollup proofs // TODO: Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks. @@ -25,10 +25,10 @@ BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& composer, Merge // check that both input proofs are either both "BASE" or "MERGE" and not a mix! // this prevents having wonky commitment, nullifier and contract subtrees. AggregationObject const aggregation_object = components::aggregate_proofs(left, right); - components::assert_both_input_proofs_of_same_rollup_type(composer, left, right); - auto current_height = components::assert_both_input_proofs_of_same_height_and_return(composer, left, right); - components::assert_equal_constants(composer, left, right); - components::assert_prev_rollups_follow_on_from_each_other(composer, left, right); + components::assert_both_input_proofs_of_same_rollup_type(builder, left, right); + auto current_height = components::assert_both_input_proofs_of_same_height_and_return(builder, left, right); + components::assert_equal_constants(builder, left, right); + components::assert_prev_rollups_follow_on_from_each_other(builder, left, right); // compute calldata hash: auto new_calldata_hash = components::compute_calldata_hash(mergeRollupInputs.previous_rollup_data); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp index 443679f4e51d..9d1e4b24772d 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp @@ -3,5 +3,5 @@ #include "init.hpp" namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& composer, MergeRollupInputs const& mergeRollupInputs); +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& builder, MergeRollupInputs const& mergeRollupInputs); } // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 88e56978b31c..b63a8bdaabda 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -138,28 +138,27 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) std::vector const messages_hash_input_bytes_vec(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP * 32, 0); auto messages_hash = sha256::sha256(messages_hash_input_bytes_vec); - utils::DummyBuilder composer = utils::DummyBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); + utils::DummyBuilder builder = utils::DummyBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - RootRollupInputs inputs = get_root_rollup_inputs(composer, kernels, l1_to_l2_messages); - RootRollupPublicInputs outputs = - aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, inputs); + RootRollupInputs inputs = get_root_rollup_inputs(builder, kernels, l1_to_l2_messages); + RootRollupPublicInputs outputs = aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(builder, inputs); // check calldata hash ASSERT_TRUE(compare_field_hash_to_expected(outputs.calldata_hash, calldata_hash)); // Check messages hash ASSERT_TRUE(compare_field_hash_to_expected(outputs.l1_to_l2_messages_hash, messages_hash)); - EXPECT_FALSE(composer.failed()); + EXPECT_FALSE(builder.failed()); run_cbind(inputs, outputs, true); } TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) { - utils::DummyBuilder composer = utils::DummyBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); + utils::DummyBuilder builder = utils::DummyBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); MemoryTree data_tree = MemoryTree(PRIVATE_DATA_TREE_HEIGHT); MemoryTree contract_tree = MemoryTree(CONTRACT_TREE_HEIGHT); @@ -242,9 +241,9 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) .next_available_leaf_index = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP }; - RootRollupInputs rootRollupInputs = get_root_rollup_inputs(composer, kernels, l1_to_l2_messages); + RootRollupInputs rootRollupInputs = get_root_rollup_inputs(builder, kernels, l1_to_l2_messages); RootRollupPublicInputs outputs = - aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, rootRollupInputs); + aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(builder, rootRollupInputs); // Check private data trees ASSERT_EQ( @@ -297,7 +296,7 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) auto root = accumulate_sha256({ left[0], left[1], right[0], right[1] }); ASSERT_EQ(outputs.calldata_hash, root); - EXPECT_FALSE(composer.failed()); + EXPECT_FALSE(builder.failed()); run_cbind(rootRollupInputs, outputs, true); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 84160d3a63e4..d2ac81d62a6e 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -52,8 +52,8 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, RootRollupInputs root_rollup_inputs; read(root_rollup_inputs_buf, root_rollup_inputs); - DummyBuilder composer = DummyBuilder("root_rollup__sim"); - RootRollupPublicInputs const public_inputs = root_rollup_circuit(composer, root_rollup_inputs); + DummyBuilder builder = DummyBuilder("root_rollup__sim"); + RootRollupPublicInputs const public_inputs = root_rollup_circuit(builder, root_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -63,7 +63,7 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *root_rollup_public_inputs_buf = raw_public_inputs_buf; *root_rollup_public_inputs_size_out = public_inputs_vec.size(); - return composer.alloc_and_serialize_first_failure(); + return builder.alloc_and_serialize_first_failure(); } WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 70ff84c0f1be..9be76231bc29 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -68,7 +68,7 @@ std::array compute_messages_hash(std::array kerne std::move(kernel_data), private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); } -std::array, 2> get_previous_rollup_data(DummyBuilder& composer, +std::array, 2> get_previous_rollup_data(DummyBuilder& builder, std::array kernel_data) { // NOTE: Still assuming that this is first and second. Don't handle more rollups atm auto base_rollup_input_1 = base_rollup_inputs_from_kernels({ kernel_data[0], kernel_data[1] }); auto base_public_input_1 = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, base_rollup_input_1); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, base_rollup_input_1); // Build the trees based on inputs in base_rollup_input_1. MerkleTree private_data_tree = MerkleTree(PRIVATE_DATA_TREE_HEIGHT); @@ -281,7 +281,7 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& com get_sibling_path(private_data_tree, 8, PRIVATE_DATA_SUBTREE_DEPTH); auto base_public_input_2 = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, base_rollup_input_2); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, base_rollup_input_2); PreviousRollupData const previous_rollup1 = { .base_or_merge_rollup_public_inputs = base_public_input_1, @@ -301,13 +301,13 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& com return { previous_rollup1, previous_rollup2 }; } -MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& composer, std::array kernel_data) +MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& builder, std::array kernel_data) { - MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)) }; + MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)) }; return inputs; } -RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& composer, +RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, std::array kernel_data, std::array l1_to_l2_messages) { @@ -346,7 +346,7 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& composer, }; RootRollupInputs rootRollupInputs = { - .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)), + .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)), .new_historic_private_data_tree_root_sibling_path = historic_data_sibling_path, .new_historic_contract_tree_root_sibling_path = historic_contract_sibling_path, .l1_to_l2_messages = l1_to_l2_messages, diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index f6911c6e2653..a50d5cee9a6f 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -87,11 +87,11 @@ NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector kernel_data, std::array l1_to_l2_messages); -MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& composer, std::array kernel_data); +MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& builder, std::array kernel_data); inline abis::PublicDataUpdateRequest make_public_data_update_request(fr leaf_index, fr old_value, fr new_value) { diff --git a/circuits/cpp/src/aztec3/utils/array.hpp b/circuits/cpp/src/aztec3/utils/array.hpp index a8850097099b..a443255b4140 100644 --- a/circuits/cpp/src/aztec3/utils/array.hpp +++ b/circuits/cpp/src/aztec3/utils/array.hpp @@ -99,12 +99,12 @@ template T array_pop(std::array& arr) /** * @brief Helper method to push an item into the first empty slot in an array * @tparam The type of the value stored in the array - * @tparam The composer type + * @tparam The builder type * @tparam The size of the array * @param The array into which we want to store the value */ template -void array_push(Builder& composer, std::array& arr, T const& value) +void array_push(Builder& builder, std::array& arr, T const& value) { for (size_t i = 0; i < arr.size(); ++i) { if (is_empty(arr[i])) { @@ -112,7 +112,7 @@ void array_push(Builder& composer, std::array& arr, T const& value) return; } } - composer.do_assert(false, "array_push cannot push to a full array", CircuitErrorCode::ARRAY_OVERFLOW); + builder.do_assert(false, "array_push cannot push to a full array", CircuitErrorCode::ARRAY_OVERFLOW); }; /** @@ -166,21 +166,21 @@ template NT::boolean is_array_empty(std::array -void push_array_to_array(Builder& composer, std::array const& source, std::array& target) +void push_array_to_array(Builder& builder, std::array const& source, std::array& target) { // Check if the `source` array is too large vs the remaining capacity of the `target` array size_t const source_size = static_cast(uint256_t(array_length(source))); size_t const target_size = static_cast(uint256_t(array_length(target))); - composer.do_assert(source_size <= size_2 - target_size, - "push_array_to_array cannot overflow the target", - CircuitErrorCode::ARRAY_OVERFLOW); + builder.do_assert(source_size <= size_2 - target_size, + "push_array_to_array cannot overflow the target", + CircuitErrorCode::ARRAY_OVERFLOW); // Ensure that there are no non-zero values in the `target` array after the first zero-valued index for (size_t i = target_size; i < size_2; i++) { - composer.do_assert(is_empty(target[i]), - "push_array_to_array inserting new array into a non empty space", - CircuitErrorCode::ARRAY_OVERFLOW); + builder.do_assert(is_empty(target[i]), + "push_array_to_array inserting new array into a non empty space", + CircuitErrorCode::ARRAY_OVERFLOW); } // Copy the non-zero elements of the `source` array to the `target` array at the first zero-valued index auto zero_index = target_size; diff --git a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp index 4a8e16f478c9..82256060c021 100644 --- a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp +++ b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp @@ -12,7 +12,7 @@ namespace aztec3::utils { class DummyBuilder { public: std::vector failure_msgs; - // method that created this composer instance. Useful for logging. + // method that created this builder instance. Useful for logging. std::string method_name; explicit DummyBuilder(std::string method_name) : method_name(std::move(method_name)) {} @@ -59,7 +59,7 @@ class DummyBuilder { if (failure.code == CircuitErrorCode::NO_ERROR) { return nullptr; } - info(this->method_name, ": composer.get_first_failure() = ", failure_msgs[0]); + info(this->method_name, ": builder.get_first_failure() = ", failure_msgs[0]); // serialize circuit failure to bytes vec diff --git a/circuits/cpp/src/aztec3/utils/types/convert.hpp b/circuits/cpp/src/aztec3/utils/types/convert.hpp index b6010eb82a0c..8d4f374d38e3 100644 --- a/circuits/cpp/src/aztec3/utils/types/convert.hpp +++ b/circuits/cpp/src/aztec3/utils/types/convert.hpp @@ -20,111 +20,110 @@ using NT = aztec3::utils::types::NativeTypes; /// TODO: Lots of identical functions here (but for their in/out types). Can we use templates? I couldn't figure out how /// to keep the NT:: or CT:: prefixes with templates. -template typename CT::boolean to_ct(Builder& composer, typename NT::boolean const& e) +template typename CT::boolean to_ct(Builder& builder, typename NT::boolean const& e) { - return typename CT::boolean(witness_t(&composer, e)); + return typename CT::boolean(witness_t(&builder, e)); }; -template typename CT::fr to_ct(Builder& composer, typename NT::fr const& e) +template typename CT::fr to_ct(Builder& builder, typename NT::fr const& e) { - return typename CT::fr(witness_t(&composer, e)); + return typename CT::fr(witness_t(&builder, e)); }; -template typename CT::fq to_ct(Builder& composer, typename NT::fq const& e) +template typename CT::fq to_ct(Builder& builder, typename NT::fq const& e) { - return typename CT::fq(witness_t(&composer, e)); + return typename CT::fq(witness_t(&builder, e)); }; -template typename CT::address to_ct(Builder& composer, typename NT::address const& e) +template typename CT::address to_ct(Builder& builder, typename NT::address const& e) { - return typename CT::address(witness_t(&composer, e)); + return typename CT::address(witness_t(&builder, e)); }; -template typename CT::uint32 to_ct(Builder& composer, typename NT::uint32 const& e) +template typename CT::uint32 to_ct(Builder& builder, typename NT::uint32 const& e) { - return typename CT::uint32(witness_t(&composer, e)); + return typename CT::uint32(witness_t(&builder, e)); }; template -typename CT::grumpkin_point to_ct(Builder& composer, typename NT::grumpkin_point const& e) +typename CT::grumpkin_point to_ct(Builder& builder, typename NT::grumpkin_point const& e) { - return plonk::stdlib::create_point_witness(composer, e, true); + return plonk::stdlib::create_point_witness(builder, e, true); }; -template -typename CT::bn254_point to_ct(Builder& composer, typename NT::bn254_point const& e) +template typename CT::bn254_point to_ct(Builder& builder, typename NT::bn254_point const& e) { - return CT::bn254_point::from_witness(&composer, e); + return CT::bn254_point::from_witness(&builder, e); }; template -typename CT::ecdsa_signature to_ct(Builder& composer, typename NT::ecdsa_signature const& e) +typename CT::ecdsa_signature to_ct(Builder& builder, typename NT::ecdsa_signature const& e) { - return CT::ecdsa_signature::template from_witness(&composer, e); + return CT::ecdsa_signature::template from_witness(&builder, e); }; template -std::optional::boolean> to_ct(Builder& composer, std::optional const& e) +std::optional::boolean> to_ct(Builder& builder, std::optional const& e) { - return e ? std::make_optional::boolean>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::boolean>(to_ct(builder, *e)) : std::nullopt; }; template -std::optional::fr> to_ct(Builder& composer, std::optional const& e) +std::optional::fr> to_ct(Builder& builder, std::optional const& e) { - return e ? std::make_optional::fr>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::fr>(to_ct(builder, *e)) : std::nullopt; }; template -std::optional::address> to_ct(Builder& composer, std::optional const& e) +std::optional::address> to_ct(Builder& builder, std::optional const& e) { - return e ? std::make_optional::address>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::address>(to_ct(builder, *e)) : std::nullopt; }; template -std::optional::grumpkin_point> to_ct(Builder& composer, +std::optional::grumpkin_point> to_ct(Builder& builder, std::optional const& e) { - return e ? std::make_optional::grumpkin_point>(to_ct(composer, *e)) : std::nullopt; + return e ? std::make_optional::grumpkin_point>(to_ct(builder, *e)) : std::nullopt; }; template -std::optional::ecdsa_signature> to_ct(Builder& composer, +std::optional::ecdsa_signature> to_ct(Builder& builder, std::optional const& e) { - return e ? std::make_optional::ecdsa_signature>(to_ct(&composer, e)) : std::nullopt; + return e ? std::make_optional::ecdsa_signature>(to_ct(&builder, e)) : std::nullopt; }; template -std::vector::fr> to_ct(Builder& composer, std::vector const& vec) +std::vector::fr> to_ct(Builder& builder, std::vector const& vec) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; return map(vec, ref_to_ct); }; template -std::optional::fr>> to_ct(Builder& composer, +std::optional::fr>> to_ct(Builder& builder, std::optional> const& vec) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; return vec ? std::make_optional::fr>>(map(*vec, ref_to_ct)) : std::nullopt; }; template -std::array::fr, SIZE> to_ct(Builder& composer, std::array const& arr) +std::array::fr, SIZE> to_ct(Builder& builder, std::array const& arr) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; return map(arr, ref_to_ct); }; template std::array::fr>, SIZE> to_ct( - Builder& composer, std::array, SIZE> const& arr) + Builder& builder, std::array, SIZE> const& arr) { - auto ref_to_ct = [&](std::optional const& e) { return to_ct(composer, e); }; + auto ref_to_ct = [&](std::optional const& e) { return to_ct(builder, e); }; return map(arr, ref_to_ct); }; @@ -133,9 +132,9 @@ template std::array -std::array to_ct(Builder& composer, std::array const& arr) +std::array to_ct(Builder& builder, std::array const& arr) { - auto ref_to_ct = [&](NT_TYPE const& e) { return e.to_circuit_type(composer); }; + auto ref_to_ct = [&](NT_TYPE const& e) { return e.to_circuit_type(builder); }; return map(arr, ref_to_ct); }; @@ -145,9 +144,9 @@ std::array to_ct(Builder& composer, std::array con * Allow array entries to be optional. */ template -std::array, SIZE> to_ct(Builder& composer, std::array, SIZE> const& arr) +std::array, SIZE> to_ct(Builder& builder, std::array, SIZE> const& arr) { - auto ref_to_ct = [&](std::optional const& e) { return e.to_circuit_type(composer); }; + auto ref_to_ct = [&](std::optional const& e) { return e.to_circuit_type(builder); }; return map(arr, ref_to_ct); }; From 86fa2cd45cf34f8417a5e5ee5a03dd74ea423723 Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 23:39:48 +0000 Subject: [PATCH 11/28] mv dummy_composer.hpp and rename class. --- .../cpp/src/aztec3/circuits/kernel/private/c_bind.cpp | 2 +- .../cpp/src/aztec3/circuits/kernel/private/common.cpp | 6 +++--- .../cpp/src/aztec3/circuits/kernel/private/common.hpp | 4 ++-- .../kernel/private/native_private_kernel_circuit_init.hpp | 4 ++-- .../private/native_private_kernel_circuit_inner.cpp | 4 ++-- .../private/native_private_kernel_circuit_inner.hpp | 4 ++-- .../private/native_private_kernel_circuit_ordering.cpp | 4 ++-- .../private/native_private_kernel_circuit_ordering.hpp | 4 ++-- .../aztec3/circuits/kernel/private/testing_harness.hpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp | 2 +- circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp | 4 ++-- circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp | 4 ++-- circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp | 2 +- ...tive_public_kernel_circuit_private_previous_kernel.cpp | 4 ++-- ...tive_public_kernel_circuit_private_previous_kernel.hpp | 4 ++-- ...ative_public_kernel_circuit_public_previous_kernel.cpp | 4 ++-- ...ative_public_kernel_circuit_public_previous_kernel.hpp | 4 ++-- circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp | 2 +- circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp | 4 ++-- circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp | 4 ++-- .../cpp/src/aztec3/circuits/rollup/components/init.hpp | 4 ++-- circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp | 2 +- circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp | 4 ++-- circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp | 4 ++-- circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp | 8 +++++--- circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp | 2 +- circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp | 4 ++-- .../cpp/src/aztec3/circuits/rollup/test_utils/init.hpp | 4 ++-- .../cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp | 2 +- .../cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp | 2 +- .../{dummy_composer.hpp => dummy_circuit_builder.hpp} | 4 ++-- 31 files changed, 57 insertions(+), 55 deletions(-) rename circuits/cpp/src/aztec3/utils/{dummy_composer.hpp => dummy_circuit_builder.hpp} (94%) diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index d471505e14ae..893117c13e16 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -11,7 +11,7 @@ namespace { using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::abis::TxRequest; using aztec3::circuits::abis::private_kernel::PrivateCallData; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index 64e91c8c597f..05ee7638afc4 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -11,9 +11,9 @@ #include "aztec3/circuits/hash.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::ContractDeploymentData; using aztec3::circuits::abis::ContractLeafPreimage; @@ -25,7 +25,7 @@ using aztec3::circuits::abis::NewContractData; using aztec3::utils::array_push; using aztec3::utils::is_array_empty; using aztec3::utils::push_array_to_array; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using aztec3::circuits::abis::private_kernel::PrivateCallData; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp index 9a4dfdd65f4c..878df40612bb 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp @@ -8,13 +8,13 @@ #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/private_kernel/private_call_data.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::ContractDeploymentData; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::MembershipWitness; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp index 39dea9a86752..b5f23f4a928f 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp @@ -4,14 +4,14 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; // using abis::private_kernel::PublicInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp index 53170f606c89..0fe63a62ddb1 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp @@ -6,7 +6,7 @@ #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::private_kernel { @@ -16,7 +16,7 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; using aztec3::utils::array_length; using aztec3::utils::array_pop; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // using plonk::stdlib::merkle_tree:: diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp index 09fd40b5c3f2..52ff291a27d6 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp @@ -4,13 +4,13 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp index fc03e3c7988a..cb0925f98e71 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp @@ -4,7 +4,7 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include @@ -13,7 +13,7 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp index f180a3bfa6bd..78f349bc8aa7 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp @@ -4,13 +4,13 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; KernelCircuitPublicInputs native_private_kernel_circuit_ordering( DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp index 493adf6378a2..b58dabe96407 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp @@ -28,7 +28,7 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::utils::zero_array; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index 321b093d2237..057e10e8dd33 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -28,7 +28,7 @@ #include namespace { -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::CallContext; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index 2fc71f4544d9..b15896d162d1 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -6,7 +6,7 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/native_types.hpp" #include @@ -14,7 +14,7 @@ namespace { using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_private_previous_kernel; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index cb883ff7d741..e07a5608186e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -9,7 +9,7 @@ #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/circuits/hash.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::ContractStorageRead; @@ -18,7 +18,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PublicDataRead; using aztec3::circuits::abis::PublicDataUpdateRequest; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::check_membership; using aztec3::circuits::compute_public_data_tree_index; using aztec3::circuits::compute_public_data_tree_value; diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index e2eb3f7a3480..9133ba940604 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -3,7 +3,7 @@ #include "aztec3/circuits/apps/oracle_wrapper.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/oracle/oracle.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp index 5c73c63b7fa7..a0c5cbddf70e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp @@ -7,7 +7,7 @@ #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; @@ -35,7 +35,7 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_initialise_end_values; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; /** * @brief Entry point for the native public kernel circuit with a private previous kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp index 9284adba36ea..46eab401e780 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp @@ -5,13 +5,13 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp index 50c36f43cf8d..22c938598fa5 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp @@ -6,7 +6,7 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; @@ -30,7 +30,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; /** * @brief Entry point for the native public kernel circuit with a public previous kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp index 3aec28994ae8..8d21acd913c8 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp @@ -5,13 +5,13 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 2c4f3a79e3d3..09e9a16b2877 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -50,7 +50,7 @@ using aztec3::circuits::abis::NewContractData; using aztec3::circuits::rollup::test_utils::utils::make_public_data_update_request; using aztec3::circuits::rollup::test_utils::utils::make_public_read; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; } // namespace namespace aztec3::circuits::rollup::base::native_base_rollup_circuit { diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 9919bd3cc3db..44f74f18549c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -5,7 +5,7 @@ #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/native_types.hpp" #include @@ -13,7 +13,7 @@ namespace { using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp index f9c437775ca0..ab57158c43c3 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -10,7 +10,7 @@ #include "aztec3/circuits/hash.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -25,7 +25,7 @@ using NT = aztec3::utils::types::NativeTypes; using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp index 36d64ea2e59e..895cdee4c417 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp @@ -9,7 +9,7 @@ #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/hash.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -25,6 +25,6 @@ using NT = aztec3::utils::types::NativeTypes; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using AppendOnlySnapshot = abis::AppendOnlyTreeSnapshot; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; } // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index ebf12d3b8898..116703970a32 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -11,7 +11,7 @@ namespace { using aztec3::circuits::rollup::merge::MergeRollupInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_merge_rollup_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index 7caf1fc1a2de..9c1fd16a7872 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -2,13 +2,13 @@ #include "index.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include namespace { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::rollup::merge::merge_rollup_circuit; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp index fc7986881e02..34ad4c1f94ec 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -7,7 +7,7 @@ #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -17,7 +17,7 @@ namespace aztec3::circuits::rollup::merge { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index b63a8bdaabda..bf717151e980 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -13,7 +13,7 @@ #include "aztec3/circuits/rollup/components/components.hpp" #include "aztec3/circuits/rollup/test_utils/utils.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include @@ -138,7 +138,8 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) std::vector const messages_hash_input_bytes_vec(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP * 32, 0); auto messages_hash = sha256::sha256(messages_hash_input_bytes_vec); - utils::DummyBuilder builder = utils::DummyBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); + utils::DummyCircuitBuilder builder = + utils::DummyCircuitBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; @@ -158,7 +159,8 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) { - utils::DummyBuilder builder = utils::DummyBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); + utils::DummyCircuitBuilder builder = + utils::DummyCircuitBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); MemoryTree data_tree = MemoryTree(PRIVATE_DATA_TREE_HEIGHT); MemoryTree contract_tree = MemoryTree(CONTRACT_TREE_HEIGHT); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index d2ac81d62a6e..9bc1e7b66f7a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -11,7 +11,7 @@ namespace { using Builder = UltraCircuitBuilder; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; using aztec3::circuits::rollup::native_root_rollup::RootRollupInputs; using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp index c09057ed7789..5b4428733f31 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp @@ -6,7 +6,7 @@ #include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -16,7 +16,7 @@ namespace aztec3::circuits::rollup::native_root_rollup { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp index b8e52f218ed0..1ebf7ace3e77 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp @@ -11,7 +11,7 @@ #include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" -#include "aztec3/utils/dummy_composer.hpp" +#include "aztec3/utils/dummy_circuit_builder.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -27,7 +27,7 @@ using NT = aztec3::utils::types::NativeTypes; using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index 55f9e7efe946..23269fecd36a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -20,7 +20,7 @@ using ConstantRollupData = aztec3::circuits::abis::ConstantRollupData; using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; using RootRollupPublicInputs = aztec3::circuits::abis::RootRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index a50d5cee9a6f..2f3819dc6b1d 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -23,7 +23,7 @@ using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using MergeRollupInputs = aztec3::circuits::abis::MergeRollupInputs; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; -using DummyBuilder = aztec3::utils::DummyBuilder; +using DummyBuilder = aztec3::utils::DummyCircuitBuilder; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; diff --git a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp b/circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp similarity index 94% rename from circuits/cpp/src/aztec3/utils/dummy_composer.hpp rename to circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp index 82256060c021..fb841ea56b0b 100644 --- a/circuits/cpp/src/aztec3/utils/dummy_composer.hpp +++ b/circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp @@ -9,13 +9,13 @@ namespace aztec3::utils { -class DummyBuilder { +class DummyCircuitBuilder { public: std::vector failure_msgs; // method that created this builder instance. Useful for logging. std::string method_name; - explicit DummyBuilder(std::string method_name) : method_name(std::move(method_name)) {} + explicit DummyCircuitBuilder(std::string method_name) : method_name(std::move(method_name)) {} void do_assert(bool const& assertion, std::string const& msg, CircuitErrorCode error_code) { From b3097e2ea9f147be64e1f1a5cb59976c772c2a7a Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 23:46:15 +0000 Subject: [PATCH 12/28] Clean change to settingss. --- .vscode/settings.json | 1 - 1 file changed, 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d60bf21d980e..e4568cdcb29d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -165,7 +165,6 @@ "testMate.cpp.test.workingDirectory": "${workspaceFolder}/circuits/cpp/build", // Filter all binaries that are not tests "testMate.cpp.test.executables": "${workspaceFolder}/circuits/cpp/build/bin/*{test,Test,TEST}*", - "cmake.configureOnOpen": true, // End C++/Circuits settings /////////////////////////////////////// } From e3eed2f7b0c3419a22a28ce8094cc9c67a4cd549 Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Jun 2023 23:49:43 +0000 Subject: [PATCH 13/28] Bump Bb. --- circuits/cpp/barretenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index 9db5fcb17f11..733fe2702179 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 9db5fcb17f118838c0574bebce93f4655d6dbccd +Subproject commit 733fe27021793ab672190ee83274abb6049cdc9a From f888db5234aea00ab52d07d12736d1515dc5a34d Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 00:49:51 +0000 Subject: [PATCH 14/28] Note on compilation errors in tests. --- .../src/aztec3/circuits/kernel/public/.test.cpp | 17 +++++++++++------ .../src/aztec3/circuits/rollup/base/.test.cpp | 14 ++++++++------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index bfb4817abe53..7035c9e65510 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -367,12 +367,15 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat .bytecode_hash = 1234567, }; - // CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { - // .private_data_tree_root = 1000, - // .contract_tree_root = 2000, - // .l1_to_l2_messages_tree_root = 3000, - // .private_kernel_vk_tree_root = 4000, - // } }; + // TODO(914) Should this be unused? + [[maybe_unused]] CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { + .private_data_tree_root = 1000, + .contract_tree_root = 2000, + .l1_to_l2_messages_tree_root = + 3000, + .private_kernel_vk_tree_root = + 4000, + } }; CombinedConstantData const end_constants = { .historic_tree_roots = @@ -1079,6 +1082,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre // Unencrypted logs hash and preimage lengths should now be correctly accumulated auto const& public_inputs_unencrypted_logs_hash = inputs.previous_kernel.public_inputs.end.unencrypted_logs_hash; auto const& unencrypted_logs_hash = inputs.public_call.call_stack_item.public_inputs.unencrypted_logs_hash; + // TODO(914) Should this be unused? [[maybe_unused]] auto const& expected_unencrypted_logs_hash = accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], public_inputs_unencrypted_logs_hash[1], @@ -1230,6 +1234,7 @@ TEST(public_kernel_tests, logs_are_handled_as_expected) // Unencrypted logs hash and preimage lengths should now be correctly accumulated auto const& public_inputs_unencrypted_logs_hash = inputs.previous_kernel.public_inputs.end.unencrypted_logs_hash; auto const& unencrypted_logs_hash = inputs.public_call.call_stack_item.public_inputs.unencrypted_logs_hash; + // TODO(914) Should this be unused? [[maybe_unused]] auto const& expected_unencrypted_logs_hash = accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], public_inputs_unencrypted_logs_hash[1], diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 6d057e00d667..50b4f323d02e 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -527,21 +527,23 @@ TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { DummyBuilder builder = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); + // TODO(914) Should this be unused? [[maybe_unused]] auto expected_calldata_hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + // TODO(914) Should this be unused? [[maybe_unused]] std::array const output_calldata_hash = outputs.calldata_hash; + // TODO(Cody): I don't understand how this was compiling before. Global variables? Is that intended? // std::array calldata_hash; - for (uint8_t i = 0; i < 16; ++i) { - // WORKTODO: ??? - // calldata_hash[i] = high_buffer[16 + i]; - // calldata_hash[16 + i] = low_buffer[16 + i]; - } - + // for (uint8_t i = 0; i < 16; ++i) { + // calldata_hash[i] = high_buffer[16 + i]; + // calldata_hash[16 + i] = low_buffer[16 + i]; + // } // ASSERT_EQ(hash, calldata_hash); + ASSERT_FALSE(builder.failed()); run_cbind(inputs, outputs); From 4958f0aef95290796dd259c60c139b2555087a38 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 00:54:20 +0000 Subject: [PATCH 15/28] Try to satisfy clang-tidy. --- circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 50b4f323d02e..e8a45f77e1d6 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -34,7 +34,6 @@ using aztec3::circuits::abis::PreviousKernelData; // using aztec3::circuits::mock::mock_circuit; using aztec3::circuits::rollup::test_utils::utils::base_rollup_inputs_from_kernels; -using aztec3::circuits::rollup::test_utils::utils::compare_field_hash_to_expected; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_initial_nullifier_tree; // using aztec3::circuits::mock::mock_kernel_inputs; From 2b8e215aabc5af1273aaca8e2ffda4e84a776644 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 01:00:32 +0000 Subject: [PATCH 16/28] Fix test that didn't compile before. --- .../src/aztec3/circuits/rollup/base/.test.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index e8a45f77e1d6..9d653462ccd5 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -34,6 +34,7 @@ using aztec3::circuits::abis::PreviousKernelData; // using aztec3::circuits::mock::mock_circuit; using aztec3::circuits::rollup::test_utils::utils::base_rollup_inputs_from_kernels; +using aztec3::circuits::rollup::test_utils::utils::compare_field_hash_to_expected; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; using aztec3::circuits::rollup::test_utils::utils::get_initial_nullifier_tree; // using aztec3::circuits::mock::mock_kernel_inputs; @@ -526,22 +527,13 @@ TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { DummyBuilder builder = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); - // TODO(914) Should this be unused? - [[maybe_unused]] auto expected_calldata_hash = sha256::sha256(zero_bytes_vec); + auto expected_calldata_hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + std::array const output_calldata_hash = outputs.calldata_hash; - // TODO(914) Should this be unused? - [[maybe_unused]] std::array const output_calldata_hash = outputs.calldata_hash; - - // TODO(Cody): I don't understand how this was compiling before. Global variables? Is that intended? - // std::array calldata_hash; - // for (uint8_t i = 0; i < 16; ++i) { - // calldata_hash[i] = high_buffer[16 + i]; - // calldata_hash[16 + i] = low_buffer[16 + i]; - // } - // ASSERT_EQ(hash, calldata_hash); + ASSERT_TRUE(compare_field_hash_to_expected(output_calldata_hash, expected_calldata_hash) == true); ASSERT_FALSE(builder.failed()); From 80d7d22495e28e0da7f203c0988b3147afae08b8 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 13:52:05 +0000 Subject: [PATCH 17/28] Respond to comments and clean up --- .../src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp | 1 - circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp | 1 - circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h | 3 +-- .../kernel/private/native_private_kernel_circuit_ordering.hpp | 2 +- circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp | 2 +- circuits/cpp/src/aztec3/utils/types/circuit_types.hpp | 2 +- 6 files changed, 4 insertions(+), 7 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp index 47819a5b861a..c9bfc1b36772 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp @@ -3,7 +3,6 @@ #include "../append_only_tree_snapshot.hpp" #include "../global_variables.hpp" -#include "barretenberg/common/serialize.hpp" #include namespace aztec3::circuits::abis { diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp index bf8efe7cf891..eb7a8aa725e3 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp @@ -6,7 +6,6 @@ #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" -#include "barretenberg/common/serialize.hpp" #include namespace aztec3::circuits::abis { diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h index b2a7823808dc..40e077b7d1b1 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h @@ -1,6 +1,5 @@ #pragma once -#include "barretenberg/serialize/cbind_fwd.hpp" -#include +#include a #include #include diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp index 9e6647c7f732..6c5289483853 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp @@ -26,7 +26,7 @@ KernelCircuitPublicInputs native_private_kernel_circuit_ordering( std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses); -CircuitResult > native_private_kernel_circuit_ordering_rr_dummy( +CircuitResult> native_private_kernel_circuit_ordering_rr_dummy( PreviousKernelData const& previous_kernel); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index f11ac44ca039..343ba12e79e7 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -1,7 +1,7 @@ #pragma once #include "init.hpp" -#include "barretenberg/plonk/flavor/flavor.hpp" +#include namespace aztec3::circuits::recursion { diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index 71b26693b0a0..ea3daa5273e5 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -7,6 +7,7 @@ using namespace proof_system::plonk; +// Note: Inner proving system type for recursion is inflexibly set to UltraPlonk. namespace aztec3::utils::types { template struct CircuitTypes { @@ -42,7 +43,6 @@ template struct CircuitTypes { using ecdsa_signature = stdlib::ecdsa::signature; using AggregationObject = stdlib::recursion::aggregation_state; - using recursive_inner_verifier_settings = stdlib::recursion::recursive_ultra_verifier_settings; using VK = stdlib::recursion::verification_key; // Notice: no CircuitType for a Proof: we only ever handle native; the verify_proof() function swallows the // 'circuit-type-ness' of the proof. From a586f3ba4ea0568e2ec1b93f00119d470ab86123 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Tue, 27 Jun 2023 14:55:08 +0100 Subject: [PATCH 18/28] use cross chain harness for uniswap e2e (#916) --- .../src/cross_chain/test_harness.ts | 53 ++++- .../src/e2e_cross_chain_messaging.test.ts | 17 +- .../e2e_public_cross_chain_messaging.test.ts | 29 +-- .../src/uniswap_trade_on_l1_from_l2.test.ts | 188 +++++++----------- 4 files changed, 135 insertions(+), 152 deletions(-) diff --git a/yarn-project/end-to-end/src/cross_chain/test_harness.ts b/yarn-project/end-to-end/src/cross_chain/test_harness.ts index a9e56bcb95a5..20c97fe4dbb2 100644 --- a/yarn-project/end-to-end/src/cross_chain/test_harness.ts +++ b/yarn-project/end-to-end/src/cross_chain/test_harness.ts @@ -4,7 +4,7 @@ import { AztecAddress, EthAddress, Fr, Point } from '@aztec/circuits.js'; import { DeployL1Contracts } from '@aztec/ethereum'; import { DebugLogger } from '@aztec/foundation/log'; import { PublicClient, HttpTransport, Chain, getContract } from 'viem'; -import { deployAndInitializeNonNativeL2TokenContracts, pointToPublicKey } from '../utils.js'; +import { deployAndInitializeNonNativeL2TokenContracts, expectStorageSlot, pointToPublicKey } from '../utils.js'; import { OutboxAbi } from '@aztec/l1-artifacts'; import { sha256ToField } from '@aztec/foundation/crypto'; import { toBufferBE } from '@aztec/foundation/bigint-buffer'; @@ -120,6 +120,10 @@ export class CrossChainTestHarness { expect(await this.underlyingERC20.read.balanceOf([this.ethAccount.toString()])).toBe(amount); } + async getL1BalanceOf(address: EthAddress) { + return await this.underlyingERC20.read.balanceOf([address.toString()]); + } + async sendTokensToPortal(bridgeAmount: bigint, secretHash: Fr) { await this.underlyingERC20.write.approve([this.tokenPortalAddress.toString(), bridgeAmount], {} as any); @@ -158,6 +162,53 @@ export class CrossChainTestHarness { expect(transferReceipt.status).toBe(TxStatus.MINED); } + async consumeMessageOnAztecAndMintSecretly(bridgeAmount: bigint, messageKey: Fr, secret: Fr) { + this.logger('Consuming messages on L2 secretively'); + // Call the mint tokens function on the noir contract + const consumptionTx = this.l2Contract.methods + .mint(bridgeAmount, this.ownerPub, this.ownerAddress, messageKey, secret, this.ethAccount.toField()) + .send({ from: this.ownerAddress }); + + await consumptionTx.isMined(0, 0.1); + const consumptionReceipt = await consumptionTx.getReceipt(); + expect(consumptionReceipt.status).toBe(TxStatus.MINED); + } + + async consumeMessageOnAztecAndMintPublicly(bridgeAmount: bigint, messageKey: Fr, secret: Fr) { + this.logger('Consuming messages on L2 Publicly'); + // Call the mint tokens function on the noir contract + const consumptionTx = this.l2Contract.methods + .mintPublic(bridgeAmount, this.ownerAddress, messageKey, secret, this.ethAccount.toField()) + .send({ from: this.ownerAddress }); + + await consumptionTx.isMined(0, 0.1); + const consumptionReceipt = await consumptionTx.getReceipt(); + expect(consumptionReceipt.status).toBe(TxStatus.MINED); + } + + async getL2BalanceOf(owner: AztecAddress) { + const ownerPublicKey = await this.aztecRpcServer.getAccountPublicKey(owner); + const [balance] = await this.l2Contract.methods.getBalance(pointToPublicKey(ownerPublicKey)).view({ from: owner }); + return balance; + } + + async expectBalanceOnL2(owner: AztecAddress, expectedBalance: bigint) { + const balance = await this.getL2BalanceOf(owner); + this.logger(`Account ${owner} balance: ${balance}`); + expect(balance).toBe(expectedBalance); + } + + async expectPublicBalanceOnL2(owner: AztecAddress, expectedBalance: bigint, publicBalanceSlot: bigint) { + await expectStorageSlot( + this.logger, + this.aztecNode, + this.l2Contract, + publicBalanceSlot, + owner.toField(), + expectedBalance, + ); + } + async checkEntryIsNotInOutbox(withdrawAmount: bigint, callerOnL1: EthAddress = EthAddress.ZERO): Promise { this.logger('Ensure that the entry is not in outbox yet'); const contractInfo = await this.aztecNode.getContractInfo(this.l2Contract.address); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 31fa7bdc30ef..23d13a2d340d 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -2,7 +2,7 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, AztecRPCServer, Contract, TxStatus } from '@aztec/aztec.js'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { Fr, Point } from '@aztec/foundation/fields'; +import { Point } from '@aztec/foundation/fields'; import { DebugLogger } from '@aztec/foundation/log'; import { delay, pointToPublicKey, setup } from './utils.js'; import { CrossChainTestHarness } from './cross_chain/test_harness.js'; @@ -65,19 +65,6 @@ describe('e2e_cross_chain_messaging', () => { expect(balance).toBe(expectedBalance); }; - const consumeMessageOnAztecAndMint = async (bridgeAmount: bigint, messageKey: Fr, secret: Fr) => { - logger('Consuming messages on L2 secretively'); - // Call the mint tokens function on the noir contract - const consumptionTx = l2Contract.methods - .mint(bridgeAmount, ownerPub, ownerAddress, messageKey, secret, ethAccount.toField()) - .send({ from: ownerAddress }); - - await consumptionTx.isMined(0, 0.1); - const consumptionReceipt = await consumptionTx.getReceipt(); - - expect(consumptionReceipt.status).toBe(TxStatus.MINED); - }; - const withdrawFundsFromAztec = async (withdrawAmount: bigint) => { logger('Send L2 tx to withdraw funds'); const withdrawTx = l2Contract.methods @@ -108,7 +95,7 @@ describe('e2e_cross_chain_messaging', () => { const transferAmount = 1n; await crossChainTestHarness.performL2Transfer(transferAmount); - await consumeMessageOnAztecAndMint(bridgeAmount, messageKey, secret); + await crossChainTestHarness.consumeMessageOnAztecAndMintSecretly(bridgeAmount, messageKey, secret); await expectBalance(ownerAddress, bridgeAmount + initialBalance - transferAmount); // time to withdraw the funds again! diff --git a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts index 9ebb9f97c5e2..f5ad44d3eec6 100644 --- a/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_public_cross_chain_messaging.test.ts @@ -2,9 +2,8 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, AztecRPCServer, Contract, TxStatus } from '@aztec/aztec.js'; import { EthAddress } from '@aztec/foundation/eth-address'; -import { Fr } from '@aztec/foundation/fields'; import { DebugLogger } from '@aztec/foundation/log'; -import { delay, expectStorageSlot, setup } from './utils.js'; +import { delay, setup } from './utils.js'; import { CrossChainTestHarness } from './cross_chain/test_harness.js'; describe('e2e_public_cross_chain_messaging', () => { @@ -58,19 +57,6 @@ describe('e2e_public_cross_chain_messaging', () => { await crossChainTestHarness?.stop(); }); - const consumeMessageOnAztec = async (bridgeAmount: bigint, messageKey: Fr, secret: Fr) => { - logger('Consuming messages on L2 Publicly'); - // Call the mint tokens function on the noir contract - const consumptionTx = l2Contract.methods - .mintPublic(bridgeAmount, ownerAddress, messageKey, secret, ethAccount.toField()) - .send({ from: ownerAddress }); - - await consumptionTx.isMined(0, 0.1); - const consumptionReceipt = await consumptionTx.getReceipt(); - - expect(consumptionReceipt.status).toBe(TxStatus.MINED); - }; - const withdrawFundsFromAztec = async (withdrawAmount: bigint) => { logger('Send L2 tx to withdraw funds'); const withdrawTx = l2Contract.methods @@ -102,22 +88,15 @@ describe('e2e_public_cross_chain_messaging', () => { const transferAmount = 1n; await crossChainTestHarness.performL2Transfer(transferAmount); - await consumeMessageOnAztec(bridgeAmount, messageKey, secret); - await expectStorageSlot(logger, aztecNode, l2Contract, publicBalanceSlot, ownerAddress.toField(), bridgeAmount); + await crossChainTestHarness.consumeMessageOnAztecAndMintPublicly(bridgeAmount, messageKey, secret); + await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount, publicBalanceSlot); // time to withdraw the funds again! logger('Withdrawing funds from L2'); const withdrawAmount = 9n; const entryKey = await crossChainTestHarness.checkEntryIsNotInOutbox(withdrawAmount); await withdrawFundsFromAztec(withdrawAmount); - await expectStorageSlot( - logger, - aztecNode, - l2Contract, - publicBalanceSlot, - ownerAddress.toField(), - bridgeAmount - withdrawAmount, - ); + await crossChainTestHarness.expectPublicBalanceOnL2(ownerAddress, bridgeAmount - withdrawAmount, publicBalanceSlot); // Check balance before and after exit. expect(await underlyingERC20.read.balanceOf([ethAccount.toString()])).toBe(l1TokenBalance - bridgeAmount); diff --git a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts index c70fbbfb19d0..dcca1928fe86 100644 --- a/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts +++ b/yarn-project/end-to-end/src/uniswap_trade_on_l1_from_l2.test.ts @@ -1,19 +1,12 @@ import { AztecNodeService } from '@aztec/aztec-node'; -import { - AztecAddress, - AztecRPCServer, - Contract, - ContractDeployer, - Fr, - TxStatus, - computeMessageSecretHash, -} from '@aztec/aztec.js'; +import { AztecAddress, AztecRPCServer, Contract, ContractDeployer, Fr, TxStatus } from '@aztec/aztec.js'; import { deployL1Contract } from '@aztec/ethereum'; import { EthAddress } from '@aztec/foundation/eth-address'; import { delay, deployAndInitializeNonNativeL2TokenContracts, pointToPublicKey, setup } from './utils.js'; +import { CrossChainTestHarness } from './cross_chain/test_harness.js'; import { DebugLogger } from '@aztec/foundation/log'; -import { Chain, HttpTransport, PublicClient, getContract, parseEther } from 'viem'; +import { getContract, parseEther } from 'viem'; import { DeployL1Contracts } from '@aztec/ethereum'; import { UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts'; import { UniswapContractAbi } from '@aztec/noir-contracts/examples'; @@ -36,9 +29,6 @@ describe('uniswap_trade_on_l1_from_l2', () => { let accounts: AztecAddress[]; let logger: DebugLogger; - let publicClient: PublicClient; - let walletClient: any; - let ethAccount: EthAddress; let ownerAddress: AztecAddress; let receiver: AztecAddress; @@ -46,25 +36,19 @@ describe('uniswap_trade_on_l1_from_l2', () => { const initialBalance = 10n; const wethAmountToBridge = parseEther('1'); + let daiCrossChainHarness: CrossChainTestHarness; + let wethCrossChainHarness: CrossChainTestHarness; + let uniswapPortal: any; let uniswapPortalAddress: EthAddress; let uniswapL2Contract: Contract; - let wethContract: any; - let wethTokenPortalAddress: EthAddress; - let wethTokenPortal: any; - let wethL2Contract: Contract; - - let daiContract: any; - let daiTokenPortalAddress: EthAddress; - let daiL2Contract: Contract; - beforeEach(async () => { let deployL1ContractsValues: DeployL1Contracts; ({ aztecNode, aztecRpcServer, deployL1ContractsValues, accounts, logger } = await setup(2)); - walletClient = deployL1ContractsValues.walletClient; - publicClient = deployL1ContractsValues.publicClient; + const walletClient = deployL1ContractsValues.walletClient; + const publicClient = deployL1ContractsValues.publicClient; if (Number(await publicClient.getBlockNumber()) < EXPECTED_FORKED_BLOCK) { throw new Error('This test must be run on a fork of mainnet with the expected fork block'); @@ -72,7 +56,8 @@ describe('uniswap_trade_on_l1_from_l2', () => { ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]); [ownerAddress, receiver] = accounts; - ownerPub = pointToPublicKey(await aztecRpcServer.getAccountPublicKey(ownerAddress)); + const ownerPubPoint = await aztecRpcServer.getAccountPublicKey(ownerAddress); + ownerPub = pointToPublicKey(ownerPubPoint); logger('Deploying DAI Portal, initializing and deploying l2 contract...'); const daiContracts = await deployAndInitializeNonNativeL2TokenContracts( @@ -84,9 +69,23 @@ describe('uniswap_trade_on_l1_from_l2', () => { ownerPub, DAI_ADDRESS, ); - daiL2Contract = daiContracts.l2Contract; - daiContract = daiContracts.underlyingERC20; - daiTokenPortalAddress = daiContracts.tokenPortalAddress; + daiCrossChainHarness = new CrossChainTestHarness( + aztecNode, + aztecRpcServer, + accounts, + logger, + daiContracts.l2Contract, + ethAccount, + daiContracts.tokenPortalAddress, + daiContracts.tokenPortal, + daiContracts.underlyingERC20, + null, + publicClient, + walletClient, + ownerAddress, + receiver, + ownerPubPoint, + ); logger('Deploying WETH Portal, initializing and deploying l2 contract...'); const wethContracts = await deployAndInitializeNonNativeL2TokenContracts( @@ -98,10 +97,23 @@ describe('uniswap_trade_on_l1_from_l2', () => { ownerPub, WETH9_ADDRESS, ); - wethL2Contract = wethContracts.l2Contract; - wethContract = wethContracts.underlyingERC20; - wethTokenPortal = wethContracts.tokenPortal; - wethTokenPortalAddress = wethContracts.tokenPortalAddress; + wethCrossChainHarness = new CrossChainTestHarness( + aztecNode, + aztecRpcServer, + accounts, + logger, + wethContracts.l2Contract, + ethAccount, + wethContracts.tokenPortalAddress, + wethContracts.tokenPortal, + wethContracts.underlyingERC20, + null, + publicClient, + walletClient, + ownerAddress, + receiver, + ownerPubPoint, + ); logger('Deploy Uniswap portal on L1 and L2...'); uniswapPortalAddress = await deployL1Contract(walletClient, publicClient, UniswapPortalAbi, UniswapPortalBytecode); @@ -130,91 +142,50 @@ describe('uniswap_trade_on_l1_from_l2', () => { }, 100_000); afterEach(async () => { - await aztecNode?.stop(); - await aztecRpcServer?.stop(); + await aztecNode.stop(); + await aztecRpcServer.stop(); + await wethCrossChainHarness.stop(); + await daiCrossChainHarness.stop(); }); - const getL2BalanceOf = async (owner: AztecAddress, l2Contract: any) => { - const ownerPublicKey = await aztecRpcServer.getAccountPublicKey(owner); - const [balance] = await l2Contract.methods.getBalance(pointToPublicKey(ownerPublicKey)).view({ from: owner }); - return balance; - }; - - const expectBalanceOnL2 = async (owner: AztecAddress, expectedBalance: bigint, l2Contract: any) => { - const balance = await getL2BalanceOf(owner, l2Contract); - logger(`Account ${owner} balance: ${balance}`); - expect(balance).toBe(expectedBalance); - }; - - const transferWethOnL2 = async (transferAmount: bigint) => { - const transferTx = wethL2Contract.methods - .transfer( - transferAmount, - pointToPublicKey(await aztecRpcServer.getAccountPublicKey(ownerAddress)), - pointToPublicKey(await aztecRpcServer.getAccountPublicKey(receiver)), - ) - .send({ from: accounts[0] }); - await transferTx.isMined(0, 0.1); - const transferReceipt = await transferTx.getReceipt(); - expect(transferReceipt.status).toBe(TxStatus.MINED); - }; - it('should uniswap trade on L1 from L2 funds privately (swaps WETH -> DAI)', async () => { - const meBeforeBalance = await wethContract.read.balanceOf([ethAccount.toString()]); - // 1. Approve weth to be bridged - await wethContract.write.approve([wethTokenPortalAddress.toString(), wethAmountToBridge], {} as any); + const meBeforeBalance = await wethCrossChainHarness.getL1BalanceOf(ethAccount); - // 2. Deposit weth into the portal and move to L2 - // generate secret - const secret = Fr.random(); - const secretHash = await computeMessageSecretHash(secret); - const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`; - const deadline = 2 ** 32 - 1; // max uint32 - 1 - logger('Sending messages to L1 portal'); - const args = [ownerAddress.toString(), wethAmountToBridge, deadline, secretString, ethAccount.toString()] as const; - const { result: messageKeyHex } = await wethTokenPortal.simulate.depositToAztec(args, { - account: ethAccount.toString(), - } as any); - await wethTokenPortal.write.depositToAztec(args, {} as any); - expect(await wethContract.read.balanceOf([ethAccount.toString()])).toBe(meBeforeBalance - wethAmountToBridge); - const messageKey = Fr.fromString(messageKeyHex); + // 1. Approve and deposit weth to the portal and move to L2 + const [secret, secretHash] = await wethCrossChainHarness.generateClaimSecret(); + const messageKey = await wethCrossChainHarness.sendTokensToPortal(wethAmountToBridge, secretHash); + expect(await wethCrossChainHarness.getL1BalanceOf(ethAccount)).toBe(meBeforeBalance - wethAmountToBridge); // Wait for the archiver to process the message await delay(5000); + // send a transfer tx to force through rollup with the message included const transferAmount = 1n; - await transferWethOnL2(transferAmount); + await wethCrossChainHarness.performL2Transfer(transferAmount); // 3. Claim WETH on L2 logger('Minting weth on L2'); - // Call the mint tokens function on the noir contract - const consumptionTx = wethL2Contract.methods - .mint(wethAmountToBridge, ownerPub, ownerAddress, messageKey, secret, ethAccount.toField()) - .send({ from: ownerAddress }); - await consumptionTx.isMined(0, 0.1); - const consumptionReceipt = await consumptionTx.getReceipt(); - expect(consumptionReceipt.status).toBe(TxStatus.MINED); - await expectBalanceOnL2(ownerAddress, wethAmountToBridge + initialBalance - transferAmount, wethL2Contract); + await wethCrossChainHarness.consumeMessageOnAztecAndMintSecretly(wethAmountToBridge, messageKey, secret); + await wethCrossChainHarness.expectBalanceOnL2(ownerAddress, wethAmountToBridge + initialBalance - transferAmount); // Store balances - const wethBalanceBeforeSwap = await getL2BalanceOf(ownerAddress, wethL2Contract); - const daiBalanceBeforeSwap = await getL2BalanceOf(ownerAddress, daiL2Contract); + const wethBalanceBeforeSwap = await wethCrossChainHarness.getL2BalanceOf(ownerAddress); + const daiBalanceBeforeSwap = await daiCrossChainHarness.getL2BalanceOf(ownerAddress); // 4. Send L2 to L1 message to withdraw funds and another message to swap assets. logger('Send L2 tx to withdraw WETH to uniswap portal and send message to swap assets on L1'); - // recipient is the uniswap portal - const selector = Fr.fromBuffer(wethL2Contract.methods.withdraw.selector); + const selector = Fr.fromBuffer(wethCrossChainHarness.l2Contract.methods.withdraw.selector); const minimumOutputAmount = 0; const withdrawTx = uniswapL2Contract.methods .swap( selector, - wethL2Contract.address.toField(), - wethTokenPortalAddress.toField(), + wethCrossChainHarness.l2Contract.address.toField(), + wethCrossChainHarness.tokenPortalAddress.toField(), wethAmountToBridge, new Fr(3000), - daiL2Contract.address.toField(), - daiTokenPortalAddress.toField(), + daiCrossChainHarness.l2Contract.address.toField(), + daiCrossChainHarness.tokenPortalAddress.toField(), new Fr(minimumOutputAmount), ownerPub, ownerAddress, @@ -230,19 +201,20 @@ describe('uniswap_trade_on_l1_from_l2', () => { expect(withdrawReceipt.status).toBe(TxStatus.MINED); // check weth balance of owner on L2 (we first briedged `wethAmountToBridge` into L2 and now withdrew it!) - await expectBalanceOnL2(ownerAddress, initialBalance - transferAmount, wethL2Contract); + await wethCrossChainHarness.expectBalanceOnL2(ownerAddress, initialBalance - transferAmount); // 5. Consume L2 to L1 message by calling uniswapPortal.swap() logger('Execute withdraw and swap on the uniswapPortal!'); - const daiBalanceOfPortalBefore = await daiContract.read.balanceOf([daiTokenPortalAddress.toString()]); + const daiBalanceOfPortalBefore = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress); + const deadline = 2 ** 32 - 1; // max uint32 - 1 const swapArgs = [ - wethTokenPortalAddress.toString(), + wethCrossChainHarness.tokenPortalAddress.toString(), wethAmountToBridge, 3000, - daiTokenPortalAddress.toString(), + daiCrossChainHarness.tokenPortalAddress.toString(), minimumOutputAmount, ownerAddress.toString(), - secretString, + secretHash.toString(true), deadline, ethAccount.toString(), true, @@ -254,28 +226,22 @@ describe('uniswap_trade_on_l1_from_l2', () => { await uniswapPortal.write.swap(swapArgs, {} as any); const depositDaiMessageKey = Fr.fromString(depositDaiMessageKeyHex); // weth was swapped to dai and send to portal - const daiBalanceOfPortalAfter = await daiContract.read.balanceOf([daiTokenPortalAddress.toString()]); + const daiBalanceOfPortalAfter = await daiCrossChainHarness.getL1BalanceOf(daiCrossChainHarness.tokenPortalAddress); expect(daiBalanceOfPortalAfter).toBeGreaterThan(daiBalanceOfPortalBefore); - const daiAmountToBridge = daiBalanceOfPortalAfter - daiBalanceOfPortalBefore; + const daiAmountToBridge = BigInt(daiBalanceOfPortalAfter - daiBalanceOfPortalBefore); // Wait for the archiver to process the message await delay(5000); // send a transfer tx to force through rollup with the message included - await transferWethOnL2(transferAmount); + await wethCrossChainHarness.performL2Transfer(transferAmount); // 6. claim dai on L2 logger('Consuming messages to mint dai on L2'); - // Call the mint tokens function on the noir contract - const daiMintTx = daiL2Contract.methods - .mint(daiAmountToBridge, ownerPub, ownerAddress, depositDaiMessageKey, secret, ethAccount.toField()) - .send({ from: ownerAddress }); - await daiMintTx.isMined(0, 0.1); - const daiMintTxReceipt = await daiMintTx.getReceipt(); - expect(daiMintTxReceipt.status).toBe(TxStatus.MINED); - await expectBalanceOnL2(ownerAddress, initialBalance + BigInt(daiAmountToBridge), daiL2Contract); + await daiCrossChainHarness.consumeMessageOnAztecAndMintSecretly(daiAmountToBridge, depositDaiMessageKey, secret); + await daiCrossChainHarness.expectBalanceOnL2(ownerAddress, initialBalance + daiAmountToBridge); - const wethBalanceAfterSwap = await getL2BalanceOf(ownerAddress, wethL2Contract); - const daiBalanceAfterSwap = await getL2BalanceOf(ownerAddress, daiL2Contract); + const wethBalanceAfterSwap = await wethCrossChainHarness.getL2BalanceOf(ownerAddress); + const daiBalanceAfterSwap = await daiCrossChainHarness.getL2BalanceOf(ownerAddress); logger('WETH balance before swap: ', wethBalanceBeforeSwap.toString()); logger('DAI balance before swap : ', daiBalanceBeforeSwap.toString()); From ee71367ef30a57ca57df38b4a4d9c873ec470673 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 13:59:32 +0000 Subject: [PATCH 19/28] Fix typo and formatting. --- circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h | 2 +- yarn-project/circuits.js/src/structs/shared.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h index 40e077b7d1b1..6e8535b1cc89 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h @@ -1,5 +1,5 @@ #pragma once -#include a +#include #include #include diff --git a/yarn-project/circuits.js/src/structs/shared.ts b/yarn-project/circuits.js/src/structs/shared.ts index 2efdbf94a633..4f33319e80da 100644 --- a/yarn-project/circuits.js/src/structs/shared.ts +++ b/yarn-project/circuits.js/src/structs/shared.ts @@ -26,8 +26,8 @@ export class Vector { export type UInt32 = number; /** - * CircuitType replaces ComposerType for now. When using Plonk, CircuitType is equivalent to the information of the proving system that will be used - * to construct a proof. In the future Aztec zk stack, more information must be specified (e.g., the curve over which circuits are constructed; + * CircuitType replaces ComposerType for now. When using Plonk, CircuitType is equivalent to the information of the proving system that will be used + * to construct a proof. In the future Aztec zk stack, more information must be specified (e.g., the curve over which circuits are constructed; * Plonk vs Honk; zk-SNARK or just SNARK; etc). */ export enum CircuitType { From 46b831f0b488b2eb7ecb5e80dec3233e89eab3b2 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 14:04:07 +0000 Subject: [PATCH 20/28] Fix compilation post-merge --- .../aztec3/circuits/abis/private_circuit_public_inputs.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index a1edca4e70d7..c85ba2ff946c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -470,8 +470,8 @@ template class OptionalPrivateCircuitPublicInputs { make_unused_element_zero(builder, contract_deployment_data); - make_unused_element_zero(composer, chain_id); - make_unused_element_zero(composer, version); + make_unused_element_zero(builder, chain_id); + make_unused_element_zero(builder, version); all_elements_populated = true; } From c10ae382c9f650fdfd2272dca0316d37fd71d1fc Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 14:43:35 +0000 Subject: [PATCH 21/28] It should be a Schnorr signature? --- circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index 1a7403278910..fd7259fd268c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) From 4bd54698d19fe35d9cdf972008896f2751ff6d89 Mon Sep 17 00:00:00 2001 From: spypsy Date: Tue, 27 Jun 2023 16:00:08 +0100 Subject: [PATCH 22/28] Sp/aztec sandbox (internal) (#904) * WIP Aztec Sandbox * fix yarn lock * Working zk contract deployment over http Aztec RPC * add expect statements to http test * Remove 'expect' * remove yarn-project build_manifest * Revert project-base dockerfile changes * add missing RPC methods, move http RPC test * move utils to aztec.js & add endpoints to rpc server * move pointToPublicKey to Aztec.js * uniswap test on sandbox * Build system work * lockfile * update rpc for deploymentTx * Fix uniswap sandbox example * CCI Deploy step * fix json rpc server tests * Deploy fix test * Submodule update * Test filter * Updated compose file * Compse file update * CCI fix * Additional compose file * Wait for Ethereum RPC server to become available * Updated CCI config * fix anvil command for docker-compose-fork * Submodule bump * Removed unnecessary dependencies --------- Co-authored-by: PhilWindle --- .circleci/config.yml | 35 ++ build-system | 2 +- build_manifest.json | 15 + build_manifest.sh | 2 + .../archiver/src/archiver/archiver.ts | 11 +- .../aztec-node/src/aztec-node/http-node.ts | 5 +- yarn-project/aztec-rpc/package.json | 3 +- .../aztec_rpc.ts} | 18 +- yarn-project/aztec-rpc/src/aztec_rpc/index.ts | 1 + .../aztec_rpc_http/aztec_rpc_http_server.ts | 33 ++ .../aztec-rpc/src/aztec_rpc_http/index.ts | 1 + .../src/aztec_rpc_server/aztec_rpc_server.ts | 111 +++++- yarn-project/aztec-rpc/src/index.ts | 3 +- yarn-project/aztec-sandbox/.eslintrc.cjs | 1 + yarn-project/aztec-sandbox/Dockerfile | 18 + yarn-project/aztec-sandbox/README.md | 1 + .../aztec-sandbox/docker-compose-fork.yml | 21 + yarn-project/aztec-sandbox/docker-compose.yml | 20 + yarn-project/aztec-sandbox/package.json | 59 +++ .../examples/uniswap_trade_on_l1_from_l2.ts | 361 ++++++++++++++++++ .../aztec-sandbox/src/examples/util.ts | 103 +++++ .../src/examples/zk_contract_deployment.ts | 56 +++ yarn-project/aztec-sandbox/src/index.ts | 83 ++++ yarn-project/aztec-sandbox/src/routes.ts | 28 ++ yarn-project/aztec-sandbox/tsconfig.json | 26 ++ .../src/aztec_rpc_client/aztec_rpc_client.ts | 56 +++ .../src/aztec_rpc_client/index.ts | 0 .../aztec.js/src/contract/contract.test.ts | 6 +- .../aztec.js/src/contract/contract.ts | 4 +- .../contract/contract_function_interaction.ts | 4 +- yarn-project/aztec.js/src/contract/sent_tx.ts | 4 +- .../contract_deployer.test.ts | 6 +- .../contract_deployer/contract_deployer.ts | 4 +- .../src/contract_deployer/deploy_method.ts | 4 +- yarn-project/aztec.js/src/index.ts | 1 + yarn-project/aztec.js/src/utils/account.ts | 31 ++ yarn-project/aztec.js/src/utils/index.ts | 2 + yarn-project/aztec.js/src/utils/pub_key.ts | 15 + .../kernel/combined_accumulated_data.ts | 13 + .../structs/kernel/combined_constant_data.ts | 12 + .../src/e2e_zk_token_contract.test.ts | 4 +- .../src/json-rpc/class_converter.ts | 91 +++-- .../json-rpc/client/json_rpc_client.test.ts | 4 +- .../src/json-rpc/client/json_rpc_client.ts | 44 ++- .../foundation/src/json-rpc/convert.ts | 33 ++ .../foundation/src/json-rpc/js_utils.ts | 9 +- .../src/json-rpc/server/json_proxy.ts | 8 +- .../json-rpc/server/json_rpc_server.test.ts | 16 +- .../src/json-rpc/server/json_rpc_server.ts | 60 ++- yarn-project/package.json | 3 +- yarn-project/tsconfig.json | 1 + yarn-project/typedoc.json | 3 +- yarn-project/types/src/logs/tx_l2_logs.ts | 4 +- yarn-project/types/src/tx.ts | 60 ++- yarn-project/types/src/tx_hash.ts | 10 + yarn-project/yarn-project-base/Dockerfile | 2 + yarn-project/yarn.lock | 45 ++- 57 files changed, 1453 insertions(+), 123 deletions(-) rename yarn-project/aztec-rpc/src/{aztec_rpc_client/aztec_rpc_client.ts => aztec_rpc/aztec_rpc.ts} (81%) create mode 100644 yarn-project/aztec-rpc/src/aztec_rpc/index.ts create mode 100644 yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts create mode 100644 yarn-project/aztec-rpc/src/aztec_rpc_http/index.ts create mode 100644 yarn-project/aztec-sandbox/.eslintrc.cjs create mode 100644 yarn-project/aztec-sandbox/Dockerfile create mode 100644 yarn-project/aztec-sandbox/README.md create mode 100644 yarn-project/aztec-sandbox/docker-compose-fork.yml create mode 100644 yarn-project/aztec-sandbox/docker-compose.yml create mode 100644 yarn-project/aztec-sandbox/package.json create mode 100644 yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts create mode 100644 yarn-project/aztec-sandbox/src/examples/util.ts create mode 100644 yarn-project/aztec-sandbox/src/examples/zk_contract_deployment.ts create mode 100644 yarn-project/aztec-sandbox/src/index.ts create mode 100644 yarn-project/aztec-sandbox/src/routes.ts create mode 100644 yarn-project/aztec-sandbox/tsconfig.json create mode 100644 yarn-project/aztec.js/src/aztec_rpc_client/aztec_rpc_client.ts rename yarn-project/{aztec-rpc => aztec.js}/src/aztec_rpc_client/index.ts (100%) create mode 100644 yarn-project/aztec.js/src/utils/account.ts create mode 100644 yarn-project/aztec.js/src/utils/pub_key.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index e895fe9f8ed7..0ce618009bb0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -319,6 +319,17 @@ jobs: name: "Build and test" command: build aztec-rpc + aztec-sandbox: + machine: + image: ubuntu-2004:202010-01 + resource_class: large + steps: + - *checkout + - *setup_env + - run: + name: "Build and test" + command: build aztec-sandbox + circuits-js: machine: image: ubuntu-2004:202010-01 @@ -535,6 +546,20 @@ jobs: name: "Noop" command: echo Noop + deploy: + machine: + image: ubuntu-2004:202010-01 + resource_class: medium + steps: + - *checkout + - *setup_env + - run: + name: "deploy-sandbox" + working_directory: aztec-sandbox + command: | + deploy_ecr aztec-sandbox + deploy_dockerhub aztec-sandbox master + # Repeatable config for defining the workflow below. tag_regex: &tag_regex /v[0-9]+(\.[0-9]+)*(-[a-zA-Z-]+\.[0-9]+)?/ defaults: &defaults @@ -615,6 +640,7 @@ workflows: - types: *yarn_project - circuits-js: *yarn_project - rollup-provider: *yarn_project + - aztec-sandbox: *yarn_project - e2e-join: requires: @@ -667,3 +693,12 @@ workflows: - integration-archiver-l1-to-l2 - e2e-p2p <<: *defaults + + - deploy: + requires: + - e2e-end + - aztec-sandbox + filters: + branches: + only: master + <<: *defaults diff --git a/build-system b/build-system index 40e2f4b4b04b..5d3ed11e8017 160000 --- a/build-system +++ b/build-system @@ -1 +1 @@ -Subproject commit 40e2f4b4b04bdef9f66d909bc3b2c49b1444b42d +Subproject commit 5d3ed11e8017e3daf574e3b287e62c7a99c24bb4 diff --git a/build_manifest.json b/build_manifest.json index fbb69a31408e..124a8cdbfb0d 100644 --- a/build_manifest.json +++ b/build_manifest.json @@ -142,6 +142,21 @@ "types" ] }, + "aztec-sandbox": { + "buildDir": "yarn-project", + "projectDir": "yarn-project/aztec-sandbox", + "dockerfile": "aztec-sandbox/Dockerfile", + "rebuildPatterns": [ + "^yarn-project/aztec-sandbox/" + ], + "dependencies": [ + "aztec-node", + "aztec-rpc", + "aztec.js", + "ethereum", + "foundation" + ] + }, "aztec.js": { "buildDir": "yarn-project", "projectDir": "yarn-project/aztec.js", diff --git a/build_manifest.sh b/build_manifest.sh index 22ba06a341e8..7f7227117a29 100755 --- a/build_manifest.sh +++ b/build_manifest.sh @@ -14,6 +14,8 @@ PROJECTS=( circuits:circuits/cpp:./dockerfiles/Dockerfile.wasm-linux-clang:circuits-wasm-linux-clang + l1-contracts:l1-contracts yarn-project-base:yarn-project end-to-end:yarn-project + aztec-sandbox:yarn-project ) diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index b516b8096cb2..d0aed6daef9e 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -47,6 +47,11 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource */ private lastProcessedBlockNumber = 0n; + /** + * Use this to track logged block in order to avoid repeating the same message. + */ + private lastLoggedBlockNumber = 0n; + /** * Creates a new instance of the Archiver. * @param publicClient - A client for interacting with the Ethereum node. @@ -123,7 +128,11 @@ export class Archiver implements L2BlockSource, L2LogsSource, ContractDataSource private async sync(blockUntilSynced: boolean) { const currentBlockNumber = await this.publicClient.getBlockNumber(); if (currentBlockNumber <= this.lastProcessedBlockNumber) { - this.log(`No new blocks to process, current block number: ${currentBlockNumber}`); + // reducing logs, otherwise this gets triggered on every loop (1s) + if (currentBlockNumber !== this.lastLoggedBlockNumber) { + this.log(`No new blocks to process, current block number: ${currentBlockNumber}`); + this.lastLoggedBlockNumber = currentBlockNumber; + } return; } diff --git a/yarn-project/aztec-node/src/aztec-node/http-node.ts b/yarn-project/aztec-node/src/aztec-node/http-node.ts index e235edf25255..93d618195ed5 100644 --- a/yarn-project/aztec-node/src/aztec-node/http-node.ts +++ b/yarn-project/aztec-node/src/aztec-node/http-node.ts @@ -33,6 +33,7 @@ export function txToJson(tx: Tx) { return { data: tx.data?.toBuffer().toString('hex'), encryptedLogs: tx.encryptedLogs?.toBuffer().toString('hex'), + unencryptedLogs: tx.unencryptedLogs?.toBuffer().toString('hex'), proof: tx.proof?.toBuffer().toString('hex'), newContractPublicFunctions: tx.newContractPublicFunctions?.map(f => f.toBuffer().toString('hex')) ?? [], enqueuedPublicFunctions: tx.enqueuedPublicFunctionCalls?.map(f => f.toBuffer().toString('hex')) ?? [], @@ -49,10 +50,10 @@ export function txFromJson(json: any) { const encryptedLogs = TxL2Logs.fromBuffer(Buffer.from(json.encryptedLogs, 'hex')); const unencryptedLogs = TxL2Logs.fromBuffer(Buffer.from(json.unencryptedLogs, 'hex')); const proof = Buffer.from(json.proof, 'hex'); - const newContractPublicFunctions = json.newContractPublicFunctions + const newContractPublicFunctions = json.newContractPublicFunctions?.length ? json.newContractPublicFunctions.map((x: string) => EncodedContractFunction.fromBuffer(Buffer.from(x, 'hex'))) : []; - const enqueuedPublicFunctions = json.enqueuedPublicFunctions + const enqueuedPublicFunctions = json.enqueuedPublicFunctions?.length ? json.enqueuedPublicFunctions.map((x: string) => PublicCallRequest.fromBuffer(Buffer.from(x, 'hex'))) : []; return Tx.createTx( diff --git a/yarn-project/aztec-rpc/package.json b/yarn-project/aztec-rpc/package.json index 0b25e5b08005..5433c624add8 100644 --- a/yarn-project/aztec-rpc/package.json +++ b/yarn-project/aztec-rpc/package.json @@ -16,7 +16,8 @@ "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T prettier -w ./src", - "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests" + "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", + "start:http": "DEBUG='aztec:*' && node ./dest/aztec_rpc_http/aztec_rpc_http_server.js" }, "inherits": [ "../package.common.json" diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_client/aztec_rpc_client.ts b/yarn-project/aztec-rpc/src/aztec_rpc/aztec_rpc.ts similarity index 81% rename from yarn-project/aztec-rpc/src/aztec_rpc_client/aztec_rpc_client.ts rename to yarn-project/aztec-rpc/src/aztec_rpc/aztec_rpc.ts index bbcac17deea2..6ad0ffbf529a 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_client/aztec_rpc_client.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc/aztec_rpc.ts @@ -1,7 +1,15 @@ import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js'; import { ContractAbi } from '@aztec/foundation/abi'; import { Point } from '@aztec/foundation/fields'; -import { ContractDeploymentTx, PartialContractAddress, Tx, TxHash } from '@aztec/types'; +import { + ContractData, + ContractDeploymentTx, + ContractPublicData, + L2BlockL2Logs, + PartialContractAddress, + Tx, + TxHash, +} from '@aztec/types'; import { TxReceipt } from '../tx/index.js'; import { CurveType, SignerType } from '../crypto/types.js'; @@ -25,12 +33,12 @@ export interface DeployedContract { } /** - * Represents an Aztec RPC client implementation. + * Represents an Aztec RPC implementation. * Provides functionality for all the operations needed to interact with the Aztec network, * including account management, contract deployment, transaction creation, and execution, * as well as storage and view functions for smart contracts. */ -export interface AztecRPCClient { +export interface AztecRPC { createSmartAccount( privKey?: Buffer, curve?: CurveType, @@ -66,4 +74,8 @@ export interface AztecRPCClient { getTxReceipt(txHash: TxHash): Promise; getStorageAt(contract: AztecAddress, storageSlot: Fr): Promise; viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress): Promise; + getContractData(contractAddress: AztecAddress): Promise; + getContractInfo(contractAddress: AztecAddress): Promise; + getUnencryptedLogs(from: number, take: number): Promise; + getBlockNum(): Promise; } diff --git a/yarn-project/aztec-rpc/src/aztec_rpc/index.ts b/yarn-project/aztec-rpc/src/aztec_rpc/index.ts new file mode 100644 index 000000000000..1314dd7a93ca --- /dev/null +++ b/yarn-project/aztec-rpc/src/aztec_rpc/index.ts @@ -0,0 +1 @@ +export * from './aztec_rpc.js'; diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts new file mode 100644 index 000000000000..dd08f287f1cd --- /dev/null +++ b/yarn-project/aztec-rpc/src/aztec_rpc_http/aztec_rpc_http_server.ts @@ -0,0 +1,33 @@ +import { foundry } from 'viem/chains'; +import { Tx, TxHash, ContractDeploymentTx } from '@aztec/types'; +import { JsonRpcServer } from '@aztec/foundation/json-rpc'; +import { AztecAddress } from '@aztec/foundation/aztec-address'; +import { Fr, Point } from '@aztec/foundation/fields'; +import { AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node'; + +import { EthAddress, createAztecRPCServer } from '../index.js'; + +export const localAnvil = foundry; + +/** + * Wraps an instance of the Aztec RPC Server implementation to a JSON RPC HTTP interface. + * @returns A new instance of the HTTP server. + */ +export async function getHttpRpcServer(nodeConfig: AztecNodeConfig): Promise { + const aztecNode = await AztecNodeService.createAndSync(nodeConfig); + const aztecRpcServer = await createAztecRPCServer(aztecNode); + const generatedRpcServer = new JsonRpcServer( + aztecRpcServer, + { + AztecAddress, + TxHash, + EthAddress, + Point, + Fr, + }, + { Tx, ContractDeploymentTx }, + false, + ['start', 'stop'], + ); + return generatedRpcServer; +} diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_http/index.ts b/yarn-project/aztec-rpc/src/aztec_rpc_http/index.ts new file mode 100644 index 000000000000..939d0ac64c84 --- /dev/null +++ b/yarn-project/aztec-rpc/src/aztec_rpc_http/index.ts @@ -0,0 +1 @@ +export * from './aztec_rpc_http_server.js'; diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts index 5f46336c99fd..57cd331363f7 100644 --- a/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts +++ b/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts @@ -14,8 +14,11 @@ import { createDebugLogger } from '@aztec/foundation/log'; import { KeyStore, PublicKey } from '@aztec/key-store'; import { SchnorrAccountContractAbi } from '@aztec/noir-contracts/examples'; import { + ContractData, ContractDeploymentTx, + ContractPublicData, ExecutionRequest, + L2BlockL2Logs, PartialContractAddress, Tx, TxExecutionRequest, @@ -24,7 +27,7 @@ import { import { AccountContract } from '../account_impl/account_contract.js'; import { AccountImplementation } from '../account_impl/index.js'; import { AccountState } from '../account_state/account_state.js'; -import { AztecRPCClient, DeployedContract } from '../aztec_rpc_client/index.js'; +import { AztecRPC, DeployedContract } from '../aztec_rpc/index.js'; import { ContractDao, toContractDao } from '../contract_database/index.js'; import { ContractTree } from '../contract_tree/index.js'; import { Database, TxDao } from '../database/index.js'; @@ -37,7 +40,7 @@ import { CurveType, SignerType, createCurve, createSigner } from '../crypto/type /** * A remote Aztec RPC Client implementation. */ -export class AztecRPCServer implements AztecRPCClient { +export class AztecRPCServer implements AztecRPC { private synchroniser: Synchroniser; constructor( @@ -95,7 +98,7 @@ export class AztecRPCServer implements AztecRPCClient { const contractAddressSalt = Fr.random(); const args: any[] = []; - const { txRequest, contract, partialContractAddress } = await this.prepareDeploy( + const { txRequest, contract, partialContractAddress } = await this.#prepareDeploy( abi, args, portalContract, @@ -103,7 +106,7 @@ export class AztecRPCServer implements AztecRPCClient { pubKey, ); - const account = await this.initAccountState( + const account = await this.#initAccountState( pubKey, contract.address, partialContractAddress, @@ -144,7 +147,7 @@ export class AztecRPCServer implements AztecRPCClient { const accountCurve = await createCurve(curve); const accountSigner = await createSigner(signer); const pubKey = this.keyStore.addAccount(accountCurve, accountSigner, privKey); - await this.initAccountState(pubKey, address, partialContractAddress, accountCurve, accountSigner, abi); + await this.#initAccountState(pubKey, address, partialContractAddress, accountCurve, accountSigner, abi); return address; } @@ -179,7 +182,7 @@ export class AztecRPCServer implements AztecRPCClient { * @returns A Promise resolving to the Point instance representing the public key. */ public getAccountPublicKey(address: AztecAddress): Promise { - const account = this.ensureAccount(address); + const account = this.#ensureAccount(address); return Promise.resolve(account.getPublicKey()); } @@ -225,10 +228,10 @@ export class AztecRPCServer implements AztecRPCClient { contractAddressSalt = Fr.random(), from?: AztecAddress, ) { - const account = this.ensureAccountOrDefault(from); + const account = this.#ensureAccountOrDefault(from); const pubKey = account.getPublicKey(); - const { txRequest, contract, partialContractAddress } = await this.prepareDeploy( + const { txRequest, contract, partialContractAddress } = await this.#prepareDeploy( abi, args, portalContract, @@ -245,7 +248,7 @@ export class AztecRPCServer implements AztecRPCClient { return new ContractDeploymentTx(tx, partialContractAddress); } - private async prepareDeploy( + async #prepareDeploy( abi: ContractAbi, args: any[], portalContract: EthAddress, @@ -305,11 +308,11 @@ export class AztecRPCServer implements AztecRPCClient { * @returns A Tx ready to send to the p2p pool for execution. */ public async createTx(functionName: string, args: any[], to: AztecAddress, optionalFromAddress?: AztecAddress) { - const account = this.ensureAccountOrDefault(optionalFromAddress); + const account = this.#ensureAccountOrDefault(optionalFromAddress); const accountContract = await this.db.getContract(account.getAddress()); - const entrypoint: AccountImplementation = this.getAccountImplementation(account, accountContract); + const entrypoint: AccountImplementation = this.#getAccountImplementation(account, accountContract); - const executionRequest = await this.getExecutionRequest(account, functionName, args, to); + const executionRequest = await this.#getExecutionRequest(account, functionName, args, to); const txContext = TxContext.empty(await this.node.getChainId(), await this.node.getVersion()); const authedTxRequest = await entrypoint.createAuthenticatedTxRequest([executionRequest], txContext); @@ -356,7 +359,7 @@ export class AztecRPCServer implements AztecRPCClient { } // TODO: Store the kind of account in account state - private getAccountImplementation(accountState: AccountState, contract: ContractDao | undefined) { + #getAccountImplementation(accountState: AccountState, contract: ContractDao | undefined) { const address = accountState.getAddress(); const pubKey = accountState.getPublicKey(); const partialContractAddress = accountState.getPartialContractAddress(); @@ -395,8 +398,8 @@ export class AztecRPCServer implements AztecRPCClient { * @returns The result of the view function call, structured based on the function ABI. */ public async viewTx(functionName: string, args: any[], to: AztecAddress, from?: AztecAddress) { - const account = this.ensureAccountOrDefault(from); - const txRequest = await this.getExecutionRequest(account, functionName, args, to); + const account = this.#ensureAccountOrDefault(from); + const txRequest = await this.#getExecutionRequest(account, functionName, args, to); const executionResult = await account.simulateUnconstrained(txRequest); @@ -457,6 +460,76 @@ export class AztecRPCServer implements AztecRPCClient { }; } + /** + * Get latest L2 block number. + * @returns The latest block number. + */ + async getBlockNum(): Promise { + return await this.node.getBlockHeight(); + } + + /** + * Lookup the L2 contract data for this contract. + * Contains the ethereum portal address and bytecode. + * @param contractAddress - The contract data address. + * @returns The complete contract data including portal address & bytecode (if we didn't throw an error). + */ + public async getContractData(contractAddress: AztecAddress): Promise { + return await this.node.getContractData(contractAddress); + } + + /** + * Lookup the L2 contract info for this contract. + * Contains the ethereum portal address . + * @param contractAddress - The contract data address. + * @returns The contract's address & portal address. + */ + public async getContractInfo(contractAddress: AztecAddress): Promise { + return await this.node.getContractInfo(contractAddress); + } + + /** + * Gets L2 block unencrypted logs. + * @param from - Number of the L2 block to which corresponds the first unencrypted logs to be returned. + * @param take - The number of unencrypted logs to return. + * @returns The requested unencrypted logs. + */ + public async getUnencryptedLogs(from: number, take: number): Promise { + return await this.node.getUnencryptedLogs(from, take); + } + + async #getExecutionRequest( + account: AccountState, + functionName: string, + args: any[], + to: AztecAddress, + ): Promise { + const contract = await this.db.getContract(to); + if (!contract) { + throw new Error('Unknown contract.'); + } + + const functionDao = contract.functions.find(f => f.name === functionName); + if (!functionDao) { + throw new Error('Unknown function.'); + } + + const flatArgs = encodeArguments(functionDao, args); + + const functionData = new FunctionData( + functionDao.selector, + functionDao.functionType === FunctionType.SECRET, + false, + ); + + return { + args: flatArgs, + from: account.getAddress(), + functionData, + to, + }; + } + /** * Initializes the account state for a given address. * It retrieves the private key from the key store and adds the account to the synchroniser. @@ -469,7 +542,7 @@ export class AztecRPCServer implements AztecRPCClient { * @param signer - The signer to be used for transaction signing. * @param abi - Implementation of the account contract backing the account. */ - private async initAccountState( + async #initAccountState( pubKey: PublicKey, address: AztecAddress, partialContractAddress: PartialContractAddress, @@ -499,13 +572,13 @@ export class AztecRPCServer implements AztecRPCClient { * @param account - (Optional) Address of the account to ensure its existence. * @returns The ensured account instance. */ - private ensureAccountOrDefault(account?: AztecAddress) { + #ensureAccountOrDefault(account?: AztecAddress) { const address = account || this.synchroniser.getAccounts()[0]?.getAddress(); if (!address) { throw new Error('No accounts available in the key store.'); } - return this.ensureAccount(address); + return this.#ensureAccount(address); } /** @@ -516,7 +589,7 @@ export class AztecRPCServer implements AztecRPCClient { * @returns The account state associated with the given address. * @throws If the account is unknown or not found in the synchroniser. */ - private ensureAccount(account: AztecAddress) { + #ensureAccount(account: AztecAddress) { const accountState = this.synchroniser.getAccount(account); if (!accountState) { throw new Error(`Unknown account: ${account.toShortString()}.`); diff --git a/yarn-project/aztec-rpc/src/index.ts b/yarn-project/aztec-rpc/src/index.ts index 556d40ff2641..c334cd7e0b52 100644 --- a/yarn-project/aztec-rpc/src/index.ts +++ b/yarn-project/aztec-rpc/src/index.ts @@ -1,6 +1,7 @@ export * from './abi_coder/index.js'; -export * from './aztec_rpc_client/index.js'; +export * from './aztec_rpc/index.js'; export * from './aztec_rpc_server/index.js'; +export * from './aztec_rpc_http/index.js'; export * from './tx/index.js'; export * from './crypto/types.js'; diff --git a/yarn-project/aztec-sandbox/.eslintrc.cjs b/yarn-project/aztec-sandbox/.eslintrc.cjs new file mode 100644 index 000000000000..e659927475c0 --- /dev/null +++ b/yarn-project/aztec-sandbox/.eslintrc.cjs @@ -0,0 +1 @@ +module.exports = require('@aztec/foundation/eslint'); diff --git a/yarn-project/aztec-sandbox/Dockerfile b/yarn-project/aztec-sandbox/Dockerfile new file mode 100644 index 000000000000..93c54d5f39b6 --- /dev/null +++ b/yarn-project/aztec-sandbox/Dockerfile @@ -0,0 +1,18 @@ +FROM 278380418400.dkr.ecr.eu-west-2.amazonaws.com/yarn-project-base AS builder + +COPY . . + +WORKDIR /usr/src/yarn-project/aztec-sandbox +RUN yarn build +# && yarn formatting && yarn test + +# Prune dev dependencies. See comment in base image. +RUN yarn cache clean +RUN yarn workspaces focus --production > /dev/null + +FROM node:18-alpine +COPY --from=builder /usr/src/ /usr/src/ +WORKDIR /usr/src/yarn-project/aztec-sandbox +ENTRYPOINT ["yarn"] +CMD [ "start" ] +EXPOSE 8080 \ No newline at end of file diff --git a/yarn-project/aztec-sandbox/README.md b/yarn-project/aztec-sandbox/README.md new file mode 100644 index 000000000000..8b61e013fde2 --- /dev/null +++ b/yarn-project/aztec-sandbox/README.md @@ -0,0 +1 @@ +# aztec-sandbox diff --git a/yarn-project/aztec-sandbox/docker-compose-fork.yml b/yarn-project/aztec-sandbox/docker-compose-fork.yml new file mode 100644 index 000000000000..399ea2bb8b0c --- /dev/null +++ b/yarn-project/aztec-sandbox/docker-compose-fork.yml @@ -0,0 +1,21 @@ +version: '3' +services: + fork: + image: ghcr.io/foundry-rs/foundry:nightly-a44aa13cfc23491ba32aaedc093e9488c1a6db43 + entrypoint: 'anvil --fork-url https://mainnet.infura.io/v3/9928b52099854248b3a096be07a6b23c --host 0.0.0.0 --fork-block-number 17514288 --chain-id 31337' + ports: + - '8545:8545' + + rpc-server: + image: aztecprotocol/aztec-sandbox:master + ports: + - '8080:8080' + environment: + DEBUG: 'aztec:*' + ETHEREUM_HOST: http://fork:8545 + CHAIN_ID: 31337 + ARCHIVER_POLLING_INTERVAL: 500 + P2P_CHECK_INTERVAL: 500 + SEQ_TX_POLLING_INTERVAL: 500 + WS_CHECK_INTERVAL: 500 + SEARCH_START_BLOCK: 17514288 diff --git a/yarn-project/aztec-sandbox/docker-compose.yml b/yarn-project/aztec-sandbox/docker-compose.yml new file mode 100644 index 000000000000..20c717278e9a --- /dev/null +++ b/yarn-project/aztec-sandbox/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + fork: + image: ghcr.io/foundry-rs/foundry:nightly-a44aa13cfc23491ba32aaedc093e9488c1a6db43 + entrypoint: 'anvil -p 8545 --host 0.0.0.0 --chain-id 31337' + ports: + - '8545:8545' + + rpc-server: + image: aztecprotocol/aztec-sandbox:master + ports: + - '8080:8080' + environment: + DEBUG: 'aztec:*' + ETHEREUM_HOST: http://fork:8545 + CHAIN_ID: 31337 + ARCHIVER_POLLING_INTERVAL: 500 + P2P_CHECK_INTERVAL: 500 + SEQ_TX_POLLING_INTERVAL: 500 + WS_CHECK_INTERVAL: 500 diff --git a/yarn-project/aztec-sandbox/package.json b/yarn-project/aztec-sandbox/package.json new file mode 100644 index 000000000000..df0bba648e2f --- /dev/null +++ b/yarn-project/aztec-sandbox/package.json @@ -0,0 +1,59 @@ +{ + "name": "@aztec/aztec-sandbox", + "version": "0.0.0", + "type": "module", + "exports": "./dest/index.js", + "typedoc": { + "entryPoint": "./src/index.ts", + "displayName": "Sandbox", + "tsconfig": "./tsconfig.json" + }, + "scripts": { + "prepare": "node ../yarn-project-base/scripts/update_build_manifest.mjs package.json", + "build": "yarn clean && tsc -b", + "start": "DEBUG='aztec:*' node ./dest", + "clean": "rm -rf ./dest .tsbuildinfo", + "formatting": "run -T prettier --check ./src && run -T eslint ./src", + "formatting:fix": "run -T prettier -w ./src", + "prepare:check": "node ../yarn-project-base/scripts/update_build_manifest.mjs package.json --check", + "build:dev": "tsc -b --watch", + "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules $(yarn bin jest) --passWithNoTests", + "run:example:token": "DEBUG='aztec:*' node ./dest/examples/zk_contract_deployment.js", + "run:example:uniswap": "DEBUG='aztec:*' node ./dest/examples/uniswap_trade_on_l1_from_l2.js" + }, + "inherits": [ + "../package.common.json" + ], + "dependencies": { + "@aztec/aztec-node": "workspace:^", + "@aztec/aztec-rpc": "workspace:^", + "@aztec/aztec.js": "workspace:^", + "@aztec/ethereum": "workspace:^", + "@aztec/foundation": "workspace:^", + "abitype": "^0.8.11", + "koa-router": "^12.0.0", + "viem": "^0.3.14" + }, + "files": [ + "dest", + "src", + "!*.test.*" + ], + "types": "./dest/index.d.ts", + "devDependencies": { + "@jest/globals": "^29.5.0", + "@types/jest": "^29.5.0", + "jest": "^29.5.0", + "ts-jest": "^29.1.0", + "ts-node": "^10.9.1", + "typescript": "^5.0.4" + }, + "jest": { + "preset": "ts-jest/presets/default-esm", + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.js$": "$1" + }, + "testRegex": "./src/.*\\.test\\.ts$", + "rootDir": "./src" + } +} diff --git a/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts b/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts new file mode 100644 index 000000000000..83c7fa24738c --- /dev/null +++ b/yarn-project/aztec-sandbox/src/examples/uniswap_trade_on_l1_from_l2.ts @@ -0,0 +1,361 @@ +import { + AztecRPC, + Contract, + ContractDeployer, + TxStatus, + computeMessageSecretHash, + createAccounts, + createAztecRpcClient, + getL1ContractAddresses, + pointToPublicKey, + AztecAddress, + EthAddress, + Fr, +} from '@aztec/aztec.js'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { UniswapContractAbi } from '@aztec/noir-contracts/examples'; +import { createPublicClient, createWalletClient, getContract, http, parseEther } from 'viem'; +import { mnemonicToAccount } from 'viem/accounts'; +import { foundry } from 'viem/chains'; +import { delay, deployAndInitializeNonNativeL2TokenContracts, deployL1Contract } from './util.js'; +import { UniswapPortalAbi, UniswapPortalBytecode } from '@aztec/l1-artifacts'; + +/** + * Type representation of a Public key's coordinates. + */ +type PublicKey = { + /** Public key X coord */ + x: bigint; + /** Public key Y coord */ + y: bigint; +}; + +const logger = createDebugLogger('aztec:http-rpc-client'); + +// const { SEARCH_START_BLOCK } = process.env; + +export const MNEMONIC = 'test test test test test test test test test test test junk'; + +const INITIAL_BALANCE = 333n; +const wethAmountToBridge = parseEther('1'); + +const WETH9_ADDRESS = EthAddress.fromString('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'); +const DAI_ADDRESS = EthAddress.fromString('0x6B175474E89094C44Da98b954EedeAC495271d0F'); + +const EXPECTED_FORKED_BLOCK = 17514288; + +// if (parseInt(SEARCH_START_BLOCK || '') !== EXPECTED_FORKED_BLOCK) { +// throw Error(`You need to set env variable SEARCH_START_BLOCK to ${EXPECTED_FORKED_BLOCK}`); +// } + +// export const privateKey = Buffer.from('ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', 'hex'); + +const aztecRpcUrl = 'http://localhost:8080'; +const ethRpcUrl = 'http://localhost:8545'; + +const hdAccount = mnemonicToAccount(MNEMONIC); +const privateKey = Buffer.from(hdAccount.getHdKey().privateKey!); + +const walletClient = createWalletClient({ + account: hdAccount, + chain: foundry, + transport: http(ethRpcUrl), +}); +const publicClient = createPublicClient({ + chain: foundry, + transport: http(ethRpcUrl), +}); + +if (Number(await publicClient.getBlockNumber()) < EXPECTED_FORKED_BLOCK) { + throw new Error('This test must be run on a fork of mainnet with the expected fork block'); +} + +const ethAccount = EthAddress.fromString((await walletClient.getAddresses())[0]); + +const aztecRpcClient = createAztecRpcClient(aztecRpcUrl); + +/** + * Deploys all l1 / l2 contracts + * @param ownerPub - Public key of deployer. + */ +async function deployAllContracts(ownerPub: PublicKey) { + const l1ContractsAddresses = await getL1ContractAddresses(aztecRpcUrl); + logger('Deploying DAI Portal, initializing and deploying l2 contract...'); + const daiContracts = await deployAndInitializeNonNativeL2TokenContracts( + aztecRpcClient, + walletClient, + publicClient, + l1ContractsAddresses!.registry, + INITIAL_BALANCE, + ownerPub, + DAI_ADDRESS, + ); + const daiL2Contract = daiContracts.l2Contract; + const daiContract = daiContracts.underlyingERC20; + const daiTokenPortalAddress = daiContracts.tokenPortalAddress; + + logger('Deploying WETH Portal, initializing and deploying l2 contract...'); + const wethContracts = await deployAndInitializeNonNativeL2TokenContracts( + aztecRpcClient, + walletClient, + publicClient, + l1ContractsAddresses!.registry, + INITIAL_BALANCE, + ownerPub, + WETH9_ADDRESS, + ); + const wethL2Contract = wethContracts.l2Contract; + const wethContract = wethContracts.underlyingERC20; + const wethTokenPortal = wethContracts.tokenPortal; + const wethTokenPortalAddress = wethContracts.tokenPortalAddress; + + logger('Deploy Uniswap portal on L1 and L2...'); + const uniswapPortalAddress = await deployL1Contract( + walletClient, + publicClient, + UniswapPortalAbi, + UniswapPortalBytecode, + ); + const uniswapPortal = getContract({ + address: uniswapPortalAddress.toString(), + abi: UniswapPortalAbi, + walletClient, + publicClient, + }); + + // deploy l2 uniswap contract and attach to portal + const deployer = new ContractDeployer(UniswapContractAbi, aztecRpcClient); + const tx = deployer.deploy().send({ portalContract: uniswapPortalAddress }); + await tx.isMined(0, 0.5); + const receipt = await tx.getReceipt(); + const uniswapL2Contract = new Contract(receipt.contractAddress!, UniswapContractAbi, aztecRpcClient); + await uniswapL2Contract.attach(uniswapPortalAddress); + + await uniswapPortal.write.initialize( + [l1ContractsAddresses!.registry.toString(), uniswapL2Contract.address.toString()], + {} as any, + ); + + return { + daiL2Contract, + daiContract, + daiTokenPortalAddress, + wethL2Contract, + wethContract, + wethTokenPortal, + wethTokenPortalAddress, + uniswapL2Contract, + uniswapPortal, + uniswapPortalAddress, + }; +} + +const getL2BalanceOf = async (aztecRpcClient: AztecRPC, owner: AztecAddress, l2Contract: any) => { + const ownerPublicKey = await aztecRpcClient.getAccountPublicKey(owner); + const [balance] = await l2Contract.methods.getBalance(pointToPublicKey(ownerPublicKey)).view({ from: owner }); + return balance; +}; + +const logExpectedBalanceOnL2 = async ( + aztecRpcClient: AztecRPC, + owner: AztecAddress, + expectedBalance: bigint, + l2Contract: any, +) => { + const balance = await getL2BalanceOf(aztecRpcClient, owner, l2Contract); + logger(`Account ${owner} balance: ${balance}. Expected to be: ${expectedBalance}`); +}; + +const transferWethOnL2 = async ( + aztecRpcClient: AztecRPC, + wethL2Contract: Contract, + ownerAddress: AztecAddress, + receiver: AztecAddress, + transferAmount: bigint, +) => { + const transferTx = wethL2Contract.methods + .transfer( + transferAmount, + pointToPublicKey(await aztecRpcClient.getAccountPublicKey(ownerAddress)), + pointToPublicKey(await aztecRpcClient.getAccountPublicKey(receiver)), + ) + .send({ from: ownerAddress }); + await transferTx.isMined(0, 0.5); + const transferReceipt = await transferTx.getReceipt(); + // expect(transferReceipt.status).toBe(TxStatus.MINED); + logger(`WETH to L2 Transfer Receipt status: ${transferReceipt.status} should be ${TxStatus.MINED}`); +}; + +/** + * main fn + */ +async function main() { + logger('Running L1/L2 messaging test on HTTP interface.'); + + const accounts = await createAccounts(aztecRpcClient, privateKey!, 2); + const [[owner], [receiver]] = accounts; + const ownerPub = pointToPublicKey(await aztecRpcClient.getAccountPublicKey(owner)); + + const result = await deployAllContracts(ownerPub); + const { + daiL2Contract, + daiContract, + daiTokenPortalAddress, + wethL2Contract, + wethContract, + wethTokenPortal, + wethTokenPortalAddress, + uniswapL2Contract, + uniswapPortal, + uniswapPortalAddress, + } = result; + + // Give me some WETH so I can deposit to L2 and do the swap... + logger('Getting some weth'); + await walletClient.sendTransaction({ to: WETH9_ADDRESS.toString(), value: parseEther('1') }); + + const meBeforeBalance = await wethContract.read.balanceOf([ethAccount.toString()]); + // 1. Approve weth to be bridged + await wethContract.write.approve([wethTokenPortalAddress.toString(), wethAmountToBridge], {} as any); + + // 2. Deposit weth into the portal and move to L2 + // generate secret + const secret = Fr.random(); + const secretHash = await computeMessageSecretHash(secret); + const secretString = `0x${secretHash.toBuffer().toString('hex')}` as `0x${string}`; + const deadline = 2 ** 32 - 1; // max uint32 - 1 + logger('Sending messages to L1 portal'); + const args = [owner.toString(), wethAmountToBridge, deadline, secretString, ethAccount.toString()] as const; + const { result: messageKeyHex } = await wethTokenPortal.simulate.depositToAztec(args, { + account: ethAccount.toString(), + } as any); + await wethTokenPortal.write.depositToAztec(args, {} as any); + // expect(await wethContract.read.balanceOf([ethAccount.toString()])).toBe(meBeforeBalance - wethAmountToBridge); + + const currentBalance = await wethContract.read.balanceOf([ethAccount.toString()]); + logger(`Current Balance: ${currentBalance}. Should be: ${meBeforeBalance - wethAmountToBridge}`); + const messageKey = Fr.fromString(messageKeyHex); + + // Wait for the archiver to process the message + await delay(5000); + // send a transfer tx to force through rollup with the message included + const transferAmount = 1n; + await transferWethOnL2(aztecRpcClient, wethL2Contract, owner, receiver, transferAmount); + + // 3. Claim WETH on L2 + logger('Minting weth on L2'); + // Call the mint tokens function on the noir contract + const consumptionTx = wethL2Contract.methods + .mint(wethAmountToBridge, ownerPub, owner, messageKey, secret, ethAccount.toField()) + .send({ from: owner }); + await consumptionTx.isMined(0, 0.5); + const consumptionReceipt = await consumptionTx.getReceipt(); + // expect(consumptionReceipt.status).toBe(TxStatus.MINED); + logger(`Consumption Receipt status: ${consumptionReceipt.status} should be ${TxStatus.MINED}`); + // await expectBalanceOnL2(ownerAddress, wethAmountToBridge + initialBalance - transferAmount, wethL2Contract); + + // Store balances + const wethBalanceBeforeSwap = await getL2BalanceOf(aztecRpcClient, owner, wethL2Contract); + const daiBalanceBeforeSwap = await getL2BalanceOf(aztecRpcClient, owner, daiL2Contract); + + // 4. Send L2 to L1 message to withdraw funds and another message to swap assets. + logger('Send L2 tx to withdraw WETH to uniswap portal and send message to swap assets on L1'); + // recipient is the uniswap portal + const selector = Fr.fromBuffer(wethL2Contract.methods.withdraw.selector); + const minimumOutputAmount = 0n; + + const withdrawTx = uniswapL2Contract.methods + .swap( + selector, + wethL2Contract.address.toField(), + wethTokenPortalAddress.toField(), + wethAmountToBridge, + new Fr(3000), + daiL2Contract.address.toField(), + daiTokenPortalAddress.toField(), + new Fr(minimumOutputAmount), + ownerPub, + owner, + secretHash, + new Fr(2 ** 32 - 1), + ethAccount.toField(), + uniswapPortalAddress, + ethAccount.toField(), + ) + .send({ from: owner }); + await withdrawTx.isMined(0, 0.5); + const withdrawReceipt = await withdrawTx.getReceipt(); + // expect(withdrawReceipt.status).toBe(TxStatus.MINED); + logger(`Withdraw receipt status: ${withdrawReceipt.status} should be ${TxStatus.MINED}`); + + // check weth balance of owner on L2 (we first briedged `wethAmountToBridge` into L2 and now withdrew it!) + await logExpectedBalanceOnL2(aztecRpcClient, owner, INITIAL_BALANCE - transferAmount, wethL2Contract); + + // 5. Consume L2 to L1 message by calling uniswapPortal.swap() + logger('Execute withdraw and swap on the uniswapPortal!'); + const daiBalanceOfPortalBefore = await daiContract.read.balanceOf([daiTokenPortalAddress.toString()]); + logger(`DAI balance of portal: ${daiBalanceOfPortalBefore}`); + const swapArgs = [ + wethTokenPortalAddress.toString(), + wethAmountToBridge, + 3000, + daiTokenPortalAddress.toString(), + minimumOutputAmount, + owner.toString(), + secretString, + deadline, + ethAccount.toString(), + true, + ] as const; + const { result: depositDaiMessageKeyHex } = await uniswapPortal.simulate.swap(swapArgs, { + account: ethAccount.toString(), + } as any); + // this should also insert a message into the inbox. + await uniswapPortal.write.swap(swapArgs, {} as any); + const depositDaiMessageKey = Fr.fromString(depositDaiMessageKeyHex); + // weth was swapped to dai and send to portal + const daiBalanceOfPortalAfter = await daiContract.read.balanceOf([daiTokenPortalAddress.toString()]); + // expect(daiBalanceOfPortalAfter).toBeGreaterThan(daiBalanceOfPortalBefore); + logger( + `DAI balance in Portal: ${daiBalanceOfPortalAfter} should be bigger than ${daiBalanceOfPortalBefore}. ${ + daiBalanceOfPortalAfter > daiBalanceOfPortalBefore + }`, + ); + const daiAmountToBridge = daiBalanceOfPortalAfter - daiBalanceOfPortalBefore; + + // Wait for the archiver to process the message + await delay(5000); + // send a transfer tx to force through rollup with the message included + await transferWethOnL2(aztecRpcClient, wethL2Contract, owner, receiver, transferAmount); + + // 6. claim dai on L2 + logger('Consuming messages to mint dai on L2'); + // Call the mint tokens function on the noir contract + const daiMintTx = daiL2Contract.methods + .mint(daiAmountToBridge, ownerPub, owner, depositDaiMessageKey, secret, ethAccount.toField()) + .send({ from: owner }); + await daiMintTx.isMined(0, 0.5); + const daiMintTxReceipt = await daiMintTx.getReceipt(); + // expect(daiMintTxReceipt.status).toBe(TxStatus.MINED); + logger(`DAI mint TX status: ${daiMintTxReceipt.status} should be ${TxStatus.MINED}`); + await logExpectedBalanceOnL2(aztecRpcClient, owner, INITIAL_BALANCE + BigInt(daiAmountToBridge), daiL2Contract); + + const wethBalanceAfterSwap = await getL2BalanceOf(aztecRpcClient, owner, wethL2Contract); + const daiBalanceAfterSwap = await getL2BalanceOf(aztecRpcClient, owner, daiL2Contract); + + logger('WETH balance before swap: ', wethBalanceBeforeSwap.toString()); + logger('DAI balance before swap : ', daiBalanceBeforeSwap.toString()); + logger('***** 🧚‍♀️ SWAP L2 assets on L1 Uniswap 🧚‍♀️ *****'); + logger('WETH balance after swap : ', wethBalanceAfterSwap.toString()); + logger('DAI balance after swap : ', daiBalanceAfterSwap.toString()); +} + +main() + .then(() => { + logger('Finished running successfuly.'); + process.exit(0); + }) + .catch(err => { + logger('Error in main fn: ', err); + process.exit(1); + }); diff --git a/yarn-project/aztec-sandbox/src/examples/util.ts b/yarn-project/aztec-sandbox/src/examples/util.ts new file mode 100644 index 000000000000..f6505d85320c --- /dev/null +++ b/yarn-project/aztec-sandbox/src/examples/util.ts @@ -0,0 +1,103 @@ +import { Account, Chain, Hex, HttpTransport, PublicClient, WalletClient, getContract } from 'viem'; +import type { Abi, Narrow } from 'abitype'; +import { PortalERC20Abi, PortalERC20Bytecode, TokenPortalAbi, TokenPortalBytecode } from '@aztec/l1-artifacts'; +import { NonNativeTokenContractAbi } from '@aztec/noir-contracts/examples'; +import { Contract, ContractDeployer, EthAddress, AztecRPC } from '@aztec/aztec.js'; + +/** + * Deploy L1 token and portal, initialize portal, deploy a non native l2 token contract and attach is to the portal. + * @param aztecRpcServer - the aztec rpc server instance + * @param walletClient - A viem WalletClient. + * @param publicClient - A viem PublicClient. + * @param rollupRegistryAddress - address of rollup registry to pass to initialize the token portal + * @param initialBalance - initial balance of the owner of the L2 contract + * @param owner - owner of the L2 contract + * @param underlyingERC20Address - address of the underlying ERC20 contract to use (if noone supplied, it deploys one) + * @returns l2 contract instance, token portal instance, token portal address and the underlying ERC20 instance + */ +export async function deployAndInitializeNonNativeL2TokenContracts( + aztecRpcServer: AztecRPC, + walletClient: WalletClient, + publicClient: PublicClient, + rollupRegistryAddress: EthAddress, + initialBalance = 0n, + owner = { x: 0n, y: 0n }, + underlyingERC20Address?: EthAddress, +) { + // deploy underlying contract if no address supplied + if (!underlyingERC20Address) { + underlyingERC20Address = await deployL1Contract(walletClient, publicClient, PortalERC20Abi, PortalERC20Bytecode); + } + const underlyingERC20: any = getContract({ + address: underlyingERC20Address.toString(), + abi: PortalERC20Abi, + walletClient, + publicClient, + }); + + // deploy the token portal + const tokenPortalAddress = await deployL1Contract(walletClient, publicClient, TokenPortalAbi, TokenPortalBytecode); + const tokenPortal: any = getContract({ + address: tokenPortalAddress.toString(), + abi: TokenPortalAbi, + walletClient, + publicClient, + }); + + // deploy l2 contract and attach to portal + const deployer = new ContractDeployer(NonNativeTokenContractAbi, aztecRpcServer); + const tx = deployer.deploy(initialBalance, owner).send({ + portalContract: tokenPortalAddress, + }); + await tx.isMined(0, 0.1); + const receipt = await tx.getReceipt(); + const l2Contract = new Contract(receipt.contractAddress!, NonNativeTokenContractAbi, aztecRpcServer); + await l2Contract.attach(tokenPortalAddress); + const l2TokenAddress = l2Contract.address.toString() as `0x${string}`; + + // initialize portal + await tokenPortal.write.initialize( + [rollupRegistryAddress.toString(), underlyingERC20Address.toString(), l2TokenAddress], + {} as any, + ); + return { l2Contract, tokenPortalAddress, tokenPortal, underlyingERC20 }; +} + +/** + * Helper function to deploy ETH contracts. + * @param walletClient - A viem WalletClient. + * @param publicClient - A viem PublicClient. + * @param abi - The ETH contract's ABI (as abitype's Abi). + * @param bytecode - The ETH contract's bytecode. + * @param args - Constructor arguments for the contract. + * @returns The ETH address the contract was deployed to. + */ +export async function deployL1Contract( + walletClient: WalletClient, + publicClient: PublicClient, + abi: Narrow, + bytecode: Hex, + args: readonly unknown[] = [], +): Promise { + const hash = await walletClient.deployContract({ + abi, + bytecode, + args, + }); + + const receipt = await publicClient.waitForTransactionReceipt({ hash }); + const contractAddress = receipt.contractAddress; + if (!contractAddress) { + throw new Error(`No contract address found in receipt: ${JSON.stringify(receipt)}`); + } + + return EthAddress.fromString(receipt.contractAddress!); +} + +/** + * Sleep for a given number of milliseconds. + * @param ms - the number of milliseconds to sleep for + */ +export function delay(ms: number): Promise { + return new Promise(resolve => setTimeout(resolve, ms)); +} diff --git a/yarn-project/aztec-sandbox/src/examples/zk_contract_deployment.ts b/yarn-project/aztec-sandbox/src/examples/zk_contract_deployment.ts new file mode 100644 index 000000000000..f39cb27bb00e --- /dev/null +++ b/yarn-project/aztec-sandbox/src/examples/zk_contract_deployment.ts @@ -0,0 +1,56 @@ +import { Contract, ContractDeployer, createAccounts, createAztecRpcClient, pointToPublicKey } from '@aztec/aztec.js'; +import { Point } from '@aztec/circuits.js'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { ZkTokenContractAbi } from '@aztec/noir-contracts/examples'; + +const logger = createDebugLogger('aztec:http-rpc-client'); + +export const privateKey = Buffer.from('ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', 'hex'); + +const url = 'http://localhost:8080'; + +const aztecRpcClient = createAztecRpcClient(url); + +const INITIAL_BALANCE = 333n; + +/** + * Deploys the ZK Token contract. + * @param pubKeyPoint - The public key Point that the initial balance will belong to. + * @returns An Aztec Contract object with the zk token's ABI. + */ +async function deployZKContract(pubKeyPoint: Point) { + logger('Deploying L2 contract...'); + const deployer = new ContractDeployer(ZkTokenContractAbi, aztecRpcClient); + const tx = deployer.deploy(INITIAL_BALANCE, pointToPublicKey(pubKeyPoint)).send(); + const receipt = await tx.getReceipt(); + const contract = new Contract(receipt.contractAddress!, ZkTokenContractAbi, aztecRpcClient); + await tx.isMined(); + await tx.getReceipt(); + logger('L2 contract deployed'); + return contract; +} + +/** + * Main function. + */ +async function main() { + logger('Running ZK contract test on HTTP interface.'); + + const [address, pubKeyPoint] = (await createAccounts(aztecRpcClient, privateKey, 1))[0]; + logger(`Created account ${address.toString()} with public key ${pubKeyPoint.toString()}`); + const zkContract = await deployZKContract(pubKeyPoint); + const accounts = await aztecRpcClient.getAccounts(); + logger(`Created ${accounts.length} accounts`); + const [balance1] = await zkContract.methods.getBalance(pointToPublicKey(pubKeyPoint)).view({ from: address }); + logger(`Initial owner balance: ${balance1}`); +} + +main() + .then(() => { + logger('Finished running successfuly.'); + process.exit(0); + }) + .catch(err => { + logger('Error in main fn: ', err); + process.exit(1); + }); diff --git a/yarn-project/aztec-sandbox/src/index.ts b/yarn-project/aztec-sandbox/src/index.ts new file mode 100644 index 000000000000..c37aba117bdb --- /dev/null +++ b/yarn-project/aztec-sandbox/src/index.ts @@ -0,0 +1,83 @@ +import http from 'http'; +import { foundry } from 'viem/chains'; +import { http as httpViemTransport, createPublicClient, HDAccount } from 'viem'; + +import { mnemonicToAccount } from 'viem/accounts'; +import { getHttpRpcServer } from '@aztec/aztec-rpc'; +import { createDebugLogger } from '@aztec/foundation/log'; +import { retryUntil } from '@aztec/foundation/retry'; +import { AztecNodeConfig, getConfigEnvVars } from '@aztec/aztec-node'; +import { deployL1Contracts } from '@aztec/ethereum'; + +import { createApiRouter } from './routes.js'; + +const { SERVER_PORT = 8080, MNEMONIC = 'test test test test test test test test test test test junk' } = process.env; + +const logger = createDebugLogger('aztec:sandbox'); + +export const localAnvil = foundry; + +/** + * Helper function that waits for the Ethereum RPC server to respond before deploying L1 contracts. + */ +async function waitThenDeploy(rpcUrl: string, hdAccount: HDAccount) { + // wait for ETH RPC to respond to a request. + const publicClient = createPublicClient({ + chain: foundry, + transport: httpViemTransport(rpcUrl), + }); + const chainID = await retryUntil( + async () => { + let chainId = 0; + try { + chainId = await publicClient.getChainId(); + } catch (err) { + logger(`Failed to get Chain ID. Retrying...`); + } + return chainId; + }, + 'isEthRpcReady', + 30, + 1, + ); + + if (!chainID) { + throw Error(`ETH RPC server unresponsive at ${rpcUrl}.`); + } + + // Deploy L1 contracts + const deployedL1Contracts = await deployL1Contracts(rpcUrl, hdAccount, localAnvil, logger); + return deployedL1Contracts; +} + +/** + * Create and start a new Aztec RCP HTTP Server + */ +async function main() { + const aztecNodeConfig: AztecNodeConfig = getConfigEnvVars(); + const hdAccount = mnemonicToAccount(MNEMONIC); + const privKey = hdAccount.getHdKey().privateKey; + + const deployedL1Contracts = await waitThenDeploy(aztecNodeConfig.rpcUrl, hdAccount); + aztecNodeConfig.publisherPrivateKey = Buffer.from(privKey!); + aztecNodeConfig.rollupContract = deployedL1Contracts.rollupAddress; + aztecNodeConfig.contractDeploymentEmitterContract = deployedL1Contracts.contractDeploymentEmitterAddress; + aztecNodeConfig.inboxContract = deployedL1Contracts.inboxAddress; + + const rpcServer = await getHttpRpcServer(aztecNodeConfig); + + const app = rpcServer.getApp(); + const apiRouter = createApiRouter(deployedL1Contracts); + app.use(apiRouter.routes()); + app.use(apiRouter.allowedMethods()); + + const httpServer = http.createServer(app.callback()); + httpServer.listen(SERVER_PORT); +} + +main() + .then(() => logger(`Aztec JSON RPC listening on port ${SERVER_PORT}`)) + .catch(err => { + logger(err); + process.exit(1); + }); diff --git a/yarn-project/aztec-sandbox/src/routes.ts b/yarn-project/aztec-sandbox/src/routes.ts new file mode 100644 index 000000000000..c037a1547dd5 --- /dev/null +++ b/yarn-project/aztec-sandbox/src/routes.ts @@ -0,0 +1,28 @@ +import Koa from 'koa'; +import Router from 'koa-router'; +import { DeployL1Contracts } from '@aztec/ethereum'; + +/** + * Creates a router for helper API endpoints of the Aztec RPC Server. + * @param aztecNode - An instance of the aztec node. + * @param config - The aztec node's configuration variables. + */ +export function createApiRouter(l1Contracts: DeployL1Contracts) { + const router = new Router({ prefix: '/api' }); + router.get('/status', (ctx: Koa.Context) => { + // TODO: add `status` to Aztec node. + ctx.status = 200; + }); + + router.get('/l1-contract-addresses', (ctx: Koa.Context) => { + ctx.body = { + rollup: l1Contracts.rollupAddress.toString(), + contractDeploymentEmitter: l1Contracts.contractDeploymentEmitterAddress.toString(), + inbox: l1Contracts.inboxAddress.toString(), + registry: l1Contracts.registryAddress.toString(), + }; + ctx.status = 200; + }); + + return router; +} diff --git a/yarn-project/aztec-sandbox/tsconfig.json b/yarn-project/aztec-sandbox/tsconfig.json new file mode 100644 index 000000000000..e92265f2b6d8 --- /dev/null +++ b/yarn-project/aztec-sandbox/tsconfig.json @@ -0,0 +1,26 @@ +{ + "extends": "..", + "compilerOptions": { + "outDir": "dest", + "rootDir": "src", + "tsBuildInfoFile": ".tsbuildinfo" + }, + "references": [ + { + "path": "../aztec-node" + }, + { + "path": "../aztec-rpc" + }, + { + "path": "../aztec.js" + }, + { + "path": "../ethereum" + }, + { + "path": "../foundation" + } + ], + "include": ["src"] +} diff --git a/yarn-project/aztec.js/src/aztec_rpc_client/aztec_rpc_client.ts b/yarn-project/aztec.js/src/aztec_rpc_client/aztec_rpc_client.ts new file mode 100644 index 000000000000..96dd4ef03644 --- /dev/null +++ b/yarn-project/aztec.js/src/aztec_rpc_client/aztec_rpc_client.ts @@ -0,0 +1,56 @@ +import { AztecAddress, AztecRPC, AztecRPCServer, EthAddress, Fr, Point, Tx, TxHash } from '@aztec/aztec-rpc'; +import { createJsonRpcClient } from '@aztec/foundation/json-rpc'; +import { ContractDeploymentTx } from '@aztec/types'; + +/** + * A dictionary of the Aztec-deployed L1 contracts. + */ +export type L1ContractAddresses = { + /** + * Address fo the main Aztec rollup contract. + */ + rollup: EthAddress; + /** + * Address of the contract that emits events on public contract deployment. + */ + contractDeploymentEmitter: EthAddress; + /** + * Address of the L1/L2 messaging inbox contract. + */ + inbox: EthAddress; + + /** + * Registry Address. + */ + registry: EthAddress; +}; + +/** + * string dictionary of aztec contract addresses that we receive over http. + */ +type L1ContractAddressesResp = { + [K in keyof L1ContractAddresses]: string; +}; + +export const createAztecRpcClient = (url: string): AztecRPC => + createJsonRpcClient( + url, + { + AztecAddress, + TxHash, + EthAddress, + Point, + Fr, + }, + { Tx, ContractDeploymentTx }, + false, + ); + +export const getL1ContractAddresses = async (url: string): Promise => { + const reqUrl = new URL(`${url}/api/l1-contract-addresses`); + const response = (await (await fetch(reqUrl.toString())).json()) as unknown as L1ContractAddressesResp; + const result = Object.fromEntries( + Object.entries(response).map(([key, value]) => [key, EthAddress.fromString(value)]), + ); + return result as L1ContractAddresses; +}; diff --git a/yarn-project/aztec-rpc/src/aztec_rpc_client/index.ts b/yarn-project/aztec.js/src/aztec_rpc_client/index.ts similarity index 100% rename from yarn-project/aztec-rpc/src/aztec_rpc_client/index.ts rename to yarn-project/aztec.js/src/aztec_rpc_client/index.ts diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index e2602deb65b9..7e5ed828720c 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -1,4 +1,4 @@ -import { AztecAddress, AztecRPCClient, DeployedContract, EthAddress, Tx, TxHash, TxReceipt } from '@aztec/aztec-rpc'; +import { AztecAddress, AztecRPC, DeployedContract, EthAddress, Tx, TxHash, TxReceipt } from '@aztec/aztec-rpc'; import { mock } from 'jest-mock-extended'; import { ABIParameterVisibility, ContractAbi, FunctionType } from '@aztec/foundation/abi'; @@ -7,7 +7,7 @@ import { Contract } from './contract.js'; import { ContractDeploymentTx } from '@aztec/types'; describe('Contract Class', () => { - let arc: ReturnType>; + let arc: ReturnType>; const contractAddress = AztecAddress.random(); const account = AztecAddress.random(); @@ -86,7 +86,7 @@ describe('Contract Class', () => { }); beforeEach(() => { - arc = mock(); + arc = mock(); arc.createDeploymentTx.mockResolvedValue(mockDeploymentTx); arc.createTx.mockResolvedValue(mockTx); arc.sendTx.mockResolvedValue(mockTxHash); diff --git a/yarn-project/aztec.js/src/contract/contract.ts b/yarn-project/aztec.js/src/contract/contract.ts index 6b2416260349..1513144fdfda 100644 --- a/yarn-project/aztec.js/src/contract/contract.ts +++ b/yarn-project/aztec.js/src/contract/contract.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient, DeployedContract, generateFunctionSelector } from '@aztec/aztec-rpc'; +import { AztecRPC, DeployedContract, generateFunctionSelector } from '@aztec/aztec-rpc'; import { ContractAbi, FunctionAbi } from '@aztec/foundation/abi'; import { ContractFunctionInteraction } from './contract_function_interaction.js'; import { AztecAddress } from '@aztec/foundation/aztec-address'; @@ -37,7 +37,7 @@ export class Contract { * The Application Binary Interface for the contract. */ public readonly abi: ContractAbi, - private arc: AztecRPCClient, + private arc: AztecRPC, ) { abi.functions.forEach((f: FunctionAbi) => { const interactionFunction = (...args: any[]) => { diff --git a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts index b7dbb072ea39..51b7e94931f4 100644 --- a/yarn-project/aztec.js/src/contract/contract_function_interaction.ts +++ b/yarn-project/aztec.js/src/contract/contract_function_interaction.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient, Tx, TxHash } from '@aztec/aztec-rpc'; +import { AztecRPC, Tx, TxHash } from '@aztec/aztec-rpc'; import { AztecAddress, Fr } from '@aztec/circuits.js'; import { FunctionType } from '@aztec/foundation/abi'; import { SentTx } from './sent_tx.js'; @@ -37,7 +37,7 @@ export class ContractFunctionInteraction { protected tx?: Tx; constructor( - protected arc: AztecRPCClient, + protected arc: AztecRPC, protected contractAddress: AztecAddress, protected functionName: string, protected args: any[], diff --git a/yarn-project/aztec.js/src/contract/sent_tx.ts b/yarn-project/aztec.js/src/contract/sent_tx.ts index f7ca73186ace..298cf8224c6c 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient, TxReceipt, TxHash, TxStatus } from '@aztec/aztec-rpc'; +import { AztecRPC, TxReceipt, TxHash, TxStatus } from '@aztec/aztec-rpc'; import { retryUntil } from '@aztec/foundation/retry'; /** @@ -6,7 +6,7 @@ import { retryUntil } from '@aztec/foundation/retry'; * its hash, receipt, and mining status. */ export class SentTx { - constructor(private arc: AztecRPCClient, private txHashPromise: Promise) {} + constructor(private arc: AztecRPC, private txHashPromise: Promise) {} /** * Retrieves the transaction hash of the SentTx instance. diff --git a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts index 686770556381..08110e3e23e1 100644 --- a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts +++ b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.test.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient, Tx, TxHash, TxReceipt } from '@aztec/aztec-rpc'; +import { AztecRPC, Tx, TxHash, TxReceipt } from '@aztec/aztec-rpc'; import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js'; import { ContractAbi, FunctionType } from '@aztec/foundation/abi'; import { randomBytes } from 'crypto'; @@ -7,7 +7,7 @@ import { ContractDeployer } from './contract_deployer.js'; import { ContractDeploymentTx } from '@aztec/types'; describe('Contract Deployer', () => { - let arc: ReturnType>; + let arc: ReturnType>; const abi: ContractAbi = { name: 'MyContract', @@ -33,7 +33,7 @@ describe('Contract Deployer', () => { const mockTxReceipt = { type: 'TxReceipt' } as any as TxReceipt; beforeEach(() => { - arc = mock(); + arc = mock(); arc.createDeploymentTx.mockResolvedValue(contractDeploymentTx); arc.createTx.mockResolvedValue(mockTx); arc.sendTx.mockResolvedValue(mockTxHash); diff --git a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts index 38a111a8b810..8b64e7aafff8 100644 --- a/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts +++ b/yarn-project/aztec.js/src/contract_deployer/contract_deployer.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient } from '@aztec/aztec-rpc'; +import { AztecRPC } from '@aztec/aztec-rpc'; import { ContractAbi } from '@aztec/foundation/abi'; import { DeployMethod } from './deploy_method.js'; @@ -6,7 +6,7 @@ import { DeployMethod } from './deploy_method.js'; * A class for deploying contract. */ export class ContractDeployer { - constructor(private abi: ContractAbi, private arc: AztecRPCClient) {} + constructor(private abi: ContractAbi, private arc: AztecRPC) {} /** * Deploy a contract using the provided ABI and constructor arguments. diff --git a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts index e42b678dfd06..abb7d3945fea 100644 --- a/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts +++ b/yarn-project/aztec.js/src/contract_deployer/deploy_method.ts @@ -1,4 +1,4 @@ -import { AztecRPCClient } from '@aztec/aztec-rpc'; +import { AztecRPC } from '@aztec/aztec-rpc'; import { ContractAbi, FunctionType } from '@aztec/foundation/abi'; import { ContractFunctionInteraction, SendMethodOptions } from '../contract/index.js'; import { EthAddress } from '@aztec/foundation/eth-address'; @@ -31,7 +31,7 @@ export class DeployMethod extends ContractFunctionInteraction { */ public partialContractAddress?: PartialContractAddress = undefined; - constructor(arc: AztecRPCClient, private abi: ContractAbi, args: any[] = []) { + constructor(arc: AztecRPC, private abi: ContractAbi, args: any[] = []) { const constructorAbi = abi.functions.find(f => f.name === 'constructor'); if (!constructorAbi) { throw new Error('Cannot find constructor in the ABI.'); diff --git a/yarn-project/aztec.js/src/index.ts b/yarn-project/aztec.js/src/index.ts index 3d4b94f9f2d6..8fc2ac3df68c 100644 --- a/yarn-project/aztec.js/src/index.ts +++ b/yarn-project/aztec.js/src/index.ts @@ -1,6 +1,7 @@ export * from './contract/index.js'; export * from './contract_deployer/index.js'; export * from './utils/index.js'; +export * from './aztec_rpc_client/index.js'; // TODO - only export necessary stuffs export * from '@aztec/aztec-rpc'; diff --git a/yarn-project/aztec.js/src/utils/account.ts b/yarn-project/aztec.js/src/utils/account.ts new file mode 100644 index 000000000000..f4e1385ecd49 --- /dev/null +++ b/yarn-project/aztec.js/src/utils/account.ts @@ -0,0 +1,31 @@ +import { AztecRPC } from '@aztec/aztec-rpc'; +import { AztecAddress, Point } from '@aztec/circuits.js'; +import { SentTx } from '../index.js'; +import { createDebugLogger } from '@aztec/foundation/log'; + +/** + * Creates an Aztec Account. + * @returns The account's address & public key. + */ +export async function createAccounts( + aztecRpcClient: AztecRPC, + privateKey: Buffer, + numberOfAccounts = 1, + logger = createDebugLogger('aztec:aztec.js:accounts'), +): Promise<[AztecAddress, Point][]> { + const results: [AztecAddress, Point][] = []; + for (let i = 0; i < numberOfAccounts; ++i) { + // We use the well-known private key and the validating account contract for the first account, + // and generate random keypairs with gullible account contracts (ie no sig validation) for the rest. + // TODO(#662): Let the aztec rpc server generate the keypair rather than hardcoding the private key + const privKey = i == 0 ? privateKey : undefined; + const [txHash, newAddress] = await aztecRpcClient.createSmartAccount(privKey); + // wait for tx to be mined + await new SentTx(aztecRpcClient, Promise.resolve(txHash)).isMined(); + const address = newAddress; + const pubKey = await aztecRpcClient.getAccountPublicKey(address); + logger(`Created account ${address.toString()} with public key ${pubKey.toString()}`); + results.push([newAddress, pubKey]); + } + return results; +} diff --git a/yarn-project/aztec.js/src/utils/index.ts b/yarn-project/aztec.js/src/utils/index.ts index 670591ba413e..1edb3e480fb7 100644 --- a/yarn-project/aztec.js/src/utils/index.ts +++ b/yarn-project/aztec.js/src/utils/index.ts @@ -1 +1,3 @@ export * from './secrets.js'; +export * from './account.js'; +export * from './pub_key.js'; diff --git a/yarn-project/aztec.js/src/utils/pub_key.ts b/yarn-project/aztec.js/src/utils/pub_key.ts new file mode 100644 index 000000000000..11e8ac609918 --- /dev/null +++ b/yarn-project/aztec.js/src/utils/pub_key.ts @@ -0,0 +1,15 @@ +import { Point } from '../index.js'; + +/** + * Converts a Point type to a public key represented by BigInt coordinates + * @param point - The Point to convert. + * @returns An object with x & y coordinates represented as bigints. + */ +export function pointToPublicKey(point: Point) { + const x = point.x.toBigInt(); + const y = point.y.toBigInt(); + return { + x, + y, + }; +} diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts index 3b183e758686..846a41f42be4 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_accumulated_data.ts @@ -362,6 +362,10 @@ export class CombinedAccumulatedData { ); } + toString() { + return this.toBuffer().toString(); + } + /** * Deserializes from a buffer or reader, corresponding to a write in cpp. * @param buffer - Buffer or reader to read from. @@ -387,6 +391,15 @@ export class CombinedAccumulatedData { ); } + /** + * Deserializes from a string, corresponding to a write in cpp. + * @param str - String to read from. + * @returns Deserialized object. + */ + static fromString(str: string) { + return CombinedAccumulatedData.fromBuffer(Buffer.from(str, 'hex')); + } + static empty() { return new CombinedAccumulatedData( AggregationObject.makeFake(), diff --git a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts index 0113ba64c047..e1f0796541f0 100644 --- a/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/combined_constant_data.ts @@ -49,6 +49,10 @@ export class PrivateHistoricTreeRoots { return serializeToBuffer(...PrivateHistoricTreeRoots.getFields(this)); } + toString() { + return this.toBuffer().toString(); + } + isEmpty() { return ( this.privateDataTreeRoot.isZero() && @@ -75,6 +79,10 @@ export class PrivateHistoricTreeRoots { ); } + static fromString(str: string): PrivateHistoricTreeRoots { + return PrivateHistoricTreeRoots.fromBuffer(Buffer.from(str, 'hex')); + } + static empty() { return new PrivateHistoricTreeRoots(Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO); } @@ -95,6 +103,10 @@ export class CombinedHistoricTreeRoots { return serializeToBuffer(this.privateHistoricTreeRoots); } + toString() { + return this.toBuffer().toString(); + } + static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); return new CombinedHistoricTreeRoots(reader.readObject(PrivateHistoricTreeRoots)); diff --git a/yarn-project/end-to-end/src/e2e_zk_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_zk_token_contract.test.ts index 5be384c72869..e68ff84f0b13 100644 --- a/yarn-project/end-to-end/src/e2e_zk_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_zk_token_contract.test.ts @@ -1,11 +1,11 @@ import { AztecNodeService } from '@aztec/aztec-node'; import { AztecAddress, AztecRPCServer, Contract, ContractDeployer, TxStatus } from '@aztec/aztec.js'; import { ZkTokenContractAbi } from '@aztec/noir-contracts/examples'; - import { DebugLogger } from '@aztec/foundation/log'; -import { pointToPublicKey, setup } from './utils.js'; import { L2BlockL2Logs } from '@aztec/types'; +import { pointToPublicKey, setup } from './utils.js'; + describe('e2e_zk_token_contract', () => { let aztecNode: AztecNodeService; let aztecRpcServer: AztecRPCServer; diff --git a/yarn-project/foundation/src/json-rpc/class_converter.ts b/yarn-project/foundation/src/json-rpc/class_converter.ts index dc6fab4cdd69..86dd9c408e7a 100644 --- a/yarn-project/foundation/src/json-rpc/class_converter.ts +++ b/yarn-project/foundation/src/json-rpc/class_converter.ts @@ -19,7 +19,12 @@ interface IOClass { /** * Creates an IOClass from a given string. */ - fromString: (str: string) => any; + fromString?: (str: string) => any; + + /** + * Creates an IOClass from a given JSON object. + */ + fromJSON?: (obj: object) => any; } /** @@ -32,7 +37,7 @@ export interface ClassConverterInput { /** * Represents a class in a JSON-friendly encoding. */ -export interface JsonEncodedClass { +export interface StringEncodedClass { /** * The class type. */ @@ -43,35 +48,69 @@ export interface JsonEncodedClass { data: string; } +/** + * Represents a class in a JSON-friendly encoding. + */ +export interface JsonEncodedClass { + /** + * The class type. + */ + type: string; + /** + * The class data string. + */ + data: object; +} +/** + * Whether a class is a complex object or simply represented by a string. + */ +export type ClassEncoding = 'string' | 'object'; + /** * Handles mapping of classes to names, and calling toString and fromString to convert to and from JSON-friendly formats. * Takes a class map as input. */ export class ClassConverter { - private toClass = new Map(); - private toName = new Map(); + private toClass = new Map(); + private toName = new Map(); /** * Create a class converter from a table of classes. - * @param input - The class table. + * @param stringClassMap - The class table of string encoded classes. + * @param objectClassMap - The class table of complex object classes */ - constructor(input: ClassConverterInput) { - for (const key of Object.keys(input)) { - this.register(key, input[key]); + constructor(stringClassMap?: ClassConverterInput, objectClassMap?: ClassConverterInput) { + if (stringClassMap) { + for (const key of Object.keys(stringClassMap)) { + this.register(key, stringClassMap[key], 'string'); + } + } + if (objectClassMap) { + for (const key of Object.keys(objectClassMap)) { + this.register(key, objectClassMap[key], 'object'); + } } } + /** * Register a class with a certain name. * This name is used for conversion from and to this class. * @param type - The class name to use for serialization. * @param class_ - The class object. + * @param encoding - Whether the class is a complex object or simply represented by a string. */ - register(type: string, class_: IOClass) { + register(type: string, class_: IOClass, encoding: ClassEncoding) { assert(type !== 'Buffer', "'Buffer' handling is hardcoded. Cannot use as name."); - assert(hasOwnProperty(class_.prototype, 'toString'), `Class ${type} must define a toString() method.`); - assert(class_['fromString'], `Class ${type} must define a fromString() static method.`); - this.toName.set(class_, type); - this.toClass.set(type, class_); + assert( + hasOwnProperty(class_.prototype, 'toString') || hasOwnProperty(class_.prototype, 'toJSON'), + `Class ${type} must define a toString() OR toJSON() method.`, + ); + assert( + class_['fromString'] || class_['fromJSON'], + `Class ${type} must define a fromString() OR fromJSON() static method.`, + ); + this.toName.set(class_, [type, encoding]); + this.toClass.set(type, [class_, encoding]); } /** @@ -95,19 +134,27 @@ export class ClassConverter { * @param jsonObj - An object encoding a class. * @returns The class object. */ - toClassObj(jsonObj: JsonEncodedClass): any { - const class_ = this.toClass.get(jsonObj.type); - assert(class_, `Could not find type in lookup.`); - return class_!.fromString(jsonObj.data); + toClassObj(jsonObj: JsonEncodedClass | StringEncodedClass): any { + const result = this.toClass.get(jsonObj.type); + assert(result, `Could not find type in lookup.`); + + const [class_, encoding] = result; + if (encoding === 'string' && typeof jsonObj.data === 'string') { + return class_!.fromString!(jsonObj.data); + } else { + return class_!.fromJSON!(jsonObj.data as object); + } } /** - * Convert a JSON-like object to a class object. + * Convert a class object to a JSON object. * @param classObj - A JSON encoding a class. * @returns The class object. */ - toJsonObj(classObj: any): JsonEncodedClass { - const type = this.toName.get(classObj.constructor); - assert(type, `Could not find class in lookup.`); - return { type: type!, data: classObj.toString() }; + toJsonObj(classObj: any): JsonEncodedClass | StringEncodedClass { + const result = this.toName.get(classObj.constructor); + assert(result, `Could not find class in lookup.`); + const [type, encoding] = result; + const data = encoding === 'string' ? classObj.toString() : classObj.toJSON(); + return { type: type!, data }; } } diff --git a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts index 60d3b8069bd4..4c6b2c4a413f 100644 --- a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts +++ b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.test.ts @@ -5,11 +5,11 @@ import { createJsonRpcClient } from './json_rpc_client.js'; test('test an RPC function over client', async () => { const mockFetch = async (host: string, method: string, body: any) => { - const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }); + const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const result = await request(server.getApp().callback()).post(`/${method}`).send(body); return JSON.parse(result.text); }; - const client = createJsonRpcClient('', { TestNote }, mockFetch); + const client = createJsonRpcClient('', { TestNote }, {}, true, mockFetch); const result = await client.addNotes([new TestNote('c')]); expect(result[0]).toBeInstanceOf(TestNote); expect(result[1]).toBeInstanceOf(TestNote); diff --git a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.ts b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.ts index 3d1cc7ae5290..f24dea4ae0c8 100644 --- a/yarn-project/foundation/src/json-rpc/client/json_rpc_client.ts +++ b/yarn-project/foundation/src/json-rpc/client/json_rpc_client.ts @@ -6,7 +6,7 @@ import { RemoteObject } from 'comlink'; import { createDebugLogger } from '../../log/index.js'; import { retry } from '../../retry/index.js'; import { ClassConverter, ClassConverterInput } from '../class_converter.js'; -import { convertFromJsonObj, convertToJsonObj } from '../convert.js'; +import { JsonStringify, convertFromJsonObj, convertToJsonObj } from '../convert.js'; const debug = createDebugLogger('json-rpc:json_rpc_client'); /** @@ -17,13 +17,22 @@ const debug = createDebugLogger('json-rpc:json_rpc_client'); * @param body - The RPC payload. * @returns The parsed JSON response, or throws an error. */ -export async function defaultFetch(host: string, rpcMethod: string, body: any) { - debug(`JsonRpcClient.fetch`, host, rpcMethod, '<-', body); - const resp = await fetch(`${host}/${rpcMethod}`, { - method: 'POST', - body: JSON.stringify(body), - headers: { 'content-type': 'application/json' }, - }); +export async function defaultFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) { + debug(`JsonRpcClient.fetch`, host, rpcMethod, '->', body); + let resp: Response; + if (useApiEndpoints) { + resp = await fetch(`${host}/${rpcMethod}`, { + method: 'POST', + body: JsonStringify(body), + headers: { 'content-type': 'application/json' }, + }); + } else { + resp = await fetch(host, { + method: 'POST', + body: JsonStringify({ ...body, method: rpcMethod }), + headers: { 'content-type': 'application/json' }, + }); + } if (!resp.ok) { throw new Error(resp.statusText); @@ -40,8 +49,8 @@ export async function defaultFetch(host: string, rpcMethod: string, body: any) { /** * A fetch function with retries. */ -export async function mustSucceedFetch(host: string, rpcMethod: string, body: any) { - return await retry(() => defaultFetch(host, rpcMethod, body), 'JsonRpcClient request'); +export async function mustSucceedFetch(host: string, rpcMethod: string, body: any, useApiEndpoints: boolean) { + return await retry(() => defaultFetch(host, rpcMethod, body, useApiEndpoints), 'JsonRpcClient request'); } /** @@ -50,10 +59,12 @@ export async function mustSucceedFetch(host: string, rpcMethod: string, body: an */ export function createJsonRpcClient( host: string, - classMap: ClassConverterInput, + stringClassMap: ClassConverterInput, + objectClassMap: ClassConverterInput, + useApiEndpoints: boolean, fetch = defaultFetch, ) { - const classConverter = new ClassConverter(classMap); + const classConverter = new ClassConverter(stringClassMap, objectClassMap); let id = 0; const request = async (method: string, params: any[]): Promise => { const body = { @@ -63,12 +74,15 @@ export function createJsonRpcClient( params: params.map(param => convertToJsonObj(classConverter, param)), }; debug(`JsonRpcClient.request`, method, '<-', params); - const res = await fetch(host, method, body); - debug(`JsonRpcClient.request`, method, '->', res); + const res = await fetch(host, method, body, useApiEndpoints); + debug(`JsonRpcClient.result`, method, '->', res); if (res.error) { throw res.error; } - return convertFromJsonObj(classConverter, res.result); + if ([null, undefined, 'null', 'undefined'].includes(res.result)) { + return; + } + return convertFromJsonObj(classConverter, JSON.parse(res.result)); }; // Intercept any RPC methods with a proxy diff --git a/yarn-project/foundation/src/json-rpc/convert.ts b/yarn-project/foundation/src/json-rpc/convert.ts index 10292584697c..17c5391f5f15 100644 --- a/yarn-project/foundation/src/json-rpc/convert.ts +++ b/yarn-project/foundation/src/json-rpc/convert.ts @@ -1,6 +1,22 @@ import { ClassConverter } from './class_converter.js'; import { Buffer } from 'buffer'; +/** + * JSON.stringify helper that handles bigints. + * @param obj - The object to be stringified. + * @returns The resulting string. + */ +export function JsonStringify(obj: object): string { + return JSON.stringify(obj, (key, value) => + typeof value === 'bigint' + ? JSON.stringify({ + type: 'bigint', + data: value.toString(), + }) + : value, + ); +} + /** * Convert a JSON-friendly object, which may encode a class object. * @param cc - The class converter. @@ -8,6 +24,10 @@ import { Buffer } from 'buffer'; * @returns The decoded object. */ export function convertFromJsonObj(cc: ClassConverter, obj: any): any { + if (obj === null) { + return undefined; // `null` doesn't work with default args. + } + if (!obj) { return obj; // Primitive type } @@ -15,6 +35,11 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any { if (obj.type === 'Buffer' && typeof obj.data === 'string') { return Buffer.from(obj.data, 'base64'); } + + if (obj.type === 'bigint' && typeof obj.data === 'string') { + return BigInt(obj.data); + } + // Is this a convertible type? if (typeof obj.type === 'string' && cc.isRegisteredClassName(obj.type)) { return cc.toClassObj(obj); @@ -51,6 +76,14 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any { if (obj instanceof Buffer) { return { type: 'Buffer', data: obj.toString('base64') }; } + + if (typeof obj === 'bigint') { + return { + type: 'bigint', + data: obj.toString(), + }; + } + // Is this a convertible type? if (cc.isRegisteredClass(obj.constructor)) { return cc.toJsonObj(obj); diff --git a/yarn-project/foundation/src/json-rpc/js_utils.ts b/yarn-project/foundation/src/json-rpc/js_utils.ts index c8e12fc5d506..c24b3d7b8974 100644 --- a/yarn-project/foundation/src/json-rpc/js_utils.ts +++ b/yarn-project/foundation/src/json-rpc/js_utils.ts @@ -8,8 +8,13 @@ export const hasOwnProperty = (obj: any, propertyName: string) => Object.prototype.hasOwnProperty.call(obj, propertyName); -export const assert = (x: any, err: string) => { +/** + * Helper function to assert a condition is truthy + * @param x - A boolean condition to assert. + * @param err - Error message to throw if x isn't met. + */ +export function assert(x: any, err: string): asserts x { if (!x) { throw new Error(err); } -}; +} diff --git a/yarn-project/foundation/src/json-rpc/server/json_proxy.ts b/yarn-project/foundation/src/json-rpc/server/json_proxy.ts index 0e5a3ae244b0..d51d68a4e10a 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_proxy.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_proxy.ts @@ -11,8 +11,8 @@ const debug = createDebugLogger('json-rpc:json_proxy'); */ export class JsonProxy { classConverter: ClassConverter; - constructor(private handler: object, input: ClassConverterInput) { - this.classConverter = new ClassConverter(input); + constructor(private handler: object, stringClassMap: ClassConverterInput, objectClassMap: ClassConverterInput) { + this.classConverter = new ClassConverter(stringClassMap, objectClassMap); } /** * Call an RPC method. @@ -27,10 +27,10 @@ export class JsonProxy { assert(Array.isArray(jsonParams), 'JsonProxy: Params not an array!'); // convert the params from json representation to classes const convertedParams = jsonParams.map(param => convertFromJsonObj(this.classConverter, param)); - debug('JsonProxy:call', this.handler, methodName, '<-', convertedParams); + debug('JsonProxy:call', methodName, '<-', convertedParams); const rawRet = await (this.handler as any)[methodName](...convertedParams); const ret = convertToJsonObj(this.classConverter, rawRet); - debug('JsonProxy:call', this.handler, methodName, '->', ret); + debug('JsonProxy:call', methodName, '->', ret); return ret; } } diff --git a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts index 2a1d054d584c..9aa25756093a 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.test.ts @@ -3,27 +3,21 @@ import { TestState, TestNote } from '../fixtures/test_state.js'; import { JsonRpcServer } from './json_rpc_server.js'; test('test an RPC function with a primitive parameter', async () => { - const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }); + const server = new JsonRpcServer(new TestState([new TestNote('a'), new TestNote('b')]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/getNote') .send({ params: [0] }); expect(response.status).toBe(200); - expect(response.text).toBe('{"result":{"type":"TestNote","data":"a"}}'); + expect(response.text).toBe(JSON.stringify({ result: JSON.stringify({ type: 'TestNote', data: 'a' }) })); }); test('test an RPC function with an array of classes', async () => { - const server = new JsonRpcServer(new TestState([]), { TN: TestNote }); + const server = new JsonRpcServer(new TestState([]), { TestNote }, {}, true); const response = await request(server.getApp().callback()) .post('/addNotes') .send({ - params: [ - [ - { type: 'TN', data: 'a' }, - { type: 'TN', data: 'b' }, - { type: 'TN', data: 'c' }, - ], - ], + params: [[{ data: 'a' }, { data: 'b' }, { data: 'c' }]], }); expect(response.status).toBe(200); - expect(response.text).toBe('{"result":[{"type":"TN","data":"a"},{"type":"TN","data":"b"},{"type":"TN","data":"c"}]}'); + expect(response.text).toBe(JSON.stringify({ result: JSON.stringify([{ data: 'a' }, { data: 'b' }, { data: 'c' }]) })); }); diff --git a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts index 06e318f5307d..a0ccf40c8dad 100644 --- a/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts +++ b/yarn-project/foundation/src/json-rpc/server/json_rpc_server.ts @@ -2,11 +2,13 @@ import http from 'http'; import Router from 'koa-router'; import cors from '@koa/cors'; import compress from 'koa-compress'; -import { ClassConverterInput } from '../class_converter.js'; import Koa from 'koa'; import bodyParser from 'koa-bodyparser'; -import { JsonProxy } from './json_proxy.js'; + import { createLogger } from '../../log/index.js'; +import { ClassConverterInput } from '../class_converter.js'; +import { JsonProxy } from './json_proxy.js'; +import { JsonStringify } from '../convert.js'; /** * JsonRpcServer. @@ -16,10 +18,13 @@ export class JsonRpcServer { proxy: JsonProxy; constructor( private handler: object, - input: ClassConverterInput, + stringClassMap: ClassConverterInput, + objectClassMap: ClassConverterInput, + private createApi: boolean, + private disallowedMethods: string[] = [], private log = createLogger('aztec:foundation:json-rpc:server'), ) { - this.proxy = new JsonProxy(handler, input); + this.proxy = new JsonProxy(handler, stringClassMap, objectClassMap); } /** @@ -40,7 +45,7 @@ export class JsonRpcServer { }; const app = new Koa(); app.on('error', error => { - this.log(`KOA app-level error. ${JSON.stringify({ error })}`); + this.log(`KOA app-level error. ${JsonStringify({ error })}`); }); app.use(compress({ br: false } as any)); app.use(bodyParser()); @@ -61,18 +66,49 @@ export class JsonRpcServer { const router = new Router({ prefix }); const proto = Object.getPrototypeOf(this.handler); // Find all our endpoints from the handler methods - for (const method of Object.getOwnPropertyNames(proto)) { - // Ignore if not a function - if (method === 'constructor' || typeof proto[method] !== 'function') { - continue; + + if (this.createApi) { + // "API mode" where an endpoint is created for each method + for (const method of Object.getOwnPropertyNames(proto)) { + // Ignore if not a function or function is not allowed + if ( + method === 'constructor' || + typeof proto[method] !== 'function' || + this.disallowedMethods.includes(method) + ) { + continue; + } + router.post(`/${method}`, async (ctx: Koa.Context) => { + const { params = [], jsonrpc, id } = ctx.request.body as any; + const result = await this.proxy.call(method, params); + ctx.body = { jsonrpc, id, result: JsonStringify(result) }; + ctx.status = 200; + }); } - router.post(`/${method}`, async (ctx: Koa.Context) => { - const { params = [], jsonrpc, id } = ctx.request.body as any; + } else { + // "JSON RPC mode" where a single endpoint is used and the method is given in the request body + router.post('/', async (ctx: Koa.Context) => { + const { params = [], jsonrpc, id, method } = ctx.request.body as any; + // Ignore if not a function + if ( + method === 'constructor' || + typeof proto[method] !== 'function' || + this.disallowedMethods.includes(method) + ) { + ctx.status = 400; + ctx.body = { error: `Invalid method name: ${method}` }; + } const result = await this.proxy.call(method, params); - ctx.body = { jsonrpc, id, result }; + + ctx.body = { + jsonrpc, + id, + result: JsonStringify(result), + }; ctx.status = 200; }); } + return router; } diff --git a/yarn-project/package.json b/yarn-project/package.json index b5a9cbc71cd9..e50eeb70e5fa 100644 --- a/yarn-project/package.json +++ b/yarn-project/package.json @@ -20,6 +20,7 @@ "archiver", "aztec-cli", "aztec-rpc", + "aztec-sandbox", "aztec.js", "circuits.js", "docs", @@ -45,7 +46,7 @@ "devDependencies": { "@monorepo-utils/workspaces-to-typescript-project-references": "^2.9.0", "eslint": "^8.21.0", - "prettier": "^2.7.1", + "prettier": "^2.8.8", "typedoc": "^0.23.26", "typescript": "^5.0.4" } diff --git a/yarn-project/tsconfig.json b/yarn-project/tsconfig.json index bfd1d34d5fba..1c73cfdd8511 100644 --- a/yarn-project/tsconfig.json +++ b/yarn-project/tsconfig.json @@ -24,6 +24,7 @@ { "path": "aztec.js/tsconfig.json" }, { "path": "aztec-node/tsconfig.json" }, { "path": "aztec-rpc/tsconfig.json" }, + { "path": "aztec-sandbox/tsconfig.json" }, { "path": "circuits.js/tsconfig.json" }, { "path": "end-to-end/tsconfig.json" }, { "path": "foundation/tsconfig.json" }, diff --git a/yarn-project/typedoc.json b/yarn-project/typedoc.json index 70ff58a3a74d..559bb768dfd7 100644 --- a/yarn-project/typedoc.json +++ b/yarn-project/typedoc.json @@ -6,6 +6,7 @@ "archiver", "aztec-cli", "aztec-rpc", + "aztec-sandbox", "aztec.js", "key-store", "noir-contracts", @@ -18,4 +19,4 @@ "world-state", "merkle-tree" ] -} +} \ No newline at end of file diff --git a/yarn-project/types/src/logs/tx_l2_logs.ts b/yarn-project/types/src/logs/tx_l2_logs.ts index 424e70e2a834..3f9fca77f268 100644 --- a/yarn-project/types/src/logs/tx_l2_logs.ts +++ b/yarn-project/types/src/logs/tx_l2_logs.ts @@ -45,8 +45,8 @@ export class TxL2Logs { * @param isLengthPrefixed - Whether the buffer is prefixed with 4 bytes for its total length. * @returns A new L2Logs object. */ - public static fromBuffer(buf: Buffer, isLengthPrefixed = true): TxL2Logs { - const reader = new BufferReader(buf, 0); + public static fromBuffer(buf: Buffer | BufferReader, isLengthPrefixed = true): TxL2Logs { + const reader = BufferReader.asReader(buf); // If the buffer is length prefixed use the length to read the array. Otherwise, the entire buffer is consumed. const logsBufLength = isLengthPrefixed ? reader.readNumber() : -1; diff --git a/yarn-project/types/src/tx.ts b/yarn-project/types/src/tx.ts index 11af9cefadc5..e0874c159b11 100644 --- a/yarn-project/types/src/tx.ts +++ b/yarn-project/types/src/tx.ts @@ -1,4 +1,4 @@ -import { KernelCircuitPublicInputs, Proof, PublicCallRequest } from '@aztec/circuits.js'; +import { Fr, KernelCircuitPublicInputs, Proof, PublicCallRequest } from '@aztec/circuits.js'; import { arrayNonEmptyLength } from '@aztec/foundation/collection'; import { EncodedContractFunction } from './contract_data.js'; @@ -10,7 +10,7 @@ import { PartialContractAddress } from './partial_contract_address.js'; * The interface of an L2 transaction. */ export class Tx { - protected constructor( + constructor( /** * Output of the private kernel circuit for this tx. */ @@ -42,7 +42,7 @@ export class Tx { // both public and private function invocations create unencrypted FunctionL2Logs object. Hence "num unencrypted" // >= "num encrypted". throw new Error( - `Number of function logs in unencrypted logs (${this.unencryptedLogs.functionLogs.length}) has to be equal + `Number of function logs in unencrypted logs (${this.unencryptedLogs.functionLogs.length}) has to be equal or larger than number function logs in encrypted logs (${this.encryptedLogs.functionLogs.length})`, ); } @@ -51,12 +51,53 @@ export class Tx { data?.end.publicCallStack && arrayNonEmptyLength(data.end.publicCallStack, item => item.isZero()); if (kernelPublicCallStackSize && kernelPublicCallStackSize > (enqueuedPublicFunctionCalls?.length ?? 0)) { throw new Error( - `Missing preimages for enqueued public function calls in kernel circuit public inputs (expected + `Missing preimages for enqueued public function calls in kernel circuit public inputs (expected ${kernelPublicCallStackSize}, got ${enqueuedPublicFunctionCalls?.length})`, ); } } + /** + * Convert a Tx class object to a plain JSON object. + * @returns A plain object with Tx properties. + */ + public toJSON() { + return { + data: this.data.toBuffer().toString('hex'), + encryptedLogs: this.encryptedLogs.toBuffer().toString('hex'), + unencryptedLogs: this.unencryptedLogs.toBuffer().toString('hex'), + proof: this.proof.toBuffer().toString('hex'), + newContractPublicFunctions: this.newContractPublicFunctions.map(f => f.toBuffer().toString('hex')) ?? [], + enqueuedPublicFunctions: this.enqueuedPublicFunctionCalls.map(f => f.toBuffer().toString('hex')) ?? [], + }; + } + + /** + * Convert a plain JSON object to a Tx class object. + * @param obj - A plain Tx JSON object. + * @returns A Tx class object. + */ + public static fromJSON(obj: any) { + const publicInputs = KernelCircuitPublicInputs.fromBuffer(Buffer.from(obj.data, 'hex')); + const encryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.encryptedLogs, 'hex')); + const unencryptedLogs = TxL2Logs.fromBuffer(Buffer.from(obj.unencryptedLogs, 'hex')); + const proof = Buffer.from(obj.proof, 'hex'); + const newContractPublicFunctions = obj.newContractPublicFunctions + ? obj.newContractPublicFunctions.map((x: string) => EncodedContractFunction.fromBuffer(Buffer.from(x, 'hex'))) + : []; + const enqueuedPublicFunctions = obj.enqueuedPublicFunctions + ? obj.enqueuedPublicFunctions.map((x: string) => PublicCallRequest.fromBuffer(Buffer.from(x, 'hex'))) + : []; + return Tx.createTx( + publicInputs, + Proof.fromBuffer(proof), + encryptedLogs, + unencryptedLogs, + newContractPublicFunctions, + enqueuedPublicFunctions, + ); + } + /** * Creates a new private transaction. * @param data - Public inputs of the private kernel circuit. @@ -141,4 +182,15 @@ export class ContractDeploymentTx { */ public readonly partialContractAddress: PartialContractAddress, ) {} + + toJSON() { + return { + tx: this.tx.toJSON(), + partialContractAddress: this.partialContractAddress.toBuffer().toString(), + }; + } + + static fromJSON(obj: any) { + return new ContractDeploymentTx(Tx.fromJSON(obj.tx), Fr.fromBuffer(Buffer.from(obj.partialContractAddress, 'hex'))); + } } diff --git a/yarn-project/types/src/tx_hash.ts b/yarn-project/types/src/tx_hash.ts index c87e88d86fa6..d85583b17aa1 100644 --- a/yarn-project/types/src/tx_hash.ts +++ b/yarn-project/types/src/tx_hash.ts @@ -48,6 +48,7 @@ export class TxHash { public toString() { return this.buffer.toString('hex'); } + /** * Convert this hash to a big int. * @returns The big int. @@ -76,4 +77,13 @@ export class TxHash { const padded = Buffer.concat([Buffer.alloc(this.SIZE - 28), buffer]); return new TxHash(padded); } + + /** + * Converts a string into a TxHash object. + * @param str - The TX hash in string format. + * @returns A new TxHash object. + */ + public static fromString(str: string): TxHash { + return new TxHash(Buffer.from(str, 'hex')); + } } diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index b23b7b0e6e92..ed613f80612f 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -22,6 +22,7 @@ COPY archiver/package.json archiver/package.json COPY aztec-cli/package.json aztec-cli/package.json COPY aztec-rpc/package.json aztec-rpc/package.json COPY aztec-node/package.json aztec-node/package.json +COPY aztec-sandbox/package.json aztec-sandbox/package.json COPY aztec.js/package.json aztec.js/package.json COPY docs/package.json docs/package.json COPY end-to-end/package.json end-to-end/package.json @@ -80,6 +81,7 @@ COPY archiver/tsconfig.json archiver/tsconfig.json COPY aztec-cli/tsconfig.json aztec-cli/tsconfig.json COPY aztec-rpc/tsconfig.json aztec-rpc/tsconfig.json COPY aztec-node/tsconfig.json aztec-node/tsconfig.json +COPY aztec-sandbox/tsconfig.json aztec-sandbox/tsconfig.json COPY aztec.js/tsconfig.json aztec.js/tsconfig.json COPY end-to-end/tsconfig.json end-to-end/tsconfig.json COPY ethereum/tsconfig.json ethereum/tsconfig.json diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index d0bd3eed7b75..4346ff453126 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -196,6 +196,27 @@ __metadata: languageName: unknown linkType: soft +"@aztec/aztec-sandbox@workspace:aztec-sandbox": + version: 0.0.0-use.local + resolution: "@aztec/aztec-sandbox@workspace:aztec-sandbox" + dependencies: + "@aztec/aztec-node": "workspace:^" + "@aztec/aztec-rpc": "workspace:^" + "@aztec/aztec.js": "workspace:^" + "@aztec/ethereum": "workspace:^" + "@aztec/foundation": "workspace:^" + "@jest/globals": ^29.5.0 + "@types/jest": ^29.5.0 + abitype: ^0.8.11 + jest: ^29.5.0 + koa-router: ^12.0.0 + ts-jest: ^29.1.0 + ts-node: ^10.9.1 + typescript: ^5.0.4 + viem: ^0.3.14 + languageName: unknown + linkType: soft + "@aztec/aztec.js@workspace:^, @aztec/aztec.js@workspace:aztec.js": version: 0.0.0-use.local resolution: "@aztec/aztec.js@workspace:aztec.js" @@ -223,7 +244,7 @@ __metadata: dependencies: "@monorepo-utils/workspaces-to-typescript-project-references": ^2.9.0 eslint: ^8.21.0 - prettier: ^2.7.1 + prettier: ^2.8.8 typedoc: ^0.23.26 typescript: ^5.0.4 languageName: unknown @@ -3535,6 +3556,19 @@ __metadata: languageName: node linkType: hard +"abitype@npm:^0.8.11": + version: 0.8.11 + resolution: "abitype@npm:0.8.11" + peerDependencies: + typescript: ">=5.0.4" + zod: ^3 >=3.19.1 + peerDependenciesMeta: + zod: + optional: true + checksum: 94e6ad5d3d3851f68ea54d090312d35e38aa15d19b65d25f02d8c54400b184a87b121adb23e930f2e92d597e9290e8ca4f2ff70751e6dada4e8f1440948e0c44 + languageName: node + linkType: hard + "abortable-iterator@npm:^5.0.0, abortable-iterator@npm:^5.0.1": version: 5.0.1 resolution: "abortable-iterator@npm:5.0.1" @@ -8234,6 +8268,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^2.8.8": + version: 2.8.8 + resolution: "prettier@npm:2.8.8" + bin: + prettier: bin-prettier.js + checksum: b49e409431bf129dd89238d64299ba80717b57ff5a6d1c1a8b1a28b590d998a34e083fa13573bc732bb8d2305becb4c9a4407f8486c81fa7d55100eb08263cf8 + languageName: node + linkType: hard + "pretty-format@npm:^29.0.0, pretty-format@npm:^29.5.0": version: 29.5.0 resolution: "pretty-format@npm:29.5.0" From ee3d9e0b95fb55ce209d12de315e2b49707983eb Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 20:02:19 +0000 Subject: [PATCH 23/28] Revert to Ecdsa --- circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index fd7259fd268c..1a7403278910 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) From bef4f57a5ec69deeeca1b1b39bd95eb6118a7302 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 20:35:21 +0000 Subject: [PATCH 24/28] Proposed fix. --- circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- .../src/structs/kernel/__snapshots__/index.test.ts.snap | 2 +- yarn-project/circuits.js/src/structs/kernel/index.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index 1a7403278910..fd7259fd268c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index 81caae287a89..6a70dcad4d33 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -113,7 +113,7 @@ value: 0xd05 " `; -exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 0 }"`; +exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101 }"`; exports[`structs/kernel serializes and prints previous_kernel_data 1`] = ` "public_inputs: end: diff --git a/yarn-project/circuits.js/src/structs/kernel/index.test.ts b/yarn-project/circuits.js/src/structs/kernel/index.test.ts index 852bb7145cbb..352d37fabba8 100644 --- a/yarn-project/circuits.js/src/structs/kernel/index.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/index.test.ts @@ -34,7 +34,7 @@ describe('structs/kernel', () => { ); }); - it(`serializes and prints EcdsaSignature`, async () => { + it(`serializes and prints SchnorrSignature`, async () => { await expectSerializeToMatchSnapshot(makeSchnorrSignature().toBuffer(), 'abis__test_roundtrip_serialize_signature'); }); From aaeb225701ece35e9825e47ce8c8baf4a562b034 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 21:09:29 +0000 Subject: [PATCH 25/28] Revert "Proposed fix." This reverts commit bef4f57a5ec69deeeca1b1b39bd95eb6118a7302. --- circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- .../src/structs/kernel/__snapshots__/index.test.ts.snap | 2 +- yarn-project/circuits.js/src/structs/kernel/index.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index fd7259fd268c..1a7403278910 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index 6a70dcad4d33..81caae287a89 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -113,7 +113,7 @@ value: 0xd05 " `; -exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101 }"`; +exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 0 }"`; exports[`structs/kernel serializes and prints previous_kernel_data 1`] = ` "public_inputs: end: diff --git a/yarn-project/circuits.js/src/structs/kernel/index.test.ts b/yarn-project/circuits.js/src/structs/kernel/index.test.ts index 352d37fabba8..852bb7145cbb 100644 --- a/yarn-project/circuits.js/src/structs/kernel/index.test.ts +++ b/yarn-project/circuits.js/src/structs/kernel/index.test.ts @@ -34,7 +34,7 @@ describe('structs/kernel', () => { ); }); - it(`serializes and prints SchnorrSignature`, async () => { + it(`serializes and prints EcdsaSignature`, async () => { await expectSerializeToMatchSnapshot(makeSchnorrSignature().toBuffer(), 'abis__test_roundtrip_serialize_signature'); }); From ec3fbf4b0de07121df2cee5fd68d2e58727865b9 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Jun 2023 21:18:11 +0000 Subject: [PATCH 26/28] Test Schnorr; update snapshot. Changing test description to reference Schnorr not Ecdsa leads to weird build error. --- circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- .../src/structs/kernel/__snapshots__/index.test.ts.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index 1a7403278910..fd7259fd268c 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index 81caae287a89..2414395c168e 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -113,7 +113,7 @@ value: 0xd05 " `; -exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 0 }"`; +exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 224 }"`; exports[`structs/kernel serializes and prints previous_kernel_data 1`] = ` "public_inputs: end: From 5d20a8da0afe129d83f5d1674f56ad9ab272eead Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 28 Jun 2023 02:07:38 +0000 Subject: [PATCH 27/28] Rebuild WASM before making snapshot. --- yarn-project/circuits.js/src/cbind/circuits.gen.ts | 2 +- .../src/structs/kernel/__snapshots__/index.test.ts.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 8d639edcb3a2..89c6531eae1d 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -855,7 +855,7 @@ export function toVerificationKeyData(o: MsgpackVerificationKeyData): Verificati export function fromVerificationKeyData(o: VerificationKeyData): MsgpackVerificationKeyData { if (o.circuitType === undefined) { - throw new Error('Expected CircuitType in VerificationKeyData serialization'); + throw new Error('Expected circuitType in VerificationKeyData serialization'); } if (o.circuitSize === undefined) { throw new Error('Expected circuitSize in VerificationKeyData serialization'); diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index 2414395c168e..6a70dcad4d33 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -113,7 +113,7 @@ value: 0xd05 " `; -exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 224 }"`; +exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101 }"`; exports[`structs/kernel serializes and prints previous_kernel_data 1`] = ` "public_inputs: end: From d9acb20e04aed33d68df755c71c606bf5c77116e Mon Sep 17 00:00:00 2001 From: Cody Gunton Date: Tue, 27 Jun 2023 22:29:31 -0400 Subject: [PATCH 28/28] Revert "refactor!: Use circuit builders" --- circuits/CODING_STANDARD.md | 6 +- circuits/README.md | 2 +- circuits/cpp/barretenberg | 2 +- .../cpp/src/aztec3/circuits/abis/.test.cpp | 14 +- .../cpp/src/aztec3/circuits/abis/README.md | 2 +- .../cpp/src/aztec3/circuits/abis/c_bind.cpp | 2 +- .../src/aztec3/circuits/abis/c_bind.test.cpp | 2 +- .../src/aztec3/circuits/abis/call_context.hpp | 18 +- .../aztec3/circuits/abis/call_stack_item.hpp | 14 +- .../abis/combined_accumulated_data.hpp | 19 +- .../circuits/abis/combined_constant_data.hpp | 14 +- .../abis/combined_historic_tree_roots.hpp | 15 +- .../abis/contract_deployment_data.hpp | 23 +- .../circuits/abis/contract_storage_read.hpp | 14 +- .../abis/contract_storage_update_request.hpp | 16 +- .../src/aztec3/circuits/abis/coordinate.hpp | 14 +- .../aztec3/circuits/abis/function_data.hpp | 14 +- .../circuits/abis/function_leaf_preimage.hpp | 14 +- .../aztec3/circuits/abis/global_variables.hpp | 10 +- .../abis/kernel_circuit_public_inputs.hpp | 21 +- .../circuits/abis/membership_witness.hpp | 8 +- .../circuits/abis/new_contract_data.hpp | 16 +- .../abis/optionally_revealed_data.hpp | 19 +- .../cpp/src/aztec3/circuits/abis/point.hpp | 14 +- .../circuits/abis/previous_kernel_data.hpp | 14 +- .../abis/private_circuit_public_inputs.hpp | 113 +++---- .../abis/private_historic_tree_roots.hpp | 15 +- .../call_context_reconciliation_data.hpp | 12 +- .../circuits/abis/private_kernel/globals.hpp | 8 +- .../abis/private_kernel/private_call_data.hpp | 18 +- .../private_kernel_inputs_init.hpp | 9 +- .../private_kernel_inputs_inner.hpp | 9 +- .../abis/public_circuit_public_inputs.hpp | 11 +- .../aztec3/circuits/abis/public_data_read.hpp | 14 +- .../abis/public_data_update_request.hpp | 15 +- .../abis/public_kernel/public_call_data.hpp | 16 +- .../public_kernel/public_kernel_inputs.hpp | 8 +- .../abis/rollup/constant_rollup_data.hpp | 1 + .../src/aztec3/circuits/abis/tx_context.hpp | 21 +- .../src/aztec3/circuits/abis/tx_request.hpp | 10 +- .../cpp/src/aztec3/circuits/apps/.test.cpp | 50 +-- .../cpp/src/aztec3/circuits/apps/contract.hpp | 2 +- .../apps/function_execution_context.hpp | 58 ++-- .../apps/notes/default_private_note/note.hpp | 16 +- .../apps/notes/default_private_note/note.tpp | 55 ++- .../default_private_note/note_preimage.hpp | 12 +- .../nullifier_preimage.hpp | 10 +- .../default_singleton_private_note/note.hpp | 16 +- .../default_singleton_private_note/note.tpp | 54 +-- .../note_preimage.hpp | 12 +- .../nullifier_preimage.hpp | 10 +- .../circuits/apps/notes/note_interface.hpp | 6 +- .../aztec3/circuits/apps/opcodes/opcodes.hpp | 20 +- .../aztec3/circuits/apps/opcodes/opcodes.tpp | 26 +- .../aztec3/circuits/apps/oracle_wrapper.hpp | 34 +- .../circuits/apps/private_state.test.cpp | 4 +- .../apps/state_vars/field_state_var.hpp | 16 +- .../apps/state_vars/mapping_state_var.hpp | 16 +- .../apps/state_vars/mapping_state_var.tpp | 12 +- .../apps/state_vars/state_var_base.hpp | 14 +- .../apps/state_vars/state_var_base.tpp | 8 +- .../apps/state_vars/utxo_set_state_var.hpp | 14 +- .../apps/state_vars/utxo_set_state_var.tpp | 14 +- .../apps/state_vars/utxo_state_var.hpp | 14 +- .../apps/state_vars/utxo_state_var.tpp | 18 +- .../basic_contract_deployment.cpp | 8 +- .../basic_contract_deployment/init.hpp | 6 +- .../circuits/apps/test_apps/escrow/.test.cpp | 54 +-- .../apps/test_apps/escrow/deposit.cpp | 8 +- .../circuits/apps/test_apps/escrow/init.hpp | 6 +- .../apps/test_apps/escrow/transfer.cpp | 16 +- .../apps/test_apps/escrow/withdraw.cpp | 12 +- .../.test.cpp | 18 +- .../function_1_1.cpp | 8 +- .../function_2_1.cpp | 8 +- .../private_to_private_function_call/init.hpp | 6 +- .../src/aztec3/circuits/apps/utxo_datum.hpp | 12 +- circuits/cpp/src/aztec3/circuits/hash.hpp | 10 +- .../aztec3/circuits/kernel/private/.test.cpp | 12 +- .../aztec3/circuits/kernel/private/c_bind.cpp | 16 +- .../aztec3/circuits/kernel/private/c_bind.h | 1 + .../aztec3/circuits/kernel/private/common.cpp | 86 ++--- .../aztec3/circuits/kernel/private/common.hpp | 12 +- .../aztec3/circuits/kernel/private/init.hpp | 8 +- .../native_private_kernel_circuit_init.cpp | 82 ++--- .../native_private_kernel_circuit_init.hpp | 6 +- ...ative_private_kernel_circuit_init.test.cpp | 210 ++++++------ .../native_private_kernel_circuit_inner.cpp | 62 ++-- .../native_private_kernel_circuit_inner.hpp | 6 +- ...tive_private_kernel_circuit_inner.test.cpp | 173 +++++----- ...native_private_kernel_circuit_ordering.cpp | 18 +- ...native_private_kernel_circuit_ordering.hpp | 6 +- ...e_private_kernel_circuit_ordering.test.cpp | 26 +- .../kernel/private/private_kernel_circuit.cpp | 53 +-- .../kernel/private/private_kernel_circuit.hpp | 2 +- .../kernel/private/testing_harness.cpp | 10 +- .../kernel/private/testing_harness.hpp | 4 +- .../aztec3/circuits/kernel/private/utils.cpp | 8 +- .../aztec3/circuits/kernel/public/.test.cpp | 315 +++++++++--------- .../aztec3/circuits/kernel/public/c_bind.cpp | 14 +- .../aztec3/circuits/kernel/public/common.cpp | 8 +- .../aztec3/circuits/kernel/public/common.hpp | 200 +++++------ .../aztec3/circuits/kernel/public/init.hpp | 8 +- ...kernel_circuit_private_previous_kernel.cpp | 34 +- ...kernel_circuit_private_previous_kernel.hpp | 6 +- ..._kernel_circuit_public_previous_kernel.cpp | 28 +- ..._kernel_circuit_public_previous_kernel.hpp | 6 +- .../src/aztec3/circuits/mock/mock_circuit.hpp | 6 +- .../circuits/mock/mock_kernel_circuit.hpp | 17 +- .../aztec3/circuits/recursion/aggregator.hpp | 11 +- .../src/aztec3/circuits/recursion/init.hpp | 6 +- .../src/aztec3/circuits/rollup/base/.test.cpp | 151 +++++---- .../aztec3/circuits/rollup/base/c_bind.cpp | 14 +- .../src/aztec3/circuits/rollup/base/init.hpp | 4 +- .../base/native_base_rollup_circuit.cpp | 102 +++--- .../base/native_base_rollup_circuit.hpp | 2 +- .../circuits/rollup/components/components.cpp | 50 +-- .../circuits/rollup/components/components.hpp | 12 +- .../circuits/rollup/components/init.hpp | 4 +- .../aztec3/circuits/rollup/merge/.test.cpp | 114 +++---- .../aztec3/circuits/rollup/merge/c_bind.cpp | 10 +- .../src/aztec3/circuits/rollup/merge/init.hpp | 4 +- .../merge/native_merge_rollup_circuit.cpp | 10 +- .../merge/native_merge_rollup_circuit.hpp | 2 +- .../src/aztec3/circuits/rollup/root/.test.cpp | 21 +- .../aztec3/circuits/rollup/root/c_bind.cpp | 10 +- .../src/aztec3/circuits/rollup/root/init.hpp | 4 +- .../root/native_root_rollup_circuit.cpp | 18 +- .../root/native_root_rollup_circuit.hpp | 2 +- .../circuits/rollup/test_utils/init.hpp | 4 +- .../circuits/rollup/test_utils/utils.cpp | 16 +- .../circuits/rollup/test_utils/utils.hpp | 6 +- circuits/cpp/src/aztec3/utils/array.hpp | 24 +- ...circuit_builder.hpp => dummy_composer.hpp} | 8 +- .../aztec3/utils/msgpack_derived_equals.hpp | 2 +- .../src/aztec3/utils/types/circuit_types.hpp | 59 ++-- .../cpp/src/aztec3/utils/types/convert.hpp | 185 +++++----- .../circuits.js/src/cbind/circuits.gen.ts | 14 +- .../circuits.js/src/kernel/private_kernel.ts | 2 +- .../kernel/__snapshots__/index.test.ts.snap | 12 +- .../__snapshots__/base_rollup.test.ts.snap | 4 +- .../__snapshots__/root_rollup.test.ts.snap | 4 +- .../circuits.js/src/structs/shared.ts | 9 +- .../src/structs/verification_key.ts | 10 +- .../circuits.js/src/tests/factories.ts | 4 +- 145 files changed, 1829 insertions(+), 1798 deletions(-) rename circuits/cpp/src/aztec3/utils/{dummy_circuit_builder.hpp => dummy_composer.hpp} (87%) diff --git a/circuits/CODING_STANDARD.md b/circuits/CODING_STANDARD.md index d9a63a92a898..057691cbf687 100644 --- a/circuits/CODING_STANDARD.md +++ b/circuits/CODING_STANDARD.md @@ -138,7 +138,7 @@ Here are the types of automation that should help stick to the standard: // ... } // namespace aztec3::circuits::abis::private_kernel ``` - * use`init.hpp` *only* for core/critical renames like `NT/CT` and for toggling core types like `CircuitBuilder` + * use`init.hpp` *only* for core/critical renames like `NT/CT` and for toggling core types like `Composer` * use unnamed/anonymous namespaces to import and shorten external names into *just this one file* * all of a file's external imports belong in a single anonymous namespace `namespace { ...\n } // namespace` at the very top of the file directly after `#include`s * use `using Rename = old::namespace::prefix::Name;` to import and shorten names from external namespaces @@ -146,7 +146,7 @@ Here are the types of automation that should help stick to the standard: * never use renames to remove the `std::` prefix * never use renames to remove a `NT::` or `CT::` prefix * `test.cpp` tests must always explicitly import every single name they intend to use - * they might want to test over multiple namespaces, native and circuit types, and builder types + * they might want to test over multiple namespaces, native and circuit types, and composer types * avoid calling barretenberg's functions directly and instead go through interface files like `circuit_types` and `native_types` * `using` statements should be sorted case according to the `LexicographicNumeric` rules @@ -155,7 +155,7 @@ Here are the types of automation that should help stick to the standard: 1. **includes** * start every header with `#pragma once` * `index.hpp` should include common headers that will be referenced by most cpp/hpp files in the current directory - * `init.hpp` should inject ONLY critical renames (like `NT`/`CT`) and type toggles (like CircuitBuilder) + * `init.hpp` should inject ONLY critical renames (like `NT`/`CT`) and type toggles (like Composer) * example `using NT = aztec3::utils::types::NativeTypes;` * avoid including headers via relative paths (`../../other_dir`) unless they are a subdir (`subdir/header.hpp`) * use full path like `aztec3/circuits/hash.hpp` diff --git a/circuits/README.md b/circuits/README.md index 6f68a4ff5290..2c28f560da88 100644 --- a/circuits/README.md +++ b/circuits/README.md @@ -198,7 +198,7 @@ The core Aztec 3 C++ code lives in `cpp/src/aztec3/`, and is split into the foll - `rollup`: rollup circuits, their interfaces, and thier tests - `recursion`: types and examples for aggregation of recursive proof objects - `mock`: mock circuits -- `oracle`: used to fetch external information (like private data notes) and inject them as inputs into the circuit during execution of circuit logic ([more here](https://github.com/AztecProtocol/aztec3-packages/tree/master/circuits/cpp/src/aztec3/oracle)) +- `oracle`: used to fetch external information (like private data notes) and inject them as inputs into the circuit "Composer" during execution of circuit logic ([more here](https://github.com/AztecProtocol/aztec3-packages/tree/master/circuits/cpp/src/aztec3/oracle)) - `dbs`: database infrastructure (_e.g._ PrivateStateDb) ### Typescript diff --git a/circuits/cpp/barretenberg b/circuits/cpp/barretenberg index 733fe2702179..0838474e6746 160000 --- a/circuits/cpp/barretenberg +++ b/circuits/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 733fe27021793ab672190ee83274abb6049cdc9a +Subproject commit 0838474e67469a6d91d6595d1ee23e1dea53863c diff --git a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp index 0bee851c6627..5fe2e078a1bf 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/.test.cpp @@ -8,11 +8,11 @@ #include namespace { -// Builder -using Builder = UltraCircuitBuilder; +// Composer +using Composer = plonk::UltraPlonkComposer; // Types -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; } // namespace @@ -74,8 +74,8 @@ TEST(abi_tests, native_to_circuit_function_data) info("function data: ", native_function_data); - Builder builder = Builder(); - FunctionData const circuit_function_data = native_function_data.to_circuit_type(builder); + Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); + FunctionData const circuit_function_data = native_function_data.to_circuit_type(composer); info("function data: ", circuit_function_data); } @@ -105,8 +105,8 @@ TEST(abi_tests, native_to_circuit_call_context) info("call context: ", native_call_context); - Builder builder = Builder(); - CallContext const circuit_call_context = native_call_context.to_circuit_type(builder); + Composer composer = Composer("../barretenberg/cpp/srs_db/ignition"); + CallContext const circuit_call_context = native_call_context.to_circuit_type(composer); info("call context: ", circuit_call_context); } diff --git a/circuits/cpp/src/aztec3/circuits/abis/README.md b/circuits/cpp/src/aztec3/circuits/abis/README.md index 192d66c0c10c..26acdf5f58fc 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/README.md +++ b/circuits/cpp/src/aztec3/circuits/abis/README.md @@ -6,4 +6,4 @@ Contains all ABIs for use by: - Kernel circuits - Rollup circuits -All ABIs are generalised by an `NCT` template parameter (meaning `NativeOrCircuitTypes`). `NCT` can be either `aztec3::utils::types::NativeTypes` or `aztec3::utils::types::CircuitTypes` for some `Builder`. The idea being, there's a single implementation of every struct/class for native and circuit types. NativeType structs can be switched to CircuitType with the `to_circuit_type()` method. +All ABIs are generalised by an `NCT` template parameter (meaning `NativeOrCircuitTypes`). `NCT` can be either `aztec3::utils::types::NativeTypes` or `aztec3::utils::types::CircuitTypes` for some `Composer`. The idea being, there's a single implementation of every struct/class for native and circuit types. NativeType structs can be switched to CircuitType with the `to_circuit_type()` method. diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp index fd7259fd268c..1a7403278910 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -511,7 +511,7 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_combined_accumulated_data WASM_EXPORT const char* abis__test_roundtrip_serialize_signature(uint8_t const* input, uint32_t* size) { - return as_string_output(input, size); + return as_string_output(input, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_private_kernel_inputs_inner(uint8_t const* input, uint32_t* size) diff --git a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index 8613d9f7071a..4e96794f0509 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -160,7 +160,7 @@ TEST(abi_tests, hash_vk) { // Initialize some random VK data NT::VKData vk_data; - vk_data.circuit_type = engine.get_random_uint32(); + vk_data.composer_type = engine.get_random_uint32(); vk_data.circuit_size = static_cast(1) << (engine.get_random_uint8() >> 3); // must be a power of two vk_data.num_public_inputs = engine.get_random_uint32(); vk_data.commitments["test1"] = g1::element::random_element(); diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp index f18abf5394f4..1a40181b8210 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_context.hpp @@ -40,14 +40,14 @@ template struct CallContext { return utils::msgpack_derived_equals(*this, other); }; - template CallContext> to_circuit_type(Builder& builder) const + template CallContext> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - CallContext> call_context = { + CallContext> call_context = { to_ct(msg_sender), to_ct(storage_contract_address), to_ct(portal_contract_address), to_ct(is_delegate_call), to_ct(is_static_call), to_ct(is_contract_deployment), @@ -56,10 +56,10 @@ template struct CallContext { return call_context; }; - template CallContext to_native_type() const + template CallContext to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; CallContext call_context = { to_nt(msg_sender), to_nt(storage_contract_address), to_nt(portal_contract_address), @@ -79,9 +79,9 @@ template struct CallContext { return NCT::compress(inputs, GeneratorIndex::CALL_CONTEXT); } - template void assert_is_zero() + template void assert_is_zero() { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); msg_sender.to_field().assert_is_zero(); storage_contract_address.to_field().assert_is_zero(); diff --git a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp index f1af212a15aa..3cb84b30ed0b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/call_stack_item.hpp @@ -49,18 +49,18 @@ template typename PrivatePublic> struct CallStac return utils::msgpack_derived_equals(*this, other); }; - template - CallStackItem, PrivatePublic> to_circuit_type(Builder& builder) const + template + CallStackItem, PrivatePublic> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - CallStackItem, PrivatePublic> call_stack_item = { + CallStackItem, PrivatePublic> call_stack_item = { to_ct(contract_address), - function_data.to_circuit_type(builder), - public_inputs.to_circuit_type(builder), + function_data.to_circuit_type(composer), + public_inputs.to_circuit_type(composer), to_ct(is_execution_request), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp index 6985af961c06..6dab632262e7 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_accumulated_data.hpp @@ -81,14 +81,15 @@ template struct CombinedAccumulatedData { public_data_reads == other.public_data_reads; }; - template CombinedAccumulatedData> to_circuit_type(Builder& builder) const + template + CombinedAccumulatedData> to_circuit_type(Composer& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; CombinedAccumulatedData acc_data = { typename CT::AggregationObject{ @@ -121,11 +122,11 @@ template struct CombinedAccumulatedData { return acc_data; }; - template CombinedAccumulatedData to_native_type() const + template CombinedAccumulatedData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; CombinedAccumulatedData acc_data = { typename NativeTypes::AggregationObject{ diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp index 2d5490bbec1b..39ebb0bf1cd0 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_constant_data.hpp @@ -30,23 +30,23 @@ template struct CombinedConstantData { return historic_tree_roots == other.historic_tree_roots && tx_context == other.tx_context; } - template CombinedConstantData> to_circuit_type(Builder& builder) const + template CombinedConstantData> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - CombinedConstantData> constant_data = { - historic_tree_roots.to_circuit_type(builder), - tx_context.to_circuit_type(builder), + CombinedConstantData> constant_data = { + historic_tree_roots.to_circuit_type(composer), + tx_context.to_circuit_type(composer), }; return constant_data; }; - template CombinedConstantData to_native_type() const + template CombinedConstantData to_native_type() const { - static_assert(std::is_same, NCT>::value); + static_assert(std::is_same, NCT>::value); - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; CombinedConstantData constant_data = { to_native_type(historic_tree_roots), diff --git a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp index dd8e72194e25..0f4152ae59d4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/combined_historic_tree_roots.hpp @@ -27,24 +27,25 @@ template struct CombinedHistoricTreeRoots { return private_historic_tree_roots == other.private_historic_tree_roots; }; - template CombinedHistoricTreeRoots> to_circuit_type(Builder& builder) const + template + CombinedHistoricTreeRoots> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - CombinedHistoricTreeRoots> data = { + CombinedHistoricTreeRoots> data = { to_circuit_type(private_historic_tree_roots), }; return data; }; - template CombinedHistoricTreeRoots to_native_type() const + template CombinedHistoricTreeRoots to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_native_type = [&](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_native_type = [&](T& e) { return e.template to_native_type(); }; CombinedHistoricTreeRoots data = { to_native_type(private_historic_tree_roots), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp index 7ca34bc73dd9..beb0f1ce4eb1 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_deployment_data.hpp @@ -37,15 +37,16 @@ template struct ContractDeploymentData { portal_contract_address == other.portal_contract_address; }; - template ContractDeploymentData> to_circuit_type(Builder& builder) const + template + ContractDeploymentData> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractDeploymentData> data = { - deployer_public_key.to_circuit_type(builder), + ContractDeploymentData> data = { + deployer_public_key.to_circuit_type(composer), to_ct(constructor_vk_hash), to_ct(function_tree_root), to_ct(contract_address_salt), @@ -55,11 +56,11 @@ template struct ContractDeploymentData { return data; }; - template ContractDeploymentData to_native_type() const + template ContractDeploymentData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; ContractDeploymentData call_context = { to_native_type(deployer_public_key), to_nt(constructor_vk_hash), to_nt(function_tree_root), @@ -69,9 +70,9 @@ template struct ContractDeploymentData { return call_context; }; - template void assert_is_zero() + template void assert_is_zero() { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); deployer_public_key.assert_is_zero(); constructor_vk_hash.assert_is_zero(); diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp index f09bee3b6264..3a13701fb820 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_read.hpp @@ -23,14 +23,14 @@ template struct ContractStorageRead { MSGPACK_FIELDS(storage_slot, current_value); bool operator==(ContractStorageRead const&) const = default; - template ContractStorageRead> to_circuit_type(Builder& builder) const + template ContractStorageRead> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractStorageRead> contract_storage_read = { + ContractStorageRead> contract_storage_read = { to_ct(storage_slot), to_ct(current_value), }; @@ -38,11 +38,11 @@ template struct ContractStorageRead { return contract_storage_read; }; - template ContractStorageRead to_native_type() const + template ContractStorageRead to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; ContractStorageRead contract_storage_read = { to_nt(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp index 862e5f3d4aa2..73109e138861 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/contract_storage_update_request.hpp @@ -23,15 +23,15 @@ template struct ContractStorageUpdateRequest { // for serialization, update with new fields MSGPACK_FIELDS(storage_slot, old_value, new_value); bool operator==(ContractStorageUpdateRequest const&) const = default; - template - ContractStorageUpdateRequest> to_circuit_type(Builder& builder) const + template + ContractStorageUpdateRequest> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - ContractStorageUpdateRequest> update_request = { + ContractStorageUpdateRequest> update_request = { to_ct(storage_slot), to_ct(old_value), to_ct(new_value), @@ -40,11 +40,11 @@ template struct ContractStorageUpdateRequest { return update_request; }; - template ContractStorageUpdateRequest to_native_type() const + template ContractStorageUpdateRequest to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; ContractStorageUpdateRequest update_request = { to_nt(storage_slot), diff --git a/circuits/cpp/src/aztec3/circuits/abis/coordinate.hpp b/circuits/cpp/src/aztec3/circuits/abis/coordinate.hpp index 05dbd9d4d16c..41ae12c64595 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/coordinate.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/coordinate.hpp @@ -22,25 +22,25 @@ template struct Coordinate { MSGPACK_FIELDS(fields); bool operator==(Coordinate const&) const = default; - template Coordinate> to_circuit_type(Builder& builder) const + template Coordinate> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - Coordinate> coordinate = { + Coordinate> coordinate = { to_ct(fields), }; return coordinate; }; - template Coordinate to_native_type() const + template Coordinate to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; Coordinate coordinate = { to_nt(fields), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp index 0248847bfe7c..6e6d939856ad 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_data.hpp @@ -29,14 +29,14 @@ template struct FunctionData { is_constructor == other.is_constructor; }; - template FunctionData> to_circuit_type(Builder& builder) const + template FunctionData> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - FunctionData> function_data = { + FunctionData> function_data = { to_ct(function_selector), to_ct(is_private), to_ct(is_constructor), @@ -45,10 +45,10 @@ template struct FunctionData { return function_data; }; - template FunctionData to_native_type() const + template FunctionData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; FunctionData function_data = { to_nt(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp index 370bf7e81286..f5297667941e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/function_leaf_preimage.hpp @@ -42,14 +42,14 @@ template struct FunctionLeafPreimage { vk_hash == other.vk_hash && acir_hash == other.acir_hash; }; - template FunctionLeafPreimage> to_circuit_type(Builder& builder) const + template FunctionLeafPreimage> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - FunctionLeafPreimage> preimage = { + FunctionLeafPreimage> preimage = { to_ct(function_selector), to_ct(is_private), to_ct(vk_hash), @@ -59,10 +59,10 @@ template struct FunctionLeafPreimage { return preimage; }; - template FunctionLeafPreimage to_native_type() const + template FunctionLeafPreimage to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; FunctionLeafPreimage preimage = { to_nt(function_selector), diff --git a/circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp b/circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp index 480dc6d166b4..7dab5aa8b973 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/global_variables.hpp @@ -30,15 +30,15 @@ template struct GlobalVariables { timestamp == other.timestamp; }; - template GlobalVariables> to_circuit_type(Builder& builder) const + template GlobalVariables> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - GlobalVariables> globals = { + GlobalVariables> globals = { to_ct(chain_id), to_ct(version), to_ct(block_number), diff --git a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp index 462f0df9265e..76b4878d5985 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/kernel_circuit_public_inputs.hpp @@ -31,16 +31,17 @@ template struct KernelCircuitPublicInputs { return end == other.end && constants == other.constants && is_private == other.is_private; }; - template KernelCircuitPublicInputs> to_circuit_type(Builder& builder) const + template + KernelCircuitPublicInputs> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - KernelCircuitPublicInputs> private_inputs = { - end.to_circuit_type(builder), - constants.to_circuit_type(builder), + KernelCircuitPublicInputs> private_inputs = { + end.to_circuit_type(composer), + constants.to_circuit_type(composer), to_ct(is_private), }; @@ -48,11 +49,11 @@ template struct KernelCircuitPublicInputs { return private_inputs; }; - template KernelCircuitPublicInputs to_native_type() const + template KernelCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; KernelCircuitPublicInputs pis = { to_native_type(end), diff --git a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp index fa4256e5d75d..67e9b423e307 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/membership_witness.hpp @@ -24,14 +24,14 @@ template struct MembershipWitness { return leaf_index == other.leaf_index && sibling_path == other.sibling_path; }; - template MembershipWitness, N> to_circuit_type(Builder& builder) const + template MembershipWitness, N> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - MembershipWitness, N> witness = { + MembershipWitness, N> witness = { to_ct(leaf_index), map(sibling_path, to_ct), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp index 462f2df45c0a..c37d6c265e11 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/new_contract_data.hpp @@ -30,24 +30,24 @@ template struct NewContractData { return utils::msgpack_derived_equals(*this, other); }; - template NewContractData> to_circuit_type(Builder& builder) const + template NewContractData> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - NewContractData> new_contract_data = { to_ct(contract_address), - to_ct(portal_contract_address), - to_ct(function_tree_root) }; + NewContractData> new_contract_data = { to_ct(contract_address), + to_ct(portal_contract_address), + to_ct(function_tree_root) }; return new_contract_data; }; - template NewContractData to_native_type() const + template NewContractData to_native_type() const { - static_assert(std::is_same, NCT>::value); + static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; NewContractData new_contract_data = { to_nt(contract_address), to_nt(portal_contract_address), diff --git a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp index 04dad9940f75..8ae52a767e57 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/optionally_revealed_data.hpp @@ -45,16 +45,17 @@ template struct OptionallyRevealedData { called_from_l1 == other.called_from_l1 && called_from_public_l2 == other.called_from_public_l2; }; - template OptionallyRevealedData> to_circuit_type(Builder& builder) const + template + OptionallyRevealedData> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - OptionallyRevealedData> data = { + OptionallyRevealedData> data = { to_ct(call_stack_item_hash), - function_data.to_circuit_type(builder), + function_data.to_circuit_type(composer), to_ct(vk_hash), to_ct(portal_contract_address), to_ct(pay_fee_from_l1), @@ -66,11 +67,11 @@ template struct OptionallyRevealedData { return data; }; - template OptionallyRevealedData to_native_type() const + template OptionallyRevealedData to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; OptionallyRevealedData data = { to_nt(call_stack_item_hash), to_native_type(function_data), to_nt(vk_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/point.hpp b/circuits/cpp/src/aztec3/circuits/abis/point.hpp index e55a25fdfea0..9dc882047dc9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/point.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/point.hpp @@ -24,23 +24,23 @@ template struct Point { MSGPACK_FIELDS(x, y); bool operator==(Point const&) const = default; - template Point> to_circuit_type(Builder& builder) const + template Point> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - Point> point = { - x.to_circuit_type(builder), - y.to_circuit_type(builder), + Point> point = { + x.to_circuit_type(composer), + y.to_circuit_type(composer), }; return point; }; - template Point to_native_type() const + template Point to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; Point point = { to_native_type(x), to_native_type(y) }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp index 5248d3a84487..fb40a0650aef 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/previous_kernel_data.hpp @@ -39,18 +39,18 @@ template struct PreviousKernelData { }; // WARNING: the `proof` does NOT get converted! - template PreviousKernelData> to_circuit_type(Builder& builder) const + template PreviousKernelData> to_circuit_type(Composer& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PreviousKernelData> data = { - public_inputs.to_circuit_type(builder), + PreviousKernelData> data = { + public_inputs.to_circuit_type(composer), proof, // Notice: not converted! Stays as native. - CT::VK::from_witness(&builder, vk), + CT::VK::from_witness(&composer, vk), to_ct(vk_index), to_ct(vk_path), }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp index c85ba2ff946c..8438ba9497b5 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp @@ -74,16 +74,16 @@ template class PrivateCircuitPublicInputs { version == other.version; }; - template - PrivateCircuitPublicInputs> to_circuit_type(Builder& builder) const + template + PrivateCircuitPublicInputs> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PrivateCircuitPublicInputs> pis = { + PrivateCircuitPublicInputs> pis = { to_circuit_type(call_context), to_ct(args_hash), @@ -118,11 +118,11 @@ template class PrivateCircuitPublicInputs { return pis; }; - template PrivateCircuitPublicInputs to_native_type() const + template PrivateCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; PrivateCircuitPublicInputs pis = { to_native_type(call_context), @@ -439,48 +439,48 @@ template class OptionalPrivateCircuitPublicInputs { } } - template void make_unused_inputs_zero(Builder& builder) + template void make_unused_inputs_zero(Composer& composer) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - make_unused_element_zero(builder, call_context); + make_unused_element_zero(composer, call_context); - make_unused_element_zero(builder, args_hash); - make_unused_array_elements_zero(builder, return_values); + make_unused_element_zero(composer, args_hash); + make_unused_array_elements_zero(composer, return_values); - make_unused_array_elements_zero(builder, read_requests); + make_unused_array_elements_zero(composer, read_requests); - make_unused_array_elements_zero(builder, new_commitments); - make_unused_array_elements_zero(builder, new_nullifiers); + make_unused_array_elements_zero(composer, new_commitments); + make_unused_array_elements_zero(composer, new_nullifiers); - make_unused_array_elements_zero(builder, private_call_stack); - make_unused_array_elements_zero(builder, public_call_stack); - make_unused_array_elements_zero(builder, new_l2_to_l1_msgs); + make_unused_array_elements_zero(composer, private_call_stack); + make_unused_array_elements_zero(composer, public_call_stack); + make_unused_array_elements_zero(composer, new_l2_to_l1_msgs); - make_unused_array_elements_zero(builder, encrypted_logs_hash); - make_unused_array_elements_zero(builder, unencrypted_logs_hash); + make_unused_array_elements_zero(composer, encrypted_logs_hash); + make_unused_array_elements_zero(composer, unencrypted_logs_hash); - make_unused_element_zero(builder, encrypted_log_preimages_length); - make_unused_element_zero(builder, unencrypted_log_preimages_length); + make_unused_element_zero(composer, encrypted_log_preimages_length); + make_unused_element_zero(composer, unencrypted_log_preimages_length); - make_unused_element_zero(builder, historic_private_data_tree_root); - make_unused_element_zero(builder, historic_nullifier_tree_root); - make_unused_element_zero(builder, historic_contract_tree_root); - make_unused_element_zero(builder, historic_l1_to_l2_messages_tree_root); + make_unused_element_zero(composer, historic_private_data_tree_root); + make_unused_element_zero(composer, historic_nullifier_tree_root); + make_unused_element_zero(composer, historic_contract_tree_root); + make_unused_element_zero(composer, historic_l1_to_l2_messages_tree_root); - make_unused_element_zero(builder, contract_deployment_data); + make_unused_element_zero(composer, contract_deployment_data); - make_unused_element_zero(builder, chain_id); - make_unused_element_zero(builder, version); + make_unused_element_zero(composer, chain_id); + make_unused_element_zero(composer, version); all_elements_populated = true; } - template void set_public(Builder& builder) + template void set_public(Composer& composer) { static_assert(!(std::is_same::value)); - make_unused_inputs_zero(builder); + make_unused_inputs_zero(composer); // Optional members are guaranteed to be nonempty from here. @@ -515,18 +515,18 @@ template class OptionalPrivateCircuitPublicInputs { (*version).set_public(); } - template - OptionalPrivateCircuitPublicInputs> to_circuit_type(Builder& builder) const + template + OptionalPrivateCircuitPublicInputs> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; auto to_circuit_type = [&](auto& e) { - return e ? std::make_optional((*e).to_circuit_type(builder)) : std::nullopt; + return e ? std::make_optional((*e).to_circuit_type(composer)) : std::nullopt; }; - OptionalPrivateCircuitPublicInputs> pis = { + OptionalPrivateCircuitPublicInputs> pis = { to_circuit_type(call_context), to_ct(args_hash), @@ -561,12 +561,12 @@ template class OptionalPrivateCircuitPublicInputs { return pis; }; - template OptionalPrivateCircuitPublicInputs to_native_type() const + template OptionalPrivateCircuitPublicInputs to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; auto to_native_type = [](const std::optional& e) { - return e ? std::make_optional((*e).template to_native_type()) : std::nullopt; + return e ? std::make_optional((*e).template to_native_type()) : std::nullopt; }; // auto to_native_type = [&](T& e) { return e.to_native_type(); }; @@ -709,37 +709,38 @@ template class OptionalPrivateCircuitPublicInputs { vec.insert(vec.end(), arr.data(), arr.data() + arr_size); } - template - void make_unused_array_elements_zero(Builder& builder, std::array, SIZE>& arr) + template + void make_unused_array_elements_zero(Composer& composer, std::array, SIZE>& arr) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); for (std::optional& e : arr) { - make_unused_element_zero(builder, e); + make_unused_element_zero(composer, e); } } - template void make_unused_element_zero(Builder& builder, std::optional& element) + template + void make_unused_element_zero(Composer& composer, std::optional& element) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); if (!element) { element = - T(witness_t(&builder, 0)); // convert the nullopt value to a circuit witness value of `0` + T(witness_t(&composer, 0)); // convert the nullopt value to a circuit witness value of `0` fr(*element).assert_is_zero(); } } // ABIStruct is a template for any of the structs in the abis/ dir. E.g. ExecutedCallback, CallbackStackItem. - template class ABIStruct> - void make_unused_element_zero(Builder& builder, std::optional>>& element) + template class ABIStruct> + void make_unused_element_zero(Composer& composer, std::optional>>& element) { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); if (!element) { element = ABIStruct().to_circuit_type( - builder); // convert the nullopt value to a circuit witness value of `0` - (*element).template assert_is_zero(); + composer); // convert the nullopt value to a circuit witness value of `0` + (*element).template assert_is_zero(); } } diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp index bbade3dd50a9..a1048a68f152 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_historic_tree_roots.hpp @@ -37,14 +37,15 @@ template struct PrivateHistoricTreeRoots { private_kernel_vk_tree_root == other.private_kernel_vk_tree_root; }; - template PrivateHistoricTreeRoots> to_circuit_type(Builder& builder) const + template + PrivateHistoricTreeRoots> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PrivateHistoricTreeRoots> data = { + PrivateHistoricTreeRoots> data = { to_ct(private_data_tree_root), to_ct(nullifier_tree_root), to_ct(contract_tree_root), to_ct(l1_to_l2_messages_tree_root), to_ct(private_kernel_vk_tree_root), }; @@ -52,10 +53,10 @@ template struct PrivateHistoricTreeRoots { return data; }; - template PrivateHistoricTreeRoots to_native_type() const + template PrivateHistoricTreeRoots to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PrivateHistoricTreeRoots data = { to_nt(private_data_tree_root), to_nt(nullifier_tree_root), to_nt(contract_tree_root), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp index 1a527f39c745..68b6bc041e87 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/call_context_reconciliation_data.hpp @@ -33,16 +33,16 @@ // std::array, NEW_L2_TO_L1_MSGS_LENGTH> l1_call_contexts; // std::array l1_counterparts; // TODO: this is probably wrong. -// template -// CallContextReconciliationData> to_circuit_type(Builder& builder) const +// template +// CallContextReconciliationData> to_circuit_type(Composer& composer) const // { // static_assert((std::is_same::value)); -// // Capture the circuit builder: -// auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; -// auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; +// // Capture the composer: +// auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; +// auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; -// CallContextReconciliationData> data = { +// CallContextReconciliationData> data = { // map(private_call_contexts, to_circuit_type), to_ct(private_counterparts), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp index c0dddfa2d656..8edb04939535 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/globals.hpp @@ -19,14 +19,14 @@ template struct Globals { boolean operator==(Globals const& other) const { return min_timestamp == other.min_timestamp; }; - template Globals> to_circuit_type(Builder& builder) const + template Globals> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - Globals> global_data = { to_ct(min_timestamp) }; + Globals> global_data = { to_ct(min_timestamp) }; return global_data; }; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp index b9887739eb21..7611fa1c82d5 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_call_data.hpp @@ -55,29 +55,29 @@ template struct PrivateCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PrivateCallData> to_circuit_type(Builder& builder) const + template PrivateCallData> to_circuit_type(Composer& composer) const { - typedef CircuitTypes CT; + typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PrivateCallData> data = { + PrivateCallData> data = { to_circuit_type(call_stack_item), map(private_call_stack_preimages, to_circuit_type), proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function // currently works. - CT::VK::from_witness(&builder, vk), + CT::VK::from_witness(&composer, vk), to_circuit_type(function_leaf_membership_witness), to_circuit_type(contract_leaf_membership_witness), - aztec3::utils::types::to_ct>( - builder, read_request_membership_witnesses), + aztec3::utils::types::to_ct>( + composer, read_request_membership_witnesses), to_ct(portal_contract_address), to_ct(acir_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp index bd49b7d3fbb5..6f6db83d8fbc 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp @@ -24,14 +24,15 @@ template struct PrivateKernelInputsInit { return tx_request == other.tx_request && private_call == other.private_call; }; - template PrivateKernelInputsInit> to_circuit_type(Builder& builder) const + template + PrivateKernelInputsInit> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - PrivateKernelInputsInit> private_inputs = { + PrivateKernelInputsInit> private_inputs = { // TODO to_ct(signature), - tx_request.to_circuit_type(builder), - private_call.to_circuit_type(builder), + tx_request.to_circuit_type(composer), + private_call.to_circuit_type(composer), }; return private_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp index 63ed04c36556..f29ab8bbc371 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp @@ -26,13 +26,14 @@ template struct PrivateKernelInputsInner { return previous_kernel == other.previous_kernel && private_call == other.private_call; }; - template PrivateKernelInputsInner> to_circuit_type(Builder& builder) const + template + PrivateKernelInputsInner> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - PrivateKernelInputsInner> private_inputs = { - previous_kernel.to_circuit_type(builder), - private_call.to_circuit_type(builder), + PrivateKernelInputsInner> private_inputs = { + previous_kernel.to_circuit_type(composer), + private_call.to_circuit_type(composer), }; return private_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp index be90f83b167f..f8982555da56 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_circuit_public_inputs.hpp @@ -69,15 +69,16 @@ template struct PublicCircuitPublicInputs { return msgpack_derived_equals(*this, other); } - template PublicCircuitPublicInputs> to_circuit_type(Builder& builder) const + template + PublicCircuitPublicInputs> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PublicCircuitPublicInputs> pis = { + PublicCircuitPublicInputs> pis = { .call_context = to_circuit_type(call_context), .args_hash = to_ct(args_hash), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp index 2d76f269ede7..f8c1830bd5f9 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_read.hpp @@ -23,14 +23,14 @@ template struct PublicDataRead { MSGPACK_FIELDS(leaf_index, value); bool operator==(PublicDataRead const&) const = default; - template PublicDataRead> to_circuit_type(Builder& builder) const + template PublicDataRead> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PublicDataRead> read = { + PublicDataRead> read = { to_ct(leaf_index), to_ct(value), }; @@ -38,11 +38,11 @@ template struct PublicDataRead { return read; }; - template PublicDataRead to_native_type() const + template PublicDataRead to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PublicDataRead read = { to_nt(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp index 152cb9c8ef19..866291ff53b4 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_data_update_request.hpp @@ -24,14 +24,15 @@ template struct PublicDataUpdateRequest { MSGPACK_FIELDS(leaf_index, old_value, new_value); bool operator==(PublicDataUpdateRequest const&) const = default; - template PublicDataUpdateRequest> to_circuit_type(Builder& builder) const + template + PublicDataUpdateRequest> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - PublicDataUpdateRequest> update_request = { + PublicDataUpdateRequest> update_request = { to_ct(leaf_index), to_ct(old_value), to_ct(new_value), @@ -40,11 +41,11 @@ template struct PublicDataUpdateRequest { return update_request; }; - template PublicDataUpdateRequest to_native_type() const + template PublicDataUpdateRequest to_native_type() const { - static_assert((std::is_same, NCT>::value)); + static_assert((std::is_same, NCT>::value)); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; PublicDataUpdateRequest update_request = { to_nt(leaf_index), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp index 3a69895231f5..d242b7f2a69e 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_call_data.hpp @@ -43,23 +43,23 @@ template struct PublicCallData { // WARNING: the `proof` does NOT get converted! (because the current implementation of `verify_proof` takes a proof // of native bytes; any conversion to circuit types happens within the `verify_proof` function) - template PublicCallData> to_circuit_type(Builder& builder) const + template PublicCallData> to_circuit_type(Composer& composer) const { - // typedef CircuitTypes CT; + // typedef CircuitTypes CT; static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - PublicCallData> data = { - call_stack_item.to_circuit_type(builder), + PublicCallData> data = { + call_stack_item.to_circuit_type(composer), map(public_call_stack_preimages, to_circuit_type), proof, // Notice: not converted! Stays as native. This is because of how the verify_proof function // currently works. - // CT::VK::from_witness(&builder, vk), + // CT::VK::from_witness(&composer, vk), // to_circuit_type(function_leaf_membership_witness), // to_circuit_type(contract_leaf_membership_witness), diff --git a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp index 38b3bbd31410..f4a50dd7e485 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp @@ -28,13 +28,13 @@ template struct PublicKernelInputs { return previous_kernel == other.previous_kernel && public_call == other.public_call; }; - template PublicKernelInputs> to_circuit_type(Builder& builder) const + template PublicKernelInputs> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - PublicKernelInputs> public_kernel_inputs = { - previous_kernel.to_circuit_type(builder), - public_call.to_circuit_type(builder), + PublicKernelInputs> public_kernel_inputs = { + previous_kernel.to_circuit_type(composer), + public_call.to_circuit_type(composer), }; return public_kernel_inputs; diff --git a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp index c9bfc1b36772..47819a5b861a 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/rollup/constant_rollup_data.hpp @@ -3,6 +3,7 @@ #include "../append_only_tree_snapshot.hpp" #include "../global_variables.hpp" +#include "barretenberg/common/serialize.hpp" #include namespace aztec3::circuits::abis { diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp index eb7a8aa725e3..16abc72fca7b 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_context.hpp @@ -6,6 +6,7 @@ #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" +#include "barretenberg/common/serialize.hpp" #include namespace aztec3::circuits::abis { @@ -42,19 +43,19 @@ template struct TxContext { version == other.version; }; - template TxContext> to_circuit_type(Builder& builder) const + template TxContext> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + // auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - TxContext> tx_context = { + TxContext> tx_context = { to_ct(is_fee_payment_tx), to_ct(is_rebate_payment_tx), to_ct(is_contract_deployment_tx), - contract_deployment_data.to_circuit_type(builder), + contract_deployment_data.to_circuit_type(composer), to_ct(chain_id), to_ct(version), }; @@ -62,11 +63,11 @@ template struct TxContext { return tx_context; }; - template TxContext to_native_type() const + template TxContext to_native_type() const { - static_assert(std::is_same, NCT>::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; - auto to_native_type = [](T& e) { return e.template to_native_type(); }; + static_assert(std::is_same, NCT>::value); + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_native_type = [](T& e) { return e.template to_native_type(); }; TxContext tx_context = { to_nt(is_fee_payment_tx), to_nt(is_rebate_payment_tx), diff --git a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp index 1a9ff0d78815..d9b74a4a9ff1 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/tx_request.hpp @@ -30,15 +30,15 @@ template struct TxRequest { tx_context == other.tx_context; }; - template TxRequest> to_circuit_type(Builder& builder) const + template TxRequest> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; - TxRequest> tx_request = { + TxRequest> tx_request = { to_ct(origin), to_circuit_type(function_data), to_ct(args_hash), diff --git a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp index ab4ca379df42..8f60b0eed1c1 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/.test.cpp @@ -24,8 +24,8 @@ #include namespace { -// Builder -using C = UltraCircuitBuilder; +// Composer +using C = plonk::UltraPlonkComposer; // Types using CT = aztec3::utils::types::CircuitTypes; @@ -55,7 +55,7 @@ using aztec3::circuits::apps::notes::DefaultPrivateNote; using aztec3::circuits::apps::notes::DefaultSingletonPrivateNote; // State variables -// Get rid of ugly `Builder` template arg from our state var types: +// Get rid of ugly `Composer` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXO = UTXOStateVar; template using UTXOSet = UTXOSetStateVar; @@ -97,11 +97,11 @@ TEST_F(state_var_tests, circuit_mapping) // contains a reference to earlier-declared classes... so we'd end up with classes containing dangling references, // if all this stuff were to be declared in a setup function's scope. // We could instead store shared_ptrs in every class...? - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); // TODO: // Interestingly, if I scope the below, the debugger works, but running the test via the command line fails. This is @@ -120,7 +120,7 @@ TEST_F(state_var_tests, circuit_mapping) Mapping my_mapping(&exec_ctx, "my_mapping"); - my_mapping[5] = to_ct(builder, NT::fr(5)); + my_mapping[5] = to_ct(composer, NT::fr(5)); // info("my_mapping[5]: ", my_mapping[5]); // info("my_mapping[5].start_slot: ", my_mapping[5].start_slot); @@ -129,11 +129,11 @@ TEST_F(state_var_tests, circuit_mapping) TEST_F(state_var_tests, circuit_mapping_within_mapping) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); // { ::Contract contract("TestContract"); @@ -151,11 +151,11 @@ TEST_F(state_var_tests, circuit_mapping_within_mapping) TEST_F(state_var_tests, circuit_partial_mapping) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); // { ::Contract contract("TestContract"); @@ -173,11 +173,11 @@ TEST_F(state_var_tests, circuit_partial_mapping) TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); @@ -220,11 +220,11 @@ TEST_F(state_var_tests, circuit_utxo_of_default_private_note_fr) TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); // bool sort(NT::uint256 i, NT::uint256 j) // { @@ -282,11 +282,11 @@ TEST_F(state_var_tests, circuit_utxo_set_of_default_private_notes_fr) TEST_F(state_var_tests, circuit_initialise_utxo_of_default_singleton_private_note_fr) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); @@ -330,11 +330,11 @@ TEST_F(state_var_tests, circuit_initialise_utxo_of_default_singleton_private_not TEST_F(state_var_tests, circuit_modify_utxo_of_default_singleton_private_note_fr) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); ::Contract contract("TestContract"); exec_ctx.register_contract(&contract); diff --git a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp index cfb880a96ccb..537d9dc8ff81 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/contract.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/contract.hpp @@ -12,7 +12,7 @@ using aztec3::circuits::abis::FunctionData; using NT = aztec3::utils::types::NativeTypes; -// template class FunctionExecutionContext; +// template class FunctionExecutionContext; template class Contract { using fr = typename NCT::fr; diff --git a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp index f44ff1cbc71a..6f90ced32977 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/function_execution_context.hpp @@ -34,34 +34,34 @@ using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using aztec3::utils::types::to_nt; -template class FunctionExecutionContext { +template class FunctionExecutionContext { using NT = NativeTypes; - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using address = typename CT::address; // We restrict only the opcodes to be able to push to the private members of the exec_ctx. // This will just help us build better separation of concerns. - friend class Opcodes; + friend class Opcodes; public: - Builder& builder; - OracleWrapperInterface& oracle; + Composer& composer; + OracleWrapperInterface& oracle; Contract* contract = nullptr; - std::array>, PRIVATE_CALL_STACK_LENGTH> + std::array>, PRIVATE_CALL_STACK_LENGTH> nested_private_call_exec_ctxs; // TODO: make this private! OptionalPrivateCircuitPublicInputs private_circuit_public_inputs{}; private: - std::vector>> new_notes; + std::vector>> new_notes; std::vector new_commitments; // Nullifier preimages can be got from the corresponding Note that they nullify. - std::vector>> nullified_notes; + std::vector>> nullified_notes; std::vector new_nullifiers; PrivateCircuitPublicInputs final_private_circuit_public_inputs{}; @@ -69,8 +69,8 @@ template class FunctionExecutionContext { bool is_finalised = false; public: - FunctionExecutionContext(Builder& builder, OracleWrapperInterface& oracle) - : builder(builder) + FunctionExecutionContext(Composer& composer, OracleWrapperInterface& oracle) + : composer(composer) , oracle(oracle) , private_circuit_public_inputs(OptionalPrivateCircuitPublicInputs::create()) { @@ -89,13 +89,13 @@ template class FunctionExecutionContext { // TODO: consider making this a debug-only method. // Not a reference, because we won't want to allow unsafe access. Hmmm, except it's a vector of pointers, so one can // still modify the pointers... But at least the original vector isn't being pushed-to or deleted-from. - std::vector>> get_new_notes() { return new_notes; } + std::vector>> get_new_notes() { return new_notes; } std::vector get_new_nullifiers() { return new_nullifiers; } - void push_new_note(NoteInterface* const note_ptr) { new_notes.push_back(note_ptr); } + void push_new_note(NoteInterface* const note_ptr) { new_notes.push_back(note_ptr); } - void push_newly_nullified_note(NoteInterface* note_ptr) { nullified_notes.push_back(note_ptr); } + void push_newly_nullified_note(NoteInterface* note_ptr) { nullified_notes.push_back(note_ptr); } PrivateCircuitPublicInputs get_final_private_circuit_public_inputs() { @@ -157,7 +157,7 @@ template class FunctionExecutionContext { std::array call( address const& f_contract_address, std::string const& f_name, - std::function&, std::vector)> f, + std::function&, std::vector)> f, std::vector const& args) { // Convert function name to bytes and use the first 4 bytes as the function encoding, for now: @@ -169,10 +169,10 @@ template class FunctionExecutionContext { fr f_encoding_ct = fr(f_encoding); // Important Note: we MUST constrain this function_selector value against a fixed selector value. Without the // below line, an attacker could pass any f_encoding as a witness. - f_encoding_ct.convert_constant_to_fixed_witness(&builder); + f_encoding_ct.convert_constant_to_fixed_witness(&composer); /// @dev The above constraining could alternatively be achieved as follows: - // fr alternative_f_encoding_ct = fr(to_ct(builder, f_encoding)); + // fr alternative_f_encoding_ct = fr(to_ct(composer, f_encoding)); // alternative_f_encoding_ct.fix_witness(); const FunctionData f_function_data_ct{ @@ -193,33 +193,33 @@ template class FunctionExecutionContext { NativeOracle f_oracle(oracle.native_oracle.db, f_contract_address.get_value(), - f_function_data_ct.template to_native_type(), - f_call_context_ct.template to_native_type(), + f_function_data_ct.template to_native_type(), + f_call_context_ct.template to_native_type(), oracle.get_msg_sender_private_key() .get_value() // TODO: consider whether a nested function should even be able to // access a private key, given that the call is now coming from a // contract (which cannot own a secret), rather than a human. ); - Builder f_builder = Builder(); + Composer f_composer = Composer("../barretenberg/cpp/srs_db/ignition"); - OracleWrapperInterface f_oracle_wrapper(f_builder, f_oracle); + OracleWrapperInterface f_oracle_wrapper(f_composer, f_oracle); // We need an exec_ctx reference which won't go out of scope, so we store a shared_ptr to the newly-created // exec_ctx in `this` exec_ctx. - auto f_exec_ctx = std::make_shared>(f_builder, f_oracle_wrapper); + auto f_exec_ctx = std::make_shared>(f_composer, f_oracle_wrapper); array_push(nested_private_call_exec_ctxs, f_exec_ctx); - auto native_args = to_nt(args); + auto native_args = to_nt(args); // This calls the function `f`, passing the arguments shown. // The f_exec_ctx will be populated with all the information about that function's execution. std::apply(f, std::forward_as_tuple(*f_exec_ctx, native_args)); - // Remember: the data held in the f_exec_ctc was built with a different builder than that + // Remember: the data held in the f_exec_ctc was built with a different composer than that // of `this` exec_ctx. So we only allow ourselves to get the native types, so that we can consciously declare - // circuit types for `this` exec_ctx using `this->builder`. + // circuit types for `this` exec_ctx using `this->composer`. auto f_public_inputs_nt = f_exec_ctx->get_final_private_circuit_public_inputs(); // Since we've made a call to another function, we now need to push a call_stack_item_hash to `this` function's @@ -228,7 +228,7 @@ template class FunctionExecutionContext { // - args // - return_values // - call_context (TODO: maybe this only needs to be done in the kernel circuit). - auto f_public_inputs_ct = f_public_inputs_nt.to_circuit_type(builder); + auto f_public_inputs_ct = f_public_inputs_nt.to_circuit_type(composer); // Constrain that the arguments of the executed function match those we expect: auto args_hash_ct = compute_var_args_hash(args); @@ -242,7 +242,7 @@ template class FunctionExecutionContext { auto call_stack_item_hash = f_call_stack_item_ct.hash(); - array_push(private_circuit_public_inputs.private_call_stack, call_stack_item_hash); + array_push(private_circuit_public_inputs.private_call_stack, call_stack_item_hash); // The return values are implicitly constrained by being returned as circuit types from this method, for // further use in the circuit. Note: ALL elements of the return_values array MUST be constrained, even if @@ -294,7 +294,7 @@ template class FunctionExecutionContext { // This is almost a visitor pattern. Call methods on each note. The note will choose what to do. for (size_t i = 0; i < new_notes.size(); ++i) { - NoteInterface& note = *new_notes[i]; + NoteInterface& note = *new_notes[i]; if (note.needs_nonce()) { const bool next_nullifier_available = new_nullifiers_copy.size() > used_nullifiers_count; @@ -320,9 +320,9 @@ template class FunctionExecutionContext { finalise_utxos(); private_circuit_public_inputs.set_commitments(new_commitments); private_circuit_public_inputs.set_nullifiers(new_nullifiers); - private_circuit_public_inputs.set_public(builder); + private_circuit_public_inputs.set_public(composer); final_private_circuit_public_inputs = - private_circuit_public_inputs.remove_optionality().template to_native_type(); + private_circuit_public_inputs.remove_optionality().template to_native_type(); is_finalised = true; } }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp index 1da0b8655502..c4c8a81e4bb4 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.hpp @@ -9,7 +9,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { -template class StateVar; +template class StateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { @@ -19,19 +19,19 @@ using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; -template class DefaultPrivateNote : public NoteInterface { +template class DefaultPrivateNote : public NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; using boolean = typename CT::boolean; - using NotePreimage = DefaultPrivateNotePreimage, ValueType>; - using NullifierPreimage = DefaultPrivateNoteNullifierPreimage>; + using NotePreimage = DefaultPrivateNotePreimage, ValueType>; + using NullifierPreimage = DefaultPrivateNoteNullifierPreimage>; - StateVar* state_var; + StateVar* state_var; private: std::optional commitment; @@ -42,7 +42,7 @@ template class DefaultPrivateNote : publi std::optional nullifier_preimage; public: - DefaultPrivateNote(StateVar* state_var, NotePreimage note_preimage) + DefaultPrivateNote(StateVar* state_var, NotePreimage note_preimage) : state_var(state_var), note_preimage(note_preimage){}; ~DefaultPrivateNote() override = default; @@ -77,7 +77,7 @@ template class DefaultPrivateNote : publi // return *partial_commitment; // }; - void constrain_against_advice(NoteInterface const& advice_note) override; + void constrain_against_advice(NoteInterface const& advice_note) override; bool needs_nonce() override; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp index 03dc64c7d1f8..15826362d3ab 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp @@ -26,35 +26,35 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template void DefaultPrivateNote::remove() +template void DefaultPrivateNote::remove() { - Opcodes::UTXO_NULL(state_var, *this); + Opcodes::UTXO_NULL(state_var, *this); } -template auto& DefaultPrivateNote::get_oracle() +template auto& DefaultPrivateNote::get_oracle() { return state_var->exec_ctx->oracle; } -template bool DefaultPrivateNote::is_partial_preimage() const +template bool DefaultPrivateNote::is_partial_preimage() const { const auto& [value, owner, creator_address, memo, salt, nonce, _] = note_preimage; return (!value || !owner || !creator_address || !memo || !salt || !nonce); } -template bool DefaultPrivateNote::is_partial_storage_slot() const +template bool DefaultPrivateNote::is_partial_storage_slot() const { return state_var->is_partial_slot; } -template bool DefaultPrivateNote::is_partial() const +template bool DefaultPrivateNote::is_partial() const { return is_partial_preimage() || is_partial_storage_slot(); } -template -typename CircuitTypes::fr DefaultPrivateNote::compute_commitment() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_commitment() { if (commitment.has_value()) { return *commitment; @@ -108,8 +108,8 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_commi return *commitment; } -template -typename CircuitTypes::grumpkin_point DefaultPrivateNote::compute_partial_commitment() +template +typename CircuitTypes::grumpkin_point DefaultPrivateNote::compute_partial_commitment() { if (partial_commitment.has_value()) { info( @@ -161,8 +161,8 @@ typename CircuitTypes::grumpkin_point DefaultPrivateNote::c return *partial_commitment; } -template -typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier() { if (is_partial()) { throw_or_abort("Can't nullify a partial note."); @@ -177,7 +177,7 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nulli fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); nullifier = - DefaultPrivateNote::compute_nullifier(*commitment, owner_private_key, note_preimage.is_dummy); + DefaultPrivateNote::compute_nullifier(*commitment, owner_private_key, note_preimage.is_dummy); nullifier_preimage = { *commitment, owner_private_key, @@ -186,21 +186,20 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nulli return *nullifier; }; -template -typename CircuitTypes::fr DefaultPrivateNote::compute_dummy_nullifier() +template +typename CircuitTypes::fr DefaultPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); fr const dummy_commitment = oracle.generate_random_element(); fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; - return DefaultPrivateNote::compute_nullifier(dummy_commitment, owner_private_key, is_dummy_commitment); + return DefaultPrivateNote::compute_nullifier(dummy_commitment, owner_private_key, is_dummy_commitment); }; -template -typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier(fr const& commitment, - fr const& owner_private_key, - boolean const& is_dummy_commitment) +template +typename CircuitTypes::fr DefaultPrivateNote::compute_nullifier( + fr const& commitment, fr const& owner_private_key, boolean const& is_dummy_commitment) { /** * Hashing the private key in this way enables the following use case: @@ -237,11 +236,11 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_nulli return fr(blake_result); }; -template -void DefaultPrivateNote::constrain_against_advice(NoteInterface const& advice_note) +template +void DefaultPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const auto& advice_note_ref = dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { @@ -260,20 +259,20 @@ void DefaultPrivateNote::constrain_against_advice(NoteInterface bool DefaultPrivateNote::needs_nonce() +template bool DefaultPrivateNote::needs_nonce() { return !note_preimage.nonce; } -template -void DefaultPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) +template +void DefaultPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) { ASSERT(!note_preimage.nonce); note_preimage.nonce = nonce; }; -template -typename CircuitTypes::fr DefaultPrivateNote::generate_nonce() +template +typename CircuitTypes::fr DefaultPrivateNote::generate_nonce() { ASSERT(!note_preimage.nonce); note_preimage.nonce = compute_dummy_nullifier(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index 7d24e75678a1..a520e8e4b852 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -31,12 +31,12 @@ template struct DefaultPrivateNotePreimage { bool operator==(DefaultPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Builder& builder) const + template auto to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; // Depending on whether the _circuit_ type version of `V` is from the stdlib, or some custom type, the // conversion method will be different. @@ -60,7 +60,7 @@ template struct DefaultPrivateNotePreimage { // When this method is called, this class must be templated over native types. We can avoid templating over the // circuit types (for the return values) (in order to make the calling syntax cleaner) with the below `decltype` // deduction of the _circuit_ version of template type `V`. - DefaultPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { + DefaultPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { circuit_value, to_ct(owner), to_ct(creator_address), to_ct(memo), to_ct(salt), to_ct(nonce), to_ct(is_dummy), }; @@ -68,11 +68,11 @@ template struct DefaultPrivateNotePreimage { return preimage; }; - template auto to_native_type() const + template auto to_native_type() const { static_assert(!std::is_same::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; // See `to_circuit_type()` for explanation of this code. const bool has_to_native_type = requires(V v) { v.to_native_type(); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp index 01a7a6e255bd..fdc9658b4587 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/nullifier_preimage.hpp @@ -21,15 +21,15 @@ template struct DefaultPrivateNoteNullifierPreimage { bool operator==(DefaultPrivateNoteNullifierPreimage const&) const = default; - template - DefaultPrivateNoteNullifierPreimage> to_circuit_type(Builder& builder) const + template + DefaultPrivateNoteNullifierPreimage> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - DefaultPrivateNoteNullifierPreimage> preimage = { + DefaultPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), to_ct(owner_private_key), to_ct(is_dummy), diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp index 3edefba7d6a5..a3f231f13075 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.hpp @@ -9,7 +9,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps::state_vars { -template class StateVar; +template class StateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::notes { @@ -19,19 +19,19 @@ using aztec3::circuits::apps::state_vars::StateVar; // Don't #include it! using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; -template class DefaultSingletonPrivateNote : public NoteInterface { +template class DefaultSingletonPrivateNote : public NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; using boolean = typename CT::boolean; - using NotePreimage = DefaultSingletonPrivateNotePreimage, ValueType>; - using NullifierPreimage = DefaultSingletonPrivateNoteNullifierPreimage>; + using NotePreimage = DefaultSingletonPrivateNotePreimage, ValueType>; + using NullifierPreimage = DefaultSingletonPrivateNoteNullifierPreimage>; - StateVar* state_var; + StateVar* state_var; private: std::optional commitment; @@ -41,7 +41,7 @@ template class DefaultSingletonPrivateNot std::optional nullifier_preimage; public: - DefaultSingletonPrivateNote(StateVar* state_var, NotePreimage note_preimage) + DefaultSingletonPrivateNote(StateVar* state_var, NotePreimage note_preimage) : state_var(state_var), note_preimage(note_preimage){}; ~DefaultSingletonPrivateNote() override = default; @@ -66,7 +66,7 @@ template class DefaultSingletonPrivateNot return compute_nullifier(); }; - void constrain_against_advice(NoteInterface const& advice_note) override; + void constrain_against_advice(NoteInterface const& advice_note) override; bool needs_nonce() override; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp index f89ccd82070c..6d7c4173037a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp @@ -26,35 +26,35 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template void DefaultSingletonPrivateNote::remove() +template void DefaultSingletonPrivateNote::remove() { - Opcodes::UTXO_NULL(state_var, *this); + Opcodes::UTXO_NULL(state_var, *this); } -template auto& DefaultSingletonPrivateNote::get_oracle() +template auto& DefaultSingletonPrivateNote::get_oracle() { return state_var->exec_ctx->oracle; } -template bool DefaultSingletonPrivateNote::is_partial_preimage() const +template bool DefaultSingletonPrivateNote::is_partial_preimage() const { const auto& [value, owner, salt, nonce] = note_preimage; return (!value || !owner || !salt || !nonce); } -template bool DefaultSingletonPrivateNote::is_partial_storage_slot() const +template bool DefaultSingletonPrivateNote::is_partial_storage_slot() const { return state_var->is_partial_slot; } -template bool DefaultSingletonPrivateNote::is_partial() const +template bool DefaultSingletonPrivateNote::is_partial() const { return is_partial_preimage() || is_partial_storage_slot(); } -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_commitment() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_commitment() { if (commitment.has_value()) { return *commitment; @@ -98,8 +98,8 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp return *commitment; } -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier() { if (is_partial()) { throw_or_abort("Can't nullify a partial note."); @@ -113,7 +113,7 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp fr const& owner_private_key = get_oracle().get_msg_sender_private_key(); - nullifier = DefaultSingletonPrivateNote::compute_nullifier(*commitment, owner_private_key); + nullifier = DefaultSingletonPrivateNote::compute_nullifier(*commitment, owner_private_key); nullifier_preimage = { *commitment, owner_private_key, @@ -121,20 +121,20 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp return *nullifier; }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_dummy_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_dummy_nullifier() { auto& oracle = get_oracle(); fr const dummy_commitment = oracle.generate_random_element(); fr const& owner_private_key = oracle.get_msg_sender_private_key(); const boolean is_dummy_commitment = true; - return DefaultSingletonPrivateNote::compute_nullifier( + return DefaultSingletonPrivateNote::compute_nullifier( dummy_commitment, owner_private_key, is_dummy_commitment); }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier( +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::compute_nullifier( fr const& commitment, fr const& owner_private_key, boolean const& is_dummy_commitment) { /** @@ -172,11 +172,11 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp return fr(blake_result); }; -template -void DefaultSingletonPrivateNote::constrain_against_advice(NoteInterface const& advice_note) +template +void DefaultSingletonPrivateNote::constrain_against_advice(NoteInterface const& advice_note) { // Cast from a ref to the base (interface) type to a ref to this derived type: - const auto& advice_note_ref = dynamic_cast&>(advice_note); + const auto& advice_note_ref = dynamic_cast&>(advice_note); auto assert_equal = [](std::optional& this_member, std::optional const& advice_member) { if (advice_member) { @@ -193,28 +193,28 @@ void DefaultSingletonPrivateNote::constrain_against_advice(NoteInter assert_equal(this_preimage.nonce, advice_preimage.nonce); } -template bool DefaultSingletonPrivateNote::needs_nonce() +template bool DefaultSingletonPrivateNote::needs_nonce() { return !note_preimage.nonce; } -template -void DefaultSingletonPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) +template +void DefaultSingletonPrivateNote::set_nonce(typename CircuitTypes::fr const& nonce) { ASSERT(!note_preimage.nonce); note_preimage.nonce = nonce; }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::generate_nonce() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::generate_nonce() { ASSERT(!note_preimage.nonce); note_preimage.nonce = compute_dummy_nullifier(); return *(note_preimage.nonce); }; -template -typename CircuitTypes::fr DefaultSingletonPrivateNote::get_initialisation_nullifier() +template +typename CircuitTypes::fr DefaultSingletonPrivateNote::get_initialisation_nullifier() { auto& oracle = get_oracle(); @@ -234,7 +234,7 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::get_ const fr compressed_storage_slot_point = CT::compress(hash_inputs, GeneratorIndex::INITIALISATION_NULLIFIER); // For now, we piggy-back on the regular nullifier function. - return DefaultSingletonPrivateNote::compute_nullifier( + return DefaultSingletonPrivateNote::compute_nullifier( compressed_storage_slot_point, owner_private_key, is_dummy); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp index df512dc60404..3e84dbb5f24d 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note_preimage.hpp @@ -27,12 +27,12 @@ template struct DefaultSingletonPrivateNotePreimage { bool operator==(DefaultSingletonPrivateNotePreimage const&) const = default; - template auto to_circuit_type(Builder& builder) const + template auto to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; // Depending on whether the _circuit_ type version of `V` is from the stdlib, or some custom type, the // conversion method will be different. @@ -56,7 +56,7 @@ template struct DefaultSingletonPrivateNotePreimage { // When this method is called, this class must be templated over native types. We can avoid templating over the // circuit types (for the return values) (in order to make the calling syntax cleaner) with the below `decltype` // deduction of the _circuit_ version of template type `V`. - DefaultSingletonPrivateNotePreimage, typename decltype(circuit_value)::value_type> + DefaultSingletonPrivateNotePreimage, typename decltype(circuit_value)::value_type> preimage = { circuit_value, to_ct(owner), @@ -67,11 +67,11 @@ template struct DefaultSingletonPrivateNotePreimage { return preimage; }; - template auto to_native_type() const + template auto to_native_type() const { static_assert(!std::is_same::value); - auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; + auto to_nt = [&](auto& e) { return aztec3::utils::types::to_nt(e); }; // See `to_circuit_type()` for explanation of this code. const bool has_to_native_type = requires(V v) { v.to_native_type(); }; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp index 3db90a996e45..0e7765e2c456 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/nullifier_preimage.hpp @@ -21,15 +21,15 @@ template struct DefaultSingletonPrivateNoteNullifierPreimage { bool operator==(DefaultSingletonPrivateNoteNullifierPreimage const&) const = default; - template - DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Builder& builder) const + template + DefaultSingletonPrivateNoteNullifierPreimage> to_circuit_type(Composer& composer) const { static_assert((std::is_same::value)); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - DefaultSingletonPrivateNoteNullifierPreimage> preimage = { + DefaultSingletonPrivateNoteNullifierPreimage> preimage = { to_ct(commitment), to_ct(owner_private_key), to_ct(is_dummy), diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp index 58cda9e8a322..beddc7167100 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/note_interface.hpp @@ -13,9 +13,9 @@ using aztec3::utils::types::CircuitTypes; * It's essentially a visitor pattern. The Opcodes and UTXOStateVar types can call all of these * methods on any Note, and the Note must choose whether to compute something, or whether to throw, for each method. */ -template class NoteInterface { +template class NoteInterface { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; @@ -40,7 +40,7 @@ template class NoteInterface { virtual fr get_initialisation_nullifier() = 0; - virtual void constrain_against_advice(NoteInterface const& advice_note) = 0; + virtual void constrain_against_advice(NoteInterface const& advice_note) = 0; virtual bool needs_nonce() = 0; diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp index 59e715f1d0f4..55c4aeacfa30 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.hpp @@ -6,9 +6,9 @@ #include namespace aztec3::circuits::apps::state_vars { -template class StateVar; -template class UTXOStateVar; -template class UTXOSetStateVar; +template class StateVar; +template class UTXOStateVar; +template class UTXOSetStateVar; } // namespace aztec3::circuits::apps::state_vars namespace aztec3::circuits::apps::opcodes { @@ -31,9 +31,9 @@ using plonk::stdlib::witness_t; * * TODO: Any oracle access or exec_ctx access should go through this class? */ -template class Opcodes { +template class Opcodes { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using address = typename CT::address; /** @@ -43,7 +43,7 @@ template class Opcodes { * - Validate the data */ template - static Note UTXO_SLOAD(UTXOStateVar* utxo_state_var, typename Note::NotePreimage const& advice); + static Note UTXO_SLOAD(UTXOStateVar* utxo_state_var, typename Note::NotePreimage const& advice); /** * @brief @@ -51,26 +51,26 @@ template class Opcodes { * - Generate constraints to prove each datum's existence in the tree * - Validate the data */ - template static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, + template static std::vector UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, size_t const& num_notes, typename Note::NotePreimage const& advice); /** * @brief Compute and push a new nullifier to the public inputs of this exec_ctx. */ - template static void UTXO_NULL(StateVar* state_var, Note& note_to_nullify); + template static void UTXO_NULL(StateVar* state_var, Note& note_to_nullify); /** * @brief Compute and push a new commitment to the public inputs of this exec_ctx, BUT ALSO compute and produce an * initialisation nullifier, to prevent this note from being initialised again in the future. */ - template static void UTXO_INIT(StateVar* state_var, Note& note_to_initialise); + template static void UTXO_INIT(StateVar* state_var, Note& note_to_initialise); /** * @brief Compute and push a new commitment to the public inputs of this exec_ctx. */ template - static void UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage); + static void UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage); }; } // namespace aztec3::circuits::apps::opcodes diff --git a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp index 9c49b7ea1b9b..f3716aefd4e0 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/opcodes/opcodes.tpp @@ -26,9 +26,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; -template template -Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, - typename Note::NotePreimage const& advice) +template template +Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, + typename Note::NotePreimage const& advice) { auto& oracle = utxo_state_var->exec_ctx->oracle; @@ -59,10 +59,10 @@ Note Opcodes::UTXO_SLOAD(UTXOStateVar* utxo_state_var, return new_note; }; -template template -std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, - size_t const& num_notes, - typename Note::NotePreimage const& advice) +template template +std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* utxo_set_state_var, + size_t const& num_notes, + typename Note::NotePreimage const& advice) { auto& oracle = utxo_set_state_var->exec_ctx->oracle; @@ -103,8 +103,8 @@ std::vector Opcodes::UTXO_SLOAD(UTXOSetStateVar* u return new_notes; }; -template template -void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nullify) +template template +void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nullify) { typename CT::fr const nullifier = note_to_nullify.get_nullifier(); @@ -117,8 +117,8 @@ void Opcodes::UTXO_NULL(StateVar* state_var, Note& note_to_nul exec_ctx->nullified_notes.push_back(nullified_note_ptr); }; -template template -void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_initialise) +template template +void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_initialise) { typename CT::fr const init_nullifier = note_to_initialise.get_initialisation_nullifier(); @@ -134,8 +134,8 @@ void Opcodes::UTXO_INIT(StateVar* state_var, Note& note_to_ini exec_ctx->new_notes.push_back(init_note_ptr); }; -template template -void Opcodes::UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage) +template template +void Opcodes::UTXO_SSTORE(StateVar* state_var, typename Note::NotePreimage new_note_preimage) { auto& exec_ctx = state_var->exec_ctx; diff --git a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp index 574f3488a174..3377c6580e53 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/oracle_wrapper.hpp @@ -20,32 +20,32 @@ using aztec3::utils::types::CircuitTypes; /** * The main purpose of this wrapper is to: * - cache values which have been already given by the oracle previously during this execution; - * - convert Native types (returned by the oracle) into circuit types, using the builder instance. + * - convert Native types (returned by the oracle) into circuit types, using the composer instance. * Note: Insecure circuits could be built if the same value is queried twice from the oracle (since a malicious prover * could provide two different witnesses for a single thing). The Native oracle will throw if you try a double-query of * certain information. */ -template class OracleWrapperInterface { - using CT = CircuitTypes; +template class OracleWrapperInterface { + using CT = CircuitTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; using address = typename CT::address; public: - Builder& builder; + Composer& composer; NativeOracle& native_oracle; // Initialise from Native. // Used when initialising for a user's first call. - OracleWrapperInterface(Builder& builder, NativeOracle& native_oracle) - : builder(builder), native_oracle(native_oracle){}; + OracleWrapperInterface(Composer& composer, NativeOracle& native_oracle) + : composer(composer), native_oracle(native_oracle){}; fr& get_msg_sender_private_key() { if (msg_sender_private_key) { return *msg_sender_private_key; } - msg_sender_private_key = aztec3::utils::types::to_ct(builder, native_oracle.get_msg_sender_private_key()); + msg_sender_private_key = aztec3::utils::types::to_ct(composer, native_oracle.get_msg_sender_private_key()); validate_msg_sender_private_key(); return *msg_sender_private_key; }; @@ -57,7 +57,7 @@ template class OracleWrapperInterface { if (call_context) { return *call_context; } - call_context = native_oracle.get_call_context().to_circuit_type(builder); + call_context = native_oracle.get_call_context().to_circuit_type(composer); return *call_context; }; @@ -66,7 +66,7 @@ template class OracleWrapperInterface { if (contract_deployment_data) { return *contract_deployment_data; } - contract_deployment_data = native_oracle.get_contract_deployment_data().to_circuit_type(builder); + contract_deployment_data = native_oracle.get_contract_deployment_data().to_circuit_type(composer); return *contract_deployment_data; }; @@ -76,37 +76,37 @@ template class OracleWrapperInterface { address& get_tx_origin() { return get_call_context().tx_origin; }; - fr generate_salt() const { return aztec3::utils::types::to_ct(builder, native_oracle.generate_salt()); } + fr generate_salt() const { return aztec3::utils::types::to_ct(composer, native_oracle.generate_salt()); } fr generate_random_element() const { - return aztec3::utils::types::to_ct(builder, native_oracle.generate_random_element()); + return aztec3::utils::types::to_ct(composer, native_oracle.generate_random_element()); } template auto get_utxo_sload_datum(grumpkin_point const& storage_slot_point, NotePreimage const& advice) { - auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); + auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); - auto native_advice = advice.template to_native_type(); + auto native_advice = advice.template to_native_type(); auto native_utxo_sload_datum = native_oracle.get_utxo_sload_datum(native_storage_slot_point, native_advice); - return native_utxo_sload_datum.to_circuit_type(builder); + return native_utxo_sload_datum.to_circuit_type(composer); } template auto get_utxo_sload_data(grumpkin_point const& storage_slot_point, size_t const& num_notes, NotePreimage const& advice) { - auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); + auto native_storage_slot_point = aztec3::utils::types::to_nt(storage_slot_point); - auto native_advice = advice.template to_native_type(); + auto native_advice = advice.template to_native_type(); auto native_utxo_sload_data = native_oracle.get_utxo_sload_data(native_storage_slot_point, num_notes, native_advice); - auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(builder); }; + auto to_circuit_type = [&](auto& e) { return e.to_circuit_type(composer); }; return map(native_utxo_sload_data, to_circuit_type); } diff --git a/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp index 4584d1d145ec..b304d32b2719 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/private_state.test.cpp @@ -8,8 +8,8 @@ // namespace aztec3::circuits::apps { // namespace { -// using Builder = aztec3::utils::types:plonk::stdlib::types::Builder; -// using CT = aztec3::utils::types::CircuitTypes; +// using Composer = aztec3::utils::types:plonk::stdlib::types::Composer; +// using CT = aztec3::utils::types::CircuitTypes; // using NT = aztec3::utils::types::NativeTypes; // // using plonk::stdlib::pedersen; // } // namespace diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp index 02a0b0aa3587..00fc50a71416 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/field_state_var.hpp @@ -11,9 +11,9 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; // TODO: we can probably generalise this to be a PrimitiveStateVar for any stdlib primitive. -template class FieldStateVar : public StateVar { +template class FieldStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -29,22 +29,22 @@ template class FieldStateVar : public StateVar { FieldStateVar() = default; // Instantiate a top-level var: - FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, fr const& start_slot) - : StateVar(exec_ctx, state_var_name, start_slot){}; + FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, fr const& start_slot) + : StateVar(exec_ctx, state_var_name, start_slot){}; // Instantiate a var nested within a container: - FieldStateVar(FunctionExecutionContext* exec_ctx, + FieldStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; - bool operator==(FieldStateVar const&) const = default; + bool operator==(FieldStateVar const&) const = default; }; -template inline std::ostream& operator<<(std::ostream& os, FieldStateVar const& v) +template inline std::ostream& operator<<(std::ostream& os, FieldStateVar const& v) { return os << v.value; } diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp index b8e76a52a281..a387c720142b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -24,9 +24,9 @@ using aztec3::utils::types::NativeTypes; * more easily (it was difficult enough to get working). You'll notice, therefore, that there's no Key template type; * only a value template type (`V`). Adding a Key template type could be a future enhancement. */ -template class MappingStateVar : public StateVar { +template class MappingStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -37,22 +37,22 @@ template class MappingStateVar : public StateVar< MappingStateVar() = default; // Instantiate a top-level mapping: - MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a nested mapping (within some other container). // Note: we assume this is called by some other StateVar, and the params have been computed correctly. // TODO: we could specify a set of `friend` classes which may access this method, to make this assumption more // explicit. - MappingStateVar(FunctionExecutionContext* exec_ctx, + MappingStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; - bool operator==(MappingStateVar const&) const = default; + bool operator==(MappingStateVar const&) const = default; V& operator[](std::optional const& key) { return this->at(key); }; V& operator[](std::string const& question_mark) diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp index 7f1f9d85076d..06419fdb1674 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp @@ -36,8 +36,8 @@ using aztec3::utils::types::NativeTypes; // start_slot_point becomes: prev_start_slot_point + k1 * B // at(k2).slot = new_start_slot_point + k2 * C -template -std::tuple MappingStateVar::compute_slot_point_at_mapping_key( +template +std::tuple MappingStateVar::compute_slot_point_at_mapping_key( NT::fr const& start_slot, size_t level_of_container_nesting, std::optional const& key) { bool const is_partial_slot = false; @@ -66,8 +66,8 @@ std::tuple MappingStateVar::compu return std::make_tuple(NativeTypes::commit(input_pairs), is_partial_slot); } -template -std::tuple::grumpkin_point, bool> MappingStateVar:: +template +std::tuple::grumpkin_point, bool> MappingStateVar:: compute_slot_point_at_mapping_key(std::optional const& key) { bool is_partial_slot = false; @@ -101,7 +101,7 @@ std::tuple::grumpkin_point, bool> MappingStateVar return std::make_tuple(CT::commit(input_pairs), is_partial_slot); } -template V& MappingStateVar::at(std::optional const& key) +template V& MappingStateVar::at(std::optional const& key) { // First calculate natively and check to see if we've already calculated this state's slot and stored it in the // cache, so we don't create unnecessary circuit gates: @@ -115,7 +115,7 @@ template V& MappingStateVar::at(std:: bool is_partial_slot = false; NativeTypes::grumpkin_point native_new_slot_point; - std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( + std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( this->start_slot.get_value(), this->level_of_container_nesting, native_key); NativeTypes::fr const native_lookup = native_new_slot_point.x; diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp index 0bead2a69c3d..718de6c3f705 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.hpp @@ -5,7 +5,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -20,15 +20,15 @@ using aztec3::utils::types::NativeTypes; * slots, and generating constraints for those slot derivations, in a protocol-consistent way, regardless of the app * being written. */ -template class StateVar { +template class StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; // The execution context of the function currently being executed. - FunctionExecutionContext* exec_ctx; + FunctionExecutionContext* exec_ctx; // Must match the name of a state which has been declared to the `Contract`. std::string state_var_name; @@ -57,11 +57,11 @@ template class StateVar { StateVar() = default; // Instantiate a top-level state: - StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name); + StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name); // Instantiate a state nested within a container: StateVar( - FunctionExecutionContext* exec_ctx, + FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, // the parent always calculates the storage_slot_point of its child. size_t level_of_container_nesting, // the parent always calculates the level of nesting of its child. @@ -72,7 +72,7 @@ template class StateVar { , level_of_container_nesting(level_of_container_nesting) , is_partial_slot(is_partial_slot){}; - bool operator==(StateVar const&) const = default; + bool operator==(StateVar const&) const = default; StateVar operator=(StateVar const& other) { diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp index b920e2ca8a4e..dfbd18e1bbf4 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/state_var_base.tpp @@ -15,8 +15,8 @@ namespace aztec3::circuits::apps::state_vars { using aztec3::utils::types::CircuitTypes; using crypto::generators::generator_index_t; -template -StateVar::StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) +template +StateVar::StateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) : exec_ctx(exec_ctx), state_var_name(state_var_name) { // NOLINTBEGIN(cppcoreguidelines-prefer-member-initializer) @@ -26,12 +26,12 @@ StateVar::StateVar(FunctionExecutionContext* exec_ctx, std::st // NOLINTEND(cppcoreguidelines-prefer-member-initializer) } -template typename CircuitTypes::grumpkin_point StateVar::compute_slot_point() +template typename CircuitTypes::grumpkin_point StateVar::compute_slot_point() { ASSERT(level_of_container_nesting == 0); return CT::commit({ start_slot }, { StorageSlotGeneratorIndex::BASE_SLOT }); } -// template class PrivateStateVar; +// template class PrivateStateVar; }; // namespace aztec3::circuits::apps::state_vars diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp index 69121dba555f..f74b60f57c93 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -25,9 +25,9 @@ using aztec3::utils::types::NativeTypes; * designed. The Note type must implement the NoteInterface. TODO: maybe explicitly have this class act on the * NoteInterface type, rather than a template type. */ -template class UTXOSetStateVar : public StateVar { +template class UTXOSetStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -37,16 +37,16 @@ template class UTXOSetStateVar : public StateV UTXOSetStateVar() = default; // Instantiate a top-level var: - UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a var nested within a container: - UTXOSetStateVar(FunctionExecutionContext* exec_ctx, + UTXOSetStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; /** diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp index 4f289777f2e8..0864cb2d2246 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_set_state_var.tpp @@ -11,17 +11,17 @@ using aztec3::circuits::apps::opcodes::Opcodes; namespace aztec3::circuits::apps::state_vars { -template -std::vector UTXOSetStateVar::get(size_t const& num_notes, - typename Note::NotePreimage const& advice) +template +std::vector UTXOSetStateVar::get(size_t const& num_notes, + typename Note::NotePreimage const& advice) { - return Opcodes::template UTXO_SLOAD(this, num_notes, advice); + return Opcodes::template UTXO_SLOAD(this, num_notes, advice); }; -template -void UTXOSetStateVar::insert(typename Note::NotePreimage new_note_preimage) +template +void UTXOSetStateVar::insert(typename Note::NotePreimage new_note_preimage) { - return Opcodes::template UTXO_SSTORE(this, new_note_preimage); + return Opcodes::template UTXO_SSTORE(this, new_note_preimage); }; } // namespace aztec3::circuits::apps::state_vars \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp index 4e18980a8c21..456de1c9a81b 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.hpp @@ -7,7 +7,7 @@ // Forward-declare from this namespace in particular: namespace aztec3::circuits::apps { -template class FunctionExecutionContext; +template class FunctionExecutionContext; } namespace aztec3::circuits::apps::state_vars { @@ -26,9 +26,9 @@ using aztec3::utils::types::NativeTypes; * designed. The Note type must implement the NoteInterface. TODO: maybe explicitly have this class act on the * NoteInterface type, rather than a template type. */ -template class UTXOStateVar : public StateVar { +template class UTXOStateVar : public StateVar { public: - using CT = CircuitTypes; + using CT = CircuitTypes; using NT = NativeTypes; using fr = typename CT::fr; using grumpkin_point = typename CT::grumpkin_point; @@ -39,16 +39,16 @@ template class UTXOStateVar : public StateVar< UTXOStateVar() = default; // Instantiate a top-level var: - UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) - : StateVar(exec_ctx, state_var_name){}; + UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name) + : StateVar(exec_ctx, state_var_name){}; // Instantiate a var nested within a container: - UTXOStateVar(FunctionExecutionContext* exec_ctx, + UTXOStateVar(FunctionExecutionContext* exec_ctx, std::string const& state_var_name, grumpkin_point const& storage_slot_point, size_t level_of_container_nesting, bool is_partial_slot) - : StateVar( + : StateVar( exec_ctx, state_var_name, storage_slot_point, level_of_container_nesting, is_partial_slot){}; /** diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp index 5f7081546683..10f963091278 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/utxo_state_var.tpp @@ -11,23 +11,23 @@ using aztec3::circuits::apps::opcodes::Opcodes; namespace aztec3::circuits::apps::state_vars { -template -Note UTXOStateVar::get(typename Note::NotePreimage const& advice) +template +Note UTXOStateVar::get(typename Note::NotePreimage const& advice) { - return Opcodes::template UTXO_SLOAD(this, advice); + return Opcodes::template UTXO_SLOAD(this, advice); }; -template -void UTXOStateVar::initialise(typename Note::NotePreimage new_note_preimage) +template +void UTXOStateVar::initialise(typename Note::NotePreimage new_note_preimage) { Note new_note{ this, new_note_preimage }; - Opcodes::template UTXO_INIT(this, new_note); + Opcodes::template UTXO_INIT(this, new_note); }; -template -void UTXOStateVar::insert(typename Note::NotePreimage new_note_preimage) +template +void UTXOStateVar::insert(typename Note::NotePreimage new_note_preimage) { - Opcodes::template UTXO_SSTORE(this, new_note_preimage); + Opcodes::template UTXO_SSTORE(this, new_note_preimage); }; } // namespace aztec3::circuits::apps::state_vars \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp index 2aff1c41490f..8c3ff1cf57b6 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/basic_contract_deployment.cpp @@ -20,11 +20,11 @@ OptionalPrivateCircuitPublicInputs constructor(FunctionExecutionContext& exe exec_ctx.register_contract(&contract); // Convert params into circuit types: - auto& builder = exec_ctx.builder; + auto& composer = exec_ctx.composer; - CT::fr const arg0 = to_ct(builder, args[0]); - CT::fr const arg1 = to_ct(builder, args[1]); - CT::fr const arg2 = to_ct(builder, args[2]); + CT::fr const arg0 = to_ct(composer, args[0]); + CT::fr const arg1 = to_ct(composer, args[1]); + CT::fr const arg2 = to_ct(composer, args[2]); auto& oracle = exec_ctx.oracle; const CT::address msg_sender = oracle.get_msg_sender(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp index 4b193f601d7d..d24db87213d5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/basic_contract_deployment/init.hpp @@ -13,8 +13,8 @@ namespace aztec3::circuits::apps::test_apps::basic_contract_deployment { -// Builder -using C = UltraCircuitBuilder; +// Composer +using C = plonk::UltraPlonkComposer; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; @@ -34,7 +34,7 @@ using aztec3::utils::types::to_ct; using apps::state_vars::MappingStateVar; using apps::state_vars::UTXOSetStateVar; -// Get rid of ugly `Builder` template arg from our state var types: +// Get rid of ugly `Composer` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXOSet = UTXOSetStateVar; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp index 5e68463937ed..bc2e12a1785e 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/.test.cpp @@ -40,11 +40,11 @@ TEST_F(escrow_tests, circuit_deposit) // contains a reference to earlier-declared classes... so we'd end up with classes containing dangling references, // if all this stuff were to be declared in a setup function's scope. // We could instead store shared_ptrs in every class...? - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); auto amount = NT::fr(5); auto asset_id = NT::fr(1); @@ -53,21 +53,21 @@ TEST_F(escrow_tests, circuit_deposit) auto result = deposit(exec_ctx, { amount, asset_id, memo }); info("result: ", result); - // info("witness: ", builder.witness); - // info("constant variables: ", builder.constant_variables); - // info("variables: ", builder.variables); - info("failed?: ", builder.failed()); - info("err: ", builder.err()); - info("n: ", builder.num_gates); + // info("witness: ", composer.witness); + // info("constant variables: ", composer.constant_variables); + // info("variables: ", composer.variables); + info("failed?: ", composer.circuit_constructor.failed()); + info("err: ", composer.circuit_constructor.err()); + info("n: ", composer.circuit_constructor.num_gates); } TEST_F(escrow_tests, circuit_transfer) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); auto amount = NT::fr(5); auto to = NT::address(657756); @@ -78,21 +78,21 @@ TEST_F(escrow_tests, circuit_transfer) transfer(exec_ctx, amount, to, asset_id, memo, reveal_msg_sender_to_recipient, fee); - // info("witness: ", builder.witness); - // info("constant variables: ", builder.constant_variables); - // info("variables: ", builder.variables); - info("failed?: ", builder.failed()); - info("err: ", builder.err()); - info("n: ", builder.num_gates); + // info("witness: ", composer.witness); + // info("constant variables: ", composer.constant_variables); + // info("variables: ", composer.variables); + info("failed?: ", composer.circuit_constructor.failed()); + info("err: ", composer.circuit_constructor.err()); + info("n: ", composer.circuit_constructor.num_gates); } TEST_F(escrow_tests, circuit_withdraw) { - C builder = C(); + C composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; NativeOracle native_oracle = get_test_native_oracle(db); - OracleWrapper oracle_wrapper = OracleWrapper(builder, native_oracle); - FunctionExecutionContext exec_ctx(builder, oracle_wrapper); + OracleWrapper oracle_wrapper = OracleWrapper(composer, native_oracle); + FunctionExecutionContext exec_ctx(composer, oracle_wrapper); auto amount = NT::fr(5); auto asset_id = NT::fr(1); @@ -102,12 +102,12 @@ TEST_F(escrow_tests, circuit_withdraw) withdraw(exec_ctx, amount, asset_id, memo, l1_withdrawal_address, fee); - // info("witness: ", builder.witness); - // info("constant variables: ", builder.constant_variables); - // info("variables: ", builder.variables); - info("failed?: ", builder.failed()); - info("err: ", builder.err()); - info("n: ", builder.num_gates); + // info("witness: ", composer.witness); + // info("constant variables: ", composer.constant_variables); + // info("variables: ", composer.variables); + info("failed?: ", composer.circuit_constructor.failed()); + info("err: ", composer.circuit_constructor.err()); + info("n: ", composer.circuit_constructor.num_gates); } } // namespace aztec3::circuits::apps::test_apps::escrow \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp index 59d2ccb50d63..1e3c72f401a1 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/deposit.cpp @@ -21,11 +21,11 @@ OptionalPrivateCircuitPublicInputs deposit(FunctionExecutionContext& exec_ct exec_ctx.register_contract(&contract); // Convert params into circuit types: - auto& builder = exec_ctx.builder; + auto& composer = exec_ctx.composer; - CT::fr amount = to_ct(builder, args[0]); - CT::fr asset_id = to_ct(builder, args[1]); - CT::fr memo = to_ct(builder, args[2]); + CT::fr amount = to_ct(composer, args[0]); + CT::fr asset_id = to_ct(composer, args[1]); + CT::fr memo = to_ct(composer, args[2]); auto& oracle = exec_ctx.oracle; const CT::address msg_sender = oracle.get_msg_sender(); diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp index 30d5da1dbbcb..757b8e5e49e6 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/init.hpp @@ -13,8 +13,8 @@ namespace aztec3::circuits::apps::test_apps::escrow { -// Builder -using C = UltraCircuitBuilder; +// Composer +using C = plonk::UltraPlonkComposer; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; @@ -34,7 +34,7 @@ using aztec3::utils::types::to_ct; using apps::state_vars::MappingStateVar; using apps::state_vars::UTXOSetStateVar; -// Get rid of ugly `Builder` template arg from our state var types: +// Get rid of ugly `Composer` template arg from our state var types: template using Mapping = MappingStateVar; template using UTXOSet = UTXOSetStateVar; diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp index 51e1a0be733c..9cd5eb61294a 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/transfer.cpp @@ -26,14 +26,14 @@ OptionalPrivateCircuitPublicInputs transfer(FunctionExecutionContext& exec_c exec_ctx.register_contract(&contract); // Convert arguments into circuit types: - auto& builder = exec_ctx.builder; - - CT::fr amount = to_ct(builder, _amount); - CT::address to = to_ct(builder, _to); - CT::fr asset_id = to_ct(builder, _asset_id); - CT::fr memo = to_ct(builder, _memo); - CT::boolean const reveal_msg_sender_to_recipient = to_ct(builder, _reveal_msg_sender_to_recipient); - CT::fr const fee = to_ct(builder, _fee); + auto& composer = exec_ctx.composer; + + CT::fr amount = to_ct(composer, _amount); + CT::address to = to_ct(composer, _to); + CT::fr asset_id = to_ct(composer, _asset_id); + CT::fr memo = to_ct(composer, _memo); + CT::boolean const reveal_msg_sender_to_recipient = to_ct(composer, _reveal_msg_sender_to_recipient); + CT::fr const fee = to_ct(composer, _fee); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp index fdba8ab35e1e..271bd1481b52 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/escrow/withdraw.cpp @@ -25,13 +25,13 @@ OptionalPrivateCircuitPublicInputs withdraw(FunctionExecutionContext& exec_c exec_ctx.register_contract(&contract); // Convert arguments into circuit types: - auto& builder = exec_ctx.builder; + auto& composer = exec_ctx.composer; - CT::fr const amount = to_ct(builder, _amount); - CT::fr asset_id = to_ct(builder, _asset_id); - CT::fr memo = to_ct(builder, _memo); - CT::fr const l1_withdrawal_address = to_ct(builder, _l1_withdrawal_address); - CT::fr const fee = to_ct(builder, _fee); + CT::fr const amount = to_ct(composer, _amount); + CT::fr asset_id = to_ct(composer, _asset_id); + CT::fr memo = to_ct(composer, _memo); + CT::fr const l1_withdrawal_address = to_ct(composer, _l1_withdrawal_address); + CT::fr const fee = to_ct(composer, _fee); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp index ba7acefda62f..2b6c64252e30 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/.test.cpp @@ -13,7 +13,7 @@ class private_to_private_function_call_tests : public ::testing::Test {}; TEST(private_to_private_function_call_tests, circuit_private_to_private_function_call) { - C fn1_builder = C(); + C fn1_composer = C("../barretenberg/cpp/srs_db/ignition"); DB db; const NT::address contract_address = 12345; @@ -37,9 +37,9 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function }; NativeOracle fn1_oracle = NativeOracle(db, contract_address, function_data, call_context, msg_sender_private_key); - OracleWrapper fn1_oracle_wrapper = OracleWrapper(fn1_builder, fn1_oracle); + OracleWrapper fn1_oracle_wrapper = OracleWrapper(fn1_composer, fn1_oracle); - FunctionExecutionContext fn1_exec_ctx(fn1_builder, fn1_oracle_wrapper); + FunctionExecutionContext fn1_exec_ctx(fn1_composer, fn1_oracle_wrapper); auto a = NT::fr(111); auto b = NT::fr(222); @@ -51,12 +51,12 @@ TEST(private_to_private_function_call_tests, circuit_private_to_private_function info("function_1_1_public_inputs: ", function_1_1_public_inputs); - // info("witness: ", fn1_builder.witness); - // info("constant variables: ", fn1_builder.constant_variables); - // info("variables: ", fn1_builder.variables); - info("failed?: ", fn1_builder.failed()); - info("err: ", fn1_builder.err()); - info("n: ", fn1_builder.num_gates); + // info("witness: ", fn1_composer.witness); + // info("constant variables: ", fn1_composer.constant_variables); + // info("variables: ", fn1_composer.variables); + info("failed?: ", fn1_composer.circuit_constructor.failed()); + info("err: ", fn1_composer.circuit_constructor.err()); + info("n: ", fn1_composer.circuit_constructor.num_gates); } } // namespace aztec3::circuits::apps::test_apps::private_to_private_function_call \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp index 4377da64a9b5..92c5a5ffa796 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_1_1.cpp @@ -19,10 +19,10 @@ void function_1_1(FunctionExecutionContext& exec_ctx, std::vector const& exec_ctx.register_contract(&contract_1); // Convert arguments into circuit types: - auto& builder = exec_ctx.builder; - const auto a = to_ct(builder, _args[0]); - const auto b = to_ct(builder, _args[1]); - const auto c = to_ct(builder, _args[2]); + auto& composer = exec_ctx.composer; + const auto a = to_ct(composer, _args[0]); + const auto b = to_ct(composer, _args[1]); + const auto c = to_ct(composer, _args[2]); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp index ac424411667e..b2ef763a06a3 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/function_2_1.cpp @@ -19,10 +19,10 @@ void function_2_1(FunctionExecutionContext& exec_ctx, std::vector const& exec_ctx.register_contract(&contract_2); // Convert arguments into circuit types: - auto& builder = exec_ctx.builder; - const auto a = to_ct(builder, _args[0]); - const auto b = to_ct(builder, _args[1]); - const auto c = to_ct(builder, _args[2]); + auto& composer = exec_ctx.composer; + const auto a = to_ct(composer, _args[0]); + const auto b = to_ct(composer, _args[1]); + const auto c = to_ct(composer, _args[2]); /**************************************************************** * Get States & Globals used by the function diff --git a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp index 7f2e42a70a47..26712cc998e5 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/test_apps/private_to_private_function_call/init.hpp @@ -12,8 +12,8 @@ namespace aztec3::circuits::apps::test_apps::private_to_private_function_call { -// Builder -using C = UltraCircuitBuilder; +// Composer +using C = plonk::UltraPlonkComposer; // Native and circuit types using CT = aztec3::utils::types::CircuitTypes; @@ -32,7 +32,7 @@ using aztec3::utils::types::to_ct; // StateVars using apps::state_vars::UTXOStateVar; -// Get rid of ugly `Builder` template arg from our state var types: +// Get rid of ugly `Composer` template arg from our state var types: template using UTXO = UTXOStateVar; using Note = apps::notes::DefaultSingletonPrivateNote; diff --git a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp index bfb7e0d9978b..ce924ce7b73c 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/utxo_datum.hpp @@ -12,7 +12,7 @@ using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; /** - * @tparam NCT - NativeTypes or CircuitTypes + * @tparam NCT - NativeTypes or CircuitTypes * @tparam NotePreimage */ template struct UTXOSLoadDatum { @@ -28,16 +28,16 @@ template struct UTXOSLoadDatum { uint32 leaf_index; fr historic_private_data_tree_root = 0; - template auto to_circuit_type(Builder& builder) const + template auto to_circuit_type(Composer& composer) const { static_assert(std::is_same::value); - // Capture the circuit builder: - auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(builder, e); }; + // Capture the composer: + auto to_ct = [&](auto& e) { return aztec3::utils::types::to_ct(composer, e); }; - auto preimage_ct = preimage.to_circuit_type(builder); + auto preimage_ct = preimage.to_circuit_type(composer); - UTXOSLoadDatum, decltype(preimage_ct)> datum = { + UTXOSLoadDatum, decltype(preimage_ct)> datum = { to_ct(commitment), to_ct(contract_address), preimage_ct, to_ct(sibling_path), to_ct(leaf_index), to_ct(historic_private_data_tree_root), }; diff --git a/circuits/cpp/src/aztec3/circuits/hash.hpp b/circuits/cpp/src/aztec3/circuits/hash.hpp index 9315dc747b7e..2401d2f02b90 100644 --- a/circuits/cpp/src/aztec3/circuits/hash.hpp +++ b/circuits/cpp/src/aztec3/circuits/hash.hpp @@ -198,8 +198,8 @@ std::array get_sibling_path(MerkleTree& tree, size_t leaf_index, size_t c return sibling_path; } -template -void check_membership(Builder& builder, +template +void check_membership(Composer& composer, typename NCT::fr const& value, typename NCT::fr const& index, std::array const& sibling_path, @@ -207,9 +207,9 @@ void check_membership(Builder& builder, std::string const& msg) { const auto calculated_root = root_from_sibling_path(value, index, sibling_path); - builder.do_assert(calculated_root == root, - std::string("Membership check failed: ") + msg, - aztec3::utils::CircuitErrorCode::MEMBERSHIP_CHECK_FAILED); + composer.do_assert(calculated_root == root, + std::string("Membership check failed: ") + msg, + aztec3::utils::CircuitErrorCode::MEMBERSHIP_CHECK_FAILED); } /** diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp index d453792d41dd..3561a5792fbc 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -59,11 +59,11 @@ TEST_F(private_kernel_tests, basic) true); // Execute and prove the first kernel iteration - Builder private_kernel_builder; - auto const& public_inputs = private_kernel_circuit(private_kernel_builder, private_inputs, true); + Composer private_kernel_composer("../barretenberg/cpp/srs_db/ignition"); + auto const& public_inputs = private_kernel_circuit(private_kernel_composer, private_inputs, true); // Check the private kernel circuit - EXPECT_TRUE(private_kernel_builder.check_circuit()); + EXPECT_TRUE(private_kernel_composer.circuit_constructor.check_circuit()); } /** @@ -88,8 +88,8 @@ TEST_F(private_kernel_tests, circuit_cbinds) encrypted_log_preimages_length, unencrypted_log_preimages_length, true); - DummyBuilder builder = DummyBuilder("private_kernel_tests__circuit_create_proof_cbinds"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__circuit_create_proof_cbinds"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); // serialize expected public inputs for later comparison std::vector expected_public_inputs_vec; @@ -114,7 +114,7 @@ TEST_F(private_kernel_tests, circuit_cbinds) std::vector private_constructor_call_vec; write(private_constructor_call_vec, private_inputs.private_call); - // uint8_t const* proof_data_buf = nullptr; + uint8_t const* proof_data_buf = nullptr; uint8_t const* public_inputs_buf = nullptr; size_t public_inputs_size = 0; // info("Simulating to generate public inputs..."); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp index 508f1ce6a2f3..82a3c0f95bc5 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.cpp @@ -13,9 +13,9 @@ #include namespace { -using Builder = UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::PreviousKernelData; using aztec3::circuits::abis::TxRequest; using aztec3::circuits::abis::private_kernel::PrivateCallData; @@ -68,7 +68,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyBuilder builder = DummyBuilder("private_kernel__sim_init"); + DummyComposer composer = DummyComposer("private_kernel__sim_init"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); @@ -81,7 +81,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, .private_call = private_call_data, }; - auto public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + auto public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -91,7 +91,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_init(uint8_t const* tx_request_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *private_kernel_public_inputs_buf = raw_public_inputs_buf; *private_kernel_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); + return composer.alloc_and_serialize_first_failure(); } WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_buf, @@ -99,7 +99,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu size_t* private_kernel_public_inputs_size_out, uint8_t const** private_kernel_public_inputs_buf) { - DummyBuilder builder = DummyBuilder("private_kernel__sim_inner"); + DummyComposer composer = DummyComposer("private_kernel__sim_inner"); PrivateCallData private_call_data; read(private_call_buf, private_call_data); @@ -111,7 +111,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu .private_call = private_call_data, }; - auto public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + auto public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -121,7 +121,7 @@ WASM_EXPORT uint8_t* private_kernel__sim_inner(uint8_t const* previous_kernel_bu memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *private_kernel_public_inputs_buf = raw_public_inputs_buf; *private_kernel_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); + return composer.alloc_and_serialize_first_failure(); } CBIND(private_kernel__sim_ordering, [](PreviousKernelData previous_kernel) { diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h index 6e8535b1cc89..b2a7823808dc 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/c_bind.h @@ -1,4 +1,5 @@ #pragma once +#include "barretenberg/serialize/cbind_fwd.hpp" #include #include diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index 3b36b36b4aa4..0b083fd7040a 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -12,9 +12,9 @@ #include "aztec3/circuits/hash.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::ContractDeploymentData; using aztec3::circuits::abis::ContractLeafPreimage; @@ -27,13 +27,13 @@ using aztec3::circuits::abis::PreviousKernelData; using aztec3::utils::array_push; using aztec3::utils::is_array_empty; using aztec3::utils::push_array_to_array; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using aztec3::circuits::abis::private_kernel::PrivateCallData; namespace aztec3::circuits::kernel::private_kernel { -void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const& private_call) +void common_validate_call_stack(DummyComposer& composer, PrivateCallData const& private_call) { const auto& stack = private_call.call_stack_item.public_inputs.private_call_stack; const auto& preimages = private_call.private_call_stack_preimages; @@ -44,9 +44,9 @@ void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const // Note: this assumes it's computationally infeasible to have `0` as a valid call_stack_item_hash. // Assumes `hash == 0` means "this stack item is empty". const auto calculated_hash = hash == 0 ? 0 : preimage.hash(); - builder.do_assert(hash == calculated_hash, - format("private_call_stack[", i, "] = ", hash, "; does not reconcile"), - CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); + composer.do_assert(hash == calculated_hash, + format("private_call_stack[", i, "] = ", hash, "; does not reconcile"), + CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); } } @@ -59,14 +59,14 @@ void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const * - https://discourse.aztec.network/t/to-read-or-not-to-read/178 * - https://discourse.aztec.network/t/spending-notes-which-havent-yet-been-inserted/180 * - * @param builder + * @param composer * @param read_requests the commitments being read by this private call * @param read_request_membership_witnesses used to compute the private data root * for a given request which is essentially a membership check. * @param historic_private_data_tree_root This is a reference to the historic root which all * read requests are checked against here. */ -void common_validate_read_requests(DummyBuilder& builder, +void common_validate_read_requests(DummyComposer& composer, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, @@ -93,20 +93,20 @@ void common_validate_read_requests(DummyBuilder& builder, if (read_request != 0 && !is_transient_read) { const auto& root_for_read_request = root_from_sibling_path(leaf, witness.leaf_index, witness.sibling_path); - builder.do_assert(root_for_read_request == historic_private_data_tree_root, - format("private data root mismatch at read_request[", - rr_idx, - "] - ", - "Expected root: ", - historic_private_data_tree_root, - ", Read request gave root: ", - root_for_read_request), - CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); + composer.do_assert(root_for_read_request == historic_private_data_tree_root, + format("private data root mismatch at read_request[", + rr_idx, + "] - ", + "Expected root: ", + historic_private_data_tree_root, + ", Read request gave root: ", + root_for_read_request), + CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } } } -void common_update_end_values(DummyBuilder& builder, +void common_update_end_values(DummyComposer& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs) { @@ -119,12 +119,12 @@ void common_update_end_values(DummyBuilder& builder, if (is_static_call) { // No state changes are allowed for static calls: - builder.do_assert(is_array_empty(new_commitments) == true, - "new_commitments must be empty for static calls", - CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL); - builder.do_assert(is_array_empty(new_nullifiers) == true, - "new_nullifiers must be empty for static calls", - CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL); + composer.do_assert(is_array_empty(new_commitments) == true, + "new_commitments must be empty for static calls", + CircuitErrorCode::PRIVATE_KERNEL__NEW_COMMITMENTS_NOT_EMPTY_FOR_STATIC_CALL); + composer.do_assert(is_array_empty(new_nullifiers) == true, + "new_nullifiers must be empty for static calls", + CircuitErrorCode::PRIVATE_KERNEL__NEW_NULLIFIERS_NOT_EMPTY_FOR_STATIC_CALL); } const auto& storage_contract_address = private_call_public_inputs.call_context.storage_contract_address; @@ -146,16 +146,16 @@ void common_update_end_values(DummyBuilder& builder, new_nullifiers[i] == 0 ? 0 : silo_nullifier(storage_contract_address, new_nullifiers[i]); } - push_array_to_array(builder, siloed_new_commitments, public_inputs.end.new_commitments); - push_array_to_array(builder, siloed_new_nullifiers, public_inputs.end.new_nullifiers); + push_array_to_array(composer, siloed_new_commitments, public_inputs.end.new_commitments); + push_array_to_array(composer, siloed_new_nullifiers, public_inputs.end.new_nullifiers); } { // call stacks const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; - push_array_to_array(builder, this_private_call_stack, public_inputs.end.private_call_stack); + push_array_to_array(composer, this_private_call_stack, public_inputs.end.private_call_stack); const auto& this_public_call_stack = private_call_public_inputs.public_call_stack; - push_array_to_array(builder, this_public_call_stack, public_inputs.end.public_call_stack); + push_array_to_array(composer, this_public_call_stack, public_inputs.end.public_call_stack); } { // new l2 to l1 messages @@ -174,7 +174,7 @@ void common_update_end_values(DummyBuilder& builder, new_l2_to_l1_msgs[i]); } } - push_array_to_array(builder, new_l2_to_l1_msgs_to_insert, public_inputs.end.new_l2_to_l1_msgs); + push_array_to_array(composer, new_l2_to_l1_msgs_to_insert, public_inputs.end.new_l2_to_l1_msgs); } { // logs hashes @@ -203,7 +203,7 @@ void common_update_end_values(DummyBuilder& builder, } } -void common_contract_logic(DummyBuilder& builder, +void common_contract_logic(DummyComposer& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, @@ -233,27 +233,27 @@ void common_contract_logic(DummyBuilder& builder, portal_contract_address, contract_dep_data.function_tree_root }; - array_push(builder, public_inputs.end.new_contracts, native_new_contract_data); - builder.do_assert(contract_dep_data.constructor_vk_hash == private_call_vk_hash, - "constructor_vk_hash doesn't match private_call_vk_hash", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); + array_push(composer, public_inputs.end.new_contracts, native_new_contract_data); + composer.do_assert(contract_dep_data.constructor_vk_hash == private_call_vk_hash, + "constructor_vk_hash doesn't match private_call_vk_hash", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); // must imply == derived address - builder.do_assert(storage_contract_address == new_contract_address, - "contract address supplied doesn't match derived address", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + composer.do_assert(storage_contract_address == new_contract_address, + "contract address supplied doesn't match derived address", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); // compute contract address nullifier auto const blake_input = new_contract_address.to_field().to_buffer(); auto const new_contract_address_nullifier = NT::fr::serialize_from_buffer(NT::blake3s(blake_input).data()); // push the contract address nullifier to nullifier vector - array_push(builder, public_inputs.end.new_nullifiers, new_contract_address_nullifier); + array_push(composer, public_inputs.end.new_nullifiers, new_contract_address_nullifier); } else { // non-contract deployments must specify contract address being interacted with - builder.do_assert(storage_contract_address != 0, - "contract address can't be 0 for non-contract deployment related transactions", - CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + composer.do_assert(storage_contract_address != 0, + "contract address can't be 0 for non-contract deployment related transactions", + CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); /* We need to compute the root of the contract tree, starting from the function's VK: * - Compute the vk_hash (done above) @@ -283,7 +283,7 @@ void common_contract_logic(DummyBuilder& builder, auto const& purported_contract_tree_root = private_call.call_stack_item.public_inputs.historic_contract_tree_root; - builder.do_assert( + composer.do_assert( computed_contract_tree_root == purported_contract_tree_root, "computed_contract_tree_root doesn't match purported_contract_tree_root", CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp index 96996779b94d..17955d1d7e2f 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.hpp @@ -8,13 +8,13 @@ #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/previous_kernel_data.hpp" #include "aztec3/circuits/abis/private_kernel/private_call_data.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::ContractDeploymentData; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::MembershipWitness; @@ -23,20 +23,20 @@ using aztec3::circuits::abis::private_kernel::PrivateCallData; // TODO(suyash): Add comments to these as well as other functions in PKC-init. -void common_validate_call_stack(DummyBuilder& builder, PrivateCallData const& private_call); +void common_validate_call_stack(DummyComposer& composer, PrivateCallData const& private_call); -void common_validate_read_requests(DummyBuilder& builder, +void common_validate_read_requests(DummyComposer& composer, NT::fr const& storage_contract_address, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, NT::fr const& historic_private_data_tree_root); -void common_update_end_values(DummyBuilder& builder, +void common_update_end_values(DummyComposer& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs); -void common_contract_logic(DummyBuilder& builder, +void common_contract_logic(DummyComposer& composer, PrivateCallData const& private_call, KernelCircuitPublicInputs& public_inputs, ContractDeploymentData const& contract_dep_data, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp index 143eb0b1d687..a9328737d0c7 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/init.hpp @@ -9,19 +9,19 @@ namespace aztec3::circuits::kernel::private_kernel { -using Builder = UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using Aggregator = aztec3::circuits::recursion::Aggregator; // Generic: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using DB = oracle::FakeDB; using oracle::NativeOracle; -using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; +using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; -using FunctionExecutionContext = aztec3::circuits::apps::FunctionExecutionContext; +using FunctionExecutionContext = aztec3::circuits::apps::FunctionExecutionContext; } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp index 937516f3a32a..c6b631dac9e1 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.cpp @@ -22,16 +22,16 @@ namespace aztec3::circuits::kernel::private_kernel { // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Builder& builder, +// CT::AggregationObject verify_proofs(Composer& composer, // PrivateKernelInputsInit const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) // { // CT::AggregationObject aggregation_object = Aggregator::aggregate( -// &builder, private_inputs.private_call.vk, private_inputs.private_call.proof, +// &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, // num_private_call_public_inputs); -// Aggregator::aggregate(&builder, +// Aggregator::aggregate(&composer, // private_inputs.previous_kernel.vk, // private_inputs.previous_kernel.proof, // num_private_kernel_public_inputs, @@ -67,7 +67,7 @@ void initialise_end_values(PrivateKernelInputsInit const& private_inputs, public_inputs.constants = constants; } -void validate_this_private_call_against_tx_request(DummyBuilder& builder, +void validate_this_private_call_against_tx_request(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs) { // TODO(mike): this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' @@ -77,29 +77,29 @@ void validate_this_private_call_against_tx_request(DummyBuilder& builder, const auto& tx_request = private_inputs.tx_request; const auto& call_stack_item = private_inputs.private_call.call_stack_item; - builder.do_assert(tx_request.origin == call_stack_item.contract_address, - "user's intent does not match initial private call (tx_request.origin must match " - "call_stack_item.contract_address)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + composer.do_assert(tx_request.origin == call_stack_item.contract_address, + "user's intent does not match initial private call (tx_request.origin must match " + "call_stack_item.contract_address)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - builder.do_assert(tx_request.function_data.hash() == call_stack_item.function_data.hash(), - "user's intent does not match initial private call (tx_request.function_data must match " - "call_stack_item.function_data)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + composer.do_assert(tx_request.function_data.hash() == call_stack_item.function_data.hash(), + "user's intent does not match initial private call (tx_request.function_data must match " + "call_stack_item.function_data)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - builder.do_assert(tx_request.args_hash == call_stack_item.public_inputs.args_hash, - "user's intent does not match initial private call (tx_request.args must match " - "call_stack_item.public_inputs.args)", - CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); + composer.do_assert(tx_request.args_hash == call_stack_item.public_inputs.args_hash, + "user's intent does not match initial private call (tx_request.args must match " + "call_stack_item.public_inputs.args)", + CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); }; -void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInit const& private_inputs) +void validate_inputs(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; - builder.do_assert(this_call_stack_item.function_data.is_private == true, - "Cannot execute a non-private function with the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); + composer.do_assert(this_call_stack_item.function_data.is_private == true, + "Cannot execute a non-private function with the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); // TODO(mike): change to allow 3 initial calls on the private call stack, so a fee can be paid and a gas // rebate can be paid. @@ -109,21 +109,21 @@ void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInit const& p * despite no longer needing a full `previous_kernel` */ - builder.do_assert(this_call_stack_item.public_inputs.call_context.is_delegate_call == false, - "Users cannot make a delegatecall", - CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - builder.do_assert(this_call_stack_item.public_inputs.call_context.is_static_call == false, - "Users cannot make a static call", - CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + composer.do_assert(this_call_stack_item.public_inputs.call_context.is_delegate_call == false, + "Users cannot make a delegatecall", + CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + composer.do_assert(this_call_stack_item.public_inputs.call_context.is_static_call == false, + "Users cannot make a static call", + CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); // The below also prevents delegatecall/staticcall in the base case - builder.do_assert(this_call_stack_item.public_inputs.call_context.storage_contract_address == - this_call_stack_item.contract_address, - "Storage contract address must be that of the called contract", - CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); + composer.do_assert(this_call_stack_item.public_inputs.call_context.storage_contract_address == + this_call_stack_item.contract_address, + "Storage contract address must be that of the called contract", + CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); } -void update_end_values(DummyBuilder& builder, +void update_end_values(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -138,7 +138,7 @@ void update_end_values(DummyBuilder& builder, ASSERT(public_inputs.end.unencrypted_log_preimages_length == fr(0)); // Since it's the first iteration, we need to push the the tx hash nullifier into the `new_nullifiers` array - array_push(builder, public_inputs.end.new_nullifiers, private_inputs.tx_request.hash()); + array_push(composer, public_inputs.end.new_nullifiers, private_inputs.tx_request.hash()); // Note that we do not need to nullify the transaction request nonce anymore. // Should an account want to additionally use nonces for replay protection or handling cancellations, @@ -149,7 +149,7 @@ void update_end_values(DummyBuilder& builder, // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& builder, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs) { // We'll be pushing data to this during execution of this circuit. @@ -158,35 +158,35 @@ KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder // Do this before any functions can modify the inputs. initialise_end_values(private_inputs, public_inputs); - validate_inputs(builder, private_inputs); + validate_inputs(composer, private_inputs); - validate_this_private_call_against_tx_request(builder, private_inputs); + validate_this_private_call_against_tx_request(composer, private_inputs); // TODO(rahul) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/499 // Noir doesn't have hash index so it can't hash private call stack item correctly // TODO(dbanks12): may need to comment out hash check in here according to TODO above // TODO(jeanmon) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/671 - // common_validate_call_stack(builder, private_inputs.private_call); + // common_validate_call_stack(composer, private_inputs.private_call); common_validate_read_requests( - builder, + composer, private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address, private_inputs.private_call.call_stack_item.public_inputs.read_requests, private_inputs.private_call.read_request_membership_witnesses, public_inputs.constants.historic_tree_roots.private_historic_tree_roots.private_data_tree_root); // TODO(dbanks12): feels like update_end_values should happen after contract logic - update_end_values(builder, private_inputs, public_inputs); - common_update_end_values(builder, private_inputs.private_call, public_inputs); + update_end_values(composer, private_inputs, public_inputs); + common_update_end_values(composer, private_inputs.private_call, public_inputs); - common_contract_logic(builder, + common_contract_logic(composer, private_inputs.private_call, public_inputs, private_inputs.tx_request.tx_context.contract_deployment_data, private_inputs.tx_request.function_data); // We'll skip any verification in this native implementation, because for a Local Developer Testnet, there won't - // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(builder, + // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(composer, // private_inputs, // _private_inputs.private_call.vk->num_public_inputs, // _private_inputs.previous_kernel.vk->num_public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp index b5f23f4a928f..c9d86e0a397e 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.hpp @@ -4,16 +4,16 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_init.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; // using abis::private_kernel::PublicInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; -KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyBuilder& builder, +KernelCircuitPublicInputs native_private_kernel_circuit_initial(DummyComposer& composer, PrivateKernelInputsInit const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp index a5eafad8aaa0..3cafd7e50e50 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_init.test.cpp @@ -60,8 +60,8 @@ TEST_F(native_private_kernel_init_tests, deposit) unencrypted_logs_hash, encrypted_log_preimages_length, unencrypted_log_preimages_length); - DummyBuilder builder = DummyBuilder("private_kernel_tests__native_deposit"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__native_deposit"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_TRUE(validate_no_new_deployed_contract(public_inputs)); @@ -81,10 +81,10 @@ TEST_F(native_private_kernel_init_tests, deposit) accumulate_sha256({ fr(0), fr(0), unencrypted_logs_hash[0], unencrypted_logs_hash[1] }); ASSERT_EQ(public_inputs.end.unencrypted_logs_hash, expected_unencrypted_logs_hash); - // Assert that builder doesn't give any errors - ASSERT_FALSE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().message, ""); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::NO_ERROR); + // Assert that composer doesn't give any errors + ASSERT_FALSE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().message, ""); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::NO_ERROR); } /** @@ -93,8 +93,8 @@ TEST_F(native_private_kernel_init_tests, deposit) TEST_F(native_private_kernel_init_tests, basic_contract_deployment) { auto const& private_inputs = do_private_call_get_kernel_inputs_init(true, constructor, standard_test_args()); - DummyBuilder builder = DummyBuilder("private_kernel_tests__native_basic_contract_deployment"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__native_basic_contract_deployment"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); EXPECT_TRUE(validate_deployed_contract_address(private_inputs, public_inputs)); @@ -108,10 +108,10 @@ TEST_F(native_private_kernel_init_tests, basic_contract_deployment) ASSERT_EQ(public_inputs.end.encrypted_logs_hash, expected_logs_hash); ASSERT_EQ(public_inputs.end.unencrypted_logs_hash, expected_logs_hash); - // Assert that builder doesn't give any errors - ASSERT_FALSE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().message, ""); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::NO_ERROR); + // Assert that composer doesn't give any errors + ASSERT_FALSE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().message, ""); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::NO_ERROR); } // TODO(suyash): Disabled until https://github.com/AztecProtocol/aztec-packages/issues/499 is resolved. @@ -122,12 +122,12 @@ TEST_F(native_private_kernel_init_tests, DISABLED_contract_deployment_call_stack // Randomise the second item in the private call stack (i.e. hash of the private call item). private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[1] = NT::fr::random_element(); - DummyBuilder builder = - DummyBuilder("private_kernel_tests__contract_deployment_call_stack_item_hash_mismatch_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__contract_deployment_call_stack_item_hash_mismatch_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); - EXPECT_EQ(builder.failed(), true); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_EQ(composer.failed(), true); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_ITEM_HASH_MISMATCH); } @@ -138,13 +138,13 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_construct // Pollute the constructor vk hash in the tx_request. private_inputs.tx_request.tx_context.contract_deployment_data.constructor_vk_hash = NT::fr::random_element(); - DummyBuilder builder = - DummyBuilder("private_kernel_tests__contract_deployment_incorrect_constructor_vk_hash_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__contract_deployment_incorrect_constructor_vk_hash_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); - EXPECT_EQ(builder.failed(), true); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); - EXPECT_EQ(builder.get_first_failure().message, "constructor_vk_hash doesn't match private_call_vk_hash"); + EXPECT_EQ(composer.failed(), true); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONSTRUCTOR_VK_HASH); + EXPECT_EQ(composer.get_first_failure().message, "constructor_vk_hash doesn't match private_call_vk_hash"); } TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_contract_address_fails) @@ -157,12 +157,13 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_incorrect_contract_ private_inputs.tx_request.origin = random_address; private_inputs.private_call.call_stack_item.contract_address = random_address; - DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__contract_deployment_incorrect_contract_address_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); - EXPECT_EQ(builder.failed(), true); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); - EXPECT_EQ(builder.get_first_failure().message, "contract address supplied doesn't match derived address"); + EXPECT_EQ(composer.failed(), true); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + EXPECT_EQ(composer.get_first_failure().message, "contract address supplied doesn't match derived address"); } TEST_F(native_private_kernel_init_tests, contract_deployment_contract_address_mismatch_fails) @@ -176,12 +177,12 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_contract_address_mi private_inputs.private_call.call_stack_item.contract_address = random_contract_address; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_contract_address_mismatch_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); } @@ -193,14 +194,14 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_function_data_misma private_inputs.tx_request.function_data.function_selector = numeric::random::get_engine().get_random_uint32(); // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_function_data_mismatch_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "user's intent does not match initial private call (tx_request.function_data must match " "call_stack_item.function_data)"); } @@ -213,14 +214,14 @@ TEST_F(native_private_kernel_init_tests, contract_deployment_args_hash_mismatch_ private_inputs.tx_request.args_hash = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__contract_deployment_args_hash_mismatch_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__USER_INTENT_MISMATCH_BETWEEN_TX_REQUEST_AND_CALL_STACK_ITEM); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "user's intent does not match initial private call (tx_request.args must match " "call_stack_item.public_inputs.args)"); } @@ -233,14 +234,14 @@ TEST_F(native_private_kernel_init_tests, private_function_is_private_false_fails private_inputs.private_call.call_stack_item.function_data.is_private = false; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_is_private_false_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__private_function_is_private_false_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "Cannot execute a non-private function with the private kernel circuit"); } @@ -253,13 +254,13 @@ TEST_F(native_private_kernel_init_tests, private_function_static_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_static_call = true; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_static_call_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__private_function_static_call_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - EXPECT_EQ(builder.get_first_failure().message, "Users cannot make a static call"); + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + EXPECT_EQ(composer.get_first_failure().message, "Users cannot make a static call"); } TEST_F(native_private_kernel_init_tests, private_function_delegate_call_fails) @@ -270,13 +271,13 @@ TEST_F(native_private_kernel_init_tests, private_function_delegate_call_fails) private_inputs.private_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_delegate_call_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__private_function_delegate_call_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); - EXPECT_EQ(builder.get_first_failure().message, "Users cannot make a delegatecall"); + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__UNSUPPORTED_OP); + EXPECT_EQ(composer.get_first_failure().message, "Users cannot make a delegatecall"); } TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_contract_address_fails) @@ -288,14 +289,14 @@ TEST_F(native_private_kernel_init_tests, private_function_incorrect_storage_cont NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = - DummyBuilder("private_kernel_tests__private_function_incorrect_storage_contract_address_fails"); - native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_storage_contract_address_fails"); + native_private_kernel_circuit_initial(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, "Storage contract address must be that of the called contract"); + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CONTRACT_ADDRESS_MISMATCH); + EXPECT_EQ(composer.get_first_failure().message, "Storage contract address must be that of the called contract"); } TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) @@ -314,13 +315,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_request"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_request"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -342,13 +343,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_leaf_index"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -370,13 +371,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_bad_sibling_path"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -408,13 +409,13 @@ TEST_F(native_private_kernel_init_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_read_request_root_mismatch"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_read_request_root_mismatch"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); // Check the first nullifier is hash of the signed tx request @@ -434,16 +435,16 @@ TEST_F(native_private_kernel_init_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_no_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_no_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -463,16 +464,16 @@ TEST_F(native_private_kernel_init_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_one_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_one_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -492,16 +493,16 @@ TEST_F(native_private_kernel_init_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_two_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_two_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -522,16 +523,16 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_init_tests__native_max_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); // Check the first nullifier is hash of the signed tx request ASSERT_EQ(public_inputs.end.new_nullifiers[0], private_inputs.tx_request.hash()); @@ -560,16 +561,17 @@ TEST_F(native_private_kernel_init_tests, native_one_transient_read_requests_work read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_init_tests__native_one_transient_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("native_private_kernel_init_tests__native_one_transient_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_works) @@ -591,17 +593,17 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_ read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = - DummyBuilder("native_private_kernel_init_tests__native_max_read_requests_one_transient_works"); - auto const& public_inputs = native_private_kernel_circuit_initial(builder, private_inputs); + DummyComposer composer = + DummyComposer("native_private_kernel_init_tests__native_max_read_requests_one_transient_works"); + auto const& public_inputs = native_private_kernel_circuit_initial(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } } // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp index 776f6139807e..e8fd836ad3d3 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.cpp @@ -7,7 +7,7 @@ #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::private_kernel { @@ -17,23 +17,23 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; using aztec3::utils::array_length; using aztec3::utils::array_pop; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // using plonk::stdlib::merkle_tree:: // // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // // private_call.call_stack_item.public_inputs! -// CT::AggregationObject verify_proofs(Builder& builder, +// CT::AggregationObject verify_proofs(Composer& composer, // PrivateInputs const& private_inputs, // size_t const& num_private_call_public_inputs, // size_t const& num_private_kernel_public_inputs) // { // CT::AggregationObject aggregation_object = Aggregator::aggregate( -// &builder, private_inputs.private_call.vk, private_inputs.private_call.proof, +// &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, // num_private_call_public_inputs); -// Aggregator::aggregate(&builder, +// Aggregator::aggregate(&composer, // private_inputs.previous_kernel.vk, // private_inputs.previous_kernel.proof, // num_private_kernel_public_inputs, @@ -42,7 +42,7 @@ using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // return aggregation_object; // } -void validate_this_private_call_hash(DummyBuilder& builder, +void validate_this_private_call_hash(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs, KernelCircuitPublicInputs& public_inputs) { @@ -51,32 +51,32 @@ void validate_this_private_call_hash(DummyBuilder& builder, const auto popped_private_call_hash = array_pop(public_inputs.end.private_call_stack); const auto calculated_this_private_call_hash = private_inputs.private_call.call_stack_item.hash(); - builder.do_assert( + composer.do_assert( popped_private_call_hash == calculated_this_private_call_hash, "calculated private_call_hash does not match provided private_call_hash at the top of the call stack", CircuitErrorCode::PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); }; -void validate_contract_tree_root(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) +void validate_contract_tree_root(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs) { auto const& purported_contract_tree_root = private_inputs.private_call.call_stack_item.public_inputs.historic_contract_tree_root; auto const& previous_kernel_contract_tree_root = private_inputs.previous_kernel.public_inputs.constants.historic_tree_roots.private_historic_tree_roots .contract_tree_root; - builder.do_assert( + composer.do_assert( purported_contract_tree_root == previous_kernel_contract_tree_root, "purported_contract_tree_root doesn't match previous_kernel_contract_tree_root", CircuitErrorCode::PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH); } -void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInner const& private_inputs) +void validate_inputs(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs) { const auto& this_call_stack_item = private_inputs.private_call.call_stack_item; - builder.do_assert(this_call_stack_item.function_data.is_private == true, - "Cannot execute a non-private function with the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); + composer.do_assert(this_call_stack_item.function_data.is_private == true, + "Cannot execute a non-private function with the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_FUNCTION_EXECUTED_WITH_PRIVATE_KERNEL); const auto& start = private_inputs.previous_kernel.public_inputs.end; @@ -85,21 +85,21 @@ void validate_inputs(DummyBuilder& builder, PrivateKernelInputsInner const& NT::fr const start_private_call_stack_length = array_length(start.private_call_stack); - builder.do_assert(private_inputs.previous_kernel.public_inputs.is_private == true, - "Cannot verify a non-private kernel snark in the private kernel circuit", - CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL); - builder.do_assert(this_call_stack_item.function_data.is_constructor == false, - "A constructor must be executed as the first tx in the recursion", - CircuitErrorCode::PRIVATE_KERNEL__CONSTRUCTOR_EXECUTED_IN_RECURSION); - builder.do_assert(start_private_call_stack_length != 0, - "Cannot execute private kernel circuit with an empty private call stack", - CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_EMPTY); + composer.do_assert(private_inputs.previous_kernel.public_inputs.is_private == true, + "Cannot verify a non-private kernel snark in the private kernel circuit", + CircuitErrorCode::PRIVATE_KERNEL__NON_PRIVATE_KERNEL_VERIFIED_WITH_PRIVATE_KERNEL); + composer.do_assert(this_call_stack_item.function_data.is_constructor == false, + "A constructor must be executed as the first tx in the recursion", + CircuitErrorCode::PRIVATE_KERNEL__CONSTRUCTOR_EXECUTED_IN_RECURSION); + composer.do_assert(start_private_call_stack_length != 0, + "Cannot execute private kernel circuit with an empty private call stack", + CircuitErrorCode::PRIVATE_KERNEL__PRIVATE_CALL_STACK_EMPTY); } // NOTE: THIS IS A VERY UNFINISHED WORK IN PROGRESS. // TODO(mike): is there a way to identify whether an input has not been used by ths circuit? This would help us // more-safely ensure we're constraining everything. -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& builder, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs) { // We'll be pushing data to this during execution of this circuit. @@ -108,19 +108,19 @@ KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& // Do this before any functions can modify the inputs. common_initialise_end_values(private_inputs.previous_kernel, public_inputs); - validate_inputs(builder, private_inputs); + validate_inputs(composer, private_inputs); // TODO(jeanmon) Resuscitate after issue 499 is fixed as explained below. // Remove the array_pop below when uncommenting this validation. - // validate_this_private_call_hash(builder, private_inputs, public_inputs); + // validate_this_private_call_hash(composer, private_inputs, public_inputs); array_pop(public_inputs.end.private_call_stack); // TODO(dbanks12): may need to comment out hash check in here according to TODO above // TODO(jeanmon) FIXME - https://github.com/AztecProtocol/aztec-packages/issues/671 - // common_validate_call_stack(builder, private_inputs.private_call); + // common_validate_call_stack(composer, private_inputs.private_call); common_validate_read_requests( - builder, + composer, private_inputs.private_call.call_stack_item.public_inputs.call_context.storage_contract_address, private_inputs.private_call.call_stack_item.public_inputs.read_requests, private_inputs.private_call.read_request_membership_witnesses, @@ -128,20 +128,20 @@ KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& // TODO(dbanks12): feels like update_end_values should happen later - common_update_end_values(builder, private_inputs.private_call, public_inputs); + common_update_end_values(composer, private_inputs.private_call, public_inputs); // ensure that historic/purported contract tree root matches the one in previous kernel - validate_contract_tree_root(builder, private_inputs); + validate_contract_tree_root(composer, private_inputs); const auto private_call_stack_item = private_inputs.private_call.call_stack_item; - common_contract_logic(builder, + common_contract_logic(composer, private_inputs.private_call, public_inputs, private_call_stack_item.public_inputs.contract_deployment_data, private_call_stack_item.function_data); // We'll skip any verification in this native implementation, because for a Local Developer Testnet, there won't - // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(builder, + // _be_ a valid proof to verify!!! auto aggregation_object = verify_proofs(composer, // private_inputs, // _private_inputs.private_call.vk->num_public_inputs, // _private_inputs.previous_kernel.vk->num_public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp index 52ff291a27d6..c9dbd8fa7d93 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.hpp @@ -4,15 +4,15 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/private_kernel/private_kernel_inputs_inner.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; -KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyBuilder& builder, +KernelCircuitPublicInputs native_private_kernel_circuit_inner(DummyComposer& composer, PrivateKernelInputsInner const& private_inputs); } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp index 8c2b2247079c..113ec30cbf74 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_inner.test.cpp @@ -50,13 +50,14 @@ TEST_F(native_private_kernel_inner_tests, private_function_zero_storage_contract private_inputs.private_call.call_stack_item.hash(); // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_zero_storage_contract_address_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_zero_storage_contract_address_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__INVALID_CONTRACT_ADDRESS); + EXPECT_EQ(composer.get_first_failure().message, "contract address can't be 0 for non-contract deployment related transactions"); } @@ -69,15 +70,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_tr .contract_tree_root = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("private_kernel_tests__private_function_incorrect_contract_tree_root_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); + EXPECT_TRUE(composer.failed()); EXPECT_EQ( - builder.get_first_failure().code, + composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__PURPORTED_CONTRACT_TREE_ROOT_AND_PREVIOUS_KERNEL_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "purported_contract_tree_root doesn't match previous_kernel_contract_tree_root"); } @@ -90,14 +91,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -109,15 +111,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_contract_le private_inputs.private_call.contract_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = - DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -130,14 +132,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.leaf_index = wrong_idx; // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_index_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -149,15 +152,15 @@ TEST_F(native_private_kernel_inner_tests, private_function_incorrect_function_le private_inputs.private_call.function_leaf_membership_witness.sibling_path[0] = fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = - DummyBuilder("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_contract_leaf_sibling_path_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__COMPUTED_CONTRACT_TREE_ROOT_AND_PURPORTED_CONTRACT_TREE_ROOT_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "computed_contract_tree_root doesn't match purported_contract_tree_root"); } @@ -170,21 +173,22 @@ TEST_F(native_private_kernel_inner_tests, DISABLED_private_function_incorrect_ca private_inputs.private_call.call_stack_item.public_inputs.private_call_stack[0] = NT::fr::random_element(); // Invoke the native private kernel circuit - DummyBuilder builder = DummyBuilder("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); - native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("private_kernel_tests__private_function_incorrect_call_stack_item_hash_fails"); + native_private_kernel_circuit_inner(composer, private_inputs); // Assertion checks - EXPECT_TRUE(builder.failed()); - EXPECT_EQ(builder.get_first_failure().code, + EXPECT_TRUE(composer.failed()); + EXPECT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__CALCULATED_PRIVATE_CALL_HASH_AND_PROVIDED_PRIVATE_CALL_HASH_MISMATCH); - EXPECT_EQ(builder.get_first_failure().message, + EXPECT_EQ(composer.get_first_failure().message, "calculated private_call_hash does not match provided private_call_hash at the top of the call stack"); } TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregating_too_many_commitments) { // Negative test to check if push_array_to_array fails if two many commitments are merged together - DummyBuilder builder = DummyBuilder("should_fail_if_aggregating_too_many_commitments"); + DummyComposer composer = DummyComposer("should_fail_if_aggregating_too_many_commitments"); PrivateKernelInputsInner private_inputs = do_private_call_get_kernel_inputs_inner(false, deposit, standard_test_args()); @@ -195,10 +199,10 @@ TEST_F(native_private_kernel_inner_tests, private_kernel_should_fail_if_aggregat full_new_commitments[i] = i + 1; } private_inputs.previous_kernel.public_inputs.end.new_commitments = full_new_commitments; - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, CircuitErrorCode::ARRAY_OVERFLOW); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::ARRAY_OVERFLOW); } /** @@ -234,13 +238,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_request) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_request"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_request"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -261,13 +265,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_leaf_index) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_leaf_index"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -288,13 +292,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_sibling_path) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_bad_sibling_path"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -325,13 +329,13 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_root_mismatch) private_inputs.private_call.call_stack_item.public_inputs.read_requests = bad_requests; private_inputs.private_call.read_request_membership_witnesses = bad_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_read_request_root_mismatch"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_read_request_root_mismatch"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().code, + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().code, CircuitErrorCode::PRIVATE_KERNEL__READ_REQUEST_PRIVATE_DATA_ROOT_MISMATCH); } @@ -348,16 +352,16 @@ TEST_F(native_private_kernel_inner_tests, native_no_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_no_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_no_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) @@ -376,16 +380,16 @@ TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_one_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_one_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) @@ -404,16 +408,16 @@ TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_two_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_two_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) @@ -433,16 +437,16 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_max_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_works) @@ -463,16 +467,17 @@ TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_wor read_request_membership_witnesses[0].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("native_private_kernel_inner_tests__native_one_transient_read_requests_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient_works) @@ -496,17 +501,17 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient read_request_membership_witnesses[1].sibling_path = zero_array(); private_inputs.private_call.read_request_membership_witnesses = read_request_membership_witnesses; - DummyBuilder builder = - DummyBuilder("native_private_kernel_inner_tests__native_max_read_requests_one_transient_works"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = + DummyComposer("native_private_kernel_inner_tests__native_max_read_requests_one_transient_works"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); validate_no_new_deployed_contract(public_inputs); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(native_private_kernel_inner_tests, native_logs_are_hashed_as_expected) @@ -532,8 +537,8 @@ TEST_F(native_private_kernel_inner_tests, native_logs_are_hashed_as_expected) public_inputs_encrypted_log_preimages_length, public_inputs_unencrypted_log_preimages_length); - DummyBuilder builder = DummyBuilder("native_private_kernel_inner_tests__native_logs_are_hashed_as_expected"); - auto const& public_inputs = native_private_kernel_circuit_inner(builder, private_inputs); + DummyComposer composer = DummyComposer("native_private_kernel_inner_tests__native_logs_are_hashed_as_expected"); + auto const& public_inputs = native_private_kernel_circuit_inner(composer, private_inputs); ASSERT_EQ(public_inputs.end.encrypted_log_preimages_length, encrypted_log_preimages_length + public_inputs_encrypted_log_preimages_length); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp index d55e29cf0df1..8e4ff12580ca 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.cpp @@ -5,7 +5,7 @@ #include "aztec3/circuits/abis/previous_kernel_data.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include @@ -15,14 +15,14 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PreviousKernelData; using aztec3::utils::CircuitResult; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; // TODO(jeanmon): the following code will be optimized based on hints regarding matching // a read request and commitment, i.e., we get pairs i,j such that read_requests[i] == new_commitments[j] // Relevant task: https://github.com/AztecProtocol/aztec-packages/issues/892 -void chop_pending_commitments(DummyBuilder& builder, +void chop_pending_commitments(DummyComposer& composer, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& read_request_membership_witnesses, @@ -43,7 +43,7 @@ void chop_pending_commitments(DummyBuilder& builder, if (match_pos != KERNEL_NEW_COMMITMENTS_LENGTH) { new_commitments[match_pos] = fr(0); } else { - builder.do_assert( + composer.do_assert( false, format("transient read request at position [", i, "] does not match any new commitment"), CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH); @@ -56,7 +56,7 @@ void chop_pending_commitments(DummyBuilder& builder, } KernelCircuitPublicInputs native_private_kernel_circuit_ordering( - DummyBuilder& builder, + DummyComposer& composer, PreviousKernelData const& previous_kernel, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& @@ -75,7 +75,7 @@ KernelCircuitPublicInputs native_private_kernel_circuit_ordering( // over all iterations of the private kernel. Therefore, we have to target commitments in public_inputs.end // Remark: The commitments in public_inputs.end have already been SILOED! chop_pending_commitments( - builder, read_requests, read_request_membership_witnesses, public_inputs.end.new_commitments); + composer, read_requests, read_request_membership_witnesses, public_inputs.end.new_commitments); return public_inputs; }; @@ -83,7 +83,7 @@ KernelCircuitPublicInputs native_private_kernel_circuit_ordering( CircuitResult> native_private_kernel_circuit_ordering_rr_dummy( PreviousKernelData const& previous_kernel) { - DummyBuilder builder = DummyBuilder("private_kernel__sim_ordering"); + DummyComposer composer = DummyComposer("private_kernel__sim_ordering"); // TODO(JEANMON): this is a temporary milestone. At a later stage, we will pass "real" read_requests and // membership_witnesses @@ -92,8 +92,8 @@ CircuitResult> native_private_kernel_circuit_order read_request_membership_witnesses{}; auto const& public_inputs = native_private_kernel_circuit_ordering( - builder, previous_kernel, read_requests, read_request_membership_witnesses); - return builder.result_or_error(public_inputs); + composer, previous_kernel, read_requests, read_request_membership_witnesses); + return composer.result_or_error(public_inputs); } } // namespace aztec3::circuits::kernel::private_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp index 6c5289483853..eee3b7d80a56 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.hpp @@ -7,7 +7,7 @@ #include "aztec3/circuits/abis/previous_kernel_data.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include @@ -15,12 +15,12 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PreviousKernelData; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::MembershipWitness; using aztec3::utils::CircuitResult; KernelCircuitPublicInputs native_private_kernel_circuit_ordering( - DummyBuilder& builder, + DummyComposer& composer, PreviousKernelData const& previous_kernel, std::array const& read_requests, std::array, READ_REQUESTS_LENGTH> const& diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp index 88c4d4ef965c..6bb35f8d2a95 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit_ordering.test.cpp @@ -42,16 +42,16 @@ TEST_F(native_private_kernel_ordering_tests, native_one_read_request_choping_com private_inputs.previous_kernel.public_inputs.end.new_commitments = new_commitments; - DummyBuilder builder = - DummyBuilder("native_private_kernel_ordering_tests__native_one_read_request_choping_commitment_works"); + DummyComposer composer = + DummyComposer("native_private_kernel_ordering_tests__native_one_read_request_choping_commitment_works"); auto const& public_inputs = native_private_kernel_circuit_ordering( - builder, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); + composer, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 0); } @@ -77,16 +77,16 @@ TEST_F(native_private_kernel_ordering_tests, native_read_requests_choping_commit private_inputs.previous_kernel.public_inputs.end.new_commitments = new_commitments; - DummyBuilder builder = - DummyBuilder("native_private_kernel_ordering_tests__native_read_requests_choping_commitment_works"); + DummyComposer composer = + DummyComposer("native_private_kernel_ordering_tests__native_read_requests_choping_commitment_works"); auto const& public_inputs = native_private_kernel_circuit_ordering( - builder, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); + composer, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); if (failure.code != CircuitErrorCode::NO_ERROR) { info("failure: ", failure); } - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); ASSERT_TRUE(array_length(public_inputs.end.new_commitments) == 2); ASSERT_TRUE(public_inputs.end.new_commitments[0] == fr(1285)); ASSERT_TRUE(public_inputs.end.new_commitments[1] == fr(1282)); @@ -118,11 +118,11 @@ TEST_F(native_private_kernel_ordering_tests, native_read_request_unknown_fails) private_inputs.previous_kernel.public_inputs.end.new_commitments = new_commitments; - DummyBuilder builder = DummyBuilder("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); + DummyComposer composer = DummyComposer("native_private_kernel_ordering_tests__native_read_request_unknown_fails"); auto const& public_inputs = native_private_kernel_circuit_ordering( - builder, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); + composer, private_inputs.previous_kernel, read_requests, read_request_membership_witnesses); - auto failure = builder.get_first_failure(); + auto failure = composer.get_first_failure(); ASSERT_EQ(failure.code, CircuitErrorCode::PRIVATE_KERNEL__TRANSIENT_READ_REQUEST_NO_MATCH); } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index 8af328b9bfed..bb76a7fdfa5c 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -27,16 +27,22 @@ using aztec3::circuits::silo_nullifier; // TODO: NEED TO RECONCILE THE `proof`'s public inputs (which are uint8's) with the // private_call.call_stack_item.public_inputs! -CT::AggregationObject verify_proofs(Builder& builder, PrivateKernelInputsInner const& private_inputs) +CT::AggregationObject verify_proofs(Composer& composer, + PrivateKernelInputsInner const& private_inputs, + size_t const& num_private_call_public_inputs, + size_t const& num_private_kernel_public_inputs) { // compute P0, P1 for private function proof - CT::AggregationObject aggregation_object = - Aggregator::aggregate(&builder, private_inputs.private_call.vk, private_inputs.private_call.proof); + CT::AggregationObject aggregation_object = Aggregator::aggregate( + &composer, private_inputs.private_call.vk, private_inputs.private_call.proof, num_private_call_public_inputs); // computes P0, P1 for previous kernel proof // AND accumulates all of it in P0_agg, P1_agg - Aggregator::aggregate( - &builder, private_inputs.previous_kernel.vk, private_inputs.previous_kernel.proof, aggregation_object); + Aggregator::aggregate(&composer, + private_inputs.previous_kernel.vk, + private_inputs.previous_kernel.proof, + num_private_kernel_public_inputs, + aggregation_object); return aggregation_object; } @@ -92,8 +98,8 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne const auto& is_static_call = private_call_public_inputs.call_context.is_static_call; // No state changes are allowed for static calls: - is_static_call.must_imply(is_array_empty(new_commitments) == true); - is_static_call.must_imply(is_array_empty(new_nullifiers) == true); + is_static_call.must_imply(is_array_empty(new_commitments) == true); + is_static_call.must_imply(is_array_empty(new_nullifiers) == true); // TODO: name change (just contract_address) const auto& storage_contract_address = private_call_public_inputs.call_context.storage_contract_address; @@ -135,7 +141,7 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne // push the contract address nullifier to nullifier vector CT::fr const conditional_contract_address_nullifier = CT::fr::conditional_assign(is_contract_deployment, contract_address_nullifier, CT::fr(0)); - array_push(public_inputs.end.new_nullifiers, conditional_contract_address_nullifier); + array_push(public_inputs.end.new_nullifiers, conditional_contract_address_nullifier); // Add new contract data if its a contract deployment function auto const new_contract_data = NewContractData{ @@ -144,8 +150,8 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne .function_tree_root = contract_deployment_data.function_tree_root, }; - array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, - new_contract_data); + array_push, KERNEL_NEW_CONTRACTS_LENGTH>(public_inputs.end.new_contracts, + new_contract_data); } { // commitments, nullifiers, and contracts @@ -161,14 +167,14 @@ void update_end_values(PrivateKernelInputsInner const& private_inputs, Kerne } // Add new commitments/etc to AggregatedData - push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); - push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); + push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); + push_array_to_array(siloed_new_nullifiers, public_inputs.end.new_nullifiers); } { // call stacks // copy the private function circuit's callstack into the AggregatedData const auto& this_private_call_stack = private_call_public_inputs.private_call_stack; - push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); + push_array_to_array(this_private_call_stack, public_inputs.end.private_call_stack); } // { @@ -193,7 +199,7 @@ void validate_this_private_call_hash(PrivateKernelInputsInner const& private const auto& start = private_inputs.previous_kernel.public_inputs.end; // TODO: this logic might need to change to accommodate the weird edge 3 initial txs (the 'main' tx, the 'fee' tx, // and the 'gas rebate' tx). - const auto this_private_call_hash = array_pop(start.private_call_stack); + const auto this_private_call_hash = array_pop(start.private_call_stack); const auto calculated_this_private_call_hash = private_inputs.private_call.call_stack_item.hash(); this_private_call_hash.assert_equal(calculated_this_private_call_hash, "this private_call_hash does not reconcile"); @@ -243,9 +249,9 @@ void validate_inputs(PrivateKernelInputsInner const& private_inputs, bool fi // These lengths are calculated by counting entries until a non-zero one is encountered // True array length is constant which is a property we need for circuit inputs, // but we want to know "length" in terms of how many nonzero entries have been inserted - CT::fr const start_private_call_stack_length = array_length(start.private_call_stack); - CT::fr const start_public_call_stack_length = array_length(start.public_call_stack); - CT::fr const start_new_l2_to_l1_msgs_length = array_length(start.new_l2_to_l1_msgs); + CT::fr const start_private_call_stack_length = array_length(start.private_call_stack); + CT::fr const start_public_call_stack_length = array_length(start.public_call_stack); + CT::fr const start_new_l2_to_l1_msgs_length = array_length(start.new_l2_to_l1_msgs); // Recall: we can't do traditional `if` statements in a circuit; all code paths are always executed. The below is // some syntactic sugar, which seeks readability similar to an `if` statement. @@ -306,14 +312,14 @@ void validate_inputs(PrivateKernelInputsInner const& private_inputs, bool fi // TODO: decide what to return. // TODO: is there a way to identify whether an input has not been used by ths circuit? This would help us more-safely // ensure we're constraining everything. -KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, +KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, PrivateKernelInputsInner const& _private_inputs, bool first_iteration) { - const PrivateKernelInputsInner private_inputs = _private_inputs.to_circuit_type(builder); + const PrivateKernelInputsInner private_inputs = _private_inputs.to_circuit_type(composer); // We'll be pushing data to this during execution of this circuit. - KernelCircuitPublicInputs public_inputs = KernelCircuitPublicInputs{}.to_circuit_type(builder); + KernelCircuitPublicInputs public_inputs = KernelCircuitPublicInputs{}.to_circuit_type(composer); // Do this before any functions can modify the inputs. initialise_end_values(private_inputs, public_inputs); @@ -328,7 +334,10 @@ KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, update_end_values(private_inputs, public_inputs); - auto aggregation_object = verify_proofs(builder, private_inputs); + auto aggregation_object = verify_proofs(composer, + private_inputs, + _private_inputs.private_call.vk->num_public_inputs, + _private_inputs.previous_kernel.vk->num_public_inputs); // TODO: kernel vk membership check! @@ -336,7 +345,7 @@ KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, public_inputs.set_public(); - return public_inputs.to_native_type(); + return public_inputs.to_native_type(); }; } // namespace aztec3::circuits::kernel::private_kernel diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp index 17d10d4561a9..1f006c8ea3fd 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.hpp @@ -10,7 +10,7 @@ namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -KernelCircuitPublicInputs private_kernel_circuit(Builder& builder, +KernelCircuitPublicInputs private_kernel_circuit(Composer& composer, PrivateKernelInputsInner const& private_inputs, bool first_iteration); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp index 8db2105ea151..fa5bb369fbe9 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp @@ -219,7 +219,7 @@ std::pair, ContractDeploymentData> create_private_call_d /** * If `is_circuit` is true, we are running a real circuit test and therefore we need to generate a real proof using - * a private function builder. For the native tests, we are using a random data as public inputs of the private + * a private function composer. For the native tests, we are using a random data as public inputs of the private * function. As the native private kernel circuit doesn't validate any proofs and we don't currently test * multi-iterative kernel circuit, this should be fine. */ @@ -227,10 +227,10 @@ std::pair, ContractDeploymentData> create_private_call_d const NT::Proof private_circuit_proof = utils::get_proof_from_file(); if (is_circuit) { //*************************************************************************** - // Create a private circuit/call using builder, oracles, execution context + // Create a private circuit/call using composer, oracles, execution context // Generate its proof and public inputs for submission with a TX request //*************************************************************************** - Builder private_circuit_builder = Builder(); + Composer private_circuit_composer = Composer("../barretenberg/cpp/srs_db/ignition"); DB dummy_db; NativeOracle oracle = @@ -243,9 +243,9 @@ std::pair, ContractDeploymentData> create_private_call_d msg_sender_private_key) : NativeOracle(dummy_db, contract_address, function_data, call_context, msg_sender_private_key); - OracleWrapper oracle_wrapper = OracleWrapper(private_circuit_builder, oracle); + OracleWrapper oracle_wrapper = OracleWrapper(private_circuit_composer, oracle); - FunctionExecutionContext ctx(private_circuit_builder, oracle_wrapper); + FunctionExecutionContext ctx(private_circuit_composer, oracle_wrapper); OptionalPrivateCircuitPublicInputs const opt_private_circuit_public_inputs = func(ctx, args_vec); private_circuit_public_inputs = opt_private_circuit_public_inputs.remove_optionality(); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp index 06b1ef9ec3c5..13a9e20eda50 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.hpp @@ -28,14 +28,14 @@ using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInner; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::utils::zero_array; // A type representing any private circuit function // (for now it works for deposit and constructor) using private_function = std::function( - FunctionExecutionContext&, std::vector const&)>; + FunctionExecutionContext&, std::vector const&)>; } // namespace diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp index a22535a3577d..f67d54013737 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/utils.cpp @@ -91,7 +91,7 @@ std::shared_ptr fake_vk() { std::map commitments; commitments["FAKE"] = *new NT::bn254_point(NT::fq(0), NT::fq(0)); - NT::VKData vk_data = { .circuit_type = static_cast(proof_system::CircuitType::TURBO), + NT::VKData vk_data = { .composer_type = proof_system::ComposerType::TURBO, .circuit_size = 2048, .num_public_inputs = 116, .commitments = commitments, @@ -113,8 +113,8 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) PreviousKernelData const init_previous_kernel{}; auto crs_factory = barretenberg::srs::get_crs_factory(); - Builder mock_kernel_builder; - auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_builder, init_previous_kernel.public_inputs); + Composer mock_kernel_composer = Composer(crs_factory); + auto mock_kernel_public_inputs = mock_kernel_circuit(mock_kernel_composer, init_previous_kernel.public_inputs); NT::Proof const mock_kernel_proof = real_vk_proof ? get_proof_from_file() : NT::Proof{ .proof_data = std::vector(64, 0) }; @@ -129,7 +129,7 @@ PreviousKernelData dummy_previous_kernel(bool real_vk_proof = false) // TODO(rahul) assertions don't work in wasm and it isn't worth updating barratenberg to handle our error code // mechanism. Apparently we are getting rid of this function (dummy_previous_kernel()) soon anyway. - assert(!mock_kernel_builder.failed()); + assert(!mock_kernel_composer.failed()); return previous_kernel; } diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp index 7035c9e65510..da155ab26467 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/.test.cpp @@ -28,7 +28,7 @@ #include namespace { -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::CallContext; @@ -367,15 +367,12 @@ PublicKernelInputs get_kernel_inputs_with_previous_kernel(NT::boolean privat .bytecode_hash = 1234567, }; - // TODO(914) Should this be unused? - [[maybe_unused]] CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { - .private_data_tree_root = 1000, - .contract_tree_root = 2000, - .l1_to_l2_messages_tree_root = - 3000, - .private_kernel_vk_tree_root = - 4000, - } }; + CombinedHistoricTreeRoots const historic_tree_roots = { .private_historic_tree_roots = { + .private_data_tree_root = 1000, + .contract_tree_root = 2000, + .l1_to_l2_messages_tree_root = 3000, + .private_kernel_vk_tree_root = 4000, + } }; CombinedConstantData const end_constants = { .historic_tree_roots = @@ -491,7 +488,8 @@ void validate_private_data_propagation(const PublicKernelInputs& inputs, TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__only_valid_public_data_reads_should_be_propagated"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__only_valid_public_data_reads_should_be_propagated"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // modify the contract storage reads so only 2 are valid and only those should be propagated @@ -512,9 +510,9 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyComposer.failed()); ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); @@ -534,7 +532,7 @@ TEST(public_kernel_tests, only_valid_public_data_reads_should_be_propagated) TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__only_valid_update_requests_should_be_propagated"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__only_valid_update_requests_should_be_propagated"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // modify the contract storage update requests so only 2 are valid and only those should be propagated @@ -557,9 +555,9 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyComposer.failed()); ASSERT_FALSE(public_inputs.is_private); ASSERT_EQ(public_inputs.constants.tx_context, inputs.previous_kernel.public_inputs.constants.tx_context); @@ -581,89 +579,90 @@ TEST(public_kernel_tests, only_valid_update_requests_should_be_propagated) TEST(public_kernel_tests, constructor_should_fail) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__constructor_should_fail"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__constructor_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.is_constructor = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); } TEST(public_kernel_tests, constructor_should_fail_2) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__constructor_should_fail_2"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__constructor_should_fail_2"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.public_inputs.call_context.is_contract_deployment = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); } TEST(public_kernel_tests, no_bytecode_hash_should_fail) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__no_bytecode_hash_should_fail"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__no_bytecode_hash_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.bytecode_hash = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); } TEST(public_kernel_tests, contract_address_must_be_valid) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__contract_address_must_be_valid"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__contract_address_must_be_valid"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.contract_address = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); } TEST(public_kernel_tests, function_selector_must_be_valid) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__function_selector_must_be_valid"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__function_selector_must_be_valid"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.function_selector = 0; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); } TEST(public_kernel_tests, private_call_should_fail) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__private_call_should_fail"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__private_call_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.public_call.call_stack_item.function_data.is_private = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); } TEST(public_kernel_tests, inconsistent_call_hash_should_fail) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyBuilder dummyBuilder = DummyBuilder(format("public_kernel_tests__inconsistent_call_hash_should_fail-", i)); + DummyComposer dummyComposer = + DummyComposer(format("public_kernel_tests__inconsistent_call_hash_should_fail-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // change a value of something in the call stack pre-image inputs.public_call.public_call_stack_preimages[i].public_inputs.args_hash++; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_MISMATCH); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_MISMATCH); } } TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_calls) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyBuilder dummyBuilder = - DummyBuilder(format("public_kernel_tests__incorrect_storage_contract_address_fails_for_regular_calls-", i)); + DummyComposer dummyComposer = DummyComposer( + format("public_kernel_tests__incorrect_storage_contract_address_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // change the storage contract address so it does not equal the contract address @@ -671,9 +670,9 @@ TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_c NT::fr(inputs.public_call.public_call_stack_preimages[i].contract_address) + 1; inputs.public_call.public_call_stack_preimages[i].public_inputs.call_context.storage_contract_address = new_contract_address; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); } } @@ -681,24 +680,24 @@ TEST(public_kernel_tests, incorrect_storage_contract_address_fails_for_regular_c TEST(public_kernel_tests, incorrect_msg_sender_fails_for_regular_calls) { for (size_t i = 0; i < PUBLIC_CALL_STACK_LENGTH; i++) { - DummyBuilder dummyBuilder = - DummyBuilder(format("public_kernel_tests__incorrect_msg_sender_fails_for_regular_calls-", i)); + DummyComposer dummyComposer = + DummyComposer(format("public_kernel_tests__incorrect_msg_sender_fails_for_regular_calls-", i)); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // set the msg sender to be the address of the called contract, which is wrong const auto new_msg_sender = inputs.public_call.public_call_stack_preimages[i].contract_address; // change the storage contract address so it does not equal the contract address inputs.public_call.public_call_stack_preimages[i].public_inputs.call_context.msg_sender = new_msg_sender; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); } } TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_succeeds_for_mixture_of_regular_and_delegate_calls"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -730,14 +729,14 @@ TEST(public_kernel_tests, public_kernel_circuit_succeeds_for_mixture_of_regular_ } inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_msg_sender_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -761,16 +760,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_msg_sender_in inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call"); + DummyComposer dummyComposer = DummyComposer( + "public_kernel_tests__public_kernel_circuit_fails_on_incorrect_storage_contract_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -792,16 +791,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_storage_contr inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); } TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_fails_on_incorrect_portal_contract_in_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -825,16 +824,16 @@ TEST(public_kernel_tests, public_kernel_circuit_fails_on_incorrect_portal_contra inputs.public_call.call_stack_item.public_inputs.public_call_stack = call_stack_hashes; inputs.public_call.public_call_stack_preimages = child_call_stacks; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); } TEST(public_kernel_tests, public_kernel_circuit_only_checks_non_empty_call_stacks) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_only_checks_non_empty_call_stacks"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_only_checks_non_empty_call_stacks"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); const auto contract_address = NT::fr(inputs.public_call.call_stack_item.contract_address); @@ -864,86 +863,86 @@ TEST(public_kernel_tests, public_kernel_circuit_only_checks_non_empty_call_stack // adjust the call stack item hash for the current call in the previous iteration inputs.previous_kernel.public_inputs.end.public_call_stack[0] = inputs.public_call.call_stack_item.hash(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_EQ(dummyBuilder.get_first_failure(), utils::CircuitError::no_error()); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_EQ(dummyComposer.get_first_failure(), utils::CircuitError::no_error()); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, public_kernel_circuit_with_private_previous_kernel_should_succeed) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_with_private_previous_kernel_should_succeed"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_with_private_previous_kernel_should_succeed"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_previous_private_kernel) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_private_kernel"); + DummyComposer dummyComposer = DummyComposer( + "public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_private_kernel"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(true); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); // test that the prior set of private kernel public inputs were copied to the outputs validate_private_data_propagation(inputs, public_inputs); validate_public_kernel_outputs_correctly_propagated(inputs, public_inputs); - ASSERT_FALSE(dummyBuilder.failed()); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, private_previous_kernel_non_empty_private_call_stack_should_fail) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__private_previous_kernel_non_empty_private_call_stack_should_fail"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__private_previous_kernel_non_empty_private_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.end.private_call_stack[0] = 1; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); } TEST(public_kernel_tests, private_previous_kernel_empty_public_call_stack_should_fail) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__private_previous_kernel_empty_public_call_stack_should_fail"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__private_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.end.public_call_stack = zero_array(); - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); } TEST(public_kernel_tests, private_previous_kernel_non_private_previous_kernel_should_fail) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__private_previous_kernel_non_private_previous_kernel_should_fail"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__private_previous_kernel_non_private_previous_kernel_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); inputs.previous_kernel.public_inputs.is_private = false; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); } TEST(public_kernel_tests, previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call) { - DummyBuilder dummyBuilder = DummyBuilder( + DummyComposer dummyComposer = DummyComposer( "public_kernel_tests__previous_private_kernel_fails_if_contract_storage_update_requests_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); // the function call has contract storage update requests so setting it to static should fail inputs.public_call.call_stack_item.public_inputs.call_context.is_static_call = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); ASSERT_EQ( - dummyBuilder.get_first_failure().code, + dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); } TEST(public_kernel_tests, previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call) { - DummyBuilder dummyBuilder = DummyBuilder( + DummyComposer dummyComposer = DummyComposer( "public_kernel_tests__previous_private_kernel_fails_if_incorrect_storage_contract_on_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(true); @@ -951,47 +950,47 @@ TEST(public_kernel_tests, previous_private_kernel_fails_if_incorrect_storage_con // delegate call inputs.public_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; - auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); } TEST(public_kernel_tests, public_kernel_circuit_with_public_previous_kernel_should_succeed) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_kernel_circuit_with_public_previous_kernel_should_succeed"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_kernel_circuit_with_public_previous_kernel_should_succeed"); PublicKernelInputs const inputs = get_kernel_inputs_with_previous_kernel(false); - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_FALSE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, public_previous_kernel_empty_public_call_stack_should_fail) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_previous_kernel_empty_public_call_stack_should_fail"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_previous_kernel_empty_public_call_stack_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); inputs.previous_kernel.public_inputs.end.public_call_stack = zero_array(); - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); } TEST(public_kernel_tests, public_previous_kernel_private_previous_kernel_should_fail) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__public_previous_kernel_private_previous_kernel_should_fail"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__public_previous_kernel_private_previous_kernel_should_fail"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); inputs.previous_kernel.public_inputs.is_private = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); } TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_previous_public_kernel) { - DummyBuilder dummyBuilder = - DummyBuilder("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_public_kernel"); + DummyComposer dummyComposer = + DummyComposer("public_kernel_tests__circuit_outputs_should_be_correctly_populated_with_previous_public_kernel"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // setup 2 previous data writes on the public inputs @@ -1043,7 +1042,7 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre initial_l2_to_l1_messages[0] = fr(1); inputs.previous_kernel.public_inputs.end.new_l2_to_l1_msgs = initial_l2_to_l1_messages; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); // test that the prior set of private kernel public inputs were copied to the outputs validate_private_data_propagation(inputs, public_inputs); @@ -1082,12 +1081,10 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre // Unencrypted logs hash and preimage lengths should now be correctly accumulated auto const& public_inputs_unencrypted_logs_hash = inputs.previous_kernel.public_inputs.end.unencrypted_logs_hash; auto const& unencrypted_logs_hash = inputs.public_call.call_stack_item.public_inputs.unencrypted_logs_hash; - // TODO(914) Should this be unused? - [[maybe_unused]] auto const& expected_unencrypted_logs_hash = - accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], - public_inputs_unencrypted_logs_hash[1], - unencrypted_logs_hash[0], - unencrypted_logs_hash[1] }); + auto const& expected_unencrypted_logs_hash = accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], + public_inputs_unencrypted_logs_hash[1], + unencrypted_logs_hash[0], + unencrypted_logs_hash[1] }); auto const& public_inputs_unencrypted_log_preimages_length = inputs.previous_kernel.public_inputs.end.unencrypted_log_preimages_length; @@ -1131,28 +1128,28 @@ TEST(public_kernel_tests, circuit_outputs_should_be_correctly_populated_with_pre expected_new_messages, public_inputs.end.new_l2_to_l1_msgs)); - ASSERT_FALSE(dummyBuilder.failed()); + ASSERT_FALSE(dummyComposer.failed()); } TEST(public_kernel_tests, previous_public_kernel_fails_if_contract_storage_update_requests_on_static_call) { - DummyBuilder dummyBuilder = DummyBuilder( + DummyComposer dummyComposer = DummyComposer( "public_kernel_tests__previous_public_kernel_fails_if_contract_storage_update_requests_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has contract storage update requests so setting it to static should fail inputs.public_call.call_stack_item.public_inputs.call_context.is_static_call = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); ASSERT_EQ( - dummyBuilder.get_first_failure().code, + dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); } TEST(public_kernel_tests, previous_public_kernel_fails_if_incorrect_storage_contract_on_delegate_call) { - DummyBuilder dummyBuilder = DummyBuilder( + DummyComposer dummyComposer = DummyComposer( "public_kernel_tests__previous_public_kernel_fails_if_incorrect_storage_contract_on_delegate_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); @@ -1160,15 +1157,15 @@ TEST(public_kernel_tests, previous_public_kernel_fails_if_incorrect_storage_cont // delegate call inputs.public_call.call_stack_item.public_inputs.call_context.is_delegate_call = true; - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); } TEST(public_kernel_tests, public_kernel_fails_creating_new_commitments_on_static_call) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_fails_creating_new_commitments_on_static_call"); + DummyComposer dummyComposer = DummyComposer("public_kernel_fails_creating_new_commitments_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has the contract address and storage contract address equal and so it should fail for a @@ -1184,15 +1181,15 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_commitments_on_static get_call_stack_item_hash(inputs.public_call.call_stack_item); // Update call stack hash - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); } TEST(public_kernel_tests, public_kernel_fails_creating_new_nullifiers_on_static_call) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_fails_creating_new_nullifiers_on_static_call"); + DummyComposer dummyComposer = DummyComposer("public_kernel_fails_creating_new_nullifiers_on_static_call"); PublicKernelInputs inputs = get_kernel_inputs_with_previous_kernel(false); // the function call has the contract address and storage contract address equal and so it should fail for a @@ -1210,15 +1207,15 @@ TEST(public_kernel_tests, public_kernel_fails_creating_new_nullifiers_on_static_ get_call_stack_item_hash(inputs.public_call.call_stack_item); // Update call stack hash - auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyBuilder, inputs); - ASSERT_TRUE(dummyBuilder.failed()); - ASSERT_EQ(dummyBuilder.get_first_failure().code, + auto public_inputs = native_public_kernel_circuit_public_previous_kernel(dummyComposer, inputs); + ASSERT_TRUE(dummyComposer.failed()); + ASSERT_EQ(dummyComposer.get_first_failure().code, CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); } TEST(public_kernel_tests, logs_are_handled_as_expected) { - DummyBuilder dummyBuilder = DummyBuilder("public_kernel_tests__logs_are_handled_as_expected"); + DummyComposer dummyComposer = DummyComposer("public_kernel_tests__logs_are_handled_as_expected"); PublicKernelInputs const& inputs = get_kernel_inputs_with_previous_kernel(true); auto const& zero_hash = zero_array(); @@ -1226,7 +1223,7 @@ TEST(public_kernel_tests, logs_are_handled_as_expected) // Ensure encrypted logs hash values are non-zero ASSERT_NE(inputs.previous_kernel.public_inputs.end.encrypted_logs_hash, zero_hash); - auto const& public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyBuilder, inputs); + auto const& public_inputs = native_public_kernel_circuit_private_previous_kernel(dummyComposer, inputs); // Encrypted logs hash values are propagated form input to output without change ASSERT_EQ(inputs.previous_kernel.public_inputs.end.encrypted_logs_hash, public_inputs.end.encrypted_logs_hash); @@ -1234,12 +1231,10 @@ TEST(public_kernel_tests, logs_are_handled_as_expected) // Unencrypted logs hash and preimage lengths should now be correctly accumulated auto const& public_inputs_unencrypted_logs_hash = inputs.previous_kernel.public_inputs.end.unencrypted_logs_hash; auto const& unencrypted_logs_hash = inputs.public_call.call_stack_item.public_inputs.unencrypted_logs_hash; - // TODO(914) Should this be unused? - [[maybe_unused]] auto const& expected_unencrypted_logs_hash = - accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], - public_inputs_unencrypted_logs_hash[1], - unencrypted_logs_hash[0], - unencrypted_logs_hash[1] }); + auto const& expected_unencrypted_logs_hash = accumulate_sha256({ public_inputs_unencrypted_logs_hash[0], + public_inputs_unencrypted_logs_hash[1], + unencrypted_logs_hash[0], + unencrypted_logs_hash[1] }); auto const& public_inputs_unencrypted_log_preimages_length = inputs.previous_kernel.public_inputs.end.unencrypted_log_preimages_length; @@ -1248,7 +1243,7 @@ TEST(public_kernel_tests, logs_are_handled_as_expected) ASSERT_EQ(public_inputs.end.unencrypted_log_preimages_length, unencrypted_log_preimages_length + public_inputs_unencrypted_log_preimages_length); - ASSERT_FALSE(dummyBuilder.failed()); + ASSERT_FALSE(dummyComposer.failed()); } } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp index b15896d162d1..1e822e170fa4 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/c_bind.cpp @@ -6,15 +6,15 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/native_types.hpp" #include namespace { -using Builder = UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::native_public_kernel_circuit_private_previous_kernel; @@ -48,10 +48,10 @@ WASM_EXPORT size_t public_kernel__init_verification_key(uint8_t const* pk_buf, u } CBIND(public_kernel__sim, [](PublicKernelInputs public_kernel_inputs) { - DummyBuilder builder = DummyBuilder("public_kernel__sim"); + DummyComposer composer = DummyComposer("public_kernel__sim"); KernelCircuitPublicInputs const result = public_kernel_inputs.previous_kernel.public_inputs.is_private - ? native_public_kernel_circuit_private_previous_kernel(builder, public_kernel_inputs) - : native_public_kernel_circuit_public_previous_kernel(builder, public_kernel_inputs); - return builder.result_or_error(result); + ? native_public_kernel_circuit_private_previous_kernel(composer, public_kernel_inputs) + : native_public_kernel_circuit_public_previous_kernel(composer, public_kernel_inputs); + return composer.result_or_error(result); }); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp index 7dfcd118be91..6a4219b4930d 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.cpp @@ -37,16 +37,16 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in /** * @brief Validates that the call stack item for this circuit iteration is at the top of the call stack - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_this_public_call_hash(DummyBuilder& builder, +void validate_this_public_call_hash(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs) { // If public call stack is empty, we bail so array_pop doesn't throw_or_abort if (array_length(public_inputs.end.public_call_stack) == 0) { - builder.do_assert( + composer.do_assert( false, "Public call stack can't be empty", CircuitErrorCode::PUBLIC_KERNEL__EMPTY_PUBLIC_CALL_STACK); return; } @@ -59,7 +59,7 @@ void validate_this_public_call_hash(DummyBuilder& builder, const auto calculated_this_public_call_hash = get_call_stack_item_hash(public_kernel_inputs.public_call.call_stack_item); - builder.do_assert( + composer.do_assert( popped_public_call_hash == calculated_this_public_call_hash, format("calculated public_call_hash (", calculated_this_public_call_hash, diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp index e07a5608186e..ab463dd36af7 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/common.hpp @@ -9,7 +9,7 @@ #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/circuits/hash.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::ContractStorageRead; @@ -18,7 +18,7 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::PublicDataRead; using aztec3::circuits::abis::PublicDataUpdateRequest; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::check_membership; using aztec3::circuits::compute_public_data_tree_index; using aztec3::circuits::compute_public_data_tree_value; @@ -33,11 +33,11 @@ namespace aztec3::circuits::kernel::public_kernel { /** * @brief Validate that all pre-images on the call stack hash to equal the accumulated data * @tparam The type of kernel input - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_stack(DummyBuilder& builder, KernelInput const& public_kernel_inputs) +void common_validate_call_stack(DummyComposer& composer, KernelInput const& public_kernel_inputs) { // Ensures that the stack of pre-images corresponds to the call stack auto& stack = public_kernel_inputs.public_call.call_stack_item.public_inputs.public_call_stack; @@ -67,7 +67,7 @@ void common_validate_call_stack(DummyBuilder& builder, KernelInput const& public const auto contract_being_called = preimage.contract_address; const auto calculated_hash = preimage.hash(); - builder.do_assert( + composer.do_assert( hash == calculated_hash, format( "public_call_stack[", i, "] = ", hash, "; does not reconcile with calculatedHash = ", calculated_hash), @@ -77,46 +77,46 @@ void common_validate_call_stack(DummyBuilder& builder, KernelInput const& public // we need to consider regular vs delegate calls const auto preimage_msg_sender = preimage.public_inputs.call_context.msg_sender; const auto expected_msg_sender = is_delegate_call ? our_msg_sender : our_contract_address; - builder.do_assert(expected_msg_sender == preimage_msg_sender, - format("call_stack_msg_sender[", - i, - "] = ", - preimage_msg_sender, - " expected ", - expected_msg_sender, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); + composer.do_assert(expected_msg_sender == preimage_msg_sender, + format("call_stack_msg_sender[", + i, + "] = ", + preimage_msg_sender, + " expected ", + expected_msg_sender, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_MSG_SENDER); // here we validate the storage address for each call on the stack // we need to consider regular vs delegate calls const auto preimage_storage_address = preimage.public_inputs.call_context.storage_contract_address; const auto expected_storage_address = is_delegate_call ? our_storage_address : contract_being_called; - builder.do_assert(expected_storage_address == preimage_storage_address, - format("call_stack_storage_address[", - i, - "] = ", - preimage_storage_address, - " expected ", - expected_storage_address, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); + composer.do_assert(expected_storage_address == preimage_storage_address, + format("call_stack_storage_address[", + i, + "] = ", + preimage_storage_address, + " expected ", + expected_storage_address, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_STORAGE_ADDRESS); // if it is a delegate call then we check that the portal contract in the pre image is our portal contract const auto preimage_portal_address = preimage.public_inputs.call_context.portal_contract_address; const auto expected_portal_address = our_portal_contract_address; - builder.do_assert(!is_delegate_call || expected_portal_address == preimage_portal_address, - format("call_stack_portal_address[", - i, - "] = ", - preimage_portal_address, - " expected ", - expected_portal_address, - "; does not reconcile"), - CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); + composer.do_assert(!is_delegate_call || expected_portal_address == preimage_portal_address, + format("call_stack_portal_address[", + i, + "] = ", + preimage_portal_address, + " expected ", + expected_portal_address, + "; does not reconcile"), + CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_INVALID_PORTAL_ADDRESS); const auto num_contract_storage_update_requests = array_length(preimage.public_inputs.contract_storage_update_requests); - builder.do_assert( + composer.do_assert( !is_static_call || num_contract_storage_update_requests == 0, format("contract_storage_update_requests[", i, "] should be empty"), CircuitErrorCode::PUBLIC_KERNEL__PUBLIC_CALL_STACK_CONTRACT_STORAGE_UPDATES_PROHIBITED_FOR_STATIC_CALL); @@ -126,11 +126,11 @@ void common_validate_call_stack(DummyBuilder& builder, KernelInput const& public /** * @brief Validates the call context of the current iteration * @tparam The type of kernel input - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_call_context(DummyBuilder& builder, KernelInput const& public_kernel_inputs) +void common_validate_call_context(DummyComposer& composer, KernelInput const& public_kernel_inputs) { const auto& call_stack_item = public_kernel_inputs.public_call.call_stack_item; const auto is_delegate_call = call_stack_item.public_inputs.call_context.is_delegate_call; @@ -140,11 +140,11 @@ void common_validate_call_context(DummyBuilder& builder, KernelInput const& publ const auto contract_storage_update_requests_length = array_length(call_stack_item.public_inputs.contract_storage_update_requests); - builder.do_assert(!is_delegate_call || contract_address != storage_contract_address, - std::string("call_context contract_address == storage_contract_address on delegate_call"), - CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); + composer.do_assert(!is_delegate_call || contract_address != storage_contract_address, + std::string("call_context contract_address == storage_contract_address on delegate_call"), + CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_INVALID_STORAGE_ADDRESS_FOR_DELEGATE_CALL); - builder.do_assert( + composer.do_assert( !is_static_call || contract_storage_update_requests_length == 0, std::string("call_context contract storage update requests found on static call"), CircuitErrorCode::PUBLIC_KERNEL__CALL_CONTEXT_CONTRACT_STORAGE_UPDATE_REQUESTS_PROHIBITED_FOR_STATIC_CALL); @@ -153,49 +153,49 @@ void common_validate_call_context(DummyBuilder& builder, KernelInput const& publ /** * @brief Validates the kernel execution of the current iteration * @tparam The type of kernel input - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_kernel_execution(DummyBuilder& builder, KernelInput const& public_kernel_inputs) +void common_validate_kernel_execution(DummyComposer& composer, KernelInput const& public_kernel_inputs) { - common_validate_call_context(builder, public_kernel_inputs); - common_validate_call_stack(builder, public_kernel_inputs); + common_validate_call_context(composer, public_kernel_inputs); + common_validate_call_stack(composer, public_kernel_inputs); }; /** * @brief Validates inputs to the kernel circuit that are common to all invocation scenarios * @tparam The type of kernel input - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ template -void common_validate_inputs(DummyBuilder& builder, KernelInput const& public_kernel_inputs) +void common_validate_inputs(DummyComposer& composer, KernelInput const& public_kernel_inputs) { // Validates commons inputs for all type of kernel inputs const auto& this_call_stack_item = public_kernel_inputs.public_call.call_stack_item; - builder.do_assert(this_call_stack_item.public_inputs.call_context.is_contract_deployment == false, - "Contract deployment can't be a public function", - CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); - builder.do_assert(this_call_stack_item.contract_address != 0, - "Contract address must be valid", - CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); - builder.do_assert(this_call_stack_item.function_data.function_selector != 0, - "Function signature must be valid", - CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); - builder.do_assert(this_call_stack_item.function_data.is_constructor == false, - "Constructors can't be public functions", - CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); - builder.do_assert(this_call_stack_item.function_data.is_private == false, - "Cannot execute a private function with the public kernel circuit", - CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); - builder.do_assert(public_kernel_inputs.public_call.bytecode_hash != 0, - "Bytecode hash must be valid", - CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); + composer.do_assert(this_call_stack_item.public_inputs.call_context.is_contract_deployment == false, + "Contract deployment can't be a public function", + CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_DEPLOYMENT_NOT_ALLOWED); + composer.do_assert(this_call_stack_item.contract_address != 0, + "Contract address must be valid", + CircuitErrorCode::PUBLIC_KERNEL__CONTRACT_ADDRESS_INVALID); + composer.do_assert(this_call_stack_item.function_data.function_selector != 0, + "Function signature must be valid", + CircuitErrorCode::PUBLIC_KERNEL__FUNCTION_SIGNATURE_INVALID); + composer.do_assert(this_call_stack_item.function_data.is_constructor == false, + "Constructors can't be public functions", + CircuitErrorCode::PUBLIC_KERNEL__CONSTRUCTOR_NOT_ALLOWED); + composer.do_assert(this_call_stack_item.function_data.is_private == false, + "Cannot execute a private function with the public kernel circuit", + CircuitErrorCode::PUBLIC_KERNEL__PRIVATE_FUNCTION_NOT_ALLOWED); + composer.do_assert(public_kernel_inputs.public_call.bytecode_hash != 0, + "Bytecode hash must be valid", + CircuitErrorCode::PUBLIC_KERNEL__BYTECODE_HASH_INVALID); } -template -void perform_static_call_checks(Builder& builder, KernelInput const& public_kernel_inputs) +template +void perform_static_call_checks(Composer& composer, KernelInput const& public_kernel_inputs) { // If the call is a static call, there should be no new commitments or nullifiers. const auto& public_call_public_inputs = public_kernel_inputs.public_call.call_stack_item.public_inputs; @@ -205,12 +205,12 @@ void perform_static_call_checks(Builder& builder, KernelInput const& public_kern const auto& new_nullifiers = public_call_public_inputs.new_nullifiers; if (is_static_call) { - builder.do_assert(utils::is_array_empty(new_commitments) == true, - "perform_static_call_checks in static call new commitments must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); - builder.do_assert(utils::is_array_empty(new_nullifiers) == true, - "perform_static_call_checks in static call new nullifiers must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); + composer.do_assert(utils::is_array_empty(new_commitments) == true, + "perform_static_call_checks in static call new commitments must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NEW_COMMITMENTS_PROHIBITED_IN_STATIC_CALL); + composer.do_assert(utils::is_array_empty(new_nullifiers) == true, + "perform_static_call_checks in static call new nullifiers must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NEW_NULLIFIERS_PROHIBITED_IN_STATIC_CALL); } } @@ -220,8 +220,8 @@ void perform_static_call_checks(Builder& builder, KernelInput const& public_kern * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_public_data_update_requests(Builder& builder, +template +void propagate_valid_public_data_update_requests(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -238,7 +238,7 @@ void propagate_valid_public_data_update_requests(Builder& builder, .old_value = compute_public_data_tree_value(update_request.old_value), .new_value = compute_public_data_tree_value(update_request.new_value), }; - array_push(builder, circuit_outputs.end.public_data_update_requests, new_write); + array_push(composer, circuit_outputs.end.public_data_update_requests, new_write); } } @@ -248,8 +248,8 @@ void propagate_valid_public_data_update_requests(Builder& builder, * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_valid_public_data_reads(Builder& builder, +template +void propagate_valid_public_data_reads(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -264,7 +264,7 @@ void propagate_valid_public_data_reads(Builder& builder, .leaf_index = compute_public_data_tree_index(contract_address, contract_storage_read.storage_slot), .value = compute_public_data_tree_value(contract_storage_read.current_value), }; - array_push(builder, circuit_outputs.end.public_data_reads, new_read); + array_push(composer, circuit_outputs.end.public_data_reads, new_read); } } @@ -272,12 +272,12 @@ void propagate_valid_public_data_reads(Builder& builder, * @brief Propagates new commitments from this iteration to the circuit output. * * @tparam The type of the kernel input - * @tparam The builder type + * @tparam The composer type * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_commitments(Builder& builder, +template +void propagate_new_commitments(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -294,19 +294,19 @@ void propagate_new_commitments(Builder& builder, } } - push_array_to_array(builder, siloed_new_commitments, circuit_outputs.end.new_commitments); + push_array_to_array(composer, siloed_new_commitments, circuit_outputs.end.new_commitments); } /** * @brief Propagates new nullifiers from this iteration to the circuit output. * * @tparam The type of the kernel input - * @tparam The builder type + * @tparam The composer type * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_nullifiers(Builder& builder, +template +void propagate_new_nullifiers(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -323,7 +323,7 @@ void propagate_new_nullifiers(Builder& builder, } } - push_array_to_array(builder, siloed_new_nullifiers, circuit_outputs.end.new_nullifiers); + push_array_to_array(composer, siloed_new_nullifiers, circuit_outputs.end.new_nullifiers); } /** @@ -333,8 +333,8 @@ void propagate_new_nullifiers(Builder& builder, * @param public_kernel_inputs The inputs to this iteration to the kernel circuit. * @param circuit_outputs The circuit outputs to be populated */ -template -void propagate_new_l2_to_l1_messages(Builder& builder, +template +void propagate_new_l2_to_l1_messages(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -358,7 +358,7 @@ void propagate_new_l2_to_l1_messages(Builder& builder, new_l2_to_l1_msgs[i]); } } - push_array_to_array(builder, new_l2_to_l1_msgs_to_insert, circuit_outputs.end.new_l2_to_l1_msgs); + push_array_to_array(composer, new_l2_to_l1_msgs_to_insert, circuit_outputs.end.new_l2_to_l1_msgs); } /** @@ -393,12 +393,12 @@ template void accumulate_unencrypted_logs(PublicKernelInputs c /** * @brief Propagates valid (i.e. non-empty) public data reads from this iteration to the circuit output * @tparam The type of kernel input - * @tparam The current builder + * @tparam The current composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param circuit_outputs The circuit outputs to be populated */ -template -void common_update_public_end_values(Builder& builder, +template +void common_update_public_end_values(Composer& composer, KernelInput const& public_kernel_inputs, KernelCircuitPublicInputs& circuit_outputs) { @@ -406,19 +406,19 @@ void common_update_public_end_values(Builder& builder, circuit_outputs.is_private = false; // If this call is a static call, certain operations are disallowed, such as creating new state. - perform_static_call_checks(builder, public_kernel_inputs); + perform_static_call_checks(composer, public_kernel_inputs); const auto& stack = public_kernel_inputs.public_call.call_stack_item.public_inputs.public_call_stack; - push_array_to_array(builder, stack, circuit_outputs.end.public_call_stack); + push_array_to_array(composer, stack, circuit_outputs.end.public_call_stack); - propagate_new_commitments(builder, public_kernel_inputs, circuit_outputs); - propagate_new_nullifiers(builder, public_kernel_inputs, circuit_outputs); + propagate_new_commitments(composer, public_kernel_inputs, circuit_outputs); + propagate_new_nullifiers(composer, public_kernel_inputs, circuit_outputs); - propagate_new_l2_to_l1_messages(builder, public_kernel_inputs, circuit_outputs); + propagate_new_l2_to_l1_messages(composer, public_kernel_inputs, circuit_outputs); - propagate_valid_public_data_update_requests(builder, public_kernel_inputs, circuit_outputs); + propagate_valid_public_data_update_requests(composer, public_kernel_inputs, circuit_outputs); - propagate_valid_public_data_reads(builder, public_kernel_inputs, circuit_outputs); + propagate_valid_public_data_reads(composer, public_kernel_inputs, circuit_outputs); } /** @@ -431,11 +431,11 @@ void common_initialise_end_values(PublicKernelInputs const& public_kernel_in /** * @brief Validates that the call stack item for this circuit iteration is at the top of the call stack - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @param public_inputs The circuit outputs */ -void validate_this_public_call_hash(DummyBuilder& builder, +void validate_this_public_call_hash(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs, KernelCircuitPublicInputs& public_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp index 9133ba940604..9c89a76aabda 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/init.hpp @@ -3,25 +3,25 @@ #include "aztec3/circuits/apps/oracle_wrapper.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/oracle/oracle.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" namespace aztec3::circuits::kernel::public_kernel { -using Builder = proof_system::UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using Aggregator = aztec3::circuits::recursion::Aggregator; // Generic: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using DB = oracle::FakeDB; using oracle::NativeOracle; -using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; +using OracleWrapper = aztec3::circuits::apps::OracleWrapperInterface; } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp index a0c5cbddf70e..5d3f722b8185 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.cpp @@ -7,24 +7,24 @@ #include "aztec3/constants.hpp" #include "aztec3/utils/array.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; /** * @brief Validates the kernel circuit inputs specific to having a private previous kernel - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) { - builder.do_assert(array_length(public_kernel_inputs.previous_kernel.public_inputs.end.private_call_stack) == 0, - "Private call stack must be empty", - CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); - builder.do_assert(public_kernel_inputs.previous_kernel.public_inputs.is_private == true, - "Previous kernel must be private", - CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); + composer.do_assert(array_length(public_kernel_inputs.previous_kernel.public_inputs.end.private_call_stack) == 0, + "Private call stack must be empty", + CircuitErrorCode::PUBLIC_KERNEL__NON_EMPTY_PRIVATE_CALL_STACK); + composer.do_assert(public_kernel_inputs.previous_kernel.public_inputs.is_private == true, + "Previous kernel must be private", + CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PRIVATE); } } // namespace @@ -35,16 +35,16 @@ using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_initialise_end_values; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; /** * @brief Entry point for the native public kernel circuit with a private previous kernel - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) + DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; @@ -53,19 +53,19 @@ KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kern common_initialise_end_values(public_kernel_inputs, public_inputs); // validate the inputs common to all invocation circumstances - common_validate_inputs(builder, public_kernel_inputs); + common_validate_inputs(composer, public_kernel_inputs); // validate the inputs unique to having a previous private kernel - validate_inputs(builder, public_kernel_inputs); + validate_inputs(composer, public_kernel_inputs); // validate the kernel execution common to all invocation circumstances - common_validate_kernel_execution(builder, public_kernel_inputs); + common_validate_kernel_execution(composer, public_kernel_inputs); // vallidate our public call hash - validate_this_public_call_hash(builder, public_kernel_inputs, public_inputs); + validate_this_public_call_hash(composer, public_kernel_inputs, public_inputs); // update the public end state of the circuit - common_update_public_end_values(builder, public_kernel_inputs, public_inputs); + common_update_public_end_values(composer, public_kernel_inputs, public_inputs); accumulate_unencrypted_logs(public_kernel_inputs, public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp index 46eab401e780..8cfba2fb8998 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_private_previous_kernel.hpp @@ -5,14 +5,14 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_public_kernel_circuit_private_previous_kernel( - DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); + DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp index 22c938598fa5..8422dab13ede 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.cpp @@ -6,21 +6,21 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" #include "aztec3/utils/array.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace { using CircuitErrorCode = aztec3::utils::CircuitErrorCode; /** * @brief Validates the kernel circuit inputs specific to having a public previous kernel - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit */ -void validate_inputs(DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) +void validate_inputs(DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) { const auto& previous_kernel = public_kernel_inputs.previous_kernel.public_inputs; - builder.do_assert(previous_kernel.is_private == false, - "Previous kernel must be public", - CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); + composer.do_assert(previous_kernel.is_private == false, + "Previous kernel must be public", + CircuitErrorCode::PUBLIC_KERNEL__PREVIOUS_KERNEL_NOT_PUBLIC); } } // namespace @@ -30,16 +30,16 @@ using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; using aztec3::circuits::kernel::public_kernel::common_validate_kernel_execution; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; /** * @brief Entry point for the native public kernel circuit with a public previous kernel - * @param builder The circuit builder + * @param composer The circuit composer * @param public_kernel_inputs The inputs to this iteration of the kernel circuit * @return The circuit public inputs */ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs) + DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs) { // construct the circuit outputs KernelCircuitPublicInputs public_inputs{}; @@ -48,19 +48,19 @@ KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kerne common_initialise_end_values(public_kernel_inputs, public_inputs); // validate the inputs common to all invocation circumstances - common_validate_inputs(builder, public_kernel_inputs); + common_validate_inputs(composer, public_kernel_inputs); // validate the inputs unique to having a previous public kernel - validate_inputs(builder, public_kernel_inputs); + validate_inputs(composer, public_kernel_inputs); // validate the kernel execution common to all invocation circumstances - common_validate_kernel_execution(builder, public_kernel_inputs); + common_validate_kernel_execution(composer, public_kernel_inputs); // validate our public call hash - validate_this_public_call_hash(builder, public_kernel_inputs, public_inputs); + validate_this_public_call_hash(composer, public_kernel_inputs, public_inputs); // update the public end state of the circuit - common_update_public_end_values(builder, public_kernel_inputs, public_inputs); + common_update_public_end_values(composer, public_kernel_inputs, public_inputs); accumulate_unencrypted_logs(public_kernel_inputs, public_inputs); diff --git a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp index 8d21acd913c8..317b06d12b08 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/public/native_public_kernel_circuit_public_previous_kernel.hpp @@ -5,14 +5,14 @@ #include "aztec3/circuits/abis/kernel_circuit_public_inputs.hpp" #include "aztec3/circuits/abis/public_kernel/public_kernel_inputs.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" namespace aztec3::circuits::kernel::public_kernel { using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::public_kernel::PublicKernelInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; KernelCircuitPublicInputs native_public_kernel_circuit_public_previous_kernel( - DummyBuilder& builder, PublicKernelInputs const& public_kernel_inputs); + DummyComposer& composer, PublicKernelInputs const& public_kernel_inputs); } // namespace aztec3::circuits::kernel::public_kernel \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp index a4c2b478f918..5c9c433fdce0 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_circuit.hpp @@ -6,13 +6,13 @@ namespace aztec3::circuits::mock { using namespace plonk::stdlib; -template void mock_circuit(Builder& builder, std::vector const& public_inputs_) +template void mock_circuit(Composer& composer, std::vector const& public_inputs_) { - const auto public_inputs = map(public_inputs_, [&](auto& i) { return field_t(witness_t(&builder, i)); }); + const auto public_inputs = map(public_inputs_, [&](auto& i) { return field_t(witness_t(&composer, i)); }); for (auto& p : public_inputs) { p.set_public(); } - plonk::stdlib::pedersen::compress(field_t(witness_t(&builder, 1)), field_t(witness_t(&builder, 1))); + plonk::stdlib::pedersen::compress(field_t(witness_t(&composer, 1)), field_t(witness_t(&composer, 1))); } } // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp index 3848c675cabc..27945263e0f4 100644 --- a/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/mock/mock_kernel_circuit.hpp @@ -17,19 +17,20 @@ using aztec3::utils::types::CircuitTypes; using plonk::stdlib::pedersen_commitment; using plonk::stdlib::witness_t; -template -KernelCircuitPublicInputs mock_kernel_circuit(Builder& builder, KernelCircuitPublicInputs const& _public_inputs) +template +KernelCircuitPublicInputs mock_kernel_circuit(Composer& composer, + KernelCircuitPublicInputs const& _public_inputs) { - typedef CircuitTypes CT; + typedef CircuitTypes CT; typedef typename CT::fr fr; - auto public_inputs = _public_inputs.to_circuit_type(builder); + auto public_inputs = _public_inputs.to_circuit_type(composer); { std::vector dummy_witness_indices; // 16 is the number of values added to `proof_witness_indices` at the end of `verify_proof`. for (size_t i = 0; i < 16; ++i) { - fr const witness = fr(witness_t(&builder, i)); + fr const witness = fr(witness_t(&composer, i)); uint32_t const witness_index = witness.get_witness_index(); dummy_witness_indices.push_back(witness_index); } @@ -42,10 +43,10 @@ KernelCircuitPublicInputs mock_kernel_circuit(Builder& builder, KernelCircui // We still add dummy witness indices in the recursive proof indices just so that we don't trigger an assertion in // while setting recursion elements as public inputs. These dummy indices would not be used as we're setting // contains_recursive_proof to be false. - builder.contains_recursive_proof = false; + composer.circuit_constructor.contains_recursive_proof = false; - plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&builder, 1)), fr(witness_t(&builder, 1))); - return public_inputs.template to_native_type(); + plonk::stdlib::pedersen_commitment::compress(fr(witness_t(&composer, 1)), fr(witness_t(&composer, 1))); + return public_inputs.template to_native_type(); } } // namespace aztec3::circuits::mock diff --git a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp index 343ba12e79e7..53e3ea525324 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/aggregator.hpp @@ -1,20 +1,21 @@ #pragma once #include "init.hpp" -#include - namespace aztec3::circuits::recursion { class Aggregator { public: static CT::AggregationObject aggregate( - Builder* builder, + Composer* composer, const std::shared_ptr& vk, const NT::Proof& proof, + const size_t& num_public_inputs, const CT::AggregationObject& previous_aggregation_output = CT::AggregationObject()) { - CT::AggregationObject result = - verify_proof(builder, vk, proof, previous_aggregation_output); + const Manifest recursive_manifest = Composer::create_manifest(num_public_inputs); + + CT::AggregationObject result = verify_proof( + composer, vk, recursive_manifest, proof, previous_aggregation_output); return result; } diff --git a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp index 427d25f502da..6731110b6cfe 100644 --- a/circuits/cpp/src/aztec3/circuits/recursion/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/recursion/init.hpp @@ -6,11 +6,11 @@ #include namespace aztec3::circuits::recursion { -// Builder -using Builder = UltraCircuitBuilder; +// Composer +using Composer = plonk::UltraPlonkComposer; // Generic types: -using CT = aztec3::utils::types::CircuitTypes; +using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; using aztec3::utils::types::to_ct; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 9d653462ccd5..f16467ca0cad 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -51,7 +51,7 @@ using aztec3::circuits::abis::NewContractData; using aztec3::circuits::rollup::test_utils::utils::make_public_data_update_request; using aztec3::circuits::rollup::test_utils::utils::make_public_read; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; } // namespace namespace aztec3::circuits::rollup::base::native_base_rollup_circuit { @@ -125,7 +125,7 @@ class base_rollup_tests : public ::testing::Test { TEST_F(base_rollup_tests, native_no_new_contract_leafs) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_no_new_contract_leafs"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_no_new_contract_leafs"); // When there are no contract deployments. The contract tree should be inserting 0 leafs, (not empty leafs); // Initially, the start_contract_tree_snapshot is empty (leaf is 0. hash it up). // Get sibling path of index 0 leaf (for circuit to check membership via sibling path) @@ -135,7 +135,7 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) auto empty_contract_tree = native_base_rollup::MerkleTree(CONTRACT_TREE_HEIGHT); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, emptyInputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, emptyInputs); AppendOnlyTreeSnapshot const expectedStartContractTreeSnapshot = { .root = empty_contract_tree.root(), @@ -148,13 +148,13 @@ TEST_F(base_rollup_tests, native_no_new_contract_leafs) ASSERT_EQ(outputs.start_contract_tree_snapshot, expectedStartContractTreeSnapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expectedEndContractTreeSnapshot); ASSERT_EQ(outputs.start_contract_tree_snapshot, emptyInputs.start_contract_tree_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(emptyInputs, outputs); } TEST_F(base_rollup_tests, native_contract_leaf_inserted) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_contract_leaf_inserted"); // When there is a contract deployment, the contract tree should be inserting 1 leaf. // The remaining leafs should be 0 leafs, (not empty leafs); @@ -185,18 +185,19 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted) BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, expected_start_contracts_snapshot); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tree) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); + DummyComposer composer = + DummyComposer("base_rollup_tests__native_contract_leaf_inserted_in_non_empty_snapshot_tree"); // Same as before except our start_contract_snapshot_tree is not empty std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; @@ -237,17 +238,17 @@ TEST_F(base_rollup_tests, native_contract_leaf_inserted_in_non_empty_snapshot_tr .next_available_leaf_index = 14, }; BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_new_commitments_tree) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_commitments_tree"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_new_commitments_tree"); // Create 4 new mock commitments. Add them to kernel data. // Then get sibling path so we can verify insert them into the tree. @@ -277,12 +278,12 @@ TEST_F(base_rollup_tests, native_new_commitments_tree) auto inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_private_data_tree_snapshot, expected_start_commitments_snapshot); ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.start_private_data_tree_snapshot); ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_end_commitments_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } @@ -320,12 +321,12 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) /** * RUN */ - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_empty"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_empty"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, empty_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, empty_inputs); /** * ASSERT @@ -338,7 +339,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_empty) ASSERT_EQ(outputs.end_nullifier_tree_snapshot.root, outputs.start_nullifier_tree_snapshot.root); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, outputs.start_nullifier_tree_snapshot.next_available_leaf_index + 8); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } void nullifier_insertion_test(std::array new_nullifiers) @@ -353,7 +354,7 @@ void nullifier_insertion_test(std::array n } auto end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyBuilder builder = DummyBuilder("base_rollup_tests__nullifier_insertion_test"); + DummyComposer composer = DummyComposer("base_rollup_tests__nullifier_insertion_test"); std::array, 2> kernel_data = { get_empty_kernel(), get_empty_kernel() }; for (uint8_t i = 0; i < 2; i++) { std::array kernel_nullifiers; @@ -365,7 +366,7 @@ void nullifier_insertion_test(std::array n BaseRollupInputs const inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); /** * ASSERT */ @@ -373,7 +374,7 @@ void nullifier_insertion_test(std::array n ASSERT_EQ(outputs.end_nullifier_tree_snapshot, end_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot.next_available_leaf_index, outputs.start_nullifier_tree_snapshot.next_available_leaf_index + KERNEL_NEW_NULLIFIERS_LENGTH * 2); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(base_rollup_tests, native_new_nullifier_tree_all_larger) @@ -401,7 +402,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) } auto expected_end_nullifier_tree_snapshot = nullifier_tree.get_snapshot(); - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_sparse"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_sparse"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::tuple, AppendOnlyTreeSnapshot> inputs_and_snapshots = test_utils::utils::generate_nullifier_tree_testing_values_explicit(empty_inputs, nullifiers, initial_values); @@ -414,7 +415,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) // Run the circuit BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); /** * ASSERT @@ -424,13 +425,13 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_sparse) // End state ASSERT_EQ(outputs.end_nullifier_tree_snapshot, expected_end_nullifier_tree_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(base_rollup_tests, native_nullifier_tree_regression) { // Regression test caught when testing the typescript nullifier tree implementation - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_nullifier_tree_regression"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_nullifier_tree_regression"); // This test runs after some data has already been inserted into the tree // This test will pre-populate the tree with 24 values (0 item + 23 more) simulating that a rollup inserting two @@ -465,7 +466,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); // Run the circuit BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); /** * ASSERT @@ -475,7 +476,7 @@ TEST_F(base_rollup_tests, native_nullifier_tree_regression) // End state ASSERT_EQ(outputs.end_nullifier_tree_snapshot, expected_end_nullifier_tree_snapshot); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } // Another regression test with values from a failing packages test @@ -508,7 +509,7 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) * DESCRIPTION */ - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_new_nullifier_tree_double_spend"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_new_nullifier_tree_double_spend"); BaseRollupInputs const empty_inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); std::array const new_nullifiers = { 11, 0, 11, 0, 0, 0, 0, 0 }; @@ -517,25 +518,25 @@ TEST_F(base_rollup_tests, native_new_nullifier_tree_double_spend) BaseRollupInputs const testing_inputs = std::get<0>(inputs_and_snapshots); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, testing_inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, testing_inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "Nullifier is not in the correct range"); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "Nullifier is not in the correct range"); } TEST_F(base_rollup_tests, native_empty_block_calldata_hash) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_empty_block_calldata_hash"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_empty_block_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto expected_calldata_hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); - std::array const output_calldata_hash = outputs.calldata_hash; + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); - ASSERT_TRUE(compare_field_hash_to_expected(output_calldata_hash, expected_calldata_hash) == true); + std::array const output_calldata_hash = outputs.calldata_hash; - ASSERT_FALSE(builder.failed()); + ASSERT_TRUE(compare_field_hash_to_expected(output_calldata_hash, expected_calldata_hash)); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } @@ -571,16 +572,16 @@ TEST_F(base_rollup_tests, native_calldata_hash) std::array const expected_calldata_hash = components::compute_kernels_calldata_hash(kernel_data); - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_calldata_hash"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_calldata_hash"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); std::array const output_calldata_hash = outputs.calldata_hash; ASSERT_EQ(expected_calldata_hash, output_calldata_hash); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } @@ -589,7 +590,8 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati // WRITE a negative test that will fail the inclusion proof // Test membership works for empty trees - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_compute_membership_historic_private_data_negative"); + DummyComposer composer = + DummyComposer("base_rollup_tests__native_compute_membership_historic_private_data_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -607,16 +609,17 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_private_data_negati }; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "Membership check failed: historic private data tree roots 0"); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "Membership check failed: historic private data tree roots 0"); } TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negative) { // Test membership works for empty trees - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); + DummyComposer composer = + DummyComposer("base_rollup_tests__native_compute_membership_historic_contract_tree_negative"); std::array, 2> const kernel_data = { get_empty_kernel(), get_empty_kernel() }; BaseRollupInputs inputs = base_rollup_inputs_from_kernels(kernel_data); @@ -634,67 +637,67 @@ TEST_F(base_rollup_tests, native_compute_membership_historic_contract_tree_negat }; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "Membership check failed: historic contract data tree roots 0"); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "Membership check failed: historic contract data tree roots 0"); } TEST_F(base_rollup_tests, native_constants_dont_change) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_constants_dont_change"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_constants_dont_change"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.constants, outputs.constants); - EXPECT_FALSE(builder.failed()); + EXPECT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_constants_dont_match_kernels_chain_id) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_constants_dont_change"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_constants_dont_change"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); inputs.constants.global_variables.chain_id = 3; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.constants, outputs.constants); - EXPECT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "kernel chain_id does not match the rollup chain_id"); + EXPECT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "kernel chain_id does not match the rollup chain_id"); } TEST_F(base_rollup_tests, native_constants_dont_match_kernels_version) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_constants_dont_change"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_constants_dont_change"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); inputs.constants.global_variables.version = 3; BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.constants, outputs.constants); - EXPECT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "kernel version does not match the rollup version"); + EXPECT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "kernel version does not match the rollup version"); } TEST_F(base_rollup_tests, native_aggregate) { // TODO(rahul): Fix this when aggregation works - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_aggregate"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_aggregate"); BaseRollupInputs inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.kernel_data[0].public_inputs.end.aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(base_rollup_tests, native_subtree_height_is_0) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_subtree_height_is_0"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_subtree_height_is_0"); BaseRollupInputs const inputs = base_rollup_inputs_from_kernels({ get_empty_kernel(), get_empty_kernel() }); BaseOrMergeRollupPublicInputs const outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.rollup_subtree_height, fr(0)); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(base_rollup_tests, native_cbind_0) @@ -707,7 +710,7 @@ TEST_F(base_rollup_tests, native_cbind_0) TEST_F(base_rollup_tests, native_single_public_state_read) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_single_public_state_read"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_single_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -725,18 +728,18 @@ TEST_F(base_rollup_tests, native_single_public_state_read) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_EQ(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_single_public_state_write) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_single_public_state_write"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_single_public_state_write"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -756,18 +759,18 @@ TEST_F(base_rollup_tests, native_single_public_state_write) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_NE(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_multiple_public_state_read_writes"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_multiple_public_state_read_writes"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -797,18 +800,18 @@ TEST_F(base_rollup_tests, native_multiple_public_state_read_writes) kernel_data, private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_NE(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); run_cbind(inputs, outputs); } TEST_F(base_rollup_tests, native_invalid_public_state_read) { - DummyBuilder builder = DummyBuilder("base_rollup_tests__native_invalid_public_state_read"); + DummyComposer composer = DummyComposer("base_rollup_tests__native_invalid_public_state_read"); native_base_rollup::MerkleTree private_data_tree(PRIVATE_DATA_TREE_HEIGHT); native_base_rollup::MerkleTree contract_tree(CONTRACT_TREE_HEIGHT); stdlib::merkle_tree::MemoryStore public_data_tree_store; @@ -830,12 +833,12 @@ TEST_F(base_rollup_tests, native_invalid_public_state_read) inputs.start_public_data_tree_root = public_data_tree.root(); BaseOrMergeRollupPublicInputs outputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, inputs); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.start_public_data_tree_root, inputs.start_public_data_tree_root); ASSERT_EQ(outputs.end_public_data_tree_root, public_data_tree.root()); ASSERT_EQ(outputs.end_public_data_tree_root, outputs.start_public_data_tree_root); - ASSERT_TRUE(builder.failed()); + ASSERT_TRUE(composer.failed()); run_cbind(inputs, outputs, true, false); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index 44f74f18549c..15fca05480c4 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -5,15 +5,15 @@ #include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/native_types.hpp" #include namespace { -using Builder = UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; @@ -51,8 +51,8 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, size_t* base_rollup_public_inputs_size_out, uint8_t const** base_or_merge_rollup_public_inputs_buf) { - DummyBuilder builder = DummyBuilder("base_rollup__sim"); - // TODO accept proving key and use that to initialize builders + DummyComposer composer = DummyComposer("base_rollup__sim"); + // TODO accept proving key and use that to initialize composers // this info is just to prevent error for unused pk_buf // TODO do we want to accept it or just get it from our factory? // auto crs_factory = std::make_shared(); @@ -60,7 +60,7 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, BaseRollupInputs base_rollup_inputs; read(base_rollup_inputs_buf, base_rollup_inputs); - BaseOrMergeRollupPublicInputs const public_inputs = base_rollup_circuit(builder, base_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = base_rollup_circuit(composer, base_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -70,6 +70,6 @@ WASM_EXPORT uint8_t* base_rollup__sim(uint8_t const* base_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *base_or_merge_rollup_public_inputs_buf = raw_public_inputs_buf; *base_rollup_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); + return composer.alloc_and_serialize_first_failure(); } } // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp index ab57158c43c3..272e9548eed8 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -10,7 +10,7 @@ #include "aztec3/circuits/hash.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/utils/circuit_errors.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -25,7 +25,7 @@ using NT = aztec3::utils::types::NativeTypes; using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using CircuitErrorCode = aztec3::utils::CircuitErrorCode; using Aggregator = aztec3::circuits::recursion::Aggregator; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index bc4d76dca0e2..1584e7e77a79 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -94,7 +94,7 @@ NT::fr calculate_contract_subtree(std::vector contract_leaves) return contracts_tree.root(); } -NT::fr calculate_commitments_subtree(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) +NT::fr calculate_commitments_subtree(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { MerkleTree commitments_tree = MerkleTree(PRIVATE_DATA_SUBTREE_DEPTH); @@ -102,9 +102,9 @@ NT::fr calculate_commitments_subtree(DummyBuilder& builder, BaseRollupInputs con auto new_commitments = baseRollupInputs.kernel_data[i].public_inputs.end.new_commitments; // Our commitments size MUST be 4 to calculate our subtrees correctly - builder.do_assert(new_commitments.size() == 4, - "New commitments in kernel data must be 4", - CircuitErrorCode::BASE__INCORRECT_NUM_OF_NEW_COMMITMENTS); + composer.do_assert(new_commitments.size() == 4, + "New commitments in kernel data must be 4", + CircuitErrorCode::BASE__INCORRECT_NUM_OF_NEW_COMMITMENTS); for (size_t j = 0; j < new_commitments.size(); j++) { // todo: batch insert @@ -122,7 +122,7 @@ NT::fr calculate_commitments_subtree(DummyBuilder& builder, BaseRollupInputs con * @param constantBaseRollupData * @param baseRollupInputs */ -void perform_historical_private_data_tree_membership_checks(DummyBuilder& builder, +void perform_historical_private_data_tree_membership_checks(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { // For each of the historic_private_data_tree_membership_checks, we need to do an inclusion proof @@ -136,7 +136,7 @@ void perform_historical_private_data_tree_membership_checks(DummyBuilder& builde abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_private_data_tree_root_membership_witnesses[i]; - check_membership(builder, + check_membership(composer, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -145,7 +145,7 @@ void perform_historical_private_data_tree_membership_checks(DummyBuilder& builde } } -void perform_historical_contract_data_tree_membership_checks(DummyBuilder& builder, +void perform_historical_contract_data_tree_membership_checks(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_contract_tree_roots_snapshot.root; @@ -157,7 +157,7 @@ void perform_historical_contract_data_tree_membership_checks(DummyBuilder& build abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_contract_tree_root_membership_witnesses[i]; - check_membership(builder, + check_membership(composer, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -166,7 +166,7 @@ void perform_historical_contract_data_tree_membership_checks(DummyBuilder& build } } -void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& builder, +void perform_historical_l1_to_l2_message_tree_membership_checks(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { auto historic_root = baseRollupInputs.constants.start_tree_of_historic_l1_to_l2_msg_tree_roots_snapshot.root; @@ -178,7 +178,7 @@ void perform_historical_l1_to_l2_message_tree_membership_checks(DummyBuilder& bu abis::MembershipWitness const historic_root_witness = baseRollupInputs.historic_l1_to_l2_msg_tree_root_membership_witnesses[i]; - check_membership(builder, + check_membership(composer, leaf, historic_root_witness.leaf_index, historic_root_witness.sibling_path, @@ -205,7 +205,7 @@ NT::fr create_nullifier_subtree( * * @returns The end nullifier tree root */ -AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyBuilder& builder, +AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { // LADIES AND GENTLEMEN The P L A N ( is simple ) @@ -280,7 +280,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB } // if not matched, our subtree will misformed - we must reject - builder.do_assert( + composer.do_assert( matched, "Nullifier subtree is malformed", CircuitErrorCode::BASE__INVALID_NULLIFIER_SUBTREE); } else { @@ -289,9 +289,9 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB if (!(is_less_than_nullifier && is_next_greater_than)) { if (low_nullifier_preimage.next_index != 0 && low_nullifier_preimage.next_value != 0) { - builder.do_assert(false, - "Nullifier is not in the correct range", - CircuitErrorCode::BASE__INVALID_NULLIFIER_RANGE); + composer.do_assert(false, + "Nullifier is not in the correct range", + CircuitErrorCode::BASE__INVALID_NULLIFIER_RANGE); } } @@ -303,12 +303,12 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB }; // perform membership check for the low nullifier against the original root - check_membership(builder, - original_low_nullifier.hash(), - witness.leaf_index, - witness.sibling_path, - current_nullifier_tree_root, - "low nullifier membership check"); + check_membership(composer, + original_low_nullifier.hash(), + witness.leaf_index, + witness.sibling_path, + current_nullifier_tree_root, + "low nullifier membership check"); // Calculate the new value of the low_nullifier_leaf auto const updated_low_nullifier = @@ -341,7 +341,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB const auto empty_nullifier_subtree_root = components::calculate_empty_tree_root(NULLIFIER_SUBTREE_DEPTH); auto leafIndexNullifierSubtreeDepth = baseRollupInputs.start_nullifier_tree_snapshot.next_available_leaf_index >> NULLIFIER_SUBTREE_DEPTH; - check_membership(builder, + check_membership(composer, empty_nullifier_subtree_root, leafIndexNullifierSubtreeDepth, baseRollupInputs.new_nullifiers_subtree_sibling_path, @@ -365,7 +365,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyB } fr insert_public_data_update_requests( - DummyBuilder& builder, + DummyComposer& composer, fr tree_root, std::array, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH> const& public_data_update_requests, @@ -382,7 +382,7 @@ fr insert_public_data_update_requests( continue; } - check_membership(builder, + check_membership(composer, state_write.old_value, state_write.leaf_index, witness, @@ -396,7 +396,7 @@ fr insert_public_data_update_requests( } void validate_public_data_reads( - DummyBuilder& builder, + DummyComposer& composer, fr tree_root, std::array, KERNEL_PUBLIC_DATA_READS_LENGTH> const& public_data_reads, size_t witnesses_offset, @@ -410,7 +410,7 @@ void validate_public_data_reads( continue; } - check_membership(builder, + check_membership(composer, public_data_read.value, public_data_read.leaf_index, witness, @@ -419,17 +419,17 @@ void validate_public_data_reads( } }; -fr validate_and_process_public_state(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) +fr validate_and_process_public_state(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { // Process public data reads and public data update requests for left input - validate_public_data_reads(builder, + validate_public_data_reads(composer, baseRollupInputs.start_public_data_tree_root, baseRollupInputs.kernel_data[0].public_inputs.end.public_data_reads, 0, baseRollupInputs.new_public_data_reads_sibling_paths); auto mid_public_data_tree_root = insert_public_data_update_requests( - builder, + composer, baseRollupInputs.start_public_data_tree_root, baseRollupInputs.kernel_data[0].public_inputs.end.public_data_update_requests, 0, @@ -437,14 +437,14 @@ fr validate_and_process_public_state(DummyBuilder& builder, BaseRollupInputs con // Process public data reads and public data update requests for right input using the resulting tree root from the // left one - validate_public_data_reads(builder, + validate_public_data_reads(composer, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_reads, KERNEL_PUBLIC_DATA_READS_LENGTH, baseRollupInputs.new_public_data_reads_sibling_paths); auto end_public_data_tree_root = insert_public_data_update_requests( - builder, + composer, mid_public_data_tree_root, baseRollupInputs.kernel_data[1].public_inputs.end.public_data_update_requests, KERNEL_PUBLIC_DATA_UPDATE_REQUESTS_LENGTH, @@ -453,26 +453,26 @@ fr validate_and_process_public_state(DummyBuilder& builder, BaseRollupInputs con return end_public_data_tree_root; } -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs) +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs) { // Verify the previous kernel proofs for (size_t i = 0; i < 2; i++) { NT::Proof const proof = baseRollupInputs.kernel_data[i].proof; - builder.do_assert(verify_kernel_proof(proof), - "kernel proof verification failed", - CircuitErrorCode::BASE__KERNEL_PROOF_VERIFICATION_FAILED); + composer.do_assert(verify_kernel_proof(proof), + "kernel proof verification failed", + CircuitErrorCode::BASE__KERNEL_PROOF_VERIFICATION_FAILED); } // Verify the kernel chain_id and versions for (size_t i = 0; i < 2; i++) { - builder.do_assert(baseRollupInputs.kernel_data[i].public_inputs.constants.tx_context.chain_id == - baseRollupInputs.constants.global_variables.chain_id, - "kernel chain_id does not match the rollup chain_id", - CircuitErrorCode::BASE__INVALID_CHAIN_ID); - builder.do_assert(baseRollupInputs.kernel_data[i].public_inputs.constants.tx_context.version == - baseRollupInputs.constants.global_variables.version, - "kernel version does not match the rollup version", - CircuitErrorCode::BASE__INVALID_VERSION); + composer.do_assert(baseRollupInputs.kernel_data[i].public_inputs.constants.tx_context.chain_id == + baseRollupInputs.constants.global_variables.chain_id, + "kernel chain_id does not match the rollup chain_id", + CircuitErrorCode::BASE__INVALID_CHAIN_ID); + composer.do_assert(baseRollupInputs.kernel_data[i].public_inputs.constants.tx_context.version == + baseRollupInputs.constants.global_variables.version, + "kernel version does not match the rollup version", + CircuitErrorCode::BASE__INVALID_VERSION); } // First we compute the contract tree leaves @@ -480,12 +480,12 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRol // Check contracts and commitments subtrees NT::fr const contracts_tree_subroot = calculate_contract_subtree(contract_leaves); - NT::fr const commitments_tree_subroot = calculate_commitments_subtree(builder, baseRollupInputs); + NT::fr const commitments_tree_subroot = calculate_commitments_subtree(composer, baseRollupInputs); // Insert commitment subtrees: const auto empty_commitments_subtree_root = components::calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH); auto end_private_data_tree_snapshot = - components::insert_subtree_to_snapshot_tree(builder, + components::insert_subtree_to_snapshot_tree(composer, baseRollupInputs.start_private_data_tree_snapshot, baseRollupInputs.new_commitments_subtree_sibling_path, empty_commitments_subtree_root, @@ -496,7 +496,7 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRol // Insert contract subtrees: const auto empty_contracts_subtree_root = components::calculate_empty_tree_root(CONTRACT_SUBTREE_DEPTH); auto end_contract_tree_snapshot = - components::insert_subtree_to_snapshot_tree(builder, + components::insert_subtree_to_snapshot_tree(composer, baseRollupInputs.start_contract_tree_snapshot, baseRollupInputs.new_contracts_subtree_sibling_path, empty_contracts_subtree_root, @@ -506,19 +506,19 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRol // Insert nullifiers: AppendOnlySnapshot const end_nullifier_tree_snapshot = - check_nullifier_tree_non_membership_and_insert_to_tree(builder, baseRollupInputs); + check_nullifier_tree_non_membership_and_insert_to_tree(composer, baseRollupInputs); // Validate public public data reads and public data update requests, and update public data tree - fr const end_public_data_tree_root = validate_and_process_public_state(builder, baseRollupInputs); + fr const end_public_data_tree_root = validate_and_process_public_state(composer, baseRollupInputs); // Calculate the overall calldata hash std::array const calldata_hash = components::compute_kernels_calldata_hash(baseRollupInputs.kernel_data); // Perform membership checks that the notes provided exist within the historic trees data - perform_historical_private_data_tree_membership_checks(builder, baseRollupInputs); - perform_historical_contract_data_tree_membership_checks(builder, baseRollupInputs); - perform_historical_l1_to_l2_message_tree_membership_checks(builder, baseRollupInputs); + perform_historical_private_data_tree_membership_checks(composer, baseRollupInputs); + perform_historical_contract_data_tree_membership_checks(composer, baseRollupInputs); + perform_historical_l1_to_l2_message_tree_membership_checks(composer, baseRollupInputs); AggregationObject const aggregation_object = aggregate_proofs(baseRollupInputs); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp index 9ea9dbb9a18c..6bfafc339346 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp @@ -12,6 +12,6 @@ namespace aztec3::circuits::rollup::native_base_rollup { -BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyBuilder& builder, BaseRollupInputs const& baseRollupInputs); +BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseRollupInputs const& baseRollupInputs); } // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp index d10f3e9b85a7..a1d9aaa91af7 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp @@ -50,13 +50,13 @@ AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& builder, +void assert_both_input_proofs_of_same_rollup_type(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - builder.do_assert(left.rollup_type == right.rollup_type, - "input proofs are of different rollup types", - utils::CircuitErrorCode::ROLLUP_TYPE_MISMATCH); + composer.do_assert(left.rollup_type == right.rollup_type, + "input proofs are of different rollup types", + utils::CircuitErrorCode::ROLLUP_TYPE_MISMATCH); } /** @@ -66,13 +66,13 @@ void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& builder, * @param right - The public inputs of the right rollup (base or merge) * @return NT::fr - The height of the rollup subtrees */ -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& builder, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - builder.do_assert(left.rollup_subtree_height == right.rollup_subtree_height, - "input proofs are of different rollup heights", - utils::CircuitErrorCode::ROLLUP_HEIGHT_MISMATCH); + composer.do_assert(left.rollup_subtree_height == right.rollup_subtree_height, + "input proofs are of different rollup heights", + utils::CircuitErrorCode::ROLLUP_HEIGHT_MISMATCH); return left.rollup_subtree_height; } @@ -82,13 +82,13 @@ NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& builder, * @param left - The public inputs of the left rollup (base or merge) * @param right - The public inputs of the right rollup (base or merge) */ -void assert_equal_constants(DummyBuilder& builder, +void assert_equal_constants(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - builder.do_assert(left.constants == right.constants, - "input proofs have different constants", - utils::CircuitErrorCode::CONSTANTS_MISMATCH); + composer.do_assert(left.constants == right.constants, + "input proofs have different constants", + utils::CircuitErrorCode::CONSTANTS_MISMATCH); } /** @@ -241,22 +241,22 @@ std::array compute_calldata_hash( // asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they // follow on from one-another). Ensures that right uses the tres that was updated by left. -void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& builder, +void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right) { - builder.do_assert(left.end_private_data_tree_snapshot == right.start_private_data_tree_snapshot, - "input proofs have different private data tree snapshots", - utils::CircuitErrorCode::PRIVATE_DATA_TREE_SNAPSHOT_MISMATCH); - builder.do_assert(left.end_nullifier_tree_snapshot == right.start_nullifier_tree_snapshot, - "input proofs have different nullifier tree snapshots", - utils::CircuitErrorCode::NULLIFIER_TREE_SNAPSHOT_MISMATCH); - builder.do_assert(left.end_contract_tree_snapshot == right.start_contract_tree_snapshot, - "input proofs have different contract tree snapshots", - utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); - builder.do_assert(left.end_public_data_tree_root == right.start_public_data_tree_root, - "input proofs have different public data tree snapshots", - utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); + composer.do_assert(left.end_private_data_tree_snapshot == right.start_private_data_tree_snapshot, + "input proofs have different private data tree snapshots", + utils::CircuitErrorCode::PRIVATE_DATA_TREE_SNAPSHOT_MISMATCH); + composer.do_assert(left.end_nullifier_tree_snapshot == right.start_nullifier_tree_snapshot, + "input proofs have different nullifier tree snapshots", + utils::CircuitErrorCode::NULLIFIER_TREE_SNAPSHOT_MISMATCH); + composer.do_assert(left.end_contract_tree_snapshot == right.start_contract_tree_snapshot, + "input proofs have different contract tree snapshots", + utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); + composer.do_assert(left.end_public_data_tree_root == right.start_public_data_tree_root, + "input proofs have different public data tree snapshots", + utils::CircuitErrorCode::CONTRACT_TREE_SNAPSHOT_MISMATCH); } } // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp index 778b382b2f89..73b1775d3447 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/components.hpp @@ -13,23 +13,23 @@ std::array compute_kernels_calldata_hash( std::array, 2> kernel_data); std::array compute_calldata_hash( std::array, 2> previous_rollup_data); -void assert_prev_rollups_follow_on_from_each_other(DummyBuilder& builder, +void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_both_input_proofs_of_same_rollup_type(DummyBuilder& builder, +void assert_both_input_proofs_of_same_rollup_type(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -NT::fr assert_both_input_proofs_of_same_height_and_return(DummyBuilder& builder, +NT::fr assert_both_input_proofs_of_same_height_and_return(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -void assert_equal_constants(DummyBuilder& builder, +void assert_equal_constants(DummyComposer& composer, BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); AggregationObject aggregate_proofs(BaseOrMergeRollupPublicInputs const& left, BaseOrMergeRollupPublicInputs const& right); -template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuilder& builder, +template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyComposer& composer, AppendOnlySnapshot snapshot, std::array siblingPath, NT::fr emptySubtreeRoot, @@ -42,7 +42,7 @@ template AppendOnlySnapshot insert_subtree_to_snapshot_tree(DummyBuil auto leafIndexAtDepth = snapshot.next_available_leaf_index >> subtreeDepth; // Check that the current root is correct and that there is an empty subtree at the insertion location - check_membership(builder, emptySubtreeRoot, leafIndexAtDepth, siblingPath, snapshot.root, message); + check_membership(composer, emptySubtreeRoot, leafIndexAtDepth, siblingPath, snapshot.root, message); // if index of leaf is x, index of its parent is x/2 or x >> 1. We need to find the parent `subtreeDepth` levels up. auto new_root = root_from_sibling_path(subtreeRootToInsert, leafIndexAtDepth, siblingPath); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp index 895cdee4c417..464cf017717c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/components/init.hpp @@ -9,7 +9,7 @@ #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/hash.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -25,6 +25,6 @@ using NT = aztec3::utils::types::NativeTypes; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using AppendOnlySnapshot = abis::AppendOnlyTreeSnapshot; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; } // namespace aztec3::circuits::rollup::components \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index e48574606913..2dd153ae03ff 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -11,7 +11,7 @@ namespace { using aztec3::circuits::rollup::merge::MergeRollupInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::rollup::test_utils::utils::compare_field_hash_to_expected; using aztec3::circuits::rollup::test_utils::utils::get_empty_kernel; @@ -70,67 +70,67 @@ class merge_rollup_tests : public ::testing::Test { TEST_F(merge_rollup_tests, native_different_rollup_type_fails) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_different_rollup_type_fails"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_different_rollup_type_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs mergeInput = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 0; mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; - merge_rollup_circuit(builder, mergeInput); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "input proofs are of different rollup types"); + merge_rollup_circuit(composer, mergeInput); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "input proofs are of different rollup types"); } TEST_F(merge_rollup_tests, native_different_rollup_height_fails) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_different_rollup_height_fails"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_different_rollup_height_fails"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs mergeInput = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs mergeInput = get_merge_rollup_inputs(composer, kernels); mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 0; mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; - merge_rollup_circuit(builder, mergeInput); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "input proofs are of different rollup heights"); + merge_rollup_circuit(composer, mergeInput); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "input proofs are of different rollup heights"); } TEST_F(merge_rollup_tests, native_constants_different_failure) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_constants_different_failure"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_constants_different_failure"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); - merge_rollup_circuit(builder, inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "input proofs have different constants"); + merge_rollup_circuit(composer, inputs); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "input proofs have different constants"); } TEST_F(merge_rollup_tests, native_constants_different_chain_id_failure) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_constants_different_failure"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_constants_different_failure"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = fr(1); inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.global_variables.chain_id = fr(0); - merge_rollup_circuit(builder, inputs); - ASSERT_TRUE(builder.failed()); - ASSERT_EQ(builder.get_first_failure().message, "input proofs have different constants"); + merge_rollup_circuit(composer, inputs); + ASSERT_TRUE(composer.failed()); + ASSERT_EQ(composer.get_first_failure().message, "input proofs have different constants"); } TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) { - DummyBuilder builderA = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); + DummyComposer composerA = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_A"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs const inputs = get_merge_rollup_inputs(builderA, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(composerA, kernels); auto inputA = inputs; inputA.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -139,12 +139,12 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(builderA, inputA); - ASSERT_TRUE(builderA.failed()); - ASSERT_EQ(builderA.get_first_failure().message, "input proofs have different private data tree snapshots"); + merge_rollup_circuit(composerA, inputA); + ASSERT_TRUE(composerA.failed()); + ASSERT_EQ(composerA.get_first_failure().message, "input proofs have different private data tree snapshots"); // do the same for nullifier tree - DummyBuilder builderB = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); + DummyComposer composerB = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_B"); auto inputB = inputs; inputB.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = { @@ -153,12 +153,12 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) inputB.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(builderB, inputB); - ASSERT_TRUE(builderB.failed()); - ASSERT_EQ(builderB.get_first_failure().message, "input proofs have different nullifier tree snapshots"); + merge_rollup_circuit(composerB, inputB); + ASSERT_TRUE(composerB.failed()); + ASSERT_EQ(composerB.get_first_failure().message, "input proofs have different nullifier tree snapshots"); // do the same for contract tree - DummyBuilder builderC = DummyBuilder("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); + DummyComposer composerC = DummyComposer("merge_rollup_tests__native_fail_if_previous_rollups_dont_follow_on_C"); auto inputC = inputs; inputC.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 @@ -166,19 +166,19 @@ TEST_F(merge_rollup_tests, native_fail_if_previous_rollups_dont_follow_on) inputC.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - merge_rollup_circuit(builderC, inputC); - ASSERT_TRUE(builderC.failed()); - ASSERT_EQ(builderC.get_first_failure().message, "input proofs have different contract tree snapshots"); + merge_rollup_circuit(composerC, inputC); + ASSERT_TRUE(composerC.failed()); + ASSERT_EQ(composerC.get_first_failure().message, "input proofs have different contract tree snapshots"); } TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_rollup_fields_are_set_correctly"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_rollup_fields_are_set_correctly"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); - BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(builder, inputs); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(composer, inputs); // check that rollup type is set to merge ASSERT_EQ(outputs.rollup_type, 1); // check that rollup height is incremented @@ -192,20 +192,20 @@ TEST_F(merge_rollup_tests, native_rollup_fields_are_set_correctly) inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; - outputs = merge_rollup_circuit(builder, inputs); + outputs = merge_rollup_circuit(composer, inputs); ASSERT_EQ(outputs.rollup_type, 1); ASSERT_EQ(outputs.rollup_subtree_height, 2); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(merge_rollup_tests, native_start_and_end_snapshots) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_start_and_end_snapshots"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_start_and_end_snapshots"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); // check that start and end snapshots are set correctly ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot); @@ -227,12 +227,12 @@ TEST_F(merge_rollup_tests, native_start_and_end_snapshots) ASSERT_EQ(outputs.end_public_data_tree_root, inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_public_data_tree_root); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(merge_rollup_tests, native_calldata_hash) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_calldata_hash"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_calldata_hash"); std::vector const zero_bytes_vec = test_utils::utils::get_empty_calldata_leaf(); auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); @@ -249,25 +249,25 @@ TEST_F(merge_rollup_tests, native_calldata_hash) std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs const inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs const inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); std::array const output_calldata_hash = outputs.calldata_hash; ASSERT_TRUE(compare_field_hash_to_expected(output_calldata_hash, expected_calldata_hash)); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(merge_rollup_tests, native_constants_dont_change) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_constants_dont_change"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_constants_dont_change"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants, outputs.constants); ASSERT_EQ(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants, outputs.constants); } @@ -275,27 +275,27 @@ TEST_F(merge_rollup_tests, native_constants_dont_change) TEST_F(merge_rollup_tests, native_aggregate) { // TODO: Fix this when aggregation works - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_aggregate"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_aggregate"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(builder, inputs); + BaseOrMergeRollupPublicInputs const outputs = merge_rollup_circuit(composer, inputs); ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); } TEST_F(merge_rollup_tests, native_merge_cbind) { - DummyBuilder builder = DummyBuilder("merge_rollup_tests__native_merge_cbind"); + DummyComposer composer = DummyComposer("merge_rollup_tests__native_merge_cbind"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - MergeRollupInputs inputs = get_merge_rollup_inputs(builder, kernels); + MergeRollupInputs inputs = get_merge_rollup_inputs(composer, kernels); - ASSERT_FALSE(builder.failed()); + ASSERT_FALSE(composer.failed()); BaseOrMergeRollupPublicInputs ignored_public_inputs; run_cbind(inputs, ignored_public_inputs, false); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp index 9c1fd16a7872..fd09dffc25a7 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/c_bind.cpp @@ -2,13 +2,13 @@ #include "index.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include namespace { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; using aztec3::circuits::rollup::merge::merge_rollup_circuit; @@ -21,11 +21,11 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, size_t* merge_rollup_public_inputs_size_out, uint8_t const** merge_rollup_public_inputs_buf) { - DummyBuilder builder = DummyBuilder("merge_rollup__sim"); + DummyComposer composer = DummyComposer("merge_rollup__sim"); MergeRollupInputs merge_rollup_inputs; read(merge_rollup_inputs_buf, merge_rollup_inputs); - BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(builder, merge_rollup_inputs); + BaseOrMergeRollupPublicInputs const public_inputs = merge_rollup_circuit(composer, merge_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -35,6 +35,6 @@ WASM_EXPORT uint8_t* merge_rollup__sim(uint8_t const* merge_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *merge_rollup_public_inputs_buf = raw_public_inputs_buf; *merge_rollup_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); + return composer.alloc_and_serialize_first_failure(); } } // extern "C" \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp index 34ad4c1f94ec..13cc7774c46a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -7,7 +7,7 @@ #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -17,7 +17,7 @@ namespace aztec3::circuits::rollup::merge { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp index 9eb114aa7a59..ea606b0da04e 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp @@ -13,7 +13,7 @@ namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& builder, MergeRollupInputs const& mergeRollupInputs) +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, MergeRollupInputs const& mergeRollupInputs) { // TODO: Verify the previous rollup proofs // TODO: Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks. @@ -25,10 +25,10 @@ BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& builder, MergeR // check that both input proofs are either both "BASE" or "MERGE" and not a mix! // this prevents having wonky commitment, nullifier and contract subtrees. AggregationObject const aggregation_object = components::aggregate_proofs(left, right); - components::assert_both_input_proofs_of_same_rollup_type(builder, left, right); - auto current_height = components::assert_both_input_proofs_of_same_height_and_return(builder, left, right); - components::assert_equal_constants(builder, left, right); - components::assert_prev_rollups_follow_on_from_each_other(builder, left, right); + components::assert_both_input_proofs_of_same_rollup_type(composer, left, right); + auto current_height = components::assert_both_input_proofs_of_same_height_and_return(composer, left, right); + components::assert_equal_constants(composer, left, right); + components::assert_prev_rollups_follow_on_from_each_other(composer, left, right); // compute calldata hash: auto new_calldata_hash = components::compute_calldata_hash(mergeRollupInputs.previous_rollup_data); diff --git a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp index 9d1e4b24772d..419f0310a66a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp @@ -3,5 +3,5 @@ #include "init.hpp" namespace aztec3::circuits::rollup::merge { -BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyBuilder& builder, MergeRollupInputs const& mergeRollupInputs); +BaseOrMergeRollupPublicInputs merge_rollup_circuit(DummyComposer& composer, MergeRollupInputs const& mergeRollupInputs); } // namespace aztec3::circuits::rollup::merge \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp index bf717151e980..9e832575aeed 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -13,7 +13,7 @@ #include "aztec3/circuits/rollup/components/components.hpp" #include "aztec3/circuits/rollup/test_utils/utils.hpp" #include "aztec3/constants.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include @@ -138,29 +138,28 @@ TEST_F(root_rollup_tests, native_check_block_hashes_empty_blocks) std::vector const messages_hash_input_bytes_vec(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP * 32, 0); auto messages_hash = sha256::sha256(messages_hash_input_bytes_vec); - utils::DummyCircuitBuilder builder = - utils::DummyCircuitBuilder("root_rollup_tests__native_check_block_hashes_empty_blocks"); + utils::DummyComposer composer = utils::DummyComposer("root_rollup_tests__native_check_block_hashes_empty_blocks"); std::array const kernels = { get_empty_kernel(), get_empty_kernel(), get_empty_kernel(), get_empty_kernel() }; - RootRollupInputs inputs = get_root_rollup_inputs(builder, kernels, l1_to_l2_messages); - RootRollupPublicInputs outputs = aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(builder, inputs); + RootRollupInputs inputs = get_root_rollup_inputs(composer, kernels, l1_to_l2_messages); + RootRollupPublicInputs outputs = + aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, inputs); // check calldata hash ASSERT_TRUE(compare_field_hash_to_expected(outputs.calldata_hash, calldata_hash)); // Check messages hash ASSERT_TRUE(compare_field_hash_to_expected(outputs.l1_to_l2_messages_hash, messages_hash)); - EXPECT_FALSE(builder.failed()); + EXPECT_FALSE(composer.failed()); run_cbind(inputs, outputs, true); } TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) { - utils::DummyCircuitBuilder builder = - utils::DummyCircuitBuilder("root_rollup_tests__native_root_missing_nullifier_logic"); + utils::DummyComposer composer = utils::DummyComposer("root_rollup_tests__native_root_missing_nullifier_logic"); MemoryTree data_tree = MemoryTree(PRIVATE_DATA_TREE_HEIGHT); MemoryTree contract_tree = MemoryTree(CONTRACT_TREE_HEIGHT); @@ -243,9 +242,9 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) .next_available_leaf_index = NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP }; - RootRollupInputs rootRollupInputs = get_root_rollup_inputs(builder, kernels, l1_to_l2_messages); + RootRollupInputs rootRollupInputs = get_root_rollup_inputs(composer, kernels, l1_to_l2_messages); RootRollupPublicInputs outputs = - aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(builder, rootRollupInputs); + aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit(composer, rootRollupInputs); // Check private data trees ASSERT_EQ( @@ -298,7 +297,7 @@ TEST_F(root_rollup_tests, native_root_missing_nullifier_logic) auto root = accumulate_sha256({ left[0], left[1], right[0], right[1] }); ASSERT_EQ(outputs.calldata_hash, root); - EXPECT_FALSE(builder.failed()); + EXPECT_FALSE(composer.failed()); run_cbind(rootRollupInputs, outputs, true); } diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp index 9bc1e7b66f7a..70da1ca64e38 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/c_bind.cpp @@ -9,9 +9,9 @@ #include namespace { -using Builder = UltraCircuitBuilder; +using Composer = plonk::UltraPlonkComposer; using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using aztec3::circuits::rollup::native_root_rollup::root_rollup_circuit; using aztec3::circuits::rollup::native_root_rollup::RootRollupInputs; using aztec3::circuits::rollup::native_root_rollup::RootRollupPublicInputs; @@ -52,8 +52,8 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, RootRollupInputs root_rollup_inputs; read(root_rollup_inputs_buf, root_rollup_inputs); - DummyBuilder builder = DummyBuilder("root_rollup__sim"); - RootRollupPublicInputs const public_inputs = root_rollup_circuit(builder, root_rollup_inputs); + DummyComposer composer = DummyComposer("root_rollup__sim"); + RootRollupPublicInputs const public_inputs = root_rollup_circuit(composer, root_rollup_inputs); // serialize public inputs to bytes vec std::vector public_inputs_vec; @@ -63,7 +63,7 @@ WASM_EXPORT uint8_t* root_rollup__sim(uint8_t const* root_rollup_inputs_buf, memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); *root_rollup_public_inputs_buf = raw_public_inputs_buf; *root_rollup_public_inputs_size_out = public_inputs_vec.size(); - return builder.alloc_and_serialize_first_failure(); + return composer.alloc_and_serialize_first_failure(); } WASM_EXPORT size_t root_rollup__verify_proof(uint8_t const* vk_buf, uint8_t const* proof, uint32_t length) diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp index 5b4428733f31..0f7e24bb5ff3 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/init.hpp @@ -6,7 +6,7 @@ #include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/root/root_rollup_public_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -16,7 +16,7 @@ namespace aztec3::circuits::rollup::native_root_rollup { using NT = aztec3::utils::types::NativeTypes; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; // Params using ConstantRollupData = abis::ConstantRollupData; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 945d3bcbbdd6..ac6a67b0fc1a 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -69,7 +69,7 @@ std::array compute_messages_hash( return { high, low }; } -RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInputs const& rootRollupInputs) +RootRollupPublicInputs root_rollup_circuit(DummyComposer& composer, RootRollupInputs const& rootRollupInputs) { // TODO: Verify the previous rollup proofs // TODO: Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks. @@ -79,14 +79,14 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu auto right = rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs; auto aggregation_object = components::aggregate_proofs(left, right); - components::assert_both_input_proofs_of_same_rollup_type(builder, left, right); - components::assert_both_input_proofs_of_same_height_and_return(builder, left, right); - components::assert_equal_constants(builder, left, right); - components::assert_prev_rollups_follow_on_from_each_other(builder, left, right); + components::assert_both_input_proofs_of_same_rollup_type(composer, left, right); + components::assert_both_input_proofs_of_same_height_and_return(composer, left, right); + components::assert_equal_constants(composer, left, right); + components::assert_prev_rollups_follow_on_from_each_other(composer, left, right); // Update the historic private data tree auto end_tree_of_historic_private_data_tree_roots_snapshot = components::insert_subtree_to_snapshot_tree( - builder, + composer, left.constants.start_tree_of_historic_private_data_tree_roots_snapshot, rootRollupInputs.new_historic_private_data_tree_root_sibling_path, fr::zero(), @@ -96,7 +96,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu // Update the historic private data tree auto end_tree_of_historic_contract_tree_roots_snapshot = - components::insert_subtree_to_snapshot_tree(builder, + components::insert_subtree_to_snapshot_tree(composer, left.constants.start_tree_of_historic_contract_tree_roots_snapshot, rootRollupInputs.new_historic_contract_tree_root_sibling_path, fr::zero(), @@ -111,7 +111,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu // // Insert subtree into the l1 to l2 data tree const auto empty_l1_to_l2_subtree_root = components::calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_DEPTH); auto new_l1_to_l2_messages_tree_snapshot = - components::insert_subtree_to_snapshot_tree(builder, + components::insert_subtree_to_snapshot_tree(composer, rootRollupInputs.start_l1_to_l2_message_tree_snapshot, rootRollupInputs.new_l1_to_l2_message_tree_root_sibling_path, empty_l1_to_l2_subtree_root, @@ -121,7 +121,7 @@ RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInpu // Update the historic l1 to l2 data tree auto end_l1_to_l2_data_roots_tree_snapshot = components::insert_subtree_to_snapshot_tree( - builder, + composer, rootRollupInputs.start_historic_tree_l1_to_l2_message_tree_roots_snapshot, rootRollupInputs.new_historic_l1_to_l2_message_roots_tree_sibling_path, fr::zero(), diff --git a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp index d611a114dfd8..c1318015cd48 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.hpp @@ -11,6 +11,6 @@ namespace aztec3::circuits::rollup::native_root_rollup { -RootRollupPublicInputs root_rollup_circuit(DummyBuilder& builder, RootRollupInputs const& rootRollupInputs); +RootRollupPublicInputs root_rollup_circuit(DummyComposer& composer, RootRollupInputs const& rootRollupInputs); } // namespace aztec3::circuits::rollup::native_root_rollup \ No newline at end of file diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp index 1ebf7ace3e77..4cf0843c6ce6 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/init.hpp @@ -11,7 +11,7 @@ #include "aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp" #include "aztec3/circuits/recursion/aggregator.hpp" #include "aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp" -#include "aztec3/utils/dummy_circuit_builder.hpp" +#include "aztec3/utils/dummy_composer.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -27,7 +27,7 @@ using NT = aztec3::utils::types::NativeTypes; using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp index 628263a199d0..01e186f60a5c 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.cpp @@ -20,7 +20,7 @@ using ConstantRollupData = aztec3::circuits::abis::ConstantRollupData; using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; using RootRollupPublicInputs = aztec3::circuits::abis::RootRollupPublicInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -238,13 +238,13 @@ BaseRollupInputs base_rollup_inputs_from_kernels(std::array kerne std::move(kernel_data), private_data_tree, contract_tree, public_data_tree, l1_to_l2_messages_tree); } -std::array, 2> get_previous_rollup_data(DummyBuilder& builder, +std::array, 2> get_previous_rollup_data(DummyComposer& composer, std::array kernel_data) { // NOTE: Still assuming that this is first and second. Don't handle more rollups atm auto base_rollup_input_1 = base_rollup_inputs_from_kernels({ kernel_data[0], kernel_data[1] }); auto base_public_input_1 = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, base_rollup_input_1); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, base_rollup_input_1); // Build the trees based on inputs in base_rollup_input_1. MerkleTree private_data_tree = MerkleTree(PRIVATE_DATA_TREE_HEIGHT); @@ -281,7 +281,7 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& bui get_sibling_path(private_data_tree, 8, PRIVATE_DATA_SUBTREE_DEPTH); auto base_public_input_2 = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(builder, base_rollup_input_2); + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(composer, base_rollup_input_2); PreviousRollupData const previous_rollup1 = { .base_or_merge_rollup_public_inputs = base_public_input_1, @@ -301,13 +301,13 @@ std::array, 2> get_previous_rollup_data(DummyBuilder& bui return { previous_rollup1, previous_rollup2 }; } -MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& builder, std::array kernel_data) +MergeRollupInputs get_merge_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data) { - MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)) }; + MergeRollupInputs inputs = { .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)) }; return inputs; } -RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, +RootRollupInputs get_root_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data, std::array l1_to_l2_messages) { @@ -346,7 +346,7 @@ RootRollupInputs get_root_rollup_inputs(utils::DummyBuilder& builder, }; RootRollupInputs rootRollupInputs = { - .previous_rollup_data = get_previous_rollup_data(builder, std::move(kernel_data)), + .previous_rollup_data = get_previous_rollup_data(composer, std::move(kernel_data)), .new_historic_private_data_tree_root_sibling_path = historic_data_sibling_path, .new_historic_contract_tree_root_sibling_path = historic_contract_sibling_path, .l1_to_l2_messages = l1_to_l2_messages, diff --git a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp index eff8c73caaf4..30db94c4d0b2 100644 --- a/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp +++ b/circuits/cpp/src/aztec3/circuits/rollup/test_utils/utils.hpp @@ -23,7 +23,7 @@ using BaseRollupInputs = aztec3::circuits::abis::BaseRollupInputs; using MergeRollupInputs = aztec3::circuits::abis::MergeRollupInputs; using BaseOrMergeRollupPublicInputs = aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using RootRollupInputs = aztec3::circuits::abis::RootRollupInputs; -using DummyBuilder = aztec3::utils::DummyCircuitBuilder; +using DummyComposer = aztec3::utils::DummyComposer; using Aggregator = aztec3::circuits::recursion::Aggregator; using AppendOnlyTreeSnapshot = aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -87,11 +87,11 @@ NullifierMemoryTreeTestingHarness get_initial_nullifier_tree(const std::vector kernel_data, std::array l1_to_l2_messages); -MergeRollupInputs get_merge_rollup_inputs(utils::DummyBuilder& builder, std::array kernel_data); +MergeRollupInputs get_merge_rollup_inputs(utils::DummyComposer& composer, std::array kernel_data); inline abis::PublicDataUpdateRequest make_public_data_update_request(fr leaf_index, fr old_value, fr new_value) { diff --git a/circuits/cpp/src/aztec3/utils/array.hpp b/circuits/cpp/src/aztec3/utils/array.hpp index a443255b4140..d027ea92ba60 100644 --- a/circuits/cpp/src/aztec3/utils/array.hpp +++ b/circuits/cpp/src/aztec3/utils/array.hpp @@ -99,12 +99,12 @@ template T array_pop(std::array& arr) /** * @brief Helper method to push an item into the first empty slot in an array * @tparam The type of the value stored in the array - * @tparam The builder type + * @tparam The composer type * @tparam The size of the array * @param The array into which we want to store the value */ -template -void array_push(Builder& builder, std::array& arr, T const& value) +template +void array_push(Composer& composer, std::array& arr, T const& value) { for (size_t i = 0; i < arr.size(); ++i) { if (is_empty(arr[i])) { @@ -112,7 +112,7 @@ void array_push(Builder& builder, std::array& arr, T const& value) return; } } - builder.do_assert(false, "array_push cannot push to a full array", CircuitErrorCode::ARRAY_OVERFLOW); + composer.do_assert(false, "array_push cannot push to a full array", CircuitErrorCode::ARRAY_OVERFLOW); }; /** @@ -165,22 +165,22 @@ template NT::boolean is_array_empty(std::array -void push_array_to_array(Builder& builder, std::array const& source, std::array& target) +template +void push_array_to_array(Composer& composer, std::array const& source, std::array& target) { // Check if the `source` array is too large vs the remaining capacity of the `target` array size_t const source_size = static_cast(uint256_t(array_length(source))); size_t const target_size = static_cast(uint256_t(array_length(target))); - builder.do_assert(source_size <= size_2 - target_size, - "push_array_to_array cannot overflow the target", - CircuitErrorCode::ARRAY_OVERFLOW); + composer.do_assert(source_size <= size_2 - target_size, + "push_array_to_array cannot overflow the target", + CircuitErrorCode::ARRAY_OVERFLOW); // Ensure that there are no non-zero values in the `target` array after the first zero-valued index for (size_t i = target_size; i < size_2; i++) { - builder.do_assert(is_empty(target[i]), - "push_array_to_array inserting new array into a non empty space", - CircuitErrorCode::ARRAY_OVERFLOW); + composer.do_assert(is_empty(target[i]), + "push_array_to_array inserting new array into a non empty space", + CircuitErrorCode::ARRAY_OVERFLOW); } // Copy the non-zero elements of the `source` array to the `target` array at the first zero-valued index auto zero_index = target_size; diff --git a/circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp similarity index 87% rename from circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp rename to circuits/cpp/src/aztec3/utils/dummy_composer.hpp index fb841ea56b0b..4c3c61da8d19 100644 --- a/circuits/cpp/src/aztec3/utils/dummy_circuit_builder.hpp +++ b/circuits/cpp/src/aztec3/utils/dummy_composer.hpp @@ -9,13 +9,13 @@ namespace aztec3::utils { -class DummyCircuitBuilder { +class DummyComposer { public: std::vector failure_msgs; - // method that created this builder instance. Useful for logging. + // method that created this composer instance. Useful for logging. std::string method_name; - explicit DummyCircuitBuilder(std::string method_name) : method_name(std::move(method_name)) {} + explicit DummyComposer(std::string method_name) : method_name(std::move(method_name)) {} void do_assert(bool const& assertion, std::string const& msg, CircuitErrorCode error_code) { @@ -59,7 +59,7 @@ class DummyCircuitBuilder { if (failure.code == CircuitErrorCode::NO_ERROR) { return nullptr; } - info(this->method_name, ": builder.get_first_failure() = ", failure_msgs[0]); + info(this->method_name, ": composer.get_first_failure() = ", failure_msgs[0]); // serialize circuit failure to bytes vec diff --git a/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp b/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp index 9d1fda1f6a2e..8a91090a4118 100644 --- a/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp +++ b/circuits/cpp/src/aztec3/utils/msgpack_derived_equals.hpp @@ -12,7 +12,7 @@ auto _compare_msgpack_tuples(const Tuple1& t1, const Tuple2& t2, std::index_sequ // Function to check equality of msgpack objects based on their values. // Normally, you should instead use operator==() = default; -// BoolLike represents a type like the boolean DSL type +// BoolLike represents a type like the boolean DSL type template BoolLike msgpack_derived_equals(const T& obj1, const T& obj2) { BoolLike are_equal; diff --git a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp index ea3daa5273e5..eb2a3042d9b2 100644 --- a/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp +++ b/circuits/cpp/src/aztec3/utils/types/circuit_types.hpp @@ -7,42 +7,45 @@ using namespace proof_system::plonk; -// Note: Inner proving system type for recursion is inflexibly set to UltraPlonk. namespace aztec3::utils::types { -template struct CircuitTypes { +template struct CircuitTypes { // Basic uint types - using boolean = stdlib::bool_t; - using uint8 = stdlib::uint8; - using uint16 = stdlib::uint16; - using uint32 = stdlib::uint32; - using uint64 = stdlib::uint64; + using boolean = stdlib::bool_t; + using uint8 = stdlib::uint8; + using uint16 = stdlib::uint16; + using uint32 = stdlib::uint32; + using uint64 = stdlib::uint64; // Types related to the bn254 curve - using fr = stdlib::field_t; - using safe_fr = stdlib::safe_uint_t; - using address = stdlib::address_t; - using fq = stdlib::bigfield; + using fr = stdlib::field_t; + using safe_fr = stdlib::safe_uint_t; + using address = stdlib::address_t; + using fq = stdlib::bigfield; - using witness = stdlib::witness_t; + using witness = stdlib::witness_t; // typedef fq grumpkin_fr; // typedef fr grumpkin_fq; - using grumpkin_point = stdlib::point; // affine - using grumpkin_group = stdlib::group; + using grumpkin_point = stdlib::point; // affine + using grumpkin_group = stdlib::group; - using bn254 = stdlib::bn254; + using bn254 = stdlib::bn254; // typedef bn254::g1_ct bn254_point; - using bn254_point = stdlib::element; // affine + using bn254_point = stdlib::element; // affine - using bit_array = stdlib::bit_array; - using byte_array = stdlib::byte_array; - using packed_byte_array = stdlib::packed_byte_array; + using bit_array = stdlib::bit_array; + using byte_array = stdlib::byte_array; + using packed_byte_array = stdlib::packed_byte_array; - using schnorr_signature = stdlib::schnorr::signature_bits; - using ecdsa_signature = stdlib::ecdsa::signature; + using schnorr_signature = stdlib::schnorr::signature_bits; + using ecdsa_signature = stdlib::ecdsa::signature; using AggregationObject = stdlib::recursion::aggregation_state; + using recursive_inner_verifier_settings = + std::conditional_t, + stdlib::recursion::recursive_turbo_verifier_settings, + stdlib::recursion::recursive_ultra_verifier_settings>; using VK = stdlib::recursion::verification_key; // Notice: no CircuitType for a Proof: we only ever handle native; the verify_proof() function swallows the // 'circuit-type-ness' of the proof. @@ -52,25 +55,25 @@ template struct CircuitTypes { // Define the 'circuit' version of the function `compress`, with the name `compress`: static fr compress(std::vector const& inputs, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::compress(inputs, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs, hash_index); } template static fr compress(std::array const& inputs, const size_t hash_index = 0) { std::vector const inputs_vec(std::begin(inputs), std::end(inputs)); - return plonk::stdlib::pedersen_commitment::compress(inputs_vec, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs_vec, hash_index); } static fr compress(std::vector const& inputs, std::vector const& hash_sub_indices, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::compress(inputs, hash_sub_indices, hash_index); + return plonk::stdlib::pedersen_commitment::compress(inputs, hash_sub_indices, hash_index); } static fr compress(const std::vector>& input_pairs) { - return plonk::stdlib::pedersen_commitment::compress(input_pairs); + return plonk::stdlib::pedersen_commitment::compress(input_pairs); }; /** @@ -86,17 +89,17 @@ template struct CircuitTypes { static fr merkle_hash(fr left, fr right) { // use 0-generator for internal merkle hashing - return plonk::stdlib::pedersen_hash::hash_multiple({ left, right }, 0); + return plonk::stdlib::pedersen_hash::hash_multiple({ left, right }, 0); }; static grumpkin_point commit(const std::vector& inputs, const size_t hash_index = 0) { - return plonk::stdlib::pedersen_commitment::commit(inputs, hash_index); + return plonk::stdlib::pedersen_commitment::commit(inputs, hash_index); }; static grumpkin_point commit(const std::vector>& input_pairs) { - return plonk::stdlib::pedersen_commitment::commit(input_pairs); + return plonk::stdlib::pedersen_commitment::commit(input_pairs); }; static byte_array blake2s(const byte_array& input) { return plonk::stdlib::blake2s(input); } diff --git a/circuits/cpp/src/aztec3/utils/types/convert.hpp b/circuits/cpp/src/aztec3/utils/types/convert.hpp index 8d4f374d38e3..ecd2113fd734 100644 --- a/circuits/cpp/src/aztec3/utils/types/convert.hpp +++ b/circuits/cpp/src/aztec3/utils/types/convert.hpp @@ -13,117 +13,118 @@ using plonk::stdlib::witness_t; namespace { -template using CT = aztec3::utils::types::CircuitTypes; +template using CT = aztec3::utils::types::CircuitTypes; using NT = aztec3::utils::types::NativeTypes; } // namespace /// TODO: Lots of identical functions here (but for their in/out types). Can we use templates? I couldn't figure out how /// to keep the NT:: or CT:: prefixes with templates. -template typename CT::boolean to_ct(Builder& builder, typename NT::boolean const& e) +template typename CT::boolean to_ct(Composer& composer, typename NT::boolean const& e) { - return typename CT::boolean(witness_t(&builder, e)); + return typename CT::boolean(witness_t(&composer, e)); }; -template typename CT::fr to_ct(Builder& builder, typename NT::fr const& e) +template typename CT::fr to_ct(Composer& composer, typename NT::fr const& e) { - return typename CT::fr(witness_t(&builder, e)); + return typename CT::fr(witness_t(&composer, e)); }; -template typename CT::fq to_ct(Builder& builder, typename NT::fq const& e) +template typename CT::fq to_ct(Composer& composer, typename NT::fq const& e) { - return typename CT::fq(witness_t(&builder, e)); + return typename CT::fq(witness_t(&composer, e)); }; -template typename CT::address to_ct(Builder& builder, typename NT::address const& e) +template typename CT::address to_ct(Composer& composer, typename NT::address const& e) { - return typename CT::address(witness_t(&builder, e)); + return typename CT::address(witness_t(&composer, e)); }; -template typename CT::uint32 to_ct(Builder& builder, typename NT::uint32 const& e) +template typename CT::uint32 to_ct(Composer& composer, typename NT::uint32 const& e) { - return typename CT::uint32(witness_t(&builder, e)); + return typename CT::uint32(witness_t(&composer, e)); }; -template -typename CT::grumpkin_point to_ct(Builder& builder, typename NT::grumpkin_point const& e) +template +typename CT::grumpkin_point to_ct(Composer& composer, typename NT::grumpkin_point const& e) { - return plonk::stdlib::create_point_witness(builder, e, true); + return plonk::stdlib::create_point_witness(composer, e, true); }; -template typename CT::bn254_point to_ct(Builder& builder, typename NT::bn254_point const& e) +template +typename CT::bn254_point to_ct(Composer& composer, typename NT::bn254_point const& e) { - return CT::bn254_point::from_witness(&builder, e); + return CT::bn254_point::from_witness(&composer, e); }; -template -typename CT::ecdsa_signature to_ct(Builder& builder, typename NT::ecdsa_signature const& e) +template +typename CT::ecdsa_signature to_ct(Composer& composer, typename NT::ecdsa_signature const& e) { - return CT::ecdsa_signature::template from_witness(&builder, e); + return CT::ecdsa_signature::template from_witness(&composer, e); }; -template -std::optional::boolean> to_ct(Builder& builder, std::optional const& e) +template +std::optional::boolean> to_ct(Composer& composer, std::optional const& e) { - return e ? std::make_optional::boolean>(to_ct(builder, *e)) : std::nullopt; + return e ? std::make_optional::boolean>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::fr> to_ct(Builder& builder, std::optional const& e) +template +std::optional::fr> to_ct(Composer& composer, std::optional const& e) { - return e ? std::make_optional::fr>(to_ct(builder, *e)) : std::nullopt; + return e ? std::make_optional::fr>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::address> to_ct(Builder& builder, std::optional const& e) +template +std::optional::address> to_ct(Composer& composer, std::optional const& e) { - return e ? std::make_optional::address>(to_ct(builder, *e)) : std::nullopt; + return e ? std::make_optional::address>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::grumpkin_point> to_ct(Builder& builder, - std::optional const& e) +template +std::optional::grumpkin_point> to_ct(Composer& composer, + std::optional const& e) { - return e ? std::make_optional::grumpkin_point>(to_ct(builder, *e)) : std::nullopt; + return e ? std::make_optional::grumpkin_point>(to_ct(composer, *e)) : std::nullopt; }; -template -std::optional::ecdsa_signature> to_ct(Builder& builder, - std::optional const& e) +template +std::optional::ecdsa_signature> to_ct(Composer& composer, + std::optional const& e) { - return e ? std::make_optional::ecdsa_signature>(to_ct(&builder, e)) : std::nullopt; + return e ? std::make_optional::ecdsa_signature>(to_ct(&composer, e)) : std::nullopt; }; -template -std::vector::fr> to_ct(Builder& builder, std::vector const& vec) +template +std::vector::fr> to_ct(Composer& composer, std::vector const& vec) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; return map(vec, ref_to_ct); }; -template -std::optional::fr>> to_ct(Builder& builder, - std::optional> const& vec) +template +std::optional::fr>> to_ct(Composer& composer, + std::optional> const& vec) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; - return vec ? std::make_optional::fr>>(map(*vec, ref_to_ct)) : std::nullopt; + return vec ? std::make_optional::fr>>(map(*vec, ref_to_ct)) : std::nullopt; }; -template -std::array::fr, SIZE> to_ct(Builder& builder, std::array const& arr) +template +std::array::fr, SIZE> to_ct(Composer& composer, std::array const& arr) { - auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(builder, e); }; + auto ref_to_ct = [&](typename NT::fr const& e) { return to_ct(composer, e); }; return map(arr, ref_to_ct); }; -template std::array::fr>, SIZE> to_ct( - Builder& builder, std::array, SIZE> const& arr) +template std::array::fr>, SIZE> to_ct( + Composer& composer, std::array, SIZE> const& arr) { - auto ref_to_ct = [&](std::optional const& e) { return to_ct(builder, e); }; + auto ref_to_ct = [&](std::optional const& e) { return to_ct(composer, e); }; return map(arr, ref_to_ct); }; @@ -131,10 +132,10 @@ template std::array -std::array to_ct(Builder& builder, std::array const& arr) +template +std::array to_ct(Composer& composer, std::array const& arr) { - auto ref_to_ct = [&](NT_TYPE const& e) { return e.to_circuit_type(builder); }; + auto ref_to_ct = [&](NT_TYPE const& e) { return e.to_circuit_type(composer); }; return map(arr, ref_to_ct); }; @@ -143,37 +144,37 @@ std::array to_ct(Builder& builder, std::array cons * @brief Convert from an array of any native types (NT_TYPE) to array of circuit types (CT_TYPE). * Allow array entries to be optional. */ -template -std::array, SIZE> to_ct(Builder& builder, std::array, SIZE> const& arr) +template +std::array, SIZE> to_ct(Composer& composer, std::array, SIZE> const& arr) { - auto ref_to_ct = [&](std::optional const& e) { return e.to_circuit_type(builder); }; + auto ref_to_ct = [&](std::optional const& e) { return e.to_circuit_type(composer); }; return map(arr, ref_to_ct); }; // to_nt() below ******************************** -template typename NT::boolean to_nt(typename CT::boolean const& e) +template typename NT::boolean to_nt(typename CT::boolean const& e) { return e.get_value(); }; -template typename NT::fr to_nt(typename CT::fr const& e) +template typename NT::fr to_nt(typename CT::fr const& e) { return e.get_value(); }; -template typename NT::fq to_nt(typename CT::fq const& e) +template typename NT::fq to_nt(typename CT::fq const& e) { return e.get_value(); }; -template typename NT::address to_nt(typename CT::address const& e) +template typename NT::address to_nt(typename CT::address const& e) { return NT::address(e.address_.get_value()); // TODO: add get_value() method to address types. }; -template typename NT::uint32 to_nt(typename CT::uint32 const& e) +template typename NT::uint32 to_nt(typename CT::uint32 const& e) { NT::uint256 const e_256 = e.get_value(); NT::uint64 const e_64 = e_256.data[0]; // TODO: check that this endianness is correct! @@ -181,17 +182,17 @@ template typename NT::uint32 to_nt(typename CT::uint return e_32; }; -template typename NT::grumpkin_point to_nt(typename CT::grumpkin_point const& e) +template typename NT::grumpkin_point to_nt(typename CT::grumpkin_point const& e) { return NT::grumpkin_point{ e.x.get_value(), e.y.get_value() }; }; -template typename NT::bn254_point to_nt(typename CT::bn254_point const& e) +template typename NT::bn254_point to_nt(typename CT::bn254_point const& e) { return e.get_value(); }; -template typename NT::ecdsa_signature to_nt(typename CT::ecdsa_signature const& e) +template typename NT::ecdsa_signature to_nt(typename CT::ecdsa_signature const& e) { std::vector r_bytes = e.r.get_value(); std::vector s_bytes = e.s.get_value(); @@ -204,71 +205,71 @@ template typename NT::ecdsa_signature to_nt(typename CT -std::optional to_nt(std::optional::boolean> const& e) +template +std::optional to_nt(std::optional::boolean> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template std::optional to_nt(std::optional::fr> const& e) +template std::optional to_nt(std::optional::fr> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::address> const& e) +template +std::optional to_nt(std::optional::address> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::grumpkin_point> const& e) +template +std::optional to_nt(std::optional::grumpkin_point> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template -std::optional to_nt(std::optional::ecdsa_signature> const& e) +template +std::optional to_nt(std::optional::ecdsa_signature> const& e) { - return e ? std::make_optional(to_nt(*e)) : std::nullopt; + return e ? std::make_optional(to_nt(*e)) : std::nullopt; }; -template std::vector to_nt(std::vector::fr> const& vec) +template std::vector to_nt(std::vector::fr> const& vec) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return map(vec, ref_to_nt); }; -template -std::optional> to_nt(std::optional::fr>> const& vec) +template +std::optional> to_nt(std::optional::fr>> const& vec) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return vec ? std::make_optional>(map(*vec, ref_to_nt)) : std::nullopt; }; -template -std::array to_nt(std::array::fr, SIZE> const& arr) +template +std::array to_nt(std::array::fr, SIZE> const& arr) { - auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; + auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; return map(arr, ref_to_nt); }; -// template +// template // std::optional> to_nt( -// std::optional::fr, SIZE>> const& arr) +// std::optional::fr, SIZE>> const& arr) // { -// auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; +// auto ref_to_nt = [&](typename CT::fr const& e) { return to_nt(e); }; // return arr ? std::make_optional>(map(arr, ref_to_nt)) : std::nullopt; // }; -template std::array, SIZE> to_nt( - std::array::fr>, SIZE> const& arr) +template std::array, SIZE> to_nt( + std::array::fr>, SIZE> const& arr) { - auto ref_to_nt = [&](std::optional::fr> const& e) { return to_nt(e); }; + auto ref_to_nt = [&](std::optional::fr> const& e) { return to_nt(e); }; return map(arr, ref_to_nt); }; diff --git a/yarn-project/circuits.js/src/cbind/circuits.gen.ts b/yarn-project/circuits.js/src/cbind/circuits.gen.ts index 89c6531eae1d..989d4a6782b7 100644 --- a/yarn-project/circuits.js/src/cbind/circuits.gen.ts +++ b/yarn-project/circuits.js/src/cbind/circuits.gen.ts @@ -816,7 +816,7 @@ export function fromKernelCircuitPublicInputs(o: KernelCircuitPublicInputs): Msg } interface MsgpackVerificationKeyData { - circuit_type: number; + composer_type: number; circuit_size: number; num_public_inputs: number; commitments: Record; @@ -825,8 +825,8 @@ interface MsgpackVerificationKeyData { } export function toVerificationKeyData(o: MsgpackVerificationKeyData): VerificationKeyData { - if (o.circuit_type === undefined) { - throw new Error('Expected circuit_type in VerificationKeyData deserialization'); + if (o.composer_type === undefined) { + throw new Error('Expected composer_type in VerificationKeyData deserialization'); } if (o.circuit_size === undefined) { throw new Error('Expected circuit_size in VerificationKeyData deserialization'); @@ -844,7 +844,7 @@ export function toVerificationKeyData(o: MsgpackVerificationKeyData): Verificati throw new Error('Expected recursive_proof_public_input_indices in VerificationKeyData deserialization'); } return new VerificationKeyData( - o.circuit_type, + o.composer_type, o.circuit_size, o.num_public_inputs, mapValues(o.commitments, (v: MsgpackG1AffineElement) => toG1AffineElement(v)), @@ -854,8 +854,8 @@ export function toVerificationKeyData(o: MsgpackVerificationKeyData): Verificati } export function fromVerificationKeyData(o: VerificationKeyData): MsgpackVerificationKeyData { - if (o.circuitType === undefined) { - throw new Error('Expected circuitType in VerificationKeyData serialization'); + if (o.composerType === undefined) { + throw new Error('Expected composerType in VerificationKeyData serialization'); } if (o.circuitSize === undefined) { throw new Error('Expected circuitSize in VerificationKeyData serialization'); @@ -873,7 +873,7 @@ export function fromVerificationKeyData(o: VerificationKeyData): MsgpackVerifica throw new Error('Expected recursiveProofPublicInputIndices in VerificationKeyData serialization'); } return { - circuit_type: o.circuitType, + composer_type: o.composerType, circuit_size: o.circuitSize, num_public_inputs: o.numPublicInputs, commitments: mapValues(o.commitments, (v: G1AffineElement) => fromG1AffineElement(v)), diff --git a/yarn-project/circuits.js/src/kernel/private_kernel.ts b/yarn-project/circuits.js/src/kernel/private_kernel.ts index f263dfdab29e..03150f84d9ca 100644 --- a/yarn-project/circuits.js/src/kernel/private_kernel.ts +++ b/yarn-project/circuits.js/src/kernel/private_kernel.ts @@ -84,7 +84,7 @@ export function privateKernelProve( firstIteration, proofOutputAddressPtr, ); - // for whenever we actually use this method, we need to do proper error handling in C++ via bberg. + // for whenever we actually use this method, we need to do proper error handling in C++ via the bberg composer. const address = uint8ArrayToNum(wasm.getMemorySlice(proofOutputAddressPtr, proofOutputAddressPtr + 4)); const proof = Buffer.from(wasm.getMemorySlice(address, address + proofSize)); wasm.call('bbfree', proofOutputAddressPtr); diff --git a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap index 6a70dcad4d33..11984045a86e 100644 --- a/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/kernel/__snapshots__/index.test.ts.snap @@ -113,7 +113,7 @@ value: 0xd05 " `; -exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101 }"`; +exports[`structs/kernel serializes and prints EcdsaSignature 1`] = `"{ 0101010101010101010101010101010101010101010101010101010101010101, 0101010101010101010101010101010101010101010101010101010101010101, 0 }"`; exports[`structs/kernel serializes and prints previous_kernel_data 1`] = ` "public_inputs: end: @@ -257,7 +257,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -515,7 +515,7 @@ is_execution_request: 0 proof: [ 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -691,7 +691,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -921,7 +921,7 @@ is_execution_request: 0 proof: [ 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ @@ -1239,7 +1239,7 @@ is_private: 1 proof: [ 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 101 key.num_public_inputs: 102 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap index 2fc43e57d835..2632cab271ad 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/base_rollup.test.ts.snap @@ -143,7 +143,7 @@ is_private: 1 proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ @@ -295,7 +295,7 @@ is_private: 1 proof: [ 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 ] vk: -key.circuit_type: 0 +key.composer_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap index e4f80d53f934..3cfde88e2980 100644 --- a/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/rollup/__snapshots__/root_rollup.test.ts.snap @@ -71,7 +71,7 @@ end_public_data_tree_root: calldata_hash: [ 0x901 0x902 ] proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ] -vk: key.circuit_type: 0 +vk: key.composer_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ @@ -154,7 +154,7 @@ end_public_data_tree_root: calldata_hash: [ 0x1901 0x1902 ] proof: [ 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 ] -vk: key.circuit_type: 0 +vk: key.composer_type: 0 key.circuit_size: 65 key.num_public_inputs: 66 key.commitments: [ diff --git a/yarn-project/circuits.js/src/structs/shared.ts b/yarn-project/circuits.js/src/structs/shared.ts index 4f33319e80da..c028bd2ffc75 100644 --- a/yarn-project/circuits.js/src/structs/shared.ts +++ b/yarn-project/circuits.js/src/structs/shared.ts @@ -26,14 +26,13 @@ export class Vector { export type UInt32 = number; /** - * CircuitType replaces ComposerType for now. When using Plonk, CircuitType is equivalent to the information of the proving system that will be used - * to construct a proof. In the future Aztec zk stack, more information must be specified (e.g., the curve over which circuits are constructed; - * Plonk vs Honk; zk-SNARK or just SNARK; etc). + * Composer prover type. */ -export enum CircuitType { +export enum ComposerType { STANDARD = 0, TURBO = 1, - ULTRA = 2, + PLOOKUP = 2, + STANDARD_HONK = 3, } /** diff --git a/yarn-project/circuits.js/src/structs/verification_key.ts b/yarn-project/circuits.js/src/structs/verification_key.ts index 2b079f86e0dc..20a5a91af5fb 100644 --- a/yarn-project/circuits.js/src/structs/verification_key.ts +++ b/yarn-project/circuits.js/src/structs/verification_key.ts @@ -1,7 +1,7 @@ import { BufferReader } from '@aztec/foundation/serialize'; import { serializeToBuffer } from '../utils/serialize.js'; import { Fq } from './index.js'; -import { CircuitType } from './shared.js'; +import { ComposerType } from './shared.js'; import times from 'lodash.times'; /** @@ -79,9 +79,9 @@ export class CommitmentMap { export class VerificationKey { constructor( /** - * For Plonk, this is equivalent to the proving system used to prove and verify. + * Composer prover type we're using. */ - public circuitType: CircuitType, + public composerType: ComposerType, /** * The number of gates in this circuit. */ @@ -110,7 +110,7 @@ export class VerificationKey { */ toBuffer() { return serializeToBuffer( - this.circuitType, + this.composerType, this.circuitSize, this.numPublicInputs, new CommitmentMap(this.commitments), @@ -142,7 +142,7 @@ export class VerificationKey { */ static makeFake(): VerificationKey { return new VerificationKey( - CircuitType.TURBO, + ComposerType.TURBO, 2048, 116, { diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 0365f75cc24d..37ed49c35b19 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -15,7 +15,7 @@ import { CombinedAccumulatedData, CombinedConstantData, CombinedHistoricTreeRoots, - CircuitType, + ComposerType, ConstantBaseRollupData, ContractDeploymentData, ContractStorageRead, @@ -382,7 +382,7 @@ export function makeMembershipWitness(size: N, start: number): */ export function makeVerificationKey(): VerificationKey { return new VerificationKey( - CircuitType.STANDARD, + ComposerType.STANDARD, 101, // arbitrary 102, // arbitrary {