Skip to content

Commit

Permalink
add rollup subtree height
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-kothari committed Apr 4, 2023
1 parent 095526f commit 02d3751
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ template <typename NCT> struct BaseRollupPublicInputs {

AggregationObject end_aggregation_object;
ConstantRollupData<NCT> constants;
// subtree height is always 0 for base.
// so that we always pass-in two base/merge circuits of the same height into the next level of recursion
fr rollup_subtree_height;

AppendOnlyTreeSnapshot<NCT> start_private_data_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> end_private_data_tree_snapshot;
Expand All @@ -42,6 +45,7 @@ template <typename NCT> void read(uint8_t const*& it, BaseRollupPublicInputs<NCT

read(it, obj.end_aggregation_object);
read(it, obj.constants);
read(it, obj.rollup_subtree_height);
read(it, obj.start_private_data_tree_snapshot);
read(it, obj.end_private_data_tree_snapshot);
read(it, obj.start_nullifier_tree_snapshot);
Expand All @@ -57,6 +61,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, BaseRollupPublicIn

write(buf, obj.end_aggregation_object);
write(buf, obj.constants);
write(buf, obj.rollup_subtree_height);
write(buf, obj.start_private_data_tree_snapshot);
write(buf, obj.end_private_data_tree_snapshot);
write(buf, obj.start_nullifier_tree_snapshot);
Expand All @@ -73,6 +78,9 @@ template <typename NCT> std::ostream& operator<<(std::ostream& os, BaseRollupPub
<< "\n"
"constants:\n"
<< obj.constants
<< "\n"
"rollup_subtree_height:\n"
<< obj.rollup_subtree_height
<< "\n"
"start_private_data_tree_snapshot:\n"
<< obj.start_private_data_tree_snapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../append_only_tree_snapshot.hpp"
#include "../../append_only_tree_snapshot.hpp"
#include "../constant_rollup_data.hpp"
#include "barretenberg/common/serialize.hpp"

namespace aztec3::circuits::abis {

Expand All @@ -20,6 +21,7 @@ template <typename NCT> struct MergeRollupPublicInputs {
typedef typename NCT::AggregationObject AggregationObject;

uint32_t rollup_type;
fr rollup_subtree_height;

AggregationObject end_aggregation_object;

Expand All @@ -46,6 +48,7 @@ template <typename NCT> void read(uint8_t const*& it, MergeRollupPublicInputs<NC
using serialize::read;

read(it, obj.rollup_type);
read(it, obj.rollup_subtree_height);
read(it, obj.end_aggregation_object);
read(it, obj.constants);
read(it, obj.start_private_data_tree_snapshot);
Expand All @@ -62,6 +65,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, MergeRollupPublicI
using serialize::write;

write(buf, obj.rollup_type);
write(buf, obj.rollup_subtree_height);
write(buf, obj.end_aggregation_object);
write(buf, obj.constants);
write(buf, obj.start_private_data_tree_snapshot);
Expand All @@ -75,7 +79,10 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, MergeRollupPublicI

template <typename NCT> std::ostream& operator<<(std::ostream& os, MergeRollupPublicInputs<NCT> const& obj)
{
return os << "rollup_type: " << obj.rollup_type << "\n"
return os << "rollup_type: " << obj.rollup_type
<< "\n"
"rollup_subtree_height:\n"
<< obj.rollup_subtree_height << "\n"
<< "end_aggregation_object:\n"
<< obj.end_aggregation_object
<< "\n"
Expand Down
7 changes: 7 additions & 0 deletions cpp/src/aztec3/circuits/rollup/base/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,13 @@ TEST_F(base_rollup_tests, test_aggregate)
outputs.end_aggregation_object.public_inputs);
}

TEST_F(base_rollup_tests, test_subtree_height_is_0)
{
BaseRollupInputs inputs = dummy_base_rollup_inputs_with_vk_proof();
BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs);
ASSERT_EQ(outputs.rollup_subtree_height, fr(0));
}

TEST_F(base_rollup_tests, test_proof_verification) {}

TEST_F(base_rollup_tests, test_cbind_0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ BaseRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs)
BaseRollupPublicInputs public_inputs = {
.end_aggregation_object = aggregation_object,
.constants = baseRollupInputs.constants,
.rollup_subtree_height = fr(0),
.start_private_data_tree_snapshot = baseRollupInputs.start_private_data_tree_snapshot,
.end_private_data_tree_snapshot = end_private_data_tree_snapshot,
.start_nullifier_tree_snapshot = baseRollupInputs.start_nullifier_tree_snapshot,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp"
#include "aztec3/constants.hpp"
#include "barretenberg/crypto/pedersen_hash/pedersen.hpp"
#include "barretenberg/crypto/sha256/sha256.hpp"
Expand All @@ -10,6 +11,7 @@

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdint>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -38,6 +40,13 @@ void assert_both_input_proofs_of_same_rollup_type(MergeRollupInputs mergeRollupI
(void)mergeRollupInputs;
}

NT::fr assert_both_input_proofs_of_same_height_and_return(MergeRollupInputs mergeRollupInputs)
{
assert(mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height ==
mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height);
return mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height;
}

void assert_equal_constants(ConstantRollupData left, ConstantRollupData right)
{
assert(left == right);
Expand Down Expand Up @@ -119,6 +128,7 @@ MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs
// check that both input proofs are either both "BASE" or "MERGE" and not a mix!
// this prevents having wonky commitment, nullifier and contract subtrees.
assert_both_input_proofs_of_same_rollup_type(mergeRollupInputs);
auto current_height = assert_both_input_proofs_of_same_height_and_return(mergeRollupInputs);

// TODO: Check both previous rollup vks (in previous_rollup_data) against the permitted set of kernel vks.
// we don't have a set of permitted kernel vks yet.
Expand All @@ -139,6 +149,8 @@ MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs
assert_equal_constants(left.constants, right.constants);

MergeRollupPublicInputs public_inputs = {
.rollup_type = abis::MERGE_ROLLUP_TYPE,
.rollup_subtree_height = current_height + 1,
.end_aggregation_object = aggregation_object,
.constants = left.constants,
.start_private_data_tree_snapshot =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ void assert_both_input_proofs_of_same_rollup_type(RootRollupInputs rootRollupInp
(void)rootRollupInputs;
}

void assert_both_input_proofs_of_same_rollup_height(RootRollupInputs rootRollupInputs)
{
assert(rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height ==
rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height);
(void)rootRollupInputs;
}

bool is_constants_equal(ConstantRollupData left, ConstantRollupData right)
{
return left == right;
Expand Down Expand Up @@ -139,6 +146,7 @@ RootRollupPublicInputs root_rollup_circuit(RootRollupInputs const& rootRollupInp
// check that both input proofs are either both "BASE" or "MERGE" and not a mix!
// this prevents having wonky commitment, nullifier and contract subtrees.
assert_both_input_proofs_of_same_rollup_type(rootRollupInputs);
assert_both_input_proofs_of_same_rollup_height(rootRollupInputs);

AggregationObject aggregation_object = aggregate_proofs(rootRollupInputs);

Expand Down

0 comments on commit 02d3751

Please sign in to comment.