Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ template <typename NCT> struct RootRollupInputs {
std::array<fr, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT> new_historic_private_data_tree_root_sibling_path;
std::array<fr, CONTRACT_TREE_ROOTS_TREE_HEIGHT> new_historic_contract_tree_root_sibling_path;

// inputs required to process l1 to l2 messages
std::array<fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP> l1_to_l2_messages;
std::array<fr, L1_TO_L2_MSG_SUBTREE_INCLUSION_CHECK_DEPTH> new_l1_to_l2_message_tree_root_sibling_path;
std::array<fr, L1_TO_L2_MSG_TREE_ROOTS_TREE_HEIGHT> new_historic_l1_to_l2_message_roots_tree_sibling_path;

AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_message_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> start_historic_tree_l1_to_l2_message_tree_roots_snapshot;

bool operator==(RootRollupInputs<NCT> const&) const = default;
};

Expand All @@ -37,6 +45,11 @@ template <typename NCT> void read(uint8_t const*& it, RootRollupInputs<NCT>& obj
read(it, obj.previous_rollup_data);
read(it, obj.new_historic_private_data_tree_root_sibling_path);
read(it, obj.new_historic_contract_tree_root_sibling_path);
read(it, obj.l1_to_l2_messages);
read(it, obj.new_l1_to_l2_message_tree_root_sibling_path);
read(it, obj.new_historic_l1_to_l2_message_roots_tree_sibling_path);
read(it, obj.start_l1_to_l2_message_tree_snapshot);
read(it, obj.start_historic_tree_l1_to_l2_message_tree_roots_snapshot);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, RootRollupInputs<NCT> const& obj)
Expand All @@ -46,14 +59,27 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, RootRollupInputs<N
write(buf, obj.previous_rollup_data);
write(buf, obj.new_historic_private_data_tree_root_sibling_path);
write(buf, obj.new_historic_contract_tree_root_sibling_path);
write(buf, obj.l1_to_l2_messages);
write(buf, obj.new_l1_to_l2_message_tree_root_sibling_path);
write(buf, obj.new_historic_l1_to_l2_message_roots_tree_sibling_path);
write(buf, obj.start_l1_to_l2_message_tree_snapshot);
write(buf, obj.start_historic_tree_l1_to_l2_message_tree_roots_snapshot);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, RootRollupInputs<NCT> const& obj)
{
return os << "previous_rollup_data: " << obj.previous_rollup_data << "\n"
<< "new_historic_private_data_tree_roots: " << obj.new_historic_private_data_tree_root_sibling_path
<< "\n"
<< "new_historic_contract_tree_roots: " << obj.new_historic_contract_tree_root_sibling_path << "\n";
<< "new_historic_contract_tree_roots: " << obj.new_historic_contract_tree_root_sibling_path << "\n"
<< "new_l1_to_l2_messages: " << obj.l1_to_l2_messages << "\n"
<< "new_l1_to_l2_message_tree_root_sibling_path: " << obj.new_l1_to_l2_message_tree_root_sibling_path
<< "\n"
<< "new_historic_l1_to_l2_message_roots_tree_sibling_path: "
<< obj.new_historic_l1_to_l2_message_roots_tree_sibling_path << "\n"
<< "start_l1_to_l2_message_tree_snapshot: " << obj.start_l1_to_l2_message_tree_snapshot << "\n"
<< "start_historic_tree_l1_to_l2_message_tree_roots_snapshot: "
<< obj.start_historic_tree_l1_to_l2_message_tree_roots_snapshot << "\n";
}

} // namespace aztec3::circuits::abis
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace aztec3::circuits::abis {
using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;


template <typename NCT> struct RootRollupPublicInputs {
using fr = typename NCT::fr;
using AggregationObject = typename NCT::AggregationObject;
Expand All @@ -40,7 +41,14 @@ template <typename NCT> struct RootRollupPublicInputs {
AppendOnlyTreeSnapshot<NCT> start_tree_of_historic_contract_tree_roots_snapshot;
AppendOnlyTreeSnapshot<NCT> end_tree_of_historic_contract_tree_roots_snapshot;

AppendOnlyTreeSnapshot<NCT> start_l1_to_l2_messages_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> end_l1_to_l2_messages_tree_snapshot;

AppendOnlyTreeSnapshot<NCT> start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot;
AppendOnlyTreeSnapshot<NCT> end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot;

std::array<fr, 2> calldata_hash;
std::array<fr, 2> l1_to_l2_messages_hash;

bool operator==(RootRollupPublicInputs<NCT> const&) const = default;

Expand All @@ -53,11 +61,15 @@ template <typename NCT> struct RootRollupPublicInputs {
write(buf, start_contract_tree_snapshot);
write(buf, start_tree_of_historic_private_data_tree_roots_snapshot);
write(buf, start_tree_of_historic_contract_tree_roots_snapshot);
write(buf, start_l1_to_l2_messages_tree_snapshot);
write(buf, start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);
write(buf, end_private_data_tree_snapshot);
write(buf, end_nullifier_tree_snapshot);
write(buf, end_contract_tree_snapshot);
write(buf, end_tree_of_historic_private_data_tree_roots_snapshot);
write(buf, end_tree_of_historic_contract_tree_roots_snapshot);
write(buf, end_l1_to_l2_messages_tree_snapshot);
write(buf, end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);

// Stitching calldata hash together
auto high_buffer = calldata_hash[0].to_buffer();
Expand All @@ -70,6 +82,17 @@ template <typename NCT> struct RootRollupPublicInputs {
buf.push_back(low_buffer[16 + i]);
}

// Stitch l1_to_l2_messages_hash
auto high_buffer_m = l1_to_l2_messages_hash[0].to_buffer();
auto low_buffer_m = l1_to_l2_messages_hash[1].to_buffer();

for (uint8_t i = 0; i < 16; i++) {
buf.push_back(high_buffer_m[16 + i]);
}
for (uint8_t i = 0; i < 16; i++) {
buf.push_back(low_buffer_m[16 + i]);
}

return sha256::sha256_to_field(buf);
}
};
Expand All @@ -91,7 +114,12 @@ template <typename NCT> void read(uint8_t const*& it, RootRollupPublicInputs<NCT
read(it, obj.end_tree_of_historic_private_data_tree_roots_snapshot);
read(it, obj.start_tree_of_historic_contract_tree_roots_snapshot);
read(it, obj.end_tree_of_historic_contract_tree_roots_snapshot);
read(it, obj.start_l1_to_l2_messages_tree_snapshot);
read(it, obj.end_l1_to_l2_messages_tree_snapshot);
read(it, obj.start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);
read(it, obj.end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);
read(it, obj.calldata_hash);
read(it, obj.l1_to_l2_messages_hash);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, RootRollupPublicInputs<NCT> const& obj)
Expand All @@ -111,7 +139,12 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, RootRollupPublicIn
write(buf, obj.end_tree_of_historic_private_data_tree_roots_snapshot);
write(buf, obj.start_tree_of_historic_contract_tree_roots_snapshot);
write(buf, obj.end_tree_of_historic_contract_tree_roots_snapshot);
write(buf, obj.start_l1_to_l2_messages_tree_snapshot);
write(buf, obj.end_l1_to_l2_messages_tree_snapshot);
write(buf, obj.start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);
write(buf, obj.end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot);
write(buf, obj.calldata_hash);
write(buf, obj.l1_to_l2_messages_hash);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, RootRollupPublicInputs<NCT> const& obj)
Expand All @@ -133,7 +166,15 @@ template <typename NCT> std::ostream& operator<<(std::ostream& os, RootRollupPub
<< obj.start_tree_of_historic_contract_tree_roots_snapshot << "\n"
<< "end_tree_of_historic_contract_tree_roots_snapshot: "
<< obj.end_tree_of_historic_contract_tree_roots_snapshot << "\n"
<< "calldata_hash: " << obj.calldata_hash << "\n";
<< "start_l1_to_l2_messages_tree_snapshot: " << obj.start_l1_to_l2_messages_tree_snapshot << "\n"
<< "end_l1_tol2_messages_tree_snapshot: " << obj.end_l1_to_l2_messages_tree_snapshot << "\n"
<< "start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot: "
<< obj.start_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot << "\n"
<< "end_tree_of_historic_l1_tol2_messages_tree_roots_snapshot: "
<< obj.end_tree_of_historic_l1_to_l2_messages_tree_roots_snapshot << "\n"
<< "calldata_hash: " << obj.calldata_hash << "\n"
<< "l1_to_l2_messages_hash: " << obj.l1_to_l2_messages_hash << "\n";
;
};

} // namespace aztec3::circuits::abis
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(DummyC
}

