From 02d3751ed4491917d2f1e0fe4e9ffa1a5c0b9313 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Tue, 4 Apr 2023 10:11:05 +0000 Subject: [PATCH] add rollup subtree height --- .../abis/rollup/base/base_rollup_public_inputs.hpp | 8 ++++++++ .../abis/rollup/merge/merge_rollup_public_inputs.hpp | 9 ++++++++- cpp/src/aztec3/circuits/rollup/base/.test.cpp | 7 +++++++ .../rollup/base/native_base_rollup_circuit.cpp | 1 + .../rollup/merge/native_merge_rollup_circuit.cpp | 12 ++++++++++++ .../rollup/root/native_root_rollup_circuit.cpp | 8 ++++++++ 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp b/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp index a48df2f5..c64fed96 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp @@ -19,6 +19,9 @@ template struct BaseRollupPublicInputs { AggregationObject end_aggregation_object; ConstantRollupData 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 start_private_data_tree_snapshot; AppendOnlyTreeSnapshot end_private_data_tree_snapshot; @@ -42,6 +45,7 @@ template void read(uint8_t const*& it, BaseRollupPublicInputs void write(std::vector& 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); @@ -73,6 +78,9 @@ template 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 diff --git a/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp b/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp index 4feb14a1..16c1a982 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp @@ -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 { @@ -20,6 +21,7 @@ template struct MergeRollupPublicInputs { typedef typename NCT::AggregationObject AggregationObject; uint32_t rollup_type; + fr rollup_subtree_height; AggregationObject end_aggregation_object; @@ -46,6 +48,7 @@ template void read(uint8_t const*& it, MergeRollupPublicInputs void write(std::vector& 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); @@ -75,7 +79,10 @@ template void write(std::vector& buf, MergeRollupPublicI template std::ostream& operator<<(std::ostream& os, MergeRollupPublicInputs 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" diff --git a/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/cpp/src/aztec3/circuits/rollup/base/.test.cpp index e7d776a0..86c94d8d 100644 --- a/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -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) diff --git a/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp b/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp index 0d95132e..3c16bec8 100644 --- a/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.cpp @@ -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, diff --git a/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp b/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp index 7f826f33..02af280e 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.cpp @@ -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" @@ -10,6 +11,7 @@ #include #include +#include #include #include #include @@ -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); @@ -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. @@ -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 = diff --git a/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp b/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp index 456b8874..63fd7cd7 100644 --- a/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/native_root_rollup_circuit.cpp @@ -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; @@ -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);