Skip to content

Commit

Permalink
chore: remove individual historic roots from privateCircuitPublicInpu…
Browse files Browse the repository at this point in the history
…ts (#1571)

Add a bit more consistency across the code base, I came into these
issues when working on
#1515.

Running this in a separate pr as it is not directly related. And to
minimise the diff between the two

## Overview
Replaces 6 seperate roots with one single data structure that is used
literally everywhere else
  • Loading branch information
Maddiaa0 authored Aug 18, 2023
1 parent 5b9aedd commit 088cbe5
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 395 deletions.
14 changes: 14 additions & 0 deletions circuits/cpp/src/aztec3/circuits/abis/historic_block_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ template <typename NCT> struct HistoricBlockData {
global_variables_hash == other.global_variables_hash;
};

template <typename Builder> void assert_is_zero()
{
static_assert((std::is_same<CircuitTypes<Builder>, 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 <typename Builder> HistoricBlockData<CircuitTypes<Builder>> to_circuit_type(Builder& builder) const
{
static_assert((std::is_same<NativeTypes, NCT>::value));
Expand Down
137 changes: 18 additions & 119 deletions circuits/cpp/src/aztec3/circuits/abis/private_circuit_public_inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -45,13 +46,7 @@ template <typename NCT> 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<NCT> historic_block_data{};

ContractDeploymentData<NCT> contract_deployment_data{};

Expand All @@ -73,13 +68,7 @@ template <typename NCT> 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);
Expand All @@ -95,13 +84,7 @@ template <typename NCT> 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;
};
Expand Down Expand Up @@ -137,13 +120,7 @@ template <typename NCT> 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),

Expand Down Expand Up @@ -182,13 +159,7 @@ template <typename NCT> 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),

Expand Down Expand Up @@ -226,13 +197,7 @@ template <typename NCT> 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());

Expand Down Expand Up @@ -282,13 +247,7 @@ template <typename NCT> 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<HistoricBlockData<NCT>> historic_block_data;

std::optional<ContractDeploymentData<NCT>> contract_deployment_data;

Expand All @@ -310,13 +269,7 @@ template <typename NCT> 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);
Expand Down Expand Up @@ -345,13 +298,7 @@ template <typename NCT> 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<HistoricBlockData<NCT>> const& historic_block_data,

std::optional<ContractDeploymentData<NCT>> const& contract_deployment_data,

Expand All @@ -371,13 +318,7 @@ template <typename NCT> 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){};
Expand Down Expand Up @@ -409,13 +350,7 @@ template <typename NCT> 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;

Expand Down Expand Up @@ -480,13 +415,7 @@ template <typename NCT> 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);

Expand Down Expand Up @@ -525,13 +454,7 @@ template <typename NCT> 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();

Expand Down Expand Up @@ -572,13 +495,7 @@ template <typename NCT> 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),

Expand Down Expand Up @@ -619,13 +536,7 @@ template <typename NCT> 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),

Expand Down Expand Up @@ -667,13 +578,7 @@ template <typename NCT> 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());

Expand Down Expand Up @@ -710,13 +615,7 @@ template <typename NCT> 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(),

Expand Down
2 changes: 1 addition & 1 deletion circuits/cpp/src/aztec3/circuits/kernel/private/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,19 +26,11 @@ void initialise_end_values(PrivateKernelInputsInit<NT> 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<NT>{
.block_data =
HistoricBlockData<NT>{
// 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,
};

Expand Down
Loading

0 comments on commit 088cbe5

Please sign in to comment.