From 92e26c93043965741b71e382da6a9b8cde1ec766 Mon Sep 17 00:00:00 2001 From: iAmMichaelConnor Date: Mon, 3 Apr 2023 11:54:58 +0000 Subject: [PATCH 1/9] align hashing of c_bind and private kernel circuit --- cpp/barretenberg | 2 +- cpp/src/aztec3/circuits/abis/c_bind.cpp | 37 +++++++----- cpp/src/aztec3/circuits/hash.hpp | 50 ++++++++++++++++ .../private/native_private_kernel_circuit.cpp | 57 ++++++++++++------- 4 files changed, 109 insertions(+), 37 deletions(-) create mode 100644 cpp/src/aztec3/circuits/hash.hpp diff --git a/cpp/barretenberg b/cpp/barretenberg index 9a56aa33..b465581a 160000 --- a/cpp/barretenberg +++ b/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 9a56aa3370306d5f9b7e9b6324220f8c713674ef +Subproject commit b465581ae5c762d277fb2c99c601405e0215d265 diff --git a/cpp/src/aztec3/circuits/abis/c_bind.cpp b/cpp/src/aztec3/circuits/abis/c_bind.cpp index 1a462456..82555fe7 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -15,6 +15,7 @@ #include "private_kernel/private_inputs.hpp" #include "private_kernel/public_inputs.hpp" +#include #include #include @@ -25,6 +26,8 @@ namespace { +using aztec3::circuits::compute_constructor_hash; +using aztec3::circuits::compute_contract_address; using aztec3::circuits::abis::FunctionData; using aztec3::circuits::abis::FunctionLeafPreimage; using aztec3::circuits::abis::TxContext; @@ -296,16 +299,17 @@ WASM_EXPORT void abis__hash_constructor(uint8_t const* function_data_buf, read(args_buf, args); read(constructor_vk_hash_buf, constructor_vk_hash); - NT::fr function_data_hash = function_data.hash(); - NT::fr args_hash = NT::compress(args, aztec3::CONSTRUCTOR_ARGS); + NT::fr constructor_hash = compute_constructor_hash(function_data, args, constructor_vk_hash); + // NT::fr function_data_hash = function_data.hash(); + // NT::fr args_hash = NT::compress(args, aztec3::CONSTRUCTOR_ARGS); - std::vector inputs = { - function_data_hash, - args_hash, - constructor_vk_hash, - }; + // std::vector inputs = { + // function_data_hash, + // args_hash, + // constructor_vk_hash, + // }; - NT::fr constructor_hash = NT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR); + // NT::fr constructor_hash = NT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR); NT::fr::serialize_to_buffer(constructor_hash, output); } @@ -341,14 +345,17 @@ WASM_EXPORT void abis__compute_contract_address(uint8_t const* deployer_address_ read(function_tree_root_buf, function_tree_root); read(constructor_hash_buf, constructor_hash); - std::vector inputs = { - deployer_address, - contract_address_salt, - function_tree_root, - constructor_hash, - }; + NT::address contract_address = + compute_contract_address(deployer_address, contract_address_salt, function_tree_root, constructor_hash); - NT::address contract_address = NT::fr(NT::compress(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS)); + // std::vector inputs = { + // deployer_address, + // contract_address_salt, + // function_tree_root, + // constructor_hash, + // }; + + // NT::address contract_address = NT::fr(NT::compress(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS)); NT::fr::serialize_to_buffer(contract_address, output); } diff --git a/cpp/src/aztec3/circuits/hash.hpp b/cpp/src/aztec3/circuits/hash.hpp new file mode 100644 index 00000000..3159213d --- /dev/null +++ b/cpp/src/aztec3/circuits/hash.hpp @@ -0,0 +1,50 @@ +#include +#include + +namespace aztec3::circuits { + +using abis::FunctionData; + +template typename NCT::fr compute_args_hash(std::array args) +{ + return NCT::compress(args, CONSTRUCTOR_ARGS); +} + +template +typename NCT::fr compute_constructor_hash(FunctionData function_data, + std::array args, + typename NCT::fr constructor_vk_hash) +{ + using fr = typename NCT::fr; + + fr function_data_hash = function_data.hash(); + fr args_hash = compute_args_hash(args); + + std::vector inputs = { + function_data_hash, + args_hash, + constructor_vk_hash, + }; + + return NCT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR); +} + +template +typename NCT::address compute_contract_address(typename NCT::address deployer_address, + typename NCT::fr contract_address_salt, + typename NCT::fr function_tree_root, + typename NCT::fr constructor_hash) +{ + using fr = typename NCT::fr; + using address = typename NCT::address; + + std::vector inputs = { + deployer_address.to_field(), + contract_address_salt, + function_tree_root, + constructor_hash, + }; + + return address(NCT::compress(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS)); +} +} // namespace aztec3::circuits \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp b/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp index 32801811..26f16d99 100644 --- a/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp +++ b/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp @@ -1,3 +1,4 @@ +#include "aztec3/constants.hpp" #include "init.hpp" #include @@ -5,6 +6,7 @@ #include #include +#include namespace aztec3::circuits::kernel::private_kernel { @@ -18,6 +20,9 @@ using aztec3::utils::array_push; using aztec3::utils::is_array_empty; using aztec3::utils::push_array_to_array; +using aztec3::circuits::compute_constructor_hash; +using aztec3::circuits::compute_contract_address; + // // 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, @@ -88,27 +93,35 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs ASSERT(storage_contract_address != 0); } - auto private_call_vk_hash = - stdlib::recursion::verification_key::compress_native(private_inputs.private_call.vk); - auto constructor_hash = - NT::compress({ private_inputs.signed_tx_request.tx_request.function_data.hash(), - NT::compress(private_call_public_inputs.args, CONSTRUCTOR_ARGS), - private_call_vk_hash }, - CONSTRUCTOR); + auto private_call_vk_hash = stdlib::recursion::verification_key::compress_native( + private_inputs.private_call.vk, GeneratorIndex::VK); + // auto constructor_hash = + // NT::compress({ private_inputs.signed_tx_request.tx_request.function_data.hash(), + // NT::compress(private_call_public_inputs.args, CONSTRUCTOR_ARGS), + // private_call_vk_hash }, + // CONSTRUCTOR); + + auto constructor_hash = compute_constructor_hash(private_inputs.signed_tx_request.tx_request.function_data, + private_call_public_inputs.args, + private_call_vk_hash); if (is_contract_deployment) { ASSERT(contract_deployment_data.constructor_vk_hash == private_call_vk_hash); } // compute the contract address - auto contract_address = NT::compress({ deployer_address.to_field(), - contract_deployment_data.contract_address_salt, - contract_deployment_data.function_tree_root, - constructor_hash }, - CONTRACT_ADDRESS); + // auto contract_address = NT::compress({ deployer_address.to_field(), + // contract_deployment_data.contract_address_salt, + // contract_deployment_data.function_tree_root, + // constructor_hash }, + // CONTRACT_ADDRESS); + auto contract_address = compute_contract_address(deployer_address, + contract_deployment_data.contract_address_salt, + contract_deployment_data.function_tree_root, + constructor_hash); // compute contract address nullifier - auto blake_input = contract_address.to_buffer(); + auto blake_input = contract_address.to_field().to_buffer(); auto contract_address_nullifier = NT::fr::serialize_from_buffer(NT::blake3s(blake_input).data()); // push the contract address nullifier to nullifier vector @@ -136,18 +149,20 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs { // commitments & nullifiers std::array siloed_new_commitments; for (size_t i = 0; i < new_commitments.size(); ++i) { - siloed_new_commitments[i] = new_commitments[i] == 0 - ? 0 - : NT::compress({ storage_contract_address.to_field(), new_commitments[i] }, - GeneratorIndex::OUTER_COMMITMENT); + siloed_new_commitments[i] = + new_commitments[i] == 0 + ? 0 + : NT::compress({ storage_contract_address.to_field(), new_commitments[i] }, + GeneratorIndex::OUTER_COMMITMENT); // TODO: implement in aztec3/circuits/hash.hpp } std::array siloed_new_nullifiers; for (size_t i = 0; i < new_nullifiers.size(); ++i) { - siloed_new_nullifiers[i] = new_nullifiers[i] == 0 - ? 0 - : NT::compress({ storage_contract_address.to_field(), new_nullifiers[i] }, - GeneratorIndex::OUTER_NULLIFIER); + siloed_new_nullifiers[i] = + new_nullifiers[i] == 0 + ? 0 + : NT::compress({ storage_contract_address.to_field(), new_nullifiers[i] }, + GeneratorIndex::OUTER_NULLIFIER); // TODO: implement in aztec3/circuits/hash.hpp } push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); From f849fa772726012f24882b20a7f5df1bc7560270 Mon Sep 17 00:00:00 2001 From: iAmMichaelConnor Date: Mon, 3 Apr 2023 12:02:25 +0000 Subject: [PATCH 2/9] pass hash_index to hashing of vk within private kernel circuit --- cpp/barretenberg | 2 +- .../aztec3/circuits/kernel/private/private_kernel_circuit.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/barretenberg b/cpp/barretenberg index b465581a..89249dbe 160000 --- a/cpp/barretenberg +++ b/cpp/barretenberg @@ -1 +1 @@ -Subproject commit b465581ae5c762d277fb2c99c601405e0215d265 +Subproject commit 89249dbe2fd184cb2f4b7b8a7b673179e674fde1 diff --git a/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index ad018071..2160597f 100644 --- a/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -1,3 +1,4 @@ +#include "aztec3/constants.hpp" #include "init.hpp" #include @@ -112,7 +113,7 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs .must_imply(storage_contract_address != CT::fr(0), "storage_contract_address is zero for a private function"); - auto private_call_vk_hash = private_inputs.private_call.vk->compress(); + auto private_call_vk_hash = private_inputs.private_call.vk->compress(GeneratorIndex::VK); auto constructor_hash = CT::compress({ private_inputs.signed_tx_request.tx_request.function_data.hash(), CT::compress(private_call_public_inputs.args, CONSTRUCTOR_ARGS), From 266d157a3be5107802b87a2edaa1d3b075b47b60 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:16:31 +0000 Subject: [PATCH 3/9] fix `abis -> hash_vk` test. --- cpp/src/aztec3/circuits/abis/c_bind.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index a3f7c761..28489ccd 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -111,7 +111,7 @@ TEST(abi_tests, hash_vk) NT::VKData vk_data; vk_data.composer_type = engine.get_random_uint32(); vk_data.circuit_size = engine.get_random_uint32(); - vk_data.num_public_inputs = engine.get_random_uint32(); + vk_data.num_public_inputs = (1ULL << (engine.get_random_uint8() >> 3)); // must be a power of two vk_data.commitments["test1"] = g1::element::random_element(); vk_data.commitments["test2"] = g1::element::random_element(); vk_data.commitments["foo1"] = g1::element::random_element(); From ec6854895c0c2e984a0ebbd6b778e49baf6f1938 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:21:23 +0000 Subject: [PATCH 4/9] update bb. --- cpp/barretenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/barretenberg b/cpp/barretenberg index 89249dbe..5b2dca0d 160000 --- a/cpp/barretenberg +++ b/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 89249dbe2fd184cb2f4b7b8a7b673179e674fde1 +Subproject commit 5b2dca0d11dea6e947eeea22d3689a905426eea3 From 05efa81afc7d30c8cb4e3eb040ab19ef5de14c06 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:28:09 +0000 Subject: [PATCH 5/9] Fix. --- cpp/src/aztec3/circuits/abis/c_bind.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index 28489ccd..f779e417 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -111,7 +111,7 @@ TEST(abi_tests, hash_vk) NT::VKData vk_data; vk_data.composer_type = engine.get_random_uint32(); vk_data.circuit_size = engine.get_random_uint32(); - vk_data.num_public_inputs = (1ULL << (engine.get_random_uint8() >> 3)); // must be a power of two + vk_data.num_public_inputs = (uint32_t(1) << (engine.get_random_uint8() >> 4)); // must be a power of two vk_data.commitments["test1"] = g1::element::random_element(); vk_data.commitments["test2"] = g1::element::random_element(); vk_data.commitments["foo1"] = g1::element::random_element(); From 57ca4740390a5719de373adfa55624cf46631998 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:34:20 +0000 Subject: [PATCH 6/9] Fix. --- cpp/src/aztec3/circuits/abis/c_bind.test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index f779e417..7b87aee2 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -110,8 +110,8 @@ 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_size = engine.get_random_uint32(); - vk_data.num_public_inputs = (uint32_t(1) << (engine.get_random_uint8() >> 4)); // must be a power of two + vk_data.circuit_size = 65536; // must be a power of two + vk_data.num_public_inputs = engine.get_random_uint32(); vk_data.commitments["test1"] = g1::element::random_element(); vk_data.commitments["test2"] = g1::element::random_element(); vk_data.commitments["foo1"] = g1::element::random_element(); From 7db7b584da6aeafe86f2e7ca6655fc5be47d1f11 Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:44:41 +0000 Subject: [PATCH 7/9] update bb. --- cpp/barretenberg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/barretenberg b/cpp/barretenberg index 5b2dca0d..6c101be1 160000 --- a/cpp/barretenberg +++ b/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 5b2dca0d11dea6e947eeea22d3689a905426eea3 +Subproject commit 6c101be134bbea01deed88a5085ebd35e6f62796 From bd7658cc1659d37daff22dc42aab27d322caef4c Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 01:53:01 +0000 Subject: [PATCH 8/9] Fix contract dep tests. --- cpp/src/aztec3/circuits/kernel/private/.test.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/src/aztec3/circuits/kernel/private/.test.cpp b/cpp/src/aztec3/circuits/kernel/private/.test.cpp index 90da6cde..27c2980c 100644 --- a/cpp/src/aztec3/circuits/kernel/private/.test.cpp +++ b/cpp/src/aztec3/circuits/kernel/private/.test.cpp @@ -530,7 +530,8 @@ TEST(private_kernel_tests, test_basic_contract_deployment) // Now we can derive the vk: std::shared_ptr constructor_vk = dummy_constructor_composer.compute_verification_key(); - auto constructor_vk_hash = stdlib::recursion::verification_key::compress_native(constructor_vk); + auto constructor_vk_hash = + stdlib::recursion::verification_key::compress_native(constructor_vk, GeneratorIndex::VK); // Now, we can proceed with the proper (non-dummy) invokation of our constructor circuit: @@ -768,7 +769,8 @@ TEST(private_kernel_tests, test_native_basic_contract_deployment) // Now we can derive the vk: std::shared_ptr constructor_vk = dummy_constructor_composer.compute_verification_key(); - auto constructor_vk_hash = stdlib::recursion::verification_key::compress_native(constructor_vk); + auto constructor_vk_hash = + stdlib::recursion::verification_key::compress_native(constructor_vk, GeneratorIndex::VK); // Now, we can proceed with the proper (non-dummy) invokation of our constructor circuit: From 161953b6350efbdd0c2f9f6a98bf7321cdaaee5a Mon Sep 17 00:00:00 2001 From: Suyash Bagad Date: Tue, 4 Apr 2023 02:23:36 +0000 Subject: [PATCH 9/9] Cleanup. --- cpp/src/aztec3/circuits/abis/c_bind.cpp | 17 ------- cpp/src/aztec3/circuits/abis/c_bind.test.cpp | 2 +- cpp/src/aztec3/circuits/hash.hpp | 27 ++++++++++++ .../private/native_private_kernel_circuit.cpp | 17 +------ .../kernel/private/private_kernel_circuit.cpp | 44 ++++++++++--------- 5 files changed, 53 insertions(+), 54 deletions(-) diff --git a/cpp/src/aztec3/circuits/abis/c_bind.cpp b/cpp/src/aztec3/circuits/abis/c_bind.cpp index 82555fe7..7ddea1cc 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -300,16 +300,7 @@ WASM_EXPORT void abis__hash_constructor(uint8_t const* function_data_buf, read(constructor_vk_hash_buf, constructor_vk_hash); NT::fr constructor_hash = compute_constructor_hash(function_data, args, constructor_vk_hash); - // NT::fr function_data_hash = function_data.hash(); - // NT::fr args_hash = NT::compress(args, aztec3::CONSTRUCTOR_ARGS); - // std::vector inputs = { - // function_data_hash, - // args_hash, - // constructor_vk_hash, - // }; - - // NT::fr constructor_hash = NT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR); NT::fr::serialize_to_buffer(constructor_hash, output); } @@ -348,14 +339,6 @@ WASM_EXPORT void abis__compute_contract_address(uint8_t const* deployer_address_ NT::address contract_address = compute_contract_address(deployer_address, contract_address_salt, function_tree_root, constructor_hash); - // std::vector inputs = { - // deployer_address, - // contract_address_salt, - // function_tree_root, - // constructor_hash, - // }; - - // NT::address contract_address = NT::fr(NT::compress(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS)); NT::fr::serialize_to_buffer(contract_address, output); } diff --git a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp index 7b87aee2..364c92ba 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.test.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.test.cpp @@ -110,7 +110,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_size = 65536; // must be a power of two + vk_data.circuit_size = uint32_t(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(); vk_data.commitments["test2"] = g1::element::random_element(); diff --git a/cpp/src/aztec3/circuits/hash.hpp b/cpp/src/aztec3/circuits/hash.hpp index 3159213d..25361f13 100644 --- a/cpp/src/aztec3/circuits/hash.hpp +++ b/cpp/src/aztec3/circuits/hash.hpp @@ -47,4 +47,31 @@ typename NCT::address compute_contract_address(typename NCT::address deployer_ad return address(NCT::compress(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS)); } + +template +typename NCT::fr add_contract_address_to_commitment(typename NCT::address contract_address, typename NCT::fr commitment) +{ + using fr = typename NCT::fr; + + std::vector inputs = { + contract_address.to_field(), + commitment, + }; + + return NCT::compress(inputs, aztec3::GeneratorIndex::OUTER_COMMITMENT); +} + +template +typename NCT::fr add_contract_address_to_nullifier(typename NCT::address contract_address, typename NCT::fr nullifier) +{ + using fr = typename NCT::fr; + + std::vector inputs = { + contract_address.to_field(), + nullifier, + }; + + return NCT::compress(inputs, aztec3::GeneratorIndex::OUTER_NULLIFIER); +} + } // namespace aztec3::circuits \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp b/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp index 26f16d99..5ea41dd4 100644 --- a/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp +++ b/cpp/src/aztec3/circuits/kernel/private/native_private_kernel_circuit.cpp @@ -95,11 +95,6 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs auto private_call_vk_hash = stdlib::recursion::verification_key::compress_native( private_inputs.private_call.vk, GeneratorIndex::VK); - // auto constructor_hash = - // NT::compress({ private_inputs.signed_tx_request.tx_request.function_data.hash(), - // NT::compress(private_call_public_inputs.args, CONSTRUCTOR_ARGS), - // private_call_vk_hash }, - // CONSTRUCTOR); auto constructor_hash = compute_constructor_hash(private_inputs.signed_tx_request.tx_request.function_data, private_call_public_inputs.args, @@ -109,12 +104,6 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs ASSERT(contract_deployment_data.constructor_vk_hash == private_call_vk_hash); } - // compute the contract address - // auto contract_address = NT::compress({ deployer_address.to_field(), - // contract_deployment_data.contract_address_salt, - // contract_deployment_data.function_tree_root, - // constructor_hash }, - // CONTRACT_ADDRESS); auto contract_address = compute_contract_address(deployer_address, contract_deployment_data.contract_address_salt, contract_deployment_data.function_tree_root, @@ -152,8 +141,7 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs siloed_new_commitments[i] = new_commitments[i] == 0 ? 0 - : NT::compress({ storage_contract_address.to_field(), new_commitments[i] }, - GeneratorIndex::OUTER_COMMITMENT); // TODO: implement in aztec3/circuits/hash.hpp + : add_contract_address_to_commitment(storage_contract_address, new_commitments[i]); } std::array siloed_new_nullifiers; @@ -161,8 +149,7 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs siloed_new_nullifiers[i] = new_nullifiers[i] == 0 ? 0 - : NT::compress({ storage_contract_address.to_field(), new_nullifiers[i] }, - GeneratorIndex::OUTER_NULLIFIER); // TODO: implement in aztec3/circuits/hash.hpp + : add_contract_address_to_nullifier(storage_contract_address, new_nullifiers[i]); } push_array_to_array(siloed_new_commitments, public_inputs.end.new_commitments); diff --git a/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp b/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp index 2160597f..3d851736 100644 --- a/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp +++ b/cpp/src/aztec3/circuits/kernel/private/private_kernel_circuit.cpp @@ -7,6 +7,8 @@ #include #include +#include + namespace aztec3::circuits::kernel::private_kernel { using aztec3::circuits::abis::private_kernel::NewContractData; @@ -19,6 +21,11 @@ using plonk::stdlib::array_push; using plonk::stdlib::is_array_empty; using plonk::stdlib::push_array_to_array; +using aztec3::circuits::add_contract_address_to_commitment; +using aztec3::circuits::add_contract_address_to_nullifier; +using aztec3::circuits::compute_constructor_hash; +using aztec3::circuits::compute_contract_address; + // 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, @@ -114,24 +121,21 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs "storage_contract_address is zero for a private function"); auto private_call_vk_hash = private_inputs.private_call.vk->compress(GeneratorIndex::VK); - auto constructor_hash = - CT::compress({ private_inputs.signed_tx_request.tx_request.function_data.hash(), - CT::compress(private_call_public_inputs.args, CONSTRUCTOR_ARGS), - private_call_vk_hash }, - CONSTRUCTOR); + auto constructor_hash = compute_constructor_hash(private_inputs.signed_tx_request.tx_request.function_data, + private_call_public_inputs.args, + private_call_vk_hash); is_contract_deployment.must_imply(contract_deployment_data.constructor_vk_hash == private_call_vk_hash, "constructor_vk_hash does not match private call vk hash"); // compute the contract address - auto contract_address = CT::compress({ deployer_address.to_field(), - contract_deployment_data.contract_address_salt, - contract_deployment_data.function_tree_root, - constructor_hash }, - CONTRACT_ADDRESS); + auto contract_address = compute_contract_address(deployer_address, + contract_deployment_data.contract_address_salt, + contract_deployment_data.function_tree_root, + constructor_hash); // compute contract address nullifier - auto blake_input = CT::byte_array(contract_address); + auto blake_input = CT::byte_array(contract_address.to_field()); auto contract_address_nullifier = CT::fr(CT::blake3s(blake_input)); // push the contract address nullifier to nullifier vector @@ -153,19 +157,17 @@ void update_end_values(PrivateInputs const& private_inputs, PublicInputs { // commitments, nullifiers, and contracts std::array siloed_new_commitments; for (size_t i = 0; i < new_commitments.size(); ++i) { - siloed_new_commitments[i] = - CT::fr::conditional_assign(new_commitments[i] == 0, - 0, - CT::compress({ storage_contract_address.to_field(), new_commitments[i] }, - GeneratorIndex::OUTER_COMMITMENT)); + siloed_new_commitments[i] = CT::fr::conditional_assign( + new_commitments[i] == 0, + 0, + add_contract_address_to_commitment(storage_contract_address, new_commitments[i])); } std::array siloed_new_nullifiers; for (size_t i = 0; i < new_nullifiers.size(); ++i) { - siloed_new_nullifiers[i] = - CT::fr::conditional_assign(new_nullifiers[i] == 0, - 0, - CT::compress({ storage_contract_address.to_field(), new_nullifiers[i] }, - GeneratorIndex::OUTER_NULLIFIER)); + siloed_new_nullifiers[i] = CT::fr::conditional_assign( + new_nullifiers[i] == 0, + 0, + add_contract_address_to_nullifier(storage_contract_address, new_nullifiers[i])); } // Add new commitments/etc to AggregatedData