// Check that the new subtree is to be inserted at the next location, and is empty currently
const auto empty_nullifier_subtree_root = calculate_empty_tree_root(NULLIFIER_SUBTREE_DEPTH);
const auto empty_nullifier_subtree_root = components::calculate_empty_tree_root(NULLIFIER_SUBTREE_DEPTH);
auto leafIndexNullifierSubtreeDepth =
baseRollupInputs.start_nullifier_tree_snapshot.next_available_leaf_index >> NULLIFIER_SUBTREE_DEPTH;
check_membership<NT>(composer,
Expand Down Expand Up @@ -541,7 +541,7 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseR
NT::fr const commitments_tree_subroot = calculate_commitments_subtree(composer, baseRollupInputs);

// Insert commitment subtrees:
const auto empty_commitments_subtree_root = calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH);
const auto empty_commitments_subtree_root = components::calculate_empty_tree_root(PRIVATE_DATA_SUBTREE_DEPTH);
auto end_private_data_tree_snapshot =
components::insert_subtree_to_snapshot_tree(composer,
baseRollupInputs.start_private_data_tree_snapshot,
Expand All @@ -552,7 +552,7 @@ BaseOrMergeRollupPublicInputs base_rollup_circuit(DummyComposer& composer, BaseR
"empty commitment subtree membership check");

// Insert contract subtrees:
const auto empty_contracts_subtree_root = calculate_empty_tree_root(CONTRACT_SUBTREE_DEPTH);
const auto empty_contracts_subtree_root = components::calculate_empty_tree_root(CONTRACT_SUBTREE_DEPTH);
auto end_contract_tree_snapshot =
components::insert_subtree_to_snapshot_tree(composer,
baseRollupInputs.start_contract_tree_snapshot,
Expand Down
13 changes: 13 additions & 0 deletions circuits/cpp/src/aztec3/circuits/rollup/components/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "barretenberg/crypto/sha256/sha256.hpp"
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/stdlib/hash/pedersen/pedersen.hpp"
#include "barretenberg/stdlib/merkle_tree/memory_tree.hpp"

#include <algorithm>
#include <array>
Expand All @@ -18,6 +19,18 @@

namespace aztec3::circuits::rollup::components {

/**
* @brief Get the root of an empty tree of a given depth
*
* @param depth
* @return NT::fr
*/
NT::fr calculate_empty_tree_root(const size_t depth)
{
stdlib::merkle_tree::MemoryTree const empty_tree = stdlib::merkle_tree::MemoryTree(depth);
return empty_tree.root();
}

/**
* @brief Create an aggregation object for the proofs that are provided
* - We add points P0 for each of our proofs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ using aztec3::circuits::check_membership;
using aztec3::circuits::root_from_sibling_path;

namespace aztec3::circuits::rollup::components {
NT::fr calculate_empty_tree_root(size_t depth);
std::array<fr, 2> compute_calldata_hash(std::array<abis::PreviousRollupData<NT>, 2> previous_rollup_data);
void assert_prev_rollups_follow_on_from_each_other(DummyComposer& composer,
BaseOrMergeRollupPublicInputs const& left,
Expand Down
Loading