diff --git a/circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp b/circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp index 43ab18e1d93..f1d70cbce0f 100644 --- a/circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp +++ b/circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp @@ -54,6 +54,20 @@ template struct HistoricBlockData { global_variables_hash == other.global_variables_hash; }; + template void assert_is_zero() + { + static_assert((std::is_same, NCT>::value)); + + private_data_tree_root.assert_is_zero(); + nullifier_tree_root.assert_is_zero(); + contract_tree_root.assert_is_zero(); + l1_to_l2_messages_tree_root.assert_is_zero(); + blocks_tree_root.assert_is_zero(); + private_kernel_vk_tree_root.assert_is_zero(); + public_data_tree_root.assert_is_zero(); + global_variables_hash.assert_is_zero(); + } + template HistoricBlockData> to_circuit_type(Builder& builder) const { static_assert((std::is_same::value)); 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 64a7c4db195..7e7bff8cdd0 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 @@ -3,6 +3,7 @@ #include "call_context.hpp" #include "contract_deployment_data.hpp" +#include "aztec3/circuits/abis/historic_block_data.hpp" #include "aztec3/constants.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" @@ -45,13 +46,7 @@ template class PrivateCircuitPublicInputs { fr encrypted_log_preimages_length = 0; fr unencrypted_log_preimages_length = 0; - fr historic_private_data_tree_root = 0; - fr historic_nullifier_tree_root = 0; - fr historic_contract_tree_root = 0; - fr historic_l1_to_l2_messages_tree_root = 0; - fr historic_blocks_tree_root = 0; - fr historic_public_data_tree_root = 0; - fr historic_global_variables_hash = 0; + HistoricBlockData historic_block_data{}; ContractDeploymentData contract_deployment_data{}; @@ -73,13 +68,7 @@ template class PrivateCircuitPublicInputs { unencrypted_logs_hash, encrypted_log_preimages_length, unencrypted_log_preimages_length, - historic_private_data_tree_root, - historic_nullifier_tree_root, - historic_contract_tree_root, - historic_l1_to_l2_messages_tree_root, - historic_blocks_tree_root, - historic_public_data_tree_root, - historic_global_variables_hash, + historic_block_data, contract_deployment_data, chain_id, version); @@ -95,13 +84,7 @@ template class PrivateCircuitPublicInputs { unencrypted_logs_hash == other.unencrypted_logs_hash && encrypted_log_preimages_length == other.encrypted_log_preimages_length && unencrypted_log_preimages_length == other.unencrypted_log_preimages_length && - historic_private_data_tree_root == other.historic_private_data_tree_root && - historic_nullifier_tree_root == other.historic_nullifier_tree_root && - historic_contract_tree_root == other.historic_contract_tree_root && - historic_l1_to_l2_messages_tree_root == other.historic_l1_to_l2_messages_tree_root && - historic_blocks_tree_root == other.historic_blocks_tree_root && - historic_public_data_tree_root == other.historic_public_data_tree_root && - historic_global_variables_hash == other.historic_global_variables_hash && + historic_block_data == other.historic_block_data && contract_deployment_data == other.contract_deployment_data && chain_id == other.chain_id && version == other.version; }; @@ -137,13 +120,7 @@ template class PrivateCircuitPublicInputs { to_ct(encrypted_log_preimages_length), to_ct(unencrypted_log_preimages_length), - to_ct(historic_private_data_tree_root), - to_ct(historic_nullifier_tree_root), - to_ct(historic_contract_tree_root), - to_ct(historic_l1_to_l2_messages_tree_root), - to_ct(historic_blocks_tree_root), - to_ct(historic_public_data_tree_root), - to_ct(historic_global_variables_hash), + to_circuit_type(historic_block_data), to_circuit_type(contract_deployment_data), @@ -182,13 +159,7 @@ template class PrivateCircuitPublicInputs { to_nt(encrypted_log_preimages_length), to_nt(unencrypted_log_preimages_length), - to_nt(historic_private_data_tree_root), - to_nt(historic_nullifier_tree_root), - to_nt(historic_contract_tree_root), - to_nt(historic_l1_to_l2_messages_tree_root), - to_nt(historic_blocks_tree_root), - to_nt(historic_public_data_tree_root), - to_nt(historic_global_variables_hash), + to_native_type(historic_block_data), to_native_type(contract_deployment_data), @@ -226,13 +197,7 @@ template class PrivateCircuitPublicInputs { inputs.push_back(encrypted_log_preimages_length); inputs.push_back(unencrypted_log_preimages_length); - inputs.push_back(historic_private_data_tree_root); - inputs.push_back(historic_nullifier_tree_root); - inputs.push_back(historic_contract_tree_root); - inputs.push_back(historic_l1_to_l2_messages_tree_root); - inputs.push_back(historic_blocks_tree_root); - inputs.push_back(historic_public_data_tree_root); - inputs.push_back(historic_global_variables_hash); + spread_arr_into_vec(historic_block_data.to_array(), inputs); inputs.push_back(contract_deployment_data.hash()); @@ -282,13 +247,7 @@ template class OptionalPrivateCircuitPublicInputs { opt_fr encrypted_log_preimages_length; opt_fr unencrypted_log_preimages_length; - opt_fr historic_private_data_tree_root; - opt_fr historic_nullifier_tree_root; - opt_fr historic_contract_tree_root; - opt_fr historic_l1_to_l2_messages_tree_root; - opt_fr historic_blocks_tree_root; - opt_fr historic_public_data_tree_root; - opt_fr historic_global_variables_hash; + std::optional> historic_block_data; std::optional> contract_deployment_data; @@ -310,13 +269,7 @@ template class OptionalPrivateCircuitPublicInputs { unencrypted_logs_hash, encrypted_log_preimages_length, unencrypted_log_preimages_length, - historic_private_data_tree_root, - historic_nullifier_tree_root, - historic_contract_tree_root, - historic_l1_to_l2_messages_tree_root, - historic_blocks_tree_root, - historic_public_data_tree_root, - historic_global_variables_hash, + historic_block_data, contract_deployment_data, chain_id, version); @@ -345,13 +298,7 @@ template class OptionalPrivateCircuitPublicInputs { opt_fr const& encrypted_log_preimages_length, opt_fr const& unencrypted_log_preimages_length, - opt_fr const& historic_private_data_tree_root, - opt_fr const& historic_nullifier_tree_root, - opt_fr const& historic_contract_tree_root, - opt_fr const& historic_l1_to_l2_messages_tree_root, - opt_fr const& historic_blocks_tree_root, - opt_fr const& historic_public_data_tree_root, - opt_fr const& historic_global_variables_hash, + std::optional> const& historic_block_data, std::optional> const& contract_deployment_data, @@ -371,13 +318,7 @@ template class OptionalPrivateCircuitPublicInputs { , unencrypted_logs_hash(unencrypted_logs_hash) , encrypted_log_preimages_length(encrypted_log_preimages_length) , unencrypted_log_preimages_length(unencrypted_log_preimages_length) - , historic_private_data_tree_root(historic_private_data_tree_root) - , historic_nullifier_tree_root(historic_nullifier_tree_root) - , historic_contract_tree_root(historic_contract_tree_root) - , historic_l1_to_l2_messages_tree_root(historic_l1_to_l2_messages_tree_root) - , historic_blocks_tree_root(historic_blocks_tree_root) - , historic_public_data_tree_root(historic_public_data_tree_root) - , historic_global_variables_hash(historic_global_variables_hash) + , historic_block_data(historic_block_data) , contract_deployment_data(contract_deployment_data) , chain_id(chain_id) , version(version){}; @@ -409,13 +350,7 @@ template class OptionalPrivateCircuitPublicInputs { new_inputs.encrypted_log_preimages_length = std::nullopt; new_inputs.unencrypted_log_preimages_length = std::nullopt; - new_inputs.historic_private_data_tree_root = std::nullopt; - new_inputs.historic_nullifier_tree_root = std::nullopt; - new_inputs.historic_contract_tree_root = std::nullopt; - new_inputs.historic_l1_to_l2_messages_tree_root = std::nullopt; - new_inputs.historic_blocks_tree_root = std::nullopt; - new_inputs.historic_public_data_tree_root = std::nullopt; - new_inputs.historic_global_variables_hash = std::nullopt; + new_inputs.historic_block_data = std::nullopt; new_inputs.contract_deployment_data = std::nullopt; @@ -480,13 +415,7 @@ template class OptionalPrivateCircuitPublicInputs { make_unused_element_zero(builder, encrypted_log_preimages_length); make_unused_element_zero(builder, 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(builder, historic_blocks_tree_root); - make_unused_element_zero(builder, historic_public_data_tree_root); - make_unused_element_zero(builder, historic_global_variables_hash); + make_unused_element_zero(builder, historic_block_data); make_unused_element_zero(builder, contract_deployment_data); @@ -525,13 +454,7 @@ template class OptionalPrivateCircuitPublicInputs { (*encrypted_log_preimages_length).set_public(); (*unencrypted_log_preimages_length).set_public(); - (*historic_private_data_tree_root).set_public(); - (*historic_nullifier_tree_root).set_public(); - (*historic_contract_tree_root).set_public(); - (*historic_l1_to_l2_messages_tree_root).set_public(); - (*historic_blocks_tree_root).set_public(); - (*historic_public_data_tree_root).set_public(); - (*historic_global_variables_hash).set_public(); + (*historic_block_data).set_public(); (*contract_deployment_data).set_public(); @@ -572,13 +495,7 @@ template class OptionalPrivateCircuitPublicInputs { to_ct(encrypted_log_preimages_length), to_ct(unencrypted_log_preimages_length), - to_ct(historic_private_data_tree_root), - to_ct(historic_nullifier_tree_root), - to_ct(historic_contract_tree_root), - to_ct(historic_l1_to_l2_messages_tree_root), - to_ct(historic_blocks_tree_root), - to_ct(historic_public_data_tree_root), - to_ct(historic_global_variables_hash), + to_circuit_type(historic_block_data), to_circuit_type(contract_deployment_data), @@ -619,13 +536,7 @@ template class OptionalPrivateCircuitPublicInputs { to_nt(encrypted_log_preimages_length), to_nt(unencrypted_log_preimages_length), - to_nt(historic_private_data_tree_root), - to_nt(historic_nullifier_tree_root), - to_nt(historic_contract_tree_root), - to_nt(historic_l1_to_l2_messages_tree_root), - to_nt(historic_blocks_tree_root), - to_nt(historic_public_data_tree_root), - to_nt(historic_global_variables_hash), + to_native_type(historic_block_data), to_native_type(contract_deployment_data), @@ -667,13 +578,7 @@ template class OptionalPrivateCircuitPublicInputs { inputs.push_back(*encrypted_log_preimages_length); inputs.push_back(*unencrypted_log_preimages_length); - inputs.push_back(*historic_private_data_tree_root); - inputs.push_back(*historic_nullifier_tree_root); - inputs.push_back(*historic_contract_tree_root); - inputs.push_back(*historic_l1_to_l2_messages_tree_root); - inputs.push_back(*historic_blocks_tree_root); - inputs.push_back(*historic_public_data_tree_root); - inputs.push_back(*historic_global_variables_hash); + spread_arr_opt_into_vec((*historic_block_data).to_array(), inputs); inputs.push_back((*contract_deployment_data).hash()); @@ -710,13 +615,7 @@ template class OptionalPrivateCircuitPublicInputs { .encrypted_log_preimages_length = encrypted_log_preimages_length.value(), .unencrypted_log_preimages_length = unencrypted_log_preimages_length.value(), - .historic_private_data_tree_root = historic_private_data_tree_root.value(), - .historic_nullifier_tree_root = historic_nullifier_tree_root.value(), - .historic_contract_tree_root = historic_contract_tree_root.value(), - .historic_l1_to_l2_messages_tree_root = historic_l1_to_l2_messages_tree_root.value(), - .historic_blocks_tree_root = historic_blocks_tree_root.value(), - .historic_public_data_tree_root = historic_public_data_tree_root.value(), - .historic_global_variables_hash = historic_global_variables_hash.value(), + .historic_block_data = historic_block_data.value(), .contract_deployment_data = contract_deployment_data.value(), diff --git a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp index 5e600138f2a..21dd8a8eee6 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp @@ -414,7 +414,7 @@ void common_contract_logic(DummyBuilder& builder, private_call.contract_leaf_membership_witness.sibling_path); auto const& purported_contract_tree_root = - private_call.call_stack_item.public_inputs.historic_contract_tree_root; + private_call.call_stack_item.public_inputs.historic_block_data.contract_tree_root; builder.do_assert( computed_contract_tree_root == purported_contract_tree_root, 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 6ba74f63032..a406869f3ad 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 @@ -12,7 +12,6 @@ namespace { using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::CombinedConstantData; -using aztec3::circuits::abis::HistoricBlockData; using aztec3::circuits::abis::KernelCircuitPublicInputs; using aztec3::circuits::abis::private_kernel::PrivateKernelInputsInit; using aztec3::utils::array_push; @@ -27,19 +26,11 @@ void initialise_end_values(PrivateKernelInputsInit const& private_inputs, // Define the constants data. auto const& private_call_public_inputs = private_inputs.private_call.call_stack_item.public_inputs; auto const constants = CombinedConstantData{ - .block_data = - HistoricBlockData{ - // TODO(dbanks12): remove historic root from app circuit public inputs and - // add it to PrivateCallData: https://github.com/AztecProtocol/aztec-packages/issues/778 - // Then use this: - // .private_data_tree_root = private_inputs.private_call.historic_private_data_tree_root, - .private_data_tree_root = private_call_public_inputs.historic_private_data_tree_root, - .nullifier_tree_root = private_call_public_inputs.historic_nullifier_tree_root, - .contract_tree_root = private_call_public_inputs.historic_contract_tree_root, - .l1_to_l2_messages_tree_root = private_call_public_inputs.historic_l1_to_l2_messages_tree_root, - .public_data_tree_root = private_call_public_inputs.historic_public_data_tree_root, - .global_variables_hash = private_call_public_inputs.historic_global_variables_hash, - }, + .block_data = private_call_public_inputs.historic_block_data, + // TODO(dbanks12): remove historic root from app circuit public inputs and + // add it to PrivateCallData: https://github.com/AztecProtocol/aztec-packages/issues/778 + // Then use this: + // .private_data_tree_root = private_inputs.private_call.historic_private_data_tree_root, .tx_context = private_inputs.tx_request.tx_context, }; 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 c861737da88..68d17b42531 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 @@ -314,7 +314,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_request) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak read_request so it gives wrong root when paired with its sibling path read_requests[1] += 1; @@ -348,7 +348,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_leaf_index) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak leaf index so it gives wrong root when paired with its request and sibling path read_request_membership_witnesses[1].leaf_index += 1; @@ -381,7 +381,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_bad_sibling_path) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak sibling path so it gives wrong root when paired with its request read_request_membership_witnesses[1].sibling_path[1] += 1; @@ -415,7 +415,7 @@ TEST_F(native_private_kernel_init_tests, native_read_request_root_mismatch) _transient_read_requests0, _transient_read_request_membership_witnesses0, root] = get_random_reads(first_nullifier, contract_address, 2); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; auto [read_requests1, read_request_membership_witnesses1, _transient_read_requests1, @@ -494,7 +494,7 @@ TEST_F(native_private_kernel_init_tests, native_one_read_requests_works) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 1); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -531,7 +531,7 @@ TEST_F(native_private_kernel_init_tests, native_two_read_requests_works) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -568,7 +568,7 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_works) _transient_read_requests, _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -609,7 +609,7 @@ TEST_F(native_private_kernel_init_tests, native_read_requests_less_than_witnesse root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); read_requests[MAX_READ_REQUESTS_PER_CALL - 1] = fr(0); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -638,7 +638,7 @@ TEST_F(native_private_kernel_init_tests, native_read_requests_more_than_witnesse read_request_membership_witnesses[MAX_READ_REQUESTS_PER_CALL - 1] = ReadRequestMembershipWitness{}; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -665,7 +665,7 @@ TEST_F(native_private_kernel_init_tests, native_one_transient_read_requests_work transient_read_requests, transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 1); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // Make the read request transient read_requests[0] = transient_read_requests[0]; @@ -703,7 +703,7 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_one_transient_ transient_read_requests, transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; private_inputs.private_call.call_stack_item.public_inputs.read_requests = read_requests; // Make the read request at position 1 transient @@ -741,7 +741,7 @@ TEST_F(native_private_kernel_init_tests, native_max_read_requests_all_transient_ transient_read_requests, transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; private_inputs.private_call.call_stack_item.public_inputs.read_requests = transient_read_requests; private_inputs.private_call.read_request_membership_witnesses = transient_read_request_membership_witnesses; 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 53bff19e0be..1ea1fbf859d 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 @@ -79,7 +79,7 @@ void pop_and_validate_this_private_call_hash( void validate_contract_tree_root(DummyCircuitBuilder& builder, PrivateKernelInputsInner const& private_inputs) { auto const& purported_contract_tree_root = - private_inputs.private_call.call_stack_item.public_inputs.historic_contract_tree_root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.contract_tree_root; auto const& previous_kernel_contract_tree_root = private_inputs.previous_kernel.public_inputs.constants.block_data.contract_tree_root; builder.do_assert( 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 94dcba72597..0599fdefd44 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 @@ -259,7 +259,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_request) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak read_request so it gives wrong root when paired with its sibling path read_requests[1] += 1; @@ -298,7 +298,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_leaf_index) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak leaf index so it gives wrong root when paired with its request and sibling path read_request_membership_witnesses[1].leaf_index += 1; @@ -336,7 +336,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_bad_sibling_path) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // tweak sibling path so it gives wrong root when paired with its request read_request_membership_witnesses[1].sibling_path[1] += 1; @@ -375,7 +375,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_request_root_mismatch) _transient_read_request_membership_witnesses0, root] = get_random_reads(first_nullifier, contract_address, 2); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; auto [read_requests1, read_request_membership_witnesses1, _transient_read_requests1, @@ -461,7 +461,7 @@ TEST_F(native_private_kernel_inner_tests, native_one_read_requests_works) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 1); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -502,7 +502,7 @@ TEST_F(native_private_kernel_inner_tests, native_two_read_requests_works) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 2); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -543,7 +543,7 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_works) _transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -585,7 +585,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_requests_less_than_witness read_requests[MAX_READ_REQUESTS_PER_CALL - 1] = fr(0); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -622,7 +622,7 @@ TEST_F(native_private_kernel_inner_tests, native_read_requests_more_than_witness ReadRequestMembershipWitness{}; private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; 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; @@ -656,7 +656,7 @@ TEST_F(native_private_kernel_inner_tests, native_one_transient_read_requests_wor transient_read_requests, transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, 1); - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // Make the read request transient read_requests[0] = transient_read_requests[0]; @@ -701,7 +701,7 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_one_transient transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; // Make the read request at position 1 transient read_requests[1] = transient_read_requests[1]; @@ -748,7 +748,7 @@ TEST_F(native_private_kernel_inner_tests, native_max_read_requests_all_transient transient_read_request_membership_witnesses, root] = get_random_reads(first_nullifier, contract_address, MAX_READ_REQUESTS_PER_CALL); private_inputs.previous_kernel.public_inputs.constants.block_data.private_data_tree_root = root; - private_inputs.private_call.call_stack_item.public_inputs.historic_private_data_tree_root = root; + private_inputs.private_call.call_stack_item.public_inputs.historic_block_data.private_data_tree_root = root; private_inputs.private_call.call_stack_item.public_inputs.read_requests = transient_read_requests; private_inputs.private_call.read_request_membership_witnesses = transient_read_request_membership_witnesses; 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 0088cdf7df5..da85d34bda0 100644 --- a/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp +++ b/circuits/cpp/src/aztec3/circuits/kernel/private/testing_harness.cpp @@ -276,7 +276,7 @@ std::pair, ContractDeploymentData> create_private_call_d OptionalPrivateCircuitPublicInputs const opt_private_circuit_public_inputs = func(ctx, args_vec); private_circuit_public_inputs = opt_private_circuit_public_inputs.remove_optionality(); // TODO(suyash): this should likely be handled as part of the DB/Oracle/Context infrastructure - private_circuit_public_inputs.historic_contract_tree_root = contract_tree_root; + private_circuit_public_inputs.historic_block_data.contract_tree_root = contract_tree_root; private_circuit_public_inputs.encrypted_logs_hash = encrypted_logs_hash; private_circuit_public_inputs.unencrypted_logs_hash = unencrypted_logs_hash; @@ -296,10 +296,7 @@ std::pair, ContractDeploymentData> create_private_call_d .unencrypted_logs_hash = unencrypted_logs_hash, .encrypted_log_preimages_length = encrypted_log_preimages_length, .unencrypted_log_preimages_length = unencrypted_log_preimages_length, - .historic_private_data_tree_root = 0, - .historic_nullifier_tree_root = 0, - .historic_contract_tree_root = contract_tree_root, - .historic_l1_to_l2_messages_tree_root = 0, + .historic_block_data = HistoricBlockData{ .contract_tree_root = contract_tree_root }, .contract_deployment_data = contract_deployment_data, }; } @@ -485,8 +482,8 @@ PrivateKernelInputsInner do_private_call_get_kernel_inputs_inner( mock_previous_kernel.public_inputs.constants = CombinedConstantData{ .block_data = HistoricBlockData{ - .private_data_tree_root = private_circuit_public_inputs.historic_private_data_tree_root, - .contract_tree_root = private_circuit_public_inputs.historic_contract_tree_root, + .private_data_tree_root = private_circuit_public_inputs.historic_block_data.private_data_tree_root, + .contract_tree_root = private_circuit_public_inputs.historic_block_data.contract_tree_root, }, .tx_context = tx_context, }; diff --git a/yarn-project/acir-simulator/src/acvm/deserialize.ts b/yarn-project/acir-simulator/src/acvm/deserialize.ts index 99d5498ff07..7f8c7f87f5c 100644 --- a/yarn-project/acir-simulator/src/acvm/deserialize.ts +++ b/yarn-project/acir-simulator/src/acvm/deserialize.ts @@ -148,13 +148,16 @@ export function extractPrivateCircuitPublicInputs( const encryptedLogPreimagesLength = witnessReader.readField(); const unencryptedLogPreimagesLength = witnessReader.readField(); - const privateDataTreeRoot = witnessReader.readField(); - const nullifierTreeRoot = witnessReader.readField(); - const contractTreeRoot = witnessReader.readField(); - const l1Tol2TreeRoot = witnessReader.readField(); - const blocksTreeRoot = witnessReader.readField(); - const prevGlobalVariablesHash = witnessReader.readField(); - const publicDataTreeRoot = witnessReader.readField(); + const historicBlockData = new HistoricBlockData( + witnessReader.readField(), + witnessReader.readField(), + witnessReader.readField(), + witnessReader.readField(), + witnessReader.readField(), + Fr.ZERO, + witnessReader.readField(), + witnessReader.readField(), + ); const contractDeploymentData = new ContractDeploymentData( new Point(witnessReader.readField(), witnessReader.readField()), @@ -182,13 +185,7 @@ export function extractPrivateCircuitPublicInputs( unencryptedLogsHash, encryptedLogPreimagesLength, unencryptedLogPreimagesLength, - privateDataTreeRoot, - nullifierTreeRoot, - contractTreeRoot, - l1Tol2TreeRoot, - blocksTreeRoot, - prevGlobalVariablesHash, - publicDataTreeRoot, + historicBlockData, contractDeploymentData, chainId, version, diff --git a/yarn-project/acir-simulator/src/acvm/serialize.ts b/yarn-project/acir-simulator/src/acvm/serialize.ts index 04b66efa167..f6186d33eba 100644 --- a/yarn-project/acir-simulator/src/acvm/serialize.ts +++ b/yarn-project/acir-simulator/src/acvm/serialize.ts @@ -2,6 +2,7 @@ import { CallContext, ContractDeploymentData, FunctionData, + HistoricBlockData, PrivateCallStackItem, PrivateCircuitPublicInputs, PublicCallRequest, @@ -60,6 +61,23 @@ export function toACVMContractDeploymentData(contractDeploymentData: ContractDep ]; } +/** + * Converts a historic block data into ACVM fields. + * @param historicBlockData - The historic block data object to convert. + * @returns The ACVM fields. + */ +export function toACVMHistoricBlockData(historicBlockData: HistoricBlockData): ACVMField[] { + return [ + toACVMField(historicBlockData.privateDataTreeRoot), + toACVMField(historicBlockData.nullifierTreeRoot), + toACVMField(historicBlockData.contractTreeRoot), + toACVMField(historicBlockData.l1ToL2MessagesTreeRoot), + toACVMField(historicBlockData.blocksTreeRoot), + toACVMField(historicBlockData.publicDataTreeRoot), + toACVMField(historicBlockData.globalVariablesHash), + ]; +} + /** * Converts the public inputs structure to ACVM fields. * @param publicInputs - The public inputs to convert. @@ -83,15 +101,11 @@ export function toACVMPublicInputs(publicInputs: PrivateCircuitPublicInputs): AC toACVMField(publicInputs.encryptedLogPreimagesLength), toACVMField(publicInputs.unencryptedLogPreimagesLength), - toACVMField(publicInputs.historicPrivateDataTreeRoot), - toACVMField(publicInputs.historicPrivateNullifierTreeRoot), - toACVMField(publicInputs.historicContractTreeRoot), - toACVMField(publicInputs.historicL1ToL2MessagesTreeRoot), - toACVMField(publicInputs.historicBlocksTreeRoot), - toACVMField(publicInputs.historicGlobalVariablesHash), - toACVMField(publicInputs.historicPublicDataTreeRoot), + + ...toACVMHistoricBlockData(publicInputs.historicBlockData), ...toACVMContractDeploymentData(publicInputs.contractDeploymentData), + toACVMField(publicInputs.chainId), toACVMField(publicInputs.version), ]; diff --git a/yarn-project/acir-simulator/src/client/private_execution.ts b/yarn-project/acir-simulator/src/client/private_execution.ts index bc6d0796bf4..fa9a4db3bae 100644 --- a/yarn-project/acir-simulator/src/client/private_execution.ts +++ b/yarn-project/acir-simulator/src/client/private_execution.ts @@ -232,13 +232,7 @@ export class PrivateFunctionExecution { this.callContext.isStaticCall, this.callContext.isContractDeployment, - blockData.privateDataTreeRoot, - blockData.nullifierTreeRoot, - blockData.contractTreeRoot, - blockData.l1ToL2MessagesTreeRoot, - blockData.blocksTreeRoot, - blockData.publicDataTreeRoot, - blockData.globalVariablesHash, + ...blockData.toArray(), contractDeploymentData.deployerPublicKey.x, contractDeploymentData.deployerPublicKey.y, diff --git a/yarn-project/acir-simulator/src/public/executor.ts b/yarn-project/acir-simulator/src/public/executor.ts index c9d58d810b2..97c1027daec 100644 --- a/yarn-project/acir-simulator/src/public/executor.ts +++ b/yarn-project/acir-simulator/src/public/executor.ts @@ -241,13 +241,7 @@ function getInitialWitness( callContext.isStaticCall, callContext.isContractDeployment, - historicBlockData.privateDataTreeRoot, - historicBlockData.nullifierTreeRoot, - historicBlockData.contractTreeRoot, - historicBlockData.l1ToL2MessagesTreeRoot, - historicBlockData.blocksTreeRoot, - historicBlockData.globalVariablesHash, - historicBlockData.publicDataTreeRoot, + ...historicBlockData.toArray(), globalVariables.chainId, globalVariables.version, diff --git a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts index b583c45f6c9..6d758889f0d 100644 --- a/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts +++ b/yarn-project/aztec-rpc/src/kernel_prover/kernel_prover.ts @@ -132,7 +132,8 @@ export class KernelProver { if (firstIteration) { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/778): remove historic root // from app circuit public inputs and add it to PrivateCallData - privateCallData.callStackItem.publicInputs.historicPrivateDataTreeRoot = await this.oracle.getPrivateDataRoot(); + privateCallData.callStackItem.publicInputs.historicBlockData.privateDataTreeRoot = + await this.oracle.getPrivateDataRoot(); output = await this.proofCreator.createProofInit(txRequest, privateCallData); } else { diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap index 88f16d51e30..00db924ad0e 100644 --- a/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap +++ b/yarn-project/circuits.js/src/structs/__snapshots__/private_circuit_public_inputs.test.ts.snap @@ -22,21 +22,23 @@ encrypted_logs_hash: [ 0x900 0x901 ] unencrypted_logs_hash: [ 0xa00 0xa01 ] encrypted_log_preimages_length: 0xb00 unencrypted_log_preimages_length: 0xc00 -historic_private_data_tree_root: 0xe00 -historic_nullifier_tree_root: 0xf00 -historic_contract_tree_root: 0xd00 -historic_l1_to_l2_messages_tree_root: 0x1000 -historic_blocks_tree_root: 0x1100 -historic_public_data_tree_root: 0x1200 -historic_global_variables_hash: 0x1300 +historic_block_data: private_data_tree_root: 0xd00 +nullifier_tree_root: 0xd01 +contract_tree_root: 0xd02 +l1_to_l2_messages_tree_root: 0xd03 +blocks_tree_root: 0xd04 +private_kernel_vk_tree_root: 0xd05 +public_data_tree_root: 0xd06 +global_variables_hash: 0xd07 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0xe00 +y: 0xe01 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0xe01 +function_tree_root: 0xe02 +contract_address_salt: 0xe03 +portal_contract_address: 0x404040404040404040404040404040404040404 chain_id: 0x1400 version: 0x1500 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 c5fcc831466..79f0a0f01f1 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 @@ -476,21 +476,23 @@ encrypted_logs_hash: [ 0x1911 0x1912 ] unencrypted_logs_hash: [ 0x1a11 0x1a12 ] encrypted_log_preimages_length: 0x1b11 unencrypted_log_preimages_length: 0x1c11 -historic_private_data_tree_root: 0x1e11 -historic_nullifier_tree_root: 0x1f11 -historic_contract_tree_root: 0x1d11 -historic_l1_to_l2_messages_tree_root: 0x2011 -historic_blocks_tree_root: 0x2111 -historic_public_data_tree_root: 0x2211 -historic_global_variables_hash: 0x2311 +historic_block_data: private_data_tree_root: 0x1d11 +nullifier_tree_root: 0x1d12 +contract_tree_root: 0x1d13 +l1_to_l2_messages_tree_root: 0x1d14 +blocks_tree_root: 0x1d15 +private_kernel_vk_tree_root: 0x1d16 +public_data_tree_root: 0x1d17 +global_variables_hash: 0x1d18 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e11 +y: 0x1e12 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e12 +function_tree_root: 0x1e13 +contract_address_salt: 0x1e14 +portal_contract_address: 0x1515151515151515151515151515151515151515 chain_id: 0x2411 version: 0x2511 @@ -524,21 +526,23 @@ encrypted_logs_hash: [ 0x1921 0x1922 ] unencrypted_logs_hash: [ 0x1a21 0x1a22 ] encrypted_log_preimages_length: 0x1b21 unencrypted_log_preimages_length: 0x1c21 -historic_private_data_tree_root: 0x1e21 -historic_nullifier_tree_root: 0x1f21 -historic_contract_tree_root: 0x1d21 -historic_l1_to_l2_messages_tree_root: 0x2021 -historic_blocks_tree_root: 0x2121 -historic_public_data_tree_root: 0x2221 -historic_global_variables_hash: 0x2321 +historic_block_data: private_data_tree_root: 0x1d21 +nullifier_tree_root: 0x1d22 +contract_tree_root: 0x1d23 +l1_to_l2_messages_tree_root: 0x1d24 +blocks_tree_root: 0x1d25 +private_kernel_vk_tree_root: 0x1d26 +public_data_tree_root: 0x1d27 +global_variables_hash: 0x1d28 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e21 +y: 0x1e22 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e22 +function_tree_root: 0x1e23 +contract_address_salt: 0x1e24 +portal_contract_address: 0x2525252525252525252525252525252525252525 chain_id: 0x2421 version: 0x2521 @@ -571,21 +575,23 @@ encrypted_logs_hash: [ 0x1922 0x1923 ] unencrypted_logs_hash: [ 0x1a22 0x1a23 ] encrypted_log_preimages_length: 0x1b22 unencrypted_log_preimages_length: 0x1c22 -historic_private_data_tree_root: 0x1e22 -historic_nullifier_tree_root: 0x1f22 -historic_contract_tree_root: 0x1d22 -historic_l1_to_l2_messages_tree_root: 0x2022 -historic_blocks_tree_root: 0x2122 -historic_public_data_tree_root: 0x2222 -historic_global_variables_hash: 0x2322 +historic_block_data: private_data_tree_root: 0x1d22 +nullifier_tree_root: 0x1d23 +contract_tree_root: 0x1d24 +l1_to_l2_messages_tree_root: 0x1d25 +blocks_tree_root: 0x1d26 +private_kernel_vk_tree_root: 0x1d27 +public_data_tree_root: 0x1d28 +global_variables_hash: 0x1d29 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e22 +y: 0x1e23 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e23 +function_tree_root: 0x1e24 +contract_address_salt: 0x1e25 +portal_contract_address: 0x2626262626262626262626262626262626262626 chain_id: 0x2422 version: 0x2522 @@ -618,21 +624,23 @@ encrypted_logs_hash: [ 0x1923 0x1924 ] unencrypted_logs_hash: [ 0x1a23 0x1a24 ] encrypted_log_preimages_length: 0x1b23 unencrypted_log_preimages_length: 0x1c23 -historic_private_data_tree_root: 0x1e23 -historic_nullifier_tree_root: 0x1f23 -historic_contract_tree_root: 0x1d23 -historic_l1_to_l2_messages_tree_root: 0x2023 -historic_blocks_tree_root: 0x2123 -historic_public_data_tree_root: 0x2223 -historic_global_variables_hash: 0x2323 +historic_block_data: private_data_tree_root: 0x1d23 +nullifier_tree_root: 0x1d24 +contract_tree_root: 0x1d25 +l1_to_l2_messages_tree_root: 0x1d26 +blocks_tree_root: 0x1d27 +private_kernel_vk_tree_root: 0x1d28 +public_data_tree_root: 0x1d29 +global_variables_hash: 0x1d2a + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e23 +y: 0x1e24 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e24 +function_tree_root: 0x1e25 +contract_address_salt: 0x1e26 +portal_contract_address: 0x2727272727272727272727272727272727272727 chain_id: 0x2423 version: 0x2523 @@ -665,21 +673,23 @@ encrypted_logs_hash: [ 0x1924 0x1925 ] unencrypted_logs_hash: [ 0x1a24 0x1a25 ] encrypted_log_preimages_length: 0x1b24 unencrypted_log_preimages_length: 0x1c24 -historic_private_data_tree_root: 0x1e24 -historic_nullifier_tree_root: 0x1f24 -historic_contract_tree_root: 0x1d24 -historic_l1_to_l2_messages_tree_root: 0x2024 -historic_blocks_tree_root: 0x2124 -historic_public_data_tree_root: 0x2224 -historic_global_variables_hash: 0x2324 +historic_block_data: private_data_tree_root: 0x1d24 +nullifier_tree_root: 0x1d25 +contract_tree_root: 0x1d26 +l1_to_l2_messages_tree_root: 0x1d27 +blocks_tree_root: 0x1d28 +private_kernel_vk_tree_root: 0x1d29 +public_data_tree_root: 0x1d2a +global_variables_hash: 0x1d2b + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e24 +y: 0x1e25 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e25 +function_tree_root: 0x1e26 +contract_address_salt: 0x1e27 +portal_contract_address: 0x2828282828282828282828282828282828282828 chain_id: 0x2424 version: 0x2524 @@ -985,21 +995,23 @@ encrypted_logs_hash: [ 0x1911 0x1912 ] unencrypted_logs_hash: [ 0x1a11 0x1a12 ] encrypted_log_preimages_length: 0x1b11 unencrypted_log_preimages_length: 0x1c11 -historic_private_data_tree_root: 0x1e11 -historic_nullifier_tree_root: 0x1f11 -historic_contract_tree_root: 0x1d11 -historic_l1_to_l2_messages_tree_root: 0x2011 -historic_blocks_tree_root: 0x2111 -historic_public_data_tree_root: 0x2211 -historic_global_variables_hash: 0x2311 +historic_block_data: private_data_tree_root: 0x1d11 +nullifier_tree_root: 0x1d12 +contract_tree_root: 0x1d13 +l1_to_l2_messages_tree_root: 0x1d14 +blocks_tree_root: 0x1d15 +private_kernel_vk_tree_root: 0x1d16 +public_data_tree_root: 0x1d17 +global_variables_hash: 0x1d18 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e11 +y: 0x1e12 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e12 +function_tree_root: 0x1e13 +contract_address_salt: 0x1e14 +portal_contract_address: 0x1515151515151515151515151515151515151515 chain_id: 0x2411 version: 0x2511 @@ -1033,21 +1045,23 @@ encrypted_logs_hash: [ 0x1921 0x1922 ] unencrypted_logs_hash: [ 0x1a21 0x1a22 ] encrypted_log_preimages_length: 0x1b21 unencrypted_log_preimages_length: 0x1c21 -historic_private_data_tree_root: 0x1e21 -historic_nullifier_tree_root: 0x1f21 -historic_contract_tree_root: 0x1d21 -historic_l1_to_l2_messages_tree_root: 0x2021 -historic_blocks_tree_root: 0x2121 -historic_public_data_tree_root: 0x2221 -historic_global_variables_hash: 0x2321 +historic_block_data: private_data_tree_root: 0x1d21 +nullifier_tree_root: 0x1d22 +contract_tree_root: 0x1d23 +l1_to_l2_messages_tree_root: 0x1d24 +blocks_tree_root: 0x1d25 +private_kernel_vk_tree_root: 0x1d26 +public_data_tree_root: 0x1d27 +global_variables_hash: 0x1d28 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e21 +y: 0x1e22 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e22 +function_tree_root: 0x1e23 +contract_address_salt: 0x1e24 +portal_contract_address: 0x2525252525252525252525252525252525252525 chain_id: 0x2421 version: 0x2521 @@ -1080,21 +1094,23 @@ encrypted_logs_hash: [ 0x1922 0x1923 ] unencrypted_logs_hash: [ 0x1a22 0x1a23 ] encrypted_log_preimages_length: 0x1b22 unencrypted_log_preimages_length: 0x1c22 -historic_private_data_tree_root: 0x1e22 -historic_nullifier_tree_root: 0x1f22 -historic_contract_tree_root: 0x1d22 -historic_l1_to_l2_messages_tree_root: 0x2022 -historic_blocks_tree_root: 0x2122 -historic_public_data_tree_root: 0x2222 -historic_global_variables_hash: 0x2322 +historic_block_data: private_data_tree_root: 0x1d22 +nullifier_tree_root: 0x1d23 +contract_tree_root: 0x1d24 +l1_to_l2_messages_tree_root: 0x1d25 +blocks_tree_root: 0x1d26 +private_kernel_vk_tree_root: 0x1d27 +public_data_tree_root: 0x1d28 +global_variables_hash: 0x1d29 + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e22 +y: 0x1e23 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e23 +function_tree_root: 0x1e24 +contract_address_salt: 0x1e25 +portal_contract_address: 0x2626262626262626262626262626262626262626 chain_id: 0x2422 version: 0x2522 @@ -1127,21 +1143,23 @@ encrypted_logs_hash: [ 0x1923 0x1924 ] unencrypted_logs_hash: [ 0x1a23 0x1a24 ] encrypted_log_preimages_length: 0x1b23 unencrypted_log_preimages_length: 0x1c23 -historic_private_data_tree_root: 0x1e23 -historic_nullifier_tree_root: 0x1f23 -historic_contract_tree_root: 0x1d23 -historic_l1_to_l2_messages_tree_root: 0x2023 -historic_blocks_tree_root: 0x2123 -historic_public_data_tree_root: 0x2223 -historic_global_variables_hash: 0x2323 +historic_block_data: private_data_tree_root: 0x1d23 +nullifier_tree_root: 0x1d24 +contract_tree_root: 0x1d25 +l1_to_l2_messages_tree_root: 0x1d26 +blocks_tree_root: 0x1d27 +private_kernel_vk_tree_root: 0x1d28 +public_data_tree_root: 0x1d29 +global_variables_hash: 0x1d2a + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e23 +y: 0x1e24 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e24 +function_tree_root: 0x1e25 +contract_address_salt: 0x1e26 +portal_contract_address: 0x2727272727272727272727272727272727272727 chain_id: 0x2423 version: 0x2523 @@ -1174,21 +1192,23 @@ encrypted_logs_hash: [ 0x1924 0x1925 ] unencrypted_logs_hash: [ 0x1a24 0x1a25 ] encrypted_log_preimages_length: 0x1b24 unencrypted_log_preimages_length: 0x1c24 -historic_private_data_tree_root: 0x1e24 -historic_nullifier_tree_root: 0x1f24 -historic_contract_tree_root: 0x1d24 -historic_l1_to_l2_messages_tree_root: 0x2024 -historic_blocks_tree_root: 0x2124 -historic_public_data_tree_root: 0x2224 -historic_global_variables_hash: 0x2324 +historic_block_data: private_data_tree_root: 0x1d24 +nullifier_tree_root: 0x1d25 +contract_tree_root: 0x1d26 +l1_to_l2_messages_tree_root: 0x1d27 +blocks_tree_root: 0x1d28 +private_kernel_vk_tree_root: 0x1d29 +public_data_tree_root: 0x1d2a +global_variables_hash: 0x1d2b + contract_deployment_data: deployer_public_key: -x: 0x1 -y: 0x2 +x: 0x1e24 +y: 0x1e25 -constructor_vk_hash: 0x2 -function_tree_root: 0x3 -contract_address_salt: 0x4 -portal_contract_address: 0x505050505050505050505050505050505050505 +constructor_vk_hash: 0x1e25 +function_tree_root: 0x1e26 +contract_address_salt: 0x1e27 +portal_contract_address: 0x2828282828282828282828282828282828282828 chain_id: 0x2424 version: 0x2524 diff --git a/yarn-project/circuits.js/src/structs/kernel/historic_block_data.ts b/yarn-project/circuits.js/src/structs/kernel/historic_block_data.ts index 82001f67a82..13645f2cf8b 100644 --- a/yarn-project/circuits.js/src/structs/kernel/historic_block_data.ts +++ b/yarn-project/circuits.js/src/structs/kernel/historic_block_data.ts @@ -81,6 +81,23 @@ export class HistoricBlockData { return this.toBuffer().toString(); } + /** + * Return the historic block data as an array of items in the order they are serialised in noir. + * @returns Array of items in the order they are stored in the contract + */ + toArray(): Fr[] { + return [ + this.privateDataTreeRoot, + this.nullifierTreeRoot, + this.contractTreeRoot, + this.l1ToL2MessagesTreeRoot, + this.blocksTreeRoot, // Note private_kernel_vk_tree_root, is not included yet as + // it is not present in noir, + this.publicDataTreeRoot, + this.globalVariablesHash, + ]; + } + static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); return new HistoricBlockData( diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 0c2b4c70fad..5e66a43c26b 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -13,6 +13,7 @@ import { import { FieldsOf, assertMemberLength } from '../utils/jsUtils.js'; import { serializeToBuffer } from '../utils/serialize.js'; import { CallContext } from './call_context.js'; +import { HistoricBlockData } from './index.js'; import { ContractDeploymentData } from './tx_context.js'; /** @@ -82,33 +83,9 @@ export class PrivateCircuitPublicInputs { */ public unencryptedLogPreimagesLength: Fr, /** - * Root of the private data tree roots tree. + * Historic roots of the data trees, used to calculate the block hash the user is proving against. */ - public historicPrivateDataTreeRoot: Fr, - /** - * Root of the nullifier tree roots tree. - */ - public historicPrivateNullifierTreeRoot: Fr, - /** - * Root of the contract tree roots tree. - */ - public historicContractTreeRoot: Fr, - /** - * Root of the L2 to L1 messages tree. - */ - public historicL1ToL2MessagesTreeRoot: Fr, - /** - * Root of the Blocks roots tree. - */ - public historicBlocksTreeRoot: Fr, - /** - * Previous blocks global variables hash. - */ - public historicGlobalVariablesHash: Fr, - /** - * Root of the Public Data tree. - */ - public historicPublicDataTreeRoot: Fr, + public historicBlockData: HistoricBlockData, /** * Deployment data of contracts being deployed in this kernel iteration. */ @@ -166,13 +143,7 @@ export class PrivateCircuitPublicInputs { frArray(NUM_FIELDS_PER_SHA256), Fr.ZERO, Fr.ZERO, - Fr.ZERO, - Fr.ZERO, - Fr.ZERO, - Fr.ZERO, - Fr.ZERO, - Fr.ZERO, - Fr.ZERO, + HistoricBlockData.empty(), ContractDeploymentData.empty(), Fr.ZERO, Fr.ZERO, @@ -200,13 +171,7 @@ export class PrivateCircuitPublicInputs { fields.unencryptedLogsHash, fields.encryptedLogPreimagesLength, fields.unencryptedLogPreimagesLength, - fields.historicPrivateDataTreeRoot, - fields.historicPrivateNullifierTreeRoot, - fields.historicContractTreeRoot, - fields.historicL1ToL2MessagesTreeRoot, - fields.historicBlocksTreeRoot, - fields.historicGlobalVariablesHash, - fields.historicPublicDataTreeRoot, + fields.historicBlockData, fields.contractDeploymentData, fields.chainId, fields.version, diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 5d15d647251..e758afa40c0 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -647,14 +647,8 @@ export function makePrivateCircuitPublicInputs(seed = 0): PrivateCircuitPublicIn unencryptedLogsHash: makeTuple(NUM_FIELDS_PER_SHA256, fr, seed + 0xa00), encryptedLogPreimagesLength: fr(seed + 0xb00), unencryptedLogPreimagesLength: fr(seed + 0xc00), - historicContractTreeRoot: fr(seed + 0xd00), - historicPrivateDataTreeRoot: fr(seed + 0xe00), - historicPrivateNullifierTreeRoot: fr(seed + 0xf00), - historicL1ToL2MessagesTreeRoot: fr(seed + 0x1000), - historicBlocksTreeRoot: fr(seed + 0x1100), - historicGlobalVariablesHash: fr(seed + 0x1200), - historicPublicDataTreeRoot: fr(seed + 0x1300), - contractDeploymentData: makeContractDeploymentData(), + historicBlockData: makeHistoricBlockData(seed + 0xd00), + contractDeploymentData: makeContractDeploymentData(seed + 0xe00), chainId: fr(seed + 0x1400), version: fr(seed + 0x1500), }); diff --git a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts index 8025fff976a..b5d6093953e 100644 --- a/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts +++ b/yarn-project/sequencer-client/src/block_builder/solo_block_builder.ts @@ -514,7 +514,8 @@ export class SoloBlockBuilder implements BlockBuilder { const wasm = await CircuitsWasm.get(); const blockData = tx.data.constants.blockData; - const { privateDataTreeRoot, nullifierTreeRoot, contractTreeRoot, l1ToL2MessagesTreeRoot } = blockData; + const { privateDataTreeRoot, nullifierTreeRoot, contractTreeRoot, l1ToL2MessagesTreeRoot, publicDataTreeRoot } = + blockData; const blockHash = computeBlockHash( wasm, blockData.globalVariablesHash, @@ -522,7 +523,7 @@ export class SoloBlockBuilder implements BlockBuilder { nullifierTreeRoot, contractTreeRoot, l1ToL2MessagesTreeRoot, - blockData.publicDataTreeRoot, + publicDataTreeRoot, ); return this.getMembershipWitnessFor(blockHash, MerkleTreeId.BLOCKS_TREE, HISTORIC_BLOCKS_TREE_HEIGHT); }