Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: l1 to l2 messaging #385

Merged
merged 40 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f944a36
feat: initial decoder contact changes
Apr 24, 2023
0dfe587
feat: add message snapshot to l2 block
Apr 24, 2023
caf51c7
feat(world_state): add l2 merkle tree
Apr 24, 2023
e460010
feat: add l1ToL2 roots tree to ts
Apr 25, 2023
0fce236
feat: historic l2 tree in l2 block
Apr 25, 2023
0d758df
feat: add l1->l2 messages types to root rollup
Apr 25, 2023
a552564
feat: add to circuit powered block builder
Apr 25, 2023
d6f3fdd
feat: add types to root rollup inputs
Apr 25, 2023
758eca9
feat: update root rollup circuit
Apr 26, 2023
658f2ab
feat: add l1tol2 messages to the rollup calldata
Apr 26, 2023
6b2f909
soldoc
Apr 26, 2023
79c31df
fix: pedersen segfault issue
Apr 26, 2023
e56dfc7
clean: fix native root tests
Apr 27, 2023
16258be
Add messages hash test
Apr 27, 2023
6ac7a02
feat: stub l1_to_l2_messages in block builder
Apr 27, 2023
006ead8
fix: update snaphshots in circuits.js
Apr 27, 2023
4dbb257
fix: activate sim tree checking in rollup builder
Apr 27, 2023
df5d344
fix: update snapshot
Apr 27, 2023
999200f
feat: add l2 block utilities
Apr 27, 2023
9b480c8
fix: rebase cpp build issues
May 2, 2023
16ee7c4
feat: update l1 contract after rebase
May 2, 2023
abcf8d1
fix: update ts tests
May 2, 2023
76081a3
chore: update viem scripts
May 2, 2023
144877c
chore: update ethjs helpers
May 2, 2023
385d71f
fix
May 2, 2023
c16ac92
feat: update decoder.t.sol
May 2, 2023
b266168
Merge branch 'master' into md/l1-l2-messaging
May 2, 2023
4f813c5
fix: re skip `l2-block-publisher.test.ts`
May 2, 2023
379a8be
chore: clang tidy fix
May 2, 2023
51de3e6
fix: clang tidy
May 2, 2023
5c63b8e
run prettier
May 2, 2023
53a86ec
fix: remove done todos
May 2, 2023
0534759
fix: re introduce test initialiser lost in merge
May 2, 2023
e61ae12
fix: move custom typing to its own file in the sequencer
May 3, 2023
4498fb5
fix: add negative tests, cleanup
May 3, 2023
3353a9d
chore: forge fmt
May 3, 2023
0b551c3
fix: rename updateRootsTree -> updateHistoricRootsTree
May 3, 2023
995c8bc
fix: update contract doc comment
May 3, 2023
6290773
fix: update cpp test and naming nits
May 3, 2023
ea8da39
fix: update trailing mock
May 3, 2023
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
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
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);
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
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