From 4f55522c480ad169921e21c75dbcbeaa1b7729ee Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 3 Apr 2023 14:39:21 +0000 Subject: [PATCH 1/8] initial version of merge rollup --- .../rollup/base/base_rollup_public_inputs.hpp | 5 +- .../merge/merge_rollup_public_inputs.hpp | 63 ++++----- cpp/src/aztec3/circuits/rollup/merge/init.hpp | 1 + .../merge/native_merge_rollup_circuit.cpp | 124 ++++++++++++++++-- 4 files changed, 150 insertions(+), 43 deletions(-) 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 db6a0b58..a48df2f5 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 @@ -30,10 +30,7 @@ template struct BaseRollupPublicInputs { AppendOnlyTreeSnapshot end_contract_tree_snapshot; // Hashes (probably sha256) to make public inputs constant-sized (to then be unpacked on-chain) - // UPDATE we should instead just hash all of the below into a single value. See big diagram of sha256 hashing - // bottom-right of here. - // TODO I've put `fr`, but these hash values' types might need to be two fields if we want all 256-bits, for - // security purposes. + // Needs to be two fields to accomodate all 256-bits of the hash std::array calldata_hash; bool operator==(BaseRollupPublicInputs const&) const = default; 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 348f4c33..9a53e11d 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 @@ -12,27 +12,31 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using std::is_same; +const uint32_t BASE_ROLLUP_TYPE = 0; +const uint32_t MERGE_ROLLUP_TYPE = 1; + template struct MergeRollupPublicInputs { typedef typename NCT::fr fr; typedef typename NCT::AggregationObject AggregationObject; - fr rollup_subtree_height; + uint32_t rollup_type; AggregationObject end_aggregation_object; ConstantRollupData constants; + AppendOnlyTreeSnapshot start_private_data_tree_snapshot; + AppendOnlyTreeSnapshot end_private_data_tree_snapshot; + // The only tree root actually updated in this circuit is the nullifier tree, because earlier leaves (of // low_nullifiers) must be updated to point to the new nullifiers in this circuit. AppendOnlyTreeSnapshot start_nullifier_tree_snapshot; - AppendOnlyTreeSnapshot end_nullifier_tree_snapshots; + AppendOnlyTreeSnapshot end_nullifier_tree_snapshot; - fr new_commitments_subtree_root; - fr new_nullifiers_subtree_root; - fr new_contract_leaves_subtree_root; + AppendOnlyTreeSnapshot start_contract_tree_snapshot; + AppendOnlyTreeSnapshot end_contract_tree_snapshot; - fr calldata_hash; - fr prover_contributions_hash; + std::array calldata_hash; bool operator==(MergeRollupPublicInputs const&) const = default; }; @@ -41,43 +45,48 @@ template void read(uint8_t const*& it, MergeRollupPublicInputs void write(std::vector& buf, MergeRollupPublicInputs const& obj) { using serialize::write; - write(buf, obj.rollup_subtree_height); + write(buf, obj.rollup_type); write(buf, obj.end_aggregation_object); write(buf, obj.constants); + write(buf, obj.start_private_data_tree_snapshot); + write(buf, obj.end_private_data_tree_snapshot); write(buf, obj.start_nullifier_tree_snapshot); write(buf, obj.end_nullifier_tree_snapshots); - write(buf, obj.new_commitments_subtree_root); - write(buf, obj.new_nullifiers_subtree_root); - write(buf, obj.new_contract_leaves_subtree_root); + write(buf, obj.start_contract_tree_snapshot); + write(buf, obj.end_contract_tree_snapshot); write(buf, obj.calldata_hash); - write(buf, obj.prover_contributions_hash); }; template std::ostream& operator<<(std::ostream& os, MergeRollupPublicInputs const& obj) { - return os << "rollup_subtree_height:\n" - << obj.rollup_subtree_height << "\n" + return os << "rollup_type: " << obj.rollup_type << "\n" << "end_aggregation_object:\n" << obj.end_aggregation_object << "\n" "constants:\n" << obj.constants + << "\n" + "start_private_data_tree_snapshot:\n" + << obj.start_private_data_tree_snapshot + << "\n" + "end_private_data_tree_snapshot:\n" + << obj.end_private_data_tree_snapshot << "\n" "start_nullifier_tree_snapshot:\n" << obj.start_nullifier_tree_snapshot @@ -85,20 +94,14 @@ template std::ostream& operator<<(std::ostream& os, MergeRollupPu "end_nullifier_tree_snapshots:\n" << obj.end_nullifier_tree_snapshots << "\n" - "new_commitments_subtree_root: " - << obj.new_commitments_subtree_root - << "\n" - "new_nullifiers_subtree_root: " - << obj.new_nullifiers_subtree_root + "start_contract_tree_snapshot:\n" + << obj.start_contract_tree_snapshot << "\n" - "new_contract_leaves_subtree_root: " - << obj.new_contract_leaves_subtree_root + "end_contract_tree_snapshot:\n" + << obj.end_contract_tree_snapshot << "\n" "calldata_hash: " - << obj.calldata_hash - << "\n" - "prover_contributions_hash: " - << obj.prover_contributions_hash << "\n"; + << obj.calldata_hash << "\n"; } } // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/cpp/src/aztec3/circuits/rollup/merge/init.hpp index 62b1e5e8..d799343a 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -19,6 +19,7 @@ namespace aztec3::circuits::rollup::native_merge_rollup { using NT = aztec3::utils::types::NativeTypes; // Params +using ConstantRollupData = abis::ConstantRollupData; using MergeRollupInputs = abis::MergeRollupInputs; using MergeRollupPublicInputs = abis::MergeRollupPublicInputs; 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 c44a5376..cf8ed251 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 @@ -27,28 +27,134 @@ namespace aztec3::circuits::rollup::native_merge_rollup { */ AggregationObject aggregate_proofs(MergeRollupInputs mergeRollupInputs) { - // TODO: NOTE: for now we simply return the aggregation object from the first proof return mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object; } -/** TODO: implement - * @brief Get the prover contribution hash object - * - * @return NT::fr - */ -NT::fr get_prover_contribution_hash() +void assert_both_input_proofs_of_same_rollup_type(MergeRollupInputs mergeRollupInputs) { - return NT::fr(0); + assert(mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); +} + +void assert_equal_constants(ConstantRollupData left, ConstantRollupData right) +{ + assert(left.base_rollup_vk_hash == right.base_rollup_vk_hash); + assert(left.merge_rollup_vk_hash == right.merge_rollup_vk_hash); + assert(left.private_kernel_vk_tree_root == right.private_kernel_vk_tree_root); + assert(left.public_kernel_vk_tree_root == right.public_kernel_vk_tree_root); + assert(left.start_tree_of_historic_private_data_tree_roots_snapshot == + right.start_tree_of_historic_private_data_tree_roots_snapshot); + assert(left.start_tree_of_historic_contract_tree_roots_snapshot == + right.start_tree_of_historic_contract_tree_roots_snapshot); + assert(left.tree_of_historic_l1_to_l2_msg_tree_roots_snapshot == + right.tree_of_historic_l1_to_l2_msg_tree_roots_snapshot); +} + +// function that does sha256 hash of the calldata from each previous rollup data +std::array compute_calldata_hash(MergeRollupInputs mergeRollupInputs) +{ + // Compute the calldata hash + std::array calldata_hash_input_bytes; + for (uint8_t i = 0; i < 2; i++) { + std::array calldata_hash_fr = + mergeRollupInputs.previous_rollup_data[i].merge_rollup_public_inputs.calldata_hash; + + auto high_buffer = calldata_hash_fr[0].to_buffer(); + auto low_buffer = calldata_hash_fr[1].to_buffer(); + + for (uint8_t j = 0; j < 16; ++j) { + calldata_hash_input_bytes[i * 32 + j] = high_buffer[16 + j]; + calldata_hash_input_bytes[i * 32 + 16 + j] = low_buffer[16 + j]; + } + } + + std::vector calldata_hash_input_bytes_vec(calldata_hash_input_bytes.begin(), + calldata_hash_input_bytes.end()); + + auto h = sha256::sha256(calldata_hash_input_bytes_vec); + + // Split the hash into two fields, a high and a low + std::array buf_1, buf_2; + for (uint8_t i = 0; i < 16; i++) { + buf_1[i] = 0; + buf_1[16 + i] = h[i]; + buf_2[i] = 0; + buf_2[16 + i] = h[i + 16]; + } + auto high = fr::serialize_from_buffer(buf_1.data()); + auto low = fr::serialize_from_buffer(buf_2.data()); + + return { high, low }; +} + +// asserts that the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they +// follow on from one-another). +void ensure_prev_rollups_follow_on_from_each_other(MergeRollupInputs mergeRollupInputs) +{ + auto privateDataEndSnapshot0 = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_private_data_tree_snapshot; + auto privateDataStartSnapshot1 = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_private_data_tree_snapshot; + + auto nullifierEndSnapshot0 = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_nullifier_tree_snapshot; + auto nullifierStartSnapshot1 = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_nullifier_tree_snapshot; + + auto contractEndSnapshot0 = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_contract_tree_snapshot; + auto contractStartSnapshot1 = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_contract_tree_snapshot; + + assert(privateDataEndSnapshot0 == privateDataStartSnapshot1 && nullifierEndSnapshot0 == nullifierStartSnapshot1 && + contractEndSnapshot0 == contractStartSnapshot1); } MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs) { // Verify the previous rollup proofs + // 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); + + // 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. + + // compute calldata hash: + auto new_calldata_hash = compute_calldata_hash(mergeRollupInputs); + + // Ensure the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they + // follow on from one-another). This ensures the low_leaves which were updated in rollup 0 are being used as the + // 'starting' pointers in rollup 1. + ensure_prev_rollups_follow_on_from_each_other(mergeRollupInputs); + AggregationObject aggregation_object = aggregate_proofs(mergeRollupInputs); - MergeRollupPublicInputs public_inputs = {}; + // Check that the constants are the same in both proofs + auto left = mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; + auto right = mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; + assert_equal_constants(left.constants, right.constants); + + MergeRollupPublicInputs public_inputs = { + .end_aggregation_object = aggregation_object, + .constants = left.constants, + .start_private_data_tree_snapshot = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_private_data_tree_snapshot, + .end_private_data_tree_snapshot = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_private_data_tree_snapshot, + .start_nullifier_tree_snapshot = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_nullifier_tree_snapshot, + .end_nullifier_tree_snapshot = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_nullifier_tree_snapshot, + .start_contract_tree_snapshot = + mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_contract_tree_snapshot, + .end_contract_tree_snapshot = + mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_contract_tree_snapshot, + .calldata_hash = new_calldata_hash, + }; + return public_inputs; } From 75b66d480f6a6f91759f91dcc6eb927b93875aca Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Mon, 3 Apr 2023 16:07:10 +0000 Subject: [PATCH 2/8] move previous rollup data from base to merge and update root --- .../abis/rollup/base/previous_rollup_data.hpp | 59 ------------- .../rollup/merge/previous_rollup_data.hpp | 2 +- .../abis/rollup/root/root_rollup_inputs.hpp | 2 +- cpp/src/aztec3/circuits/rollup/base/.test.cpp | 20 ----- .../aztec3/circuits/rollup/base/c_bind.cpp | 17 ---- cpp/src/aztec3/circuits/rollup/base/init.hpp | 1 - cpp/src/aztec3/circuits/rollup/base/utils.cpp | 22 ----- cpp/src/aztec3/circuits/rollup/base/utils.hpp | 2 - .../aztec3/circuits/rollup/merge/utils.cpp | 85 +++++++++++++++++++ .../aztec3/circuits/rollup/merge/utils.hpp | 20 +++++ cpp/src/aztec3/circuits/rollup/root/.test.cpp | 20 +++-- .../root/native_root_rollup_circuit.cpp | 18 +++- 12 files changed, 133 insertions(+), 135 deletions(-) delete mode 100644 cpp/src/aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp create mode 100644 cpp/src/aztec3/circuits/rollup/merge/utils.cpp create mode 100644 cpp/src/aztec3/circuits/rollup/merge/utils.hpp diff --git a/cpp/src/aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp b/cpp/src/aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp deleted file mode 100644 index 31d73d4a..00000000 --- a/cpp/src/aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once -#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/membership_witness.hpp" -#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" -#include "aztec3/constants.hpp" -#include -#include -#include -#include - -namespace aztec3::circuits::abis { - -using aztec3::utils::types::CircuitTypes; -using aztec3::utils::types::NativeTypes; -using std::is_same; - -template struct PreviousRollupData { - BaseRollupPublicInputs base_rollup_public_inputs; - - NativeTypes::Proof proof; - std::shared_ptr vk; - NativeTypes::uint32 vk_index; - MembershipWitness vk_sibling_path; - - bool operator==(PreviousRollupData const&) const = default; -}; - -template void read(uint8_t const*& it, PreviousRollupData& obj) -{ - using serialize::read; - - read(it, obj.base_rollup_public_inputs); - read(it, obj.proof); - read(it, obj.vk); - read(it, obj.vk_index); - read(it, obj.vk_sibling_path); -}; - -template void write(std::vector& buf, PreviousRollupData const& obj) -{ - using serialize::write; - - write(buf, obj.base_rollup_public_inputs); - write(buf, obj.proof); - write(buf, *obj.vk); - write(buf, obj.vk_index); - write(buf, obj.vk_sibling_path); -}; - -template std::ostream& operator<<(std::ostream& os, PreviousRollupData const& obj) -{ - return os << "merge_rollup_public_inputs: " << obj.base_rollup_public_inputs << "\n" - << "proof: " << obj.proof << "\n" - << "vk: " << *(obj.vk) << "\n" - << "vk_index: " << obj.vk_index << "\n" - << "vk_sibling_path: " << obj.vk_sibling_path << "\n"; -}; - -} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp b/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp index 327391c3..10c10bbb 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp @@ -18,7 +18,7 @@ template struct PreviousRollupData { MergeRollupPublicInputs merge_rollup_public_inputs; NativeTypes::Proof proof; - NativeTypes::VK vk; + std::shared_ptr vk; NativeTypes::uint32 vk_index; MembershipWitness vk_sibling_path; diff --git a/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp b/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp index 58e415e9..f93c3fcb 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/root/root_rollup_inputs.hpp @@ -2,7 +2,7 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp" +#include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" #include "aztec3/constants.hpp" #include #include diff --git a/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/cpp/src/aztec3/circuits/rollup/base/.test.cpp index 65f60ab4..e7d776a0 100644 --- a/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -90,7 +90,6 @@ using aztec3::circuits::abis::AppendOnlyTreeSnapshot; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::NullifierLeafPreimage; -using aztec3::circuits::abis::PreviousRollupData; using aztec3::circuits::rollup::native_base_rollup::BaseRollupInputs; using aztec3::circuits::rollup::native_base_rollup::BaseRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::ConstantRollupData; @@ -463,23 +462,4 @@ TEST_F(base_rollup_tests, test_cbind_0) run_cbind(inputs, ignored_public_inputs, false); } -TEST(private_kernel_tests, test_dummy_previous_rollup_cbind) -{ - uint8_t const* cbind_previous_buf; - size_t cbind_buf_size = base_rollup__dummy_previous_rollup(&cbind_previous_buf); - - PreviousRollupData previous = utils::dummy_previous_rollup_with_vk_proof(); - std::vector expected_vec; - write(expected_vec, previous); - - // Just compare the first 10 bytes of the serialized public outputs - // TODO this is not a good test - if (cbind_buf_size > 10) { - // for (size_t 0; i < public_inputs_size; i++) { - for (size_t i = 0; i < 10; i++) { - ASSERT_EQ(cbind_previous_buf[i], expected_vec[i]); - } - } -} - } // namespace aztec3::circuits::rollup::base::native_base_rollup_circuit diff --git a/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index b801b508..d40a4787 100644 --- a/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -20,8 +20,6 @@ namespace { using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::BaseRollupInputs; using aztec3::circuits::abis::BaseRollupPublicInputs; -using aztec3::circuits::abis::PreviousRollupData; -using aztec3::circuits::rollup::base::utils::dummy_previous_rollup_with_vk_proof; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; using plonk::TurboComposer; @@ -56,21 +54,6 @@ WASM_EXPORT size_t base_rollup__init_verification_key(uint8_t const* pk_buf, uin return vk_vec.size(); } -WASM_EXPORT size_t base_rollup__dummy_previous_rollup(uint8_t const** previous_rollup_buf) -{ - PreviousRollupData previous_rollup = dummy_previous_rollup_with_vk_proof(); - - std::vector previous_rollup_vec; - write(previous_rollup_vec, previous_rollup); - - auto raw_buf = (uint8_t*)malloc(previous_rollup_vec.size()); - memcpy(raw_buf, (void*)previous_rollup_vec.data(), previous_rollup_vec.size()); - - *previous_rollup_buf = raw_buf; - - return previous_rollup_vec.size(); -} - WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, uint8_t const** base_rollup_public_inputs_buf) { diff --git a/cpp/src/aztec3/circuits/rollup/base/init.hpp b/cpp/src/aztec3/circuits/rollup/base/init.hpp index d9b5dc8d..70b232d8 100644 --- a/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -3,7 +3,6 @@ #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" -#include "aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" diff --git a/cpp/src/aztec3/circuits/rollup/base/utils.cpp b/cpp/src/aztec3/circuits/rollup/base/utils.cpp index 542f1088..106cab7e 100644 --- a/cpp/src/aztec3/circuits/rollup/base/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/utils.cpp @@ -5,7 +5,6 @@ #include #include #include "aztec3/circuits/abis/private_kernel/new_contract_data.hpp" -#include "aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp" namespace { using NT = aztec3::utils::types::NativeTypes; @@ -17,7 +16,6 @@ using aztec3::circuits::abis::BaseRollupPublicInputs; using aztec3::circuits::abis::ConstantRollupData; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::NullifierLeafPreimage; -using aztec3::circuits::abis::PreviousRollupData; using aztec3::circuits::abis::private_kernel::NewContractData; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_with_vk_proof; @@ -89,24 +87,4 @@ BaseRollupInputs dummy_base_rollup_inputs_with_vk_proof() return baseRollupInputs; } -PreviousRollupData dummy_previous_rollup_with_vk_proof() -{ - BaseRollupInputs emptyInputs = dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); - - // just for mocked vk and proof - // TODO create generic utility for mocked vk and proof - PreviousKernelData mocked_kernel = dummy_previous_kernel_with_vk_proof(); - - PreviousRollupData previous_rollup = { - .base_rollup_public_inputs = outputs, - .proof = mocked_kernel.proof, - .vk = mocked_kernel.vk, - .vk_index = 0, - .vk_sibling_path = MembershipWitness(), - }; - - return previous_rollup; -} - } // namespace aztec3::circuits::rollup::base::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/base/utils.hpp b/cpp/src/aztec3/circuits/rollup/base/utils.hpp index b9222925..36840ccc 100644 --- a/cpp/src/aztec3/circuits/rollup/base/utils.hpp +++ b/cpp/src/aztec3/circuits/rollup/base/utils.hpp @@ -7,10 +7,8 @@ namespace aztec3::circuits::rollup::base::utils { namespace { using NT = aztec3::utils::types::NativeTypes; using aztec3::circuits::abis::BaseRollupInputs; -using aztec3::circuits::abis::PreviousRollupData; } // namespace BaseRollupInputs dummy_base_rollup_inputs_with_vk_proof(); -PreviousRollupData dummy_previous_rollup_with_vk_proof(); } // namespace aztec3::circuits::rollup::base::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp new file mode 100644 index 00000000..15415aed --- /dev/null +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp @@ -0,0 +1,85 @@ +#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" +#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/rollup/merge/utils.hpp" +#include "aztec3/constants.hpp" +#include "barretenberg/proof_system/verification_key/verification_key.hpp" +#include "index.hpp" +#include "init.hpp" + +#include +#include +#include "aztec3/circuits/abis/private_kernel/new_contract_data.hpp" +#include "aztec3/circuits/rollup/base/utils.hpp" +// #include "aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp" + +namespace { +using NT = aztec3::utils::types::NativeTypes; +using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; + +using aztec3::circuits::abis::AppendOnlyTreeSnapshot; +using aztec3::circuits::abis::BaseRollupPublicInputs; +using aztec3::circuits::abis::ConstantRollupData; +using aztec3::circuits::abis::MembershipWitness; +using aztec3::circuits::abis::MergeRollupInputs; +using aztec3::circuits::abis::MergeRollupPublicInputs; +using aztec3::circuits::abis::PreviousRollupData; +using aztec3::circuits::abis::private_kernel::NewContractData; + +using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_with_vk_proof; + +using plonk::TurboComposer; +} // namespace + +namespace aztec3::circuits::rollup::base::utils { + +// Helper method since MergeRollupInputs.PreviousRollupData can only take the type of `MergeRollupPublicInputs` +// So we convert the output of base to look like output of merge and add the `rollup_type` field. +MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( + BaseRollupPublicInputs baseRollupPublicInputs) +{ + MergeRollupPublicInputs mergeRollupPublicInputs = { + .rollup_type = abis::BASE_ROLLUP_TYPE, + .end_aggregation_object = baseRollupPublicInputs.end_aggregation_object, + .constants = baseRollupPublicInputs.constants, + .start_private_data_tree_snapshot = baseRollupPublicInputs.start_private_data_tree_snapshot, + .end_private_data_tree_snapshot = baseRollupPublicInputs.end_private_data_tree_snapshot, + .start_nullifier_tree_snapshot = baseRollupPublicInputs.start_nullifier_tree_snapshot, + .end_nullifier_tree_snapshot = baseRollupPublicInputs.end_nullifier_tree_snapshot, + .start_contract_tree_snapshot = baseRollupPublicInputs.start_contract_tree_snapshot, + .end_contract_tree_snapshot = baseRollupPublicInputs.end_contract_tree_snapshot, + .calldata_hash = baseRollupPublicInputs.calldata_hash + }; + return mergeRollupPublicInputs; +} + +PreviousRollupData dummy_previous_rollup_with_vk_proof() +{ + // MergeInput requires base_rollup_public_inputs. So create a dummy BaseRollupInput object and pass it through the + // base rollup circuit. + auto emptyInputs = dummy_base_rollup_inputs_with_vk_proof(); + BaseRollupPublicInputs dummy_base_public_inputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); + + // just for mocked vk and proof + // Need a way to extract a proof from Base Rollup Circuit. Until then use kernel as a hack. + PreviousKernelData mocked_kernel = dummy_previous_kernel_with_vk_proof(); + + PreviousRollupData previous_rollup = { + .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(dummy_base_public_inputs), + .proof = mocked_kernel.proof, + .vk = mocked_kernel.vk, + .vk_index = 0, + .vk_sibling_path = MembershipWitness(), + }; + + return previous_rollup; +} + +MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof() +{ + MergeRollupInputs merge_rollup_inputs = { .previous_rollup_data = { dummy_previous_rollup_with_vk_proof(), + dummy_previous_rollup_with_vk_proof() } }; + return merge_rollup_inputs; +} +} // namespace aztec3::circuits::rollup::base::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp new file mode 100644 index 00000000..eb86ed87 --- /dev/null +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" +#include "index.hpp" +#include "init.hpp" + +namespace aztec3::circuits::rollup::merge::utils { + +namespace { +using NT = aztec3::utils::types::NativeTypes; +using aztec3::circuits::abis::BaseRollupPublicInputs; +using aztec3::circuits::abis::MergeRollupInputs; +using aztec3::circuits::abis::MergeRollupPublicInputs; +using aztec3::circuits::abis::PreviousRollupData; +} // namespace + +MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs(BaseRollupPublicInputs); +MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof(); +PreviousRollupData dummy_previous_rollup_with_vk_proof(); + +} // namespace aztec3::circuits::rollup::merge::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 0fa7fb89..21e25b73 100644 --- a/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -7,11 +7,12 @@ #include "aztec3/circuits/abis/membership_witness.hpp" #include "aztec3/circuits/abis/private_kernel/new_contract_data.hpp" #include "aztec3/circuits/abis/private_kernel/previous_kernel_data.hpp" -#include "aztec3/circuits/abis/rollup/base/previous_rollup_data.hpp" +#include "aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/nullifier_leaf_preimage.hpp" #include "aztec3/circuits/rollup/base/init.hpp" #include "aztec3/circuits/rollup/base/utils.hpp" #include "aztec3/circuits/kernel/private/utils.hpp" +#include "aztec3/circuits/rollup/merge/utils.hpp" #include "aztec3/constants.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" @@ -86,7 +87,8 @@ using aztec3::circuits::apps::test_apps::escrow::deposit; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_with_vk_proof; using aztec3::circuits::mock::mock_kernel_circuit; using aztec3::circuits::rollup::base::utils::dummy_base_rollup_inputs_with_vk_proof; -using aztec3::circuits::rollup::base::utils::dummy_previous_rollup_with_vk_proof; +using aztec3::circuits::rollup::merge::utils::convert_base_public_inputs_to_merge_public_inputs; +using aztec3::circuits::rollup::merge::utils::dummy_previous_rollup_with_vk_proof; // using aztec3::circuits::mock::mock_kernel_inputs; using aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -183,8 +185,8 @@ class root_rollup_tests : public ::testing::Test { dummy_previous_rollup_with_vk_proof(), }; - previous_rollup_data[1].base_rollup_public_inputs.constants = - previous_rollup_data[0].base_rollup_public_inputs.constants; + previous_rollup_data[1].merge_rollup_public_inputs.constants = + previous_rollup_data[0].merge_rollup_public_inputs.constants; RootRollupInputs rootRollupInputs = { .previous_rollup_data = previous_rollup_data, @@ -313,16 +315,18 @@ TEST_F(root_rollup_tests, almost_full_root) base_inputs_2.constants = base_inputs_1.constants; PreviousRollupData r1 = { - .base_rollup_public_inputs = base_outputs_1, - .proof = base_inputs_1.kernel_data[0].proof, + .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_outputs_1), + .proof = base_inputs_1.kernel_data[0].proof, // TODO: this is a hack, we should be able to use the proof from + // base_outputs_1 .vk = base_inputs_1.kernel_data[0].vk, .vk_index = 0, .vk_sibling_path = MembershipWitness(), }; PreviousRollupData r2 = { - .base_rollup_public_inputs = base_outputs_2, - .proof = base_inputs_1.kernel_data[0].proof, + .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_outputs_2), + .proof = base_inputs_1.kernel_data[0].proof, // TODO: this is a hack, we should be able to use the proof from + // base_outputs_2 .vk = base_inputs_1.kernel_data[0].vk, .vk_index = 0, .vk_sibling_path = MembershipWitness(), 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 c14adc60..765c92ab 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 @@ -35,7 +35,13 @@ bool verify_merge_proof(NT::Proof merge_proof) AggregationObject aggregate_proofs(RootRollupInputs const& rootRollupInputs) { // TODO: NOTE: for now we simply return the aggregation object from the first proof - return rootRollupInputs.previous_rollup_data[0].base_rollup_public_inputs.end_aggregation_object; + return rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object; +} + +void assert_both_input_proofs_of_same_rollup_type(RootRollupInputs rootRollupInputs) +{ + assert(rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == + rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); } bool is_constants_equal(ConstantRollupData left, ConstantRollupData right) @@ -74,7 +80,7 @@ std::array compute_calldata_hash(RootRollupInputs const& rootRollupInputs std::array calldata_hash_input_bytes; for (uint8_t i = 0; i < 2; i++) { std::array calldata_hash_fr = - rootRollupInputs.previous_rollup_data[i].base_rollup_public_inputs.calldata_hash; + rootRollupInputs.previous_rollup_data[i].merge_rollup_public_inputs.calldata_hash; auto high_buffer = calldata_hash_fr[0].to_buffer(); auto low_buffer = calldata_hash_fr[1].to_buffer(); @@ -129,6 +135,10 @@ RootRollupPublicInputs root_rollup_circuit(RootRollupInputs const& rootRollupInp // old -> leftmost // new -> rightmost + // 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); + AggregationObject aggregation_object = aggregate_proofs(rootRollupInputs); // Verify the previous merge proofs (for now these are actually base proofs) @@ -137,8 +147,8 @@ RootRollupPublicInputs root_rollup_circuit(RootRollupInputs const& rootRollupInp assert(verify_merge_proof(proof)); } - auto left = rootRollupInputs.previous_rollup_data[0].base_rollup_public_inputs; - auto right = rootRollupInputs.previous_rollup_data[1].base_rollup_public_inputs; + auto left = rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; + auto right = rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; // Constants must be the same between left and right assert(is_constants_equal(left.constants, right.constants)); From 095526fea2c9a889aad3ef3d0c561a7273f4231b Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Tue, 4 Apr 2023 09:40:26 +0000 Subject: [PATCH 3/8] fix ci --- .../merge/merge_rollup_public_inputs.hpp | 8 +++---- .../merge/native_merge_rollup_circuit.cpp | 21 ++++++++++--------- .../aztec3/circuits/rollup/merge/utils.cpp | 7 +++---- .../aztec3/circuits/rollup/merge/utils.hpp | 3 ++- .../root/native_root_rollup_circuit.cpp | 1 + 5 files changed, 21 insertions(+), 19 deletions(-) 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 9a53e11d..4feb14a1 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 @@ -51,7 +51,7 @@ template void read(uint8_t const*& it, MergeRollupPublicInputs void write(std::vector& buf, MergeRollupPublicI write(buf, obj.start_private_data_tree_snapshot); write(buf, obj.end_private_data_tree_snapshot); write(buf, obj.start_nullifier_tree_snapshot); - write(buf, obj.end_nullifier_tree_snapshots); + write(buf, obj.end_nullifier_tree_snapshot); write(buf, obj.start_contract_tree_snapshot); write(buf, obj.end_contract_tree_snapshot); write(buf, obj.calldata_hash); @@ -91,8 +91,8 @@ template std::ostream& operator<<(std::ostream& os, MergeRollupPu "start_nullifier_tree_snapshot:\n" << obj.start_nullifier_tree_snapshot << "\n" - "end_nullifier_tree_snapshots:\n" - << obj.end_nullifier_tree_snapshots + "end_nullifier_tree_snapshot:\n" + << obj.end_nullifier_tree_snapshot << "\n" "start_contract_tree_snapshot:\n" << obj.start_contract_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 cf8ed251..7f826f33 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 @@ -35,20 +35,14 @@ void assert_both_input_proofs_of_same_rollup_type(MergeRollupInputs mergeRollupI { assert(mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); + (void)mergeRollupInputs; } void assert_equal_constants(ConstantRollupData left, ConstantRollupData right) { - assert(left.base_rollup_vk_hash == right.base_rollup_vk_hash); - assert(left.merge_rollup_vk_hash == right.merge_rollup_vk_hash); - assert(left.private_kernel_vk_tree_root == right.private_kernel_vk_tree_root); - assert(left.public_kernel_vk_tree_root == right.public_kernel_vk_tree_root); - assert(left.start_tree_of_historic_private_data_tree_roots_snapshot == - right.start_tree_of_historic_private_data_tree_roots_snapshot); - assert(left.start_tree_of_historic_contract_tree_roots_snapshot == - right.start_tree_of_historic_contract_tree_roots_snapshot); - assert(left.tree_of_historic_l1_to_l2_msg_tree_roots_snapshot == - right.tree_of_historic_l1_to_l2_msg_tree_roots_snapshot); + assert(left == right); + (void)left; + (void)right; } // function that does sha256 hash of the calldata from each previous rollup data @@ -109,6 +103,13 @@ void ensure_prev_rollups_follow_on_from_each_other(MergeRollupInputs mergeRollup assert(privateDataEndSnapshot0 == privateDataStartSnapshot1 && nullifierEndSnapshot0 == nullifierStartSnapshot1 && contractEndSnapshot0 == contractStartSnapshot1); + // void variables since despite using in assert, it says, "unused variable" + (void)privateDataEndSnapshot0; + (void)privateDataStartSnapshot1; + (void)nullifierEndSnapshot0; + (void)nullifierStartSnapshot1; + (void)contractEndSnapshot0; + (void)contractStartSnapshot1; } MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs) diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp index 15415aed..49669e9b 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp @@ -1,7 +1,6 @@ #include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" -#include "aztec3/circuits/rollup/merge/utils.hpp" #include "aztec3/constants.hpp" #include "barretenberg/proof_system/verification_key/verification_key.hpp" #include "index.hpp" @@ -31,7 +30,7 @@ using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_wit using plonk::TurboComposer; } // namespace -namespace aztec3::circuits::rollup::base::utils { +namespace aztec3::circuits::rollup::merge::utils { // Helper method since MergeRollupInputs.PreviousRollupData can only take the type of `MergeRollupPublicInputs` // So we convert the output of base to look like output of merge and add the `rollup_type` field. @@ -57,7 +56,7 @@ PreviousRollupData dummy_previous_rollup_with_vk_proof() { // MergeInput requires base_rollup_public_inputs. So create a dummy BaseRollupInput object and pass it through the // base rollup circuit. - auto emptyInputs = dummy_base_rollup_inputs_with_vk_proof(); + auto emptyInputs = base::utils::dummy_base_rollup_inputs_with_vk_proof(); BaseRollupPublicInputs dummy_base_public_inputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); @@ -82,4 +81,4 @@ MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof() dummy_previous_rollup_with_vk_proof() } }; return merge_rollup_inputs; } -} // namespace aztec3::circuits::rollup::base::utils \ No newline at end of file +} // namespace aztec3::circuits::rollup::merge::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp index eb86ed87..1a574060 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp @@ -13,7 +13,8 @@ using aztec3::circuits::abis::MergeRollupPublicInputs; using aztec3::circuits::abis::PreviousRollupData; } // namespace -MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs(BaseRollupPublicInputs); +MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( + BaseRollupPublicInputs baseRollupPublicInputs); MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof(); PreviousRollupData dummy_previous_rollup_with_vk_proof(); 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 765c92ab..456b8874 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 @@ -42,6 +42,7 @@ void assert_both_input_proofs_of_same_rollup_type(RootRollupInputs rootRollupInp { assert(rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); + (void)rootRollupInputs; } bool is_constants_equal(ConstantRollupData left, ConstantRollupData right) From 4b6aed4350b0e69a995f7fe46dadcf34cd6b6a21 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Tue, 4 Apr 2023 10:11:05 +0000 Subject: [PATCH 4/8] 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 ++++++++++++ cpp/src/aztec3/circuits/rollup/merge/utils.cpp | 1 + .../rollup/root/native_root_rollup_circuit.cpp | 8 ++++++++ 7 files changed, 45 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/merge/utils.cpp b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp index 49669e9b..d91723d5 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp @@ -39,6 +39,7 @@ MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( { MergeRollupPublicInputs mergeRollupPublicInputs = { .rollup_type = abis::BASE_ROLLUP_TYPE, + .rollup_subtree_height = baseRollupPublicInputs.rollup_subtree_height, .end_aggregation_object = baseRollupPublicInputs.end_aggregation_object, .constants = baseRollupPublicInputs.constants, .start_private_data_tree_snapshot = baseRollupPublicInputs.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); From 29da979e544103434952c022829fe73c0b20f38a Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Tue, 4 Apr 2023 13:52:04 +0000 Subject: [PATCH 5/8] add tests --- .../aztec3/circuits/rollup/merge/.test.cpp | 167 ++++++++++++++++++ .../merge/native_merge_rollup_circuit.cpp | 14 +- .../aztec3/circuits/rollup/merge/utils.cpp | 35 ++-- .../aztec3/circuits/rollup/merge/utils.hpp | 2 +- cpp/src/aztec3/circuits/rollup/root/.test.cpp | 13 +- 5 files changed, 204 insertions(+), 27 deletions(-) diff --git a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index e69de29b..b4ff1bad 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -0,0 +1,167 @@ +#include +#include +#include "aztec3/circuits/rollup/merge/init.hpp" +#include "aztec3/circuits/rollup/merge/utils.hpp" + +namespace { +using aztec3::circuits::rollup::merge::utils::dummy_merge_rollup_inputs_with_vk_proof; +using aztec3::circuits::rollup::native_merge_rollup::merge_rollup_circuit; +using aztec3::circuits::rollup::native_merge_rollup::MergeRollupInputs; +using aztec3::circuits::rollup::native_merge_rollup::MergeRollupPublicInputs; +using aztec3::circuits::rollup::native_merge_rollup::NT; + +} // namespace +namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit { + +class merge_rollup_tests : public ::testing::Test {}; + +TEST_F(merge_rollup_tests, test_different_rollup_type_fails) +{ + auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); + mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type = 0; + mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type = 1; + EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_rollup_type.*failed."); +} + +TEST_F(merge_rollup_tests, test_different_rollup_height_fails) +{ + auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); + mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height = 0; + mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height = 1; + EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_height_and_return.*failed."); +} + +TEST_F(merge_rollup_tests, test_constants_different_failure) +{ + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + inputs.previous_rollup_data[0].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); + inputs.previous_rollup_data[1].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); + + EXPECT_DEATH(merge_rollup_circuit(inputs), ".*assert_equal_constants.*failed."); +} + +TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) +{ + MergeRollupInputs dummyInputs = dummy_merge_rollup_inputs_with_vk_proof(); + auto inputA = dummyInputs; + inputA.previous_rollup_data[0].merge_rollup_public_inputs.end_private_data_tree_snapshot = { + .root = fr(0), .next_available_leaf_index = 0 + }; + inputA.previous_rollup_data[1].merge_rollup_public_inputs.start_private_data_tree_snapshot = { + .root = fr(1), .next_available_leaf_index = 0 + }; + + EXPECT_DEATH(merge_rollup_circuit(inputA), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); + + // do the same for nullifier tree + auto inputB = dummyInputs; + inputB.previous_rollup_data[0].merge_rollup_public_inputs.end_nullifier_tree_snapshot = { + .root = fr(0), .next_available_leaf_index = 0 + }; + inputB.previous_rollup_data[1].merge_rollup_public_inputs.start_nullifier_tree_snapshot = { + .root = fr(1), .next_available_leaf_index = 0 + }; + EXPECT_DEATH(merge_rollup_circuit(inputB), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); + + // do the same for contract tree + auto inputC = dummyInputs; + inputC.previous_rollup_data[0].merge_rollup_public_inputs.end_contract_tree_snapshot = { + .root = fr(0), .next_available_leaf_index = 0 + }; + inputC.previous_rollup_data[1].merge_rollup_public_inputs.start_contract_tree_snapshot = { + .root = fr(1), .next_available_leaf_index = 0 + }; + EXPECT_DEATH(merge_rollup_circuit(inputC), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); +} + +TEST_F(merge_rollup_tests, test_rollup_fields_are_set_correctly) +{ + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + // check that rollup type is set to merge + ASSERT_EQ(outputs.rollup_type, 1); + // check that rollup height is incremented + ASSERT_EQ(outputs.rollup_subtree_height, + inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height + 1); + + // set inputs to have a merge rollup type and set the rollup height and test again. + inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type = 1; + inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height = 1; + + inputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type = 1; + inputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height = 1; + + outputs = merge_rollup_circuit(inputs); + ASSERT_EQ(outputs.rollup_type, 1); + ASSERT_EQ(outputs.rollup_subtree_height, 2); +} + +TEST_F(merge_rollup_tests, test_start_and_end_snapshots) +{ + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + // check that start and end snapshots are set correctly + ASSERT_EQ(outputs.start_private_data_tree_snapshot, + inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_private_data_tree_snapshot); + ASSERT_EQ(outputs.end_private_data_tree_snapshot, + inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_private_data_tree_snapshot); + + ASSERT_EQ(outputs.start_nullifier_tree_snapshot, + inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_nullifier_tree_snapshot); + ASSERT_EQ(outputs.end_nullifier_tree_snapshot, + inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_nullifier_tree_snapshot); + + ASSERT_EQ(outputs.start_contract_tree_snapshot, + inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_contract_tree_snapshot); + ASSERT_EQ(outputs.end_contract_tree_snapshot, + inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_contract_tree_snapshot); +} + +TEST_F(merge_rollup_tests, test_calldata_hash) +{ + std::vector zero_bytes_vec(704, 0); + auto call_data_hash_inner = sha256::sha256(zero_bytes_vec); + + std::array hash_input; + for (uint8_t i = 0; i < 32; ++i) { + hash_input[i] = call_data_hash_inner[i]; + hash_input[32 + i] = call_data_hash_inner[i]; + } + + std::vector calldata_hash_input_bytes_vec(hash_input.begin(), hash_input.end()); + + auto expected_calldata_hash = sha256::sha256(calldata_hash_input_bytes_vec); + + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + + std::array actual_calldata_hash_fr = outputs.calldata_hash; + auto high_buffer = actual_calldata_hash_fr[0].to_buffer(); + auto low_buffer = actual_calldata_hash_fr[1].to_buffer(); + + std::array actual_calldata_hash; + for (uint8_t i = 0; i < 16; ++i) { + actual_calldata_hash[i] = high_buffer[16 + i]; + actual_calldata_hash[16 + i] = low_buffer[16 + i]; + } + + ASSERT_EQ(expected_calldata_hash, actual_calldata_hash); +} + +TEST_F(merge_rollup_tests, test_constants_dont_change) +{ + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + ASSERT_EQ(inputs.previous_rollup_data[0].merge_rollup_public_inputs.constants, outputs.constants); + ASSERT_EQ(inputs.previous_rollup_data[1].merge_rollup_public_inputs.constants, outputs.constants); +} + +TEST_F(merge_rollup_tests, test_aggregate) +{ + // TODO: Fix this when aggregation works + MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); + MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + ASSERT_EQ(inputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object.public_inputs, + outputs.end_aggregation_object.public_inputs); +} +} // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit 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 02af280e..5436d1ee 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 @@ -133,20 +133,20 @@ MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs 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. - // compute calldata hash: - auto new_calldata_hash = compute_calldata_hash(mergeRollupInputs); + // Check that the constants are the same in both proofs + auto left = mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; + auto right = mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; + assert_equal_constants(left.constants, right.constants); // Ensure the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they // follow on from one-another). This ensures the low_leaves which were updated in rollup 0 are being used as the // 'starting' pointers in rollup 1. ensure_prev_rollups_follow_on_from_each_other(mergeRollupInputs); - AggregationObject aggregation_object = aggregate_proofs(mergeRollupInputs); + // compute calldata hash: + auto new_calldata_hash = compute_calldata_hash(mergeRollupInputs); - // Check that the constants are the same in both proofs - auto left = mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; - auto right = mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; - assert_equal_constants(left.constants, right.constants); + AggregationObject aggregation_object = aggregate_proofs(mergeRollupInputs); MergeRollupPublicInputs public_inputs = { .rollup_type = abis::MERGE_ROLLUP_TYPE, diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp index d91723d5..7def4b18 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp @@ -1,3 +1,4 @@ +#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" @@ -53,33 +54,45 @@ MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( return mergeRollupPublicInputs; } -PreviousRollupData dummy_previous_rollup_with_vk_proof() +std::array, 2> previous_rollups_with_vk_proof_that_follow_on() { - // MergeInput requires base_rollup_public_inputs. So create a dummy BaseRollupInput object and pass it through the - // base rollup circuit. - auto emptyInputs = base::utils::dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs dummy_base_public_inputs = - aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); + auto input1 = base::utils::dummy_base_rollup_inputs_with_vk_proof(); + BaseRollupPublicInputs base_public_input1 = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(input1); + + auto input2 = input1; + input2.start_private_data_tree_snapshot = base_public_input1.end_private_data_tree_snapshot; + input2.start_nullifier_tree_snapshot = base_public_input1.end_nullifier_tree_snapshot; + input2.start_contract_tree_snapshot = base_public_input1.end_contract_tree_snapshot; + BaseRollupPublicInputs base_public_input2 = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(input2); // just for mocked vk and proof // Need a way to extract a proof from Base Rollup Circuit. Until then use kernel as a hack. PreviousKernelData mocked_kernel = dummy_previous_kernel_with_vk_proof(); - PreviousRollupData previous_rollup = { - .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(dummy_base_public_inputs), + PreviousRollupData previous_rollup1 = { + .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_public_input1), + .proof = mocked_kernel.proof, + .vk = mocked_kernel.vk, + .vk_index = 0, + .vk_sibling_path = MembershipWitness(), + }; + PreviousRollupData previous_rollup2 = { + .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_public_input2), .proof = mocked_kernel.proof, .vk = mocked_kernel.vk, .vk_index = 0, .vk_sibling_path = MembershipWitness(), }; - return previous_rollup; + return { previous_rollup1, previous_rollup2 }; } MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof() { - MergeRollupInputs merge_rollup_inputs = { .previous_rollup_data = { dummy_previous_rollup_with_vk_proof(), - dummy_previous_rollup_with_vk_proof() } }; + MergeRollupInputs merge_rollup_inputs = { .previous_rollup_data = + previous_rollups_with_vk_proof_that_follow_on() }; return merge_rollup_inputs; } } // namespace aztec3::circuits::rollup::merge::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp index 1a574060..95bf9ea0 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp @@ -16,6 +16,6 @@ using aztec3::circuits::abis::PreviousRollupData; MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( BaseRollupPublicInputs baseRollupPublicInputs); MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof(); -PreviousRollupData dummy_previous_rollup_with_vk_proof(); +std::array, 2> previous_rollups_with_vk_proof_that_follow_on(); } // namespace aztec3::circuits::rollup::merge::utils \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 21e25b73..28c0d2b9 100644 --- a/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -88,7 +88,7 @@ using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_wit using aztec3::circuits::mock::mock_kernel_circuit; using aztec3::circuits::rollup::base::utils::dummy_base_rollup_inputs_with_vk_proof; using aztec3::circuits::rollup::merge::utils::convert_base_public_inputs_to_merge_public_inputs; -using aztec3::circuits::rollup::merge::utils::dummy_previous_rollup_with_vk_proof; +using aztec3::circuits::rollup::merge::utils::previous_rollups_with_vk_proof_that_follow_on; // using aztec3::circuits::mock::mock_kernel_inputs; using aztec3::circuits::abis::AppendOnlyTreeSnapshot; @@ -180,16 +180,13 @@ class root_rollup_tests : public ::testing::Test { protected: RootRollupInputs getEmptyRootRollupInputs() { - std::array, 2> previous_rollup_data = { - dummy_previous_rollup_with_vk_proof(), - dummy_previous_rollup_with_vk_proof(), - }; + // std::array, 2> previous_rollup_data = previous_rollups_with_vk_proof_that_follow_on(); - previous_rollup_data[1].merge_rollup_public_inputs.constants = - previous_rollup_data[0].merge_rollup_public_inputs.constants; + // previous_rollup_data[1].merge_rollup_public_inputs.constants = + // previous_rollup_data[0].merge_rollup_public_inputs.constants; RootRollupInputs rootRollupInputs = { - .previous_rollup_data = previous_rollup_data, + .previous_rollup_data = previous_rollups_with_vk_proof_that_follow_on(), .new_historic_private_data_tree_root_sibling_path = { 0 }, .new_historic_contract_tree_root_sibling_path = { 0 }, }; From c71594a1a6b2a1619de01d4e90981c8eed1f2eb1 Mon Sep 17 00:00:00 2001 From: Lasse Herskind <16536249+LHerskind@users.noreply.github.com> Date: Wed, 5 Apr 2023 14:18:12 +0200 Subject: [PATCH 6/8] test: change expectd failure regex (#164) --- cpp/src/aztec3/circuits/rollup/merge/.test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index b4ff1bad..5d5012f7 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -20,7 +20,7 @@ TEST_F(merge_rollup_tests, test_different_rollup_type_fails) auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type = 0; mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type = 1; - EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_rollup_type.*failed."); + EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_rollup_type.*"); } TEST_F(merge_rollup_tests, test_different_rollup_height_fails) @@ -28,7 +28,7 @@ TEST_F(merge_rollup_tests, test_different_rollup_height_fails) auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height = 0; mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height = 1; - EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_height_and_return.*failed."); + EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_height_and_return.*"); } TEST_F(merge_rollup_tests, test_constants_different_failure) @@ -37,7 +37,7 @@ TEST_F(merge_rollup_tests, test_constants_different_failure) inputs.previous_rollup_data[0].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); inputs.previous_rollup_data[1].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); - EXPECT_DEATH(merge_rollup_circuit(inputs), ".*assert_equal_constants.*failed."); + EXPECT_DEATH(merge_rollup_circuit(inputs), ".*assert_equal_constants.*"); } TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) @@ -51,7 +51,7 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) .root = fr(1), .next_available_leaf_index = 0 }; - EXPECT_DEATH(merge_rollup_circuit(inputA), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); + EXPECT_DEATH(merge_rollup_circuit(inputA), ".*ensure_prev_rollups_follow_on_from_each_other.*"); // do the same for nullifier tree auto inputB = dummyInputs; @@ -61,7 +61,7 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) inputB.previous_rollup_data[1].merge_rollup_public_inputs.start_nullifier_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - EXPECT_DEATH(merge_rollup_circuit(inputB), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); + EXPECT_DEATH(merge_rollup_circuit(inputB), ".*ensure_prev_rollups_follow_on_from_each_other.*"); // do the same for contract tree auto inputC = dummyInputs; @@ -71,7 +71,7 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) inputC.previous_rollup_data[1].merge_rollup_public_inputs.start_contract_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; - EXPECT_DEATH(merge_rollup_circuit(inputC), ".*ensure_prev_rollups_follow_on_from_each_other.*failed."); + EXPECT_DEATH(merge_rollup_circuit(inputC), ".*ensure_prev_rollups_follow_on_from_each_other.*"); } TEST_F(merge_rollup_tests, test_rollup_fields_are_set_correctly) From fa3eb6c72c82929961dc1b1c48b43c24f691e0c8 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Wed, 5 Apr 2023 16:36:33 +0100 Subject: [PATCH 7/8] just use one type of public inputs for base/merge (#168) --- cpp/barretenberg | 2 +- cpp/src/aztec3/circuits/abis/c_bind.cpp | 14 +-- ...=> base_or_merge_rollup_public_inputs.hpp} | 34 ++++-- .../merge/merge_rollup_public_inputs.hpp | 114 ------------------ .../rollup/merge/previous_rollup_data.hpp | 10 +- cpp/src/aztec3/circuits/rollup/base/.test.cpp | 41 ++++--- .../aztec3/circuits/rollup/base/c_bind.cpp | 15 +-- cpp/src/aztec3/circuits/rollup/base/init.hpp | 4 +- .../base/native_base_rollup_circuit.cpp | 9 +- .../base/native_base_rollup_circuit.hpp | 4 +- cpp/src/aztec3/circuits/rollup/base/utils.cpp | 2 +- .../aztec3/circuits/rollup/merge/.test.cpp | 64 +++++----- cpp/src/aztec3/circuits/rollup/merge/init.hpp | 4 +- .../merge/native_merge_rollup_circuit.cpp | 50 ++++---- .../merge/native_merge_rollup_circuit.hpp | 2 +- .../aztec3/circuits/rollup/merge/utils.cpp | 40 ++---- .../aztec3/circuits/rollup/merge/utils.hpp | 6 +- cpp/src/aztec3/circuits/rollup/root/.test.cpp | 11 +- .../root/native_root_rollup_circuit.cpp | 16 +-- 19 files changed, 156 insertions(+), 286 deletions(-) rename cpp/src/aztec3/circuits/abis/rollup/base/{base_rollup_public_inputs.hpp => base_or_merge_rollup_public_inputs.hpp} (83%) delete mode 100644 cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp diff --git a/cpp/barretenberg b/cpp/barretenberg index 9a56aa33..72332474 160000 --- a/cpp/barretenberg +++ b/cpp/barretenberg @@ -1 +1 @@ -Subproject commit 9a56aa3370306d5f9b7e9b6324220f8c713674ef +Subproject commit 723324747c043b1a04d7d014a32d1005e679b635 diff --git a/cpp/src/aztec3/circuits/abis/c_bind.cpp b/cpp/src/aztec3/circuits/abis/c_bind.cpp index 7ddea1cc..784f7cb6 100644 --- a/cpp/src/aztec3/circuits/abis/c_bind.cpp +++ b/cpp/src/aztec3/circuits/abis/c_bind.cpp @@ -8,7 +8,7 @@ #include "function_data.hpp" #include "function_leaf_preimage.hpp" #include "rollup/base/base_rollup_inputs.hpp" -#include "rollup/base/base_rollup_public_inputs.hpp" +#include "rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "rollup/root/root_rollup_public_inputs.hpp" #include "rollup/root/root_rollup_inputs.hpp" #include "private_kernel/previous_kernel_data.hpp" @@ -404,16 +404,16 @@ WASM_EXPORT const char* abis__test_roundtrip_serialize_previous_kernel_data(uint return as_string_output>(kernel_data_buf, size); } -WASM_EXPORT const char* abis__test_roundtrip_serialize_base_rollup_public_inputs(uint8_t const* rollup_inputs_buf, - uint32_t* size) +WASM_EXPORT const char* abis__test_roundtrip_serialize_base_or_merge_rollup_public_inputs( + uint8_t const* rollup_inputs_buf, uint32_t* size) { - return as_string_output>(rollup_inputs_buf, size); + return as_string_output>(rollup_inputs_buf, size); } -WASM_EXPORT const char* abis__test_roundtrip_reserialize_base_rollup_public_inputs(uint8_t const* rollup_inputs_buf, - uint32_t* size) +WASM_EXPORT const char* abis__test_roundtrip_reserialize_base_or_merge_rollup_public_inputs( + uint8_t const* rollup_inputs_buf, uint32_t* size) { - return as_serialized_output>(rollup_inputs_buf, size); + return as_serialized_output>(rollup_inputs_buf, size); } WASM_EXPORT const char* abis__test_roundtrip_serialize_root_rollup_inputs(uint8_t const* rollup_inputs_buf, diff --git a/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp b/cpp/src/aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp similarity index 83% rename from cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp rename to cpp/src/aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp index c64fed96..bd561537 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp @@ -13,16 +13,21 @@ using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using std::is_same; -template struct BaseRollupPublicInputs { +const uint32_t BASE_ROLLUP_TYPE = 0; +const uint32_t MERGE_ROLLUP_TYPE = 1; + +template struct BaseOrMergeRollupPublicInputs { typedef typename NCT::fr fr; typedef typename NCT::AggregationObject AggregationObject; - AggregationObject end_aggregation_object; - ConstantRollupData constants; + uint32_t rollup_type; // 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; + AggregationObject end_aggregation_object; + ConstantRollupData constants; + AppendOnlyTreeSnapshot start_private_data_tree_snapshot; AppendOnlyTreeSnapshot end_private_data_tree_snapshot; @@ -36,16 +41,17 @@ template struct BaseRollupPublicInputs { // Needs to be two fields to accomodate all 256-bits of the hash std::array calldata_hash; - bool operator==(BaseRollupPublicInputs const&) const = default; + bool operator==(BaseOrMergeRollupPublicInputs const&) const = default; }; -template void read(uint8_t const*& it, BaseRollupPublicInputs& obj) +template void read(uint8_t const*& it, BaseOrMergeRollupPublicInputs& obj) { 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.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); @@ -55,13 +61,14 @@ template void read(uint8_t const*& it, BaseRollupPublicInputs void write(std::vector& buf, BaseRollupPublicInputs const& obj) +template void write(std::vector& buf, BaseOrMergeRollupPublicInputs const& obj) { 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.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); @@ -71,16 +78,17 @@ template void write(std::vector& buf, BaseRollupPublicIn write(buf, obj.calldata_hash); }; -template std::ostream& operator<<(std::ostream& os, BaseRollupPublicInputs const& obj) +template std::ostream& operator<<(std::ostream& os, BaseOrMergeRollupPublicInputs const& obj) { - return os << "end_aggregation_object:\n" + return os << "rollup_type:\n" + << obj.rollup_type << "\n" + << "rollup_subtree_height:\n" + << obj.rollup_subtree_height << "\n" + << "end_aggregation_object:\n" << obj.end_aggregation_object << "\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 deleted file mode 100644 index 16c1a982..00000000 --- a/cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once -#include -#include -#include -#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 { - -using aztec3::utils::types::CircuitTypes; -using aztec3::utils::types::NativeTypes; -using std::is_same; - -const uint32_t BASE_ROLLUP_TYPE = 0; -const uint32_t MERGE_ROLLUP_TYPE = 1; - -template struct MergeRollupPublicInputs { - typedef typename NCT::fr fr; - typedef typename NCT::AggregationObject AggregationObject; - - uint32_t rollup_type; - fr rollup_subtree_height; - - AggregationObject end_aggregation_object; - - ConstantRollupData constants; - - AppendOnlyTreeSnapshot start_private_data_tree_snapshot; - AppendOnlyTreeSnapshot end_private_data_tree_snapshot; - - // The only tree root actually updated in this circuit is the nullifier tree, because earlier leaves (of - // low_nullifiers) must be updated to point to the new nullifiers in this circuit. - AppendOnlyTreeSnapshot start_nullifier_tree_snapshot; - AppendOnlyTreeSnapshot end_nullifier_tree_snapshot; - - AppendOnlyTreeSnapshot start_contract_tree_snapshot; - AppendOnlyTreeSnapshot end_contract_tree_snapshot; - - std::array calldata_hash; - - bool operator==(MergeRollupPublicInputs const&) const = default; -}; - -template void read(uint8_t const*& it, MergeRollupPublicInputs& obj) -{ - 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); - read(it, obj.end_private_data_tree_snapshot); - read(it, obj.start_nullifier_tree_snapshot); - read(it, obj.end_nullifier_tree_snapshot); - read(it, obj.start_contract_tree_snapshot); - read(it, obj.end_contract_tree_snapshot); - read(it, obj.calldata_hash); -}; - -template void write(std::vector& buf, MergeRollupPublicInputs const& obj) -{ - 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); - write(buf, obj.end_private_data_tree_snapshot); - write(buf, obj.start_nullifier_tree_snapshot); - write(buf, obj.end_nullifier_tree_snapshot); - write(buf, obj.start_contract_tree_snapshot); - write(buf, obj.end_contract_tree_snapshot); - write(buf, obj.calldata_hash); -}; - -template std::ostream& operator<<(std::ostream& os, MergeRollupPublicInputs const& obj) -{ - 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" - "constants:\n" - << obj.constants - << "\n" - "start_private_data_tree_snapshot:\n" - << obj.start_private_data_tree_snapshot - << "\n" - "end_private_data_tree_snapshot:\n" - << obj.end_private_data_tree_snapshot - << "\n" - "start_nullifier_tree_snapshot:\n" - << obj.start_nullifier_tree_snapshot - << "\n" - "end_nullifier_tree_snapshot:\n" - << obj.end_nullifier_tree_snapshot - << "\n" - "start_contract_tree_snapshot:\n" - << obj.start_contract_tree_snapshot - << "\n" - "end_contract_tree_snapshot:\n" - << obj.end_contract_tree_snapshot - << "\n" - "calldata_hash: " - << obj.calldata_hash << "\n"; -} - -} // namespace aztec3::circuits::abis \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp b/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp index 10c10bbb..4c150adc 100644 --- a/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp +++ b/cpp/src/aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp @@ -1,7 +1,7 @@ #pragma once #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/membership_witness.hpp" -#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" #include #include @@ -15,7 +15,7 @@ using aztec3::utils::types::NativeTypes; using std::is_same; template struct PreviousRollupData { - MergeRollupPublicInputs merge_rollup_public_inputs; + BaseOrMergeRollupPublicInputs base_or_merge_rollup_public_inputs; NativeTypes::Proof proof; std::shared_ptr vk; @@ -29,7 +29,7 @@ template void read(uint8_t const*& it, PreviousRollupData& o { using serialize::read; - read(it, obj.merge_rollup_public_inputs); + read(it, obj.base_or_merge_rollup_public_inputs); read(it, obj.proof); read(it, obj.vk); read(it, obj.vk_index); @@ -40,7 +40,7 @@ template void write(std::vector& buf, PreviousRollupData { using serialize::write; - write(buf, obj.merge_rollup_public_inputs); + write(buf, obj.base_or_merge_rollup_public_inputs); write(buf, obj.proof); write(buf, *obj.vk); write(buf, obj.vk_index); @@ -49,7 +49,7 @@ template void write(std::vector& buf, PreviousRollupData template std::ostream& operator<<(std::ostream& os, PreviousRollupData const& obj) { - return os << "merge_rollup_public_inputs: " << obj.merge_rollup_public_inputs << "\n" + return os << "base_or_merge_rollup_public_inputs: " << obj.base_or_merge_rollup_public_inputs << "\n" << "proof: " << obj.proof << "\n" << "vk: " << obj.vk << "\n" << "vk_index: " << obj.vk_index << "\n" diff --git a/cpp/src/aztec3/circuits/rollup/base/.test.cpp b/cpp/src/aztec3/circuits/rollup/base/.test.cpp index ac4c66a1..a077927e 100644 --- a/cpp/src/aztec3/circuits/rollup/base/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/.test.cpp @@ -96,8 +96,8 @@ using aztec3::circuits::abis::AppendOnlyTreeSnapshot; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::NullifierLeafPreimage; +using aztec3::circuits::rollup::native_base_rollup::BaseOrMergeRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::BaseRollupInputs; -using aztec3::circuits::rollup::native_base_rollup::BaseRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::ConstantRollupData; using aztec3::circuits::rollup::native_base_rollup::NT; @@ -111,7 +111,7 @@ namespace aztec3::circuits::rollup::base::native_base_rollup_circuit { class base_rollup_tests : public ::testing::Test { protected: void run_cbind(BaseRollupInputs& base_rollup_inputs, - BaseRollupPublicInputs& expected_public_inputs, + BaseOrMergeRollupPublicInputs& expected_public_inputs, bool compare_pubins = true) { // TODO might be able to get rid of proving key buffer @@ -136,7 +136,7 @@ class base_rollup_tests : public ::testing::Test { info("PublicInputs size: ", public_inputs_size); if (compare_pubins) { - BaseRollupPublicInputs public_inputs; + BaseOrMergeRollupPublicInputs public_inputs; info("about to read..."); uint8_t const* public_inputs_buf_tmp = public_inputs_buf; read(public_inputs_buf_tmp, public_inputs); @@ -204,7 +204,8 @@ TEST_F(base_rollup_tests, no_new_contract_leafs) // Set the new_contracts_subtree_sibling_path emptyInputs.new_contracts_subtree_sibling_path = sibling_path_of_0; - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); + BaseOrMergeRollupPublicInputs outputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(emptyInputs); AppendOnlyTreeSnapshot expectedEndContractTreeSnapshot = { .root = empty_contract_tree.root(), @@ -245,7 +246,7 @@ TEST_F(base_rollup_tests, contract_leaf_inserted) .root = expeted_end_contracts_snapshot_tree.root(), .next_available_leaf_index = 2, }; - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); @@ -291,7 +292,7 @@ TEST_F(base_rollup_tests, contract_leaf_inserted_in_non_empty_snapshot_tree) .root = expeted_end_contracts_snapshot_tree.root(), .next_available_leaf_index = 14, }; - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(outputs.start_contract_tree_snapshot, inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, expected_end_contracts_snapshot); @@ -330,7 +331,7 @@ TEST_F(base_rollup_tests, new_commitments_tree) .next_available_leaf_index = 8, }; - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(outputs.start_private_data_tree_snapshot, inputs.start_private_data_tree_snapshot); ASSERT_EQ(outputs.end_private_data_tree_snapshot, expected_end_commitments_snapshot); run_cbind(inputs, outputs); @@ -373,7 +374,8 @@ TEST_F(base_rollup_tests, new_nullifier_tree_empty) */ // Run the circuit - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); + BaseOrMergeRollupPublicInputs outputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); /** * ASSERT @@ -406,7 +408,8 @@ TEST_F(base_rollup_tests, new_nullifier_tree_all_larger) */ // Run the circuit - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); + BaseOrMergeRollupPublicInputs outputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); /** * ASSERT @@ -437,7 +440,8 @@ TEST_F(base_rollup_tests, new_nullifier_tree_sparse) */ // Run the circuit - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); + BaseOrMergeRollupPublicInputs outputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); /** * ASSERT @@ -464,7 +468,8 @@ TEST_F(base_rollup_tests, new_nullifier_tree_sparse_attack) BaseRollupInputs testing_inputs = std::get<0>(inputs_and_snapshots); // Run the circuit (SHOULD FAIL WITH AN ASSERT INSTEAD OF THIS!) - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); + BaseOrMergeRollupPublicInputs outputs = + aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(testing_inputs); } // TEST_F(base_rollup_tests, new_commitments_tree) {} @@ -475,7 +480,7 @@ TEST_F(base_rollup_tests, empty_block_calldata_hash) std::vector zero_bytes_vec(704, 0); auto hash = sha256::sha256(zero_bytes_vec); BaseRollupInputs inputs = dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); std::array calldata_hash_fr = outputs.calldata_hash; auto high_buffer = calldata_hash_fr[0].to_buffer(); @@ -545,7 +550,7 @@ TEST_F(base_rollup_tests, calldata_hash) auto hash = sha256::sha256(input_data); - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); // Take the two fields and stich them together to get the calldata hash. std::array calldata_hash_fr = outputs.calldata_hash; @@ -585,13 +590,13 @@ TEST_F(base_rollup_tests, test_compute_membership_historic_private_data) .sibling_path = sibling_path, }; - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); } TEST_F(base_rollup_tests, test_constants_dont_change) { BaseRollupInputs inputs = dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(inputs.constants, outputs.constants); run_cbind(inputs, outputs); } @@ -600,7 +605,7 @@ TEST_F(base_rollup_tests, test_aggregate) { // TODO: Fix this when aggregation works BaseRollupInputs inputs = dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(inputs.kernel_data[0].public_inputs.end.aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); } @@ -608,7 +613,7 @@ TEST_F(base_rollup_tests, test_aggregate) 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); + BaseOrMergeRollupPublicInputs outputs = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(inputs); ASSERT_EQ(outputs.rollup_subtree_height, fr(0)); } @@ -617,7 +622,7 @@ TEST_F(base_rollup_tests, test_proof_verification) {} TEST_F(base_rollup_tests, test_cbind_0) { BaseRollupInputs inputs = dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs ignored_public_inputs; + BaseOrMergeRollupPublicInputs ignored_public_inputs; run_cbind(inputs, ignored_public_inputs, false); } diff --git a/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp b/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp index d40a4787..e2dd0dd8 100644 --- a/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/c_bind.cpp @@ -1,3 +1,4 @@ +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "index.hpp" #include "init.hpp" #include "utils.hpp" @@ -18,8 +19,8 @@ namespace { using NT = aztec3::utils::types::NativeTypes; +using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; -using aztec3::circuits::abis::BaseRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit; using plonk::TurboComposer; @@ -55,7 +56,7 @@ WASM_EXPORT size_t base_rollup__init_verification_key(uint8_t const* pk_buf, uin } WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, - uint8_t const** base_rollup_public_inputs_buf) + uint8_t const** base_or_merge_rollup_public_inputs_buf) { // TODO accept proving key and use that to initialize composers // this info is just to prevent error for unused pk_buf @@ -65,7 +66,7 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, BaseRollupInputs base_rollup_inputs; read(base_rollup_inputs_buf, base_rollup_inputs); - BaseRollupPublicInputs public_inputs = base_rollup_circuit(base_rollup_inputs); + BaseOrMergeRollupPublicInputs public_inputs = base_rollup_circuit(base_rollup_inputs); // TODO for circuit proof version of this function // NT::Proof base_rollup_proof; @@ -80,14 +81,14 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, // copy public inputs to output buffer auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); - *base_rollup_public_inputs_buf = raw_public_inputs_buf; + *base_or_merge_rollup_public_inputs_buf = raw_public_inputs_buf; return public_inputs_vec.size(); } // WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, // bool second_present, -// uint8_t const** base_rollup_public_inputs_buf) +// uint8_t const** base_or_merge_rollup_public_inputs_buf) //{ // // TODO accept proving key and use that to initialize composers // // this info is just to prevent error for unused pk_buf @@ -98,7 +99,7 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, // read(base_rollup_inputs_buf, base_rollup_inputs); // // NT::Proof base_rollup_proof; -// BaseRollupPublicInputs public_inputs; +// BaseOrMergeRollupPublicInputs public_inputs; // if (proverless) { // public_inputs = base_rollup_circuit(base_rollup_inputs); // // mocked proof - zeros @@ -124,7 +125,7 @@ WASM_EXPORT size_t base_rollup__sim(uint8_t const* base_rollup_inputs_buf, // // copy public inputs to output buffer // auto raw_public_inputs_buf = (uint8_t*)malloc(public_inputs_vec.size()); // memcpy(raw_public_inputs_buf, (void*)public_inputs_vec.data(), public_inputs_vec.size()); -// *base_rollup_public_inputs_buf = raw_public_inputs_buf; +// *base_or_merge_rollup_public_inputs_buf = raw_public_inputs_buf; // // return base_rollup_proof.proof_data.size(); //} diff --git a/cpp/src/aztec3/circuits/rollup/base/init.hpp b/cpp/src/aztec3/circuits/rollup/base/init.hpp index 70b232d8..b4e6ee8f 100644 --- a/cpp/src/aztec3/circuits/rollup/base/init.hpp +++ b/cpp/src/aztec3/circuits/rollup/base/init.hpp @@ -4,7 +4,7 @@ #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" #include "aztec3/circuits/abis/rollup/base/base_rollup_inputs.hpp" -#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "barretenberg/stdlib/merkle_tree/memory_tree.hpp" #include "barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp" #include @@ -25,7 +25,7 @@ using NT = aztec3::utils::types::NativeTypes; // Params using ConstantRollupData = abis::ConstantRollupData; using BaseRollupInputs = abis::BaseRollupInputs; -using BaseRollupPublicInputs = abis::BaseRollupPublicInputs; +using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = utils::types::NativeTypes::AggregationObject; 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 29f2c697..287fb084 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 @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include @@ -429,7 +429,7 @@ AppendOnlySnapshot check_nullifier_tree_non_membership_and_insert_to_tree(BaseRo }; } -BaseRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs) +BaseOrMergeRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs) { // TODO: move this into a constant - calc empty nullifier_subtree hash // calc empty subtree root @@ -504,10 +504,11 @@ BaseRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs) AggregationObject aggregation_object = aggregate_proofs(baseRollupInputs); - BaseRollupPublicInputs public_inputs = { + BaseOrMergeRollupPublicInputs public_inputs = { + .rollup_type = abis::BASE_ROLLUP_TYPE, + .rollup_subtree_height = fr(0), .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/base/native_base_rollup_circuit.hpp b/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp index ddf08581..6f920e6d 100644 --- a/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp +++ b/cpp/src/aztec3/circuits/rollup/base/native_base_rollup_circuit.hpp @@ -9,12 +9,12 @@ #include #include -#include +#include #include #include namespace aztec3::circuits::rollup::native_base_rollup { -BaseRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs); +BaseOrMergeRollupPublicInputs base_rollup_circuit(BaseRollupInputs baseRollupInputs); } // namespace aztec3::circuits::rollup::native_base_rollup \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/base/utils.cpp b/cpp/src/aztec3/circuits/rollup/base/utils.cpp index c1ee239d..065dffe3 100644 --- a/cpp/src/aztec3/circuits/rollup/base/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/base/utils.cpp @@ -13,8 +13,8 @@ using NT = aztec3::utils::types::NativeTypes; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; using aztec3::circuits::abis::AppendOnlyTreeSnapshot; +using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::BaseRollupInputs; -using aztec3::circuits::abis::BaseRollupPublicInputs; using aztec3::circuits::abis::ConstantRollupData; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::NullifierLeafPreimage; diff --git a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index 5d5012f7..6d4cd6f5 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -5,9 +5,9 @@ namespace { using aztec3::circuits::rollup::merge::utils::dummy_merge_rollup_inputs_with_vk_proof; +using aztec3::circuits::rollup::native_merge_rollup::BaseOrMergeRollupPublicInputs; using aztec3::circuits::rollup::native_merge_rollup::merge_rollup_circuit; using aztec3::circuits::rollup::native_merge_rollup::MergeRollupInputs; -using aztec3::circuits::rollup::native_merge_rollup::MergeRollupPublicInputs; using aztec3::circuits::rollup::native_merge_rollup::NT; } // namespace @@ -18,24 +18,24 @@ class merge_rollup_tests : public ::testing::Test {}; TEST_F(merge_rollup_tests, test_different_rollup_type_fails) { auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); - mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type = 0; - mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type = 1; + mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 0; + mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_rollup_type.*"); } TEST_F(merge_rollup_tests, test_different_rollup_height_fails) { auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); - mergeInput.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height = 0; - mergeInput.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height = 1; + mergeInput.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 0; + mergeInput.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; EXPECT_DEATH(merge_rollup_circuit(mergeInput), ".*assert_both_input_proofs_of_same_height_and_return.*"); } TEST_F(merge_rollup_tests, test_constants_different_failure) { MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - inputs.previous_rollup_data[0].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); - inputs.previous_rollup_data[1].merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(1); + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.public_kernel_vk_tree_root = fr(0); EXPECT_DEATH(merge_rollup_circuit(inputs), ".*assert_equal_constants.*"); } @@ -44,10 +44,10 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) { MergeRollupInputs dummyInputs = dummy_merge_rollup_inputs_with_vk_proof(); auto inputA = dummyInputs; - inputA.previous_rollup_data[0].merge_rollup_public_inputs.end_private_data_tree_snapshot = { + inputA.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 }; - inputA.previous_rollup_data[1].merge_rollup_public_inputs.start_private_data_tree_snapshot = { + inputA.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; @@ -55,20 +55,20 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) // do the same for nullifier tree auto inputB = dummyInputs; - inputB.previous_rollup_data[0].merge_rollup_public_inputs.end_nullifier_tree_snapshot = { + inputB.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 }; - inputB.previous_rollup_data[1].merge_rollup_public_inputs.start_nullifier_tree_snapshot = { + inputB.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; EXPECT_DEATH(merge_rollup_circuit(inputB), ".*ensure_prev_rollups_follow_on_from_each_other.*"); // do the same for contract tree auto inputC = dummyInputs; - inputC.previous_rollup_data[0].merge_rollup_public_inputs.end_contract_tree_snapshot = { + inputC.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = { .root = fr(0), .next_available_leaf_index = 0 }; - inputC.previous_rollup_data[1].merge_rollup_public_inputs.start_contract_tree_snapshot = { + inputC.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot = { .root = fr(1), .next_available_leaf_index = 0 }; EXPECT_DEATH(merge_rollup_circuit(inputC), ".*ensure_prev_rollups_follow_on_from_each_other.*"); @@ -77,19 +77,19 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) TEST_F(merge_rollup_tests, test_rollup_fields_are_set_correctly) { MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); // check that rollup type is set to merge ASSERT_EQ(outputs.rollup_type, 1); // check that rollup height is incremented ASSERT_EQ(outputs.rollup_subtree_height, - inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height + 1); + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height + 1); // set inputs to have a merge rollup type and set the rollup height and test again. - inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type = 1; - inputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_subtree_height = 1; + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = 1; + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; - inputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type = 1; - inputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_subtree_height = 1; + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = 1; + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; outputs = merge_rollup_circuit(inputs); ASSERT_EQ(outputs.rollup_type, 1); @@ -99,22 +99,22 @@ TEST_F(merge_rollup_tests, test_rollup_fields_are_set_correctly) TEST_F(merge_rollup_tests, test_start_and_end_snapshots) { MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); // check that start and end snapshots are set correctly ASSERT_EQ(outputs.start_private_data_tree_snapshot, - inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_private_data_tree_snapshot); + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot); ASSERT_EQ(outputs.end_private_data_tree_snapshot, - inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_private_data_tree_snapshot); + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot); ASSERT_EQ(outputs.start_nullifier_tree_snapshot, - inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_nullifier_tree_snapshot); + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot); ASSERT_EQ(outputs.end_nullifier_tree_snapshot, - inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_nullifier_tree_snapshot); + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot); ASSERT_EQ(outputs.start_contract_tree_snapshot, - inputs.previous_rollup_data[0].merge_rollup_public_inputs.start_contract_tree_snapshot); + inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot); ASSERT_EQ(outputs.end_contract_tree_snapshot, - inputs.previous_rollup_data[1].merge_rollup_public_inputs.end_contract_tree_snapshot); + inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot); } TEST_F(merge_rollup_tests, test_calldata_hash) @@ -133,7 +133,7 @@ TEST_F(merge_rollup_tests, test_calldata_hash) auto expected_calldata_hash = sha256::sha256(calldata_hash_input_bytes_vec); MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); std::array actual_calldata_hash_fr = outputs.calldata_hash; auto high_buffer = actual_calldata_hash_fr[0].to_buffer(); @@ -151,17 +151,17 @@ TEST_F(merge_rollup_tests, test_calldata_hash) TEST_F(merge_rollup_tests, test_constants_dont_change) { MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); - ASSERT_EQ(inputs.previous_rollup_data[0].merge_rollup_public_inputs.constants, outputs.constants); - ASSERT_EQ(inputs.previous_rollup_data[1].merge_rollup_public_inputs.constants, outputs.constants); + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants, outputs.constants); + ASSERT_EQ(inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants, outputs.constants); } TEST_F(merge_rollup_tests, test_aggregate) { // TODO: Fix this when aggregation works MergeRollupInputs inputs = dummy_merge_rollup_inputs_with_vk_proof(); - MergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); - ASSERT_EQ(inputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object.public_inputs, + BaseOrMergeRollupPublicInputs outputs = merge_rollup_circuit(inputs); + ASSERT_EQ(inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object.public_inputs, outputs.end_aggregation_object.public_inputs); } } // namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit diff --git a/cpp/src/aztec3/circuits/rollup/merge/init.hpp b/cpp/src/aztec3/circuits/rollup/merge/init.hpp index d799343a..01890908 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/init.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/init.hpp @@ -3,7 +3,7 @@ #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" #include "aztec3/circuits/abis/rollup/constant_rollup_data.hpp" -#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" #include #include @@ -21,7 +21,7 @@ using NT = aztec3::utils::types::NativeTypes; // Params using ConstantRollupData = abis::ConstantRollupData; using MergeRollupInputs = abis::MergeRollupInputs; -using MergeRollupPublicInputs = abis::MergeRollupPublicInputs; +using BaseOrMergeRollupPublicInputs = abis::BaseOrMergeRollupPublicInputs; using Aggregator = aztec3::circuits::recursion::Aggregator; using AggregationObject = utils::types::NativeTypes::AggregationObject; 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 5436d1ee..ce4070e4 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,4 +1,4 @@ -#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" #include "barretenberg/crypto/pedersen_hash/pedersen.hpp" #include "barretenberg/crypto/sha256/sha256.hpp" @@ -30,21 +30,21 @@ namespace aztec3::circuits::rollup::native_merge_rollup { AggregationObject aggregate_proofs(MergeRollupInputs mergeRollupInputs) { // TODO: NOTE: for now we simply return the aggregation object from the first proof - return mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object; + return mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object; } void assert_both_input_proofs_of_same_rollup_type(MergeRollupInputs mergeRollupInputs) { - assert(mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); + assert(mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type == + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type); (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; + assert(mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height == + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height); + return mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height; } void assert_equal_constants(ConstantRollupData left, ConstantRollupData right) @@ -61,7 +61,7 @@ std::array compute_calldata_hash(MergeRollupInputs mergeRollupInputs) std::array calldata_hash_input_bytes; for (uint8_t i = 0; i < 2; i++) { std::array calldata_hash_fr = - mergeRollupInputs.previous_rollup_data[i].merge_rollup_public_inputs.calldata_hash; + mergeRollupInputs.previous_rollup_data[i].base_or_merge_rollup_public_inputs.calldata_hash; auto high_buffer = calldata_hash_fr[0].to_buffer(); auto low_buffer = calldata_hash_fr[1].to_buffer(); @@ -96,19 +96,19 @@ std::array compute_calldata_hash(MergeRollupInputs mergeRollupInputs) void ensure_prev_rollups_follow_on_from_each_other(MergeRollupInputs mergeRollupInputs) { auto privateDataEndSnapshot0 = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_private_data_tree_snapshot; + mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot; auto privateDataStartSnapshot1 = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_private_data_tree_snapshot; + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot; auto nullifierEndSnapshot0 = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_nullifier_tree_snapshot; + mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot; auto nullifierStartSnapshot1 = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_nullifier_tree_snapshot; + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot; auto contractEndSnapshot0 = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_contract_tree_snapshot; + mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot; auto contractStartSnapshot1 = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.start_contract_tree_snapshot; + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot; assert(privateDataEndSnapshot0 == privateDataStartSnapshot1 && nullifierEndSnapshot0 == nullifierStartSnapshot1 && contractEndSnapshot0 == contractStartSnapshot1); @@ -121,7 +121,7 @@ void ensure_prev_rollups_follow_on_from_each_other(MergeRollupInputs mergeRollup (void)contractStartSnapshot1; } -MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs) +BaseOrMergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs) { // Verify the previous rollup proofs @@ -134,8 +134,8 @@ MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs // we don't have a set of permitted kernel vks yet. // Check that the constants are the same in both proofs - auto left = mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; - auto right = mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; + auto left = mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs; + auto right = mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs; assert_equal_constants(left.constants, right.constants); // Ensure the end snapshot of previous_rollup 0 equals the start snapshot of previous_rollup 1 (i.e. ensure they @@ -148,23 +148,23 @@ MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs AggregationObject aggregation_object = aggregate_proofs(mergeRollupInputs); - MergeRollupPublicInputs public_inputs = { + BaseOrMergeRollupPublicInputs 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 = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_private_data_tree_snapshot, + .start_private_data_tree_snapshot = mergeRollupInputs.previous_rollup_data[0] + .base_or_merge_rollup_public_inputs.start_private_data_tree_snapshot, .end_private_data_tree_snapshot = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_private_data_tree_snapshot, + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_private_data_tree_snapshot, .start_nullifier_tree_snapshot = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_nullifier_tree_snapshot, + mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot, .end_nullifier_tree_snapshot = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_nullifier_tree_snapshot, + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot, .start_contract_tree_snapshot = - mergeRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.start_contract_tree_snapshot, + mergeRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot, .end_contract_tree_snapshot = - mergeRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.end_contract_tree_snapshot, + mergeRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot, .calldata_hash = new_calldata_hash, }; diff --git a/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp b/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp index 7d427775..f4d99f41 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/native_merge_rollup_circuit.hpp @@ -12,6 +12,6 @@ namespace aztec3::circuits::rollup::native_merge_rollup { -MergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs); +BaseOrMergeRollupPublicInputs merge_rollup_circuit(MergeRollupInputs mergeRollupInputs); } // namespace aztec3::circuits::rollup::native_merge_rollup \ No newline at end of file diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp index 7def4b18..342793bc 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.cpp @@ -1,7 +1,7 @@ #include "aztec3/circuits/abis/append_only_tree_snapshot.hpp" -#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp" -#include "aztec3/circuits/abis/rollup/merge/merge_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "aztec3/constants.hpp" #include "barretenberg/proof_system/verification_key/verification_key.hpp" #include "index.hpp" @@ -17,54 +17,28 @@ namespace { using NT = aztec3::utils::types::NativeTypes; using AggregationObject = aztec3::utils::types::NativeTypes::AggregationObject; -using aztec3::circuits::abis::AppendOnlyTreeSnapshot; -using aztec3::circuits::abis::BaseRollupPublicInputs; -using aztec3::circuits::abis::ConstantRollupData; +using aztec3::circuits::abis::BaseOrMergeRollupPublicInputs; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::MergeRollupInputs; -using aztec3::circuits::abis::MergeRollupPublicInputs; using aztec3::circuits::abis::PreviousRollupData; -using aztec3::circuits::abis::private_kernel::NewContractData; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_with_vk_proof; -using plonk::TurboComposer; } // namespace namespace aztec3::circuits::rollup::merge::utils { -// Helper method since MergeRollupInputs.PreviousRollupData can only take the type of `MergeRollupPublicInputs` -// So we convert the output of base to look like output of merge and add the `rollup_type` field. -MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( - BaseRollupPublicInputs baseRollupPublicInputs) -{ - MergeRollupPublicInputs mergeRollupPublicInputs = { - .rollup_type = abis::BASE_ROLLUP_TYPE, - .rollup_subtree_height = baseRollupPublicInputs.rollup_subtree_height, - .end_aggregation_object = baseRollupPublicInputs.end_aggregation_object, - .constants = baseRollupPublicInputs.constants, - .start_private_data_tree_snapshot = baseRollupPublicInputs.start_private_data_tree_snapshot, - .end_private_data_tree_snapshot = baseRollupPublicInputs.end_private_data_tree_snapshot, - .start_nullifier_tree_snapshot = baseRollupPublicInputs.start_nullifier_tree_snapshot, - .end_nullifier_tree_snapshot = baseRollupPublicInputs.end_nullifier_tree_snapshot, - .start_contract_tree_snapshot = baseRollupPublicInputs.start_contract_tree_snapshot, - .end_contract_tree_snapshot = baseRollupPublicInputs.end_contract_tree_snapshot, - .calldata_hash = baseRollupPublicInputs.calldata_hash - }; - return mergeRollupPublicInputs; -} - std::array, 2> previous_rollups_with_vk_proof_that_follow_on() { auto input1 = base::utils::dummy_base_rollup_inputs_with_vk_proof(); - BaseRollupPublicInputs base_public_input1 = + BaseOrMergeRollupPublicInputs base_public_input1 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(input1); auto input2 = input1; input2.start_private_data_tree_snapshot = base_public_input1.end_private_data_tree_snapshot; input2.start_nullifier_tree_snapshot = base_public_input1.end_nullifier_tree_snapshot; input2.start_contract_tree_snapshot = base_public_input1.end_contract_tree_snapshot; - BaseRollupPublicInputs base_public_input2 = + BaseOrMergeRollupPublicInputs base_public_input2 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(input2); // just for mocked vk and proof @@ -72,14 +46,14 @@ std::array, 2> previous_rollups_with_vk_proof_that_follow PreviousKernelData mocked_kernel = dummy_previous_kernel_with_vk_proof(); PreviousRollupData previous_rollup1 = { - .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_public_input1), + .base_or_merge_rollup_public_inputs = base_public_input1, .proof = mocked_kernel.proof, .vk = mocked_kernel.vk, .vk_index = 0, .vk_sibling_path = MembershipWitness(), }; PreviousRollupData previous_rollup2 = { - .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_public_input2), + .base_or_merge_rollup_public_inputs = base_public_input2, .proof = mocked_kernel.proof, .vk = mocked_kernel.vk, .vk_index = 0, diff --git a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp index 95bf9ea0..7dd85a2a 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/utils.hpp +++ b/cpp/src/aztec3/circuits/rollup/merge/utils.hpp @@ -1,5 +1,5 @@ #pragma once -#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp" +#include "aztec3/circuits/abis/rollup/base/base_or_merge_rollup_public_inputs.hpp" #include "index.hpp" #include "init.hpp" @@ -7,14 +7,10 @@ namespace aztec3::circuits::rollup::merge::utils { namespace { using NT = aztec3::utils::types::NativeTypes; -using aztec3::circuits::abis::BaseRollupPublicInputs; using aztec3::circuits::abis::MergeRollupInputs; -using aztec3::circuits::abis::MergeRollupPublicInputs; using aztec3::circuits::abis::PreviousRollupData; } // namespace -MergeRollupPublicInputs convert_base_public_inputs_to_merge_public_inputs( - BaseRollupPublicInputs baseRollupPublicInputs); MergeRollupInputs dummy_merge_rollup_inputs_with_vk_proof(); std::array, 2> previous_rollups_with_vk_proof_that_follow_on(); diff --git a/cpp/src/aztec3/circuits/rollup/root/.test.cpp b/cpp/src/aztec3/circuits/rollup/root/.test.cpp index 28c0d2b9..a1a7311b 100644 --- a/cpp/src/aztec3/circuits/rollup/root/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/root/.test.cpp @@ -87,7 +87,6 @@ using aztec3::circuits::apps::test_apps::escrow::deposit; using aztec3::circuits::kernel::private_kernel::utils::dummy_previous_kernel_with_vk_proof; using aztec3::circuits::mock::mock_kernel_circuit; using aztec3::circuits::rollup::base::utils::dummy_base_rollup_inputs_with_vk_proof; -using aztec3::circuits::rollup::merge::utils::convert_base_public_inputs_to_merge_public_inputs; using aztec3::circuits::rollup::merge::utils::previous_rollups_with_vk_proof_that_follow_on; // using aztec3::circuits::mock::mock_kernel_inputs; @@ -95,8 +94,8 @@ using aztec3::circuits::abis::AppendOnlyTreeSnapshot; using aztec3::circuits::abis::MembershipWitness; using aztec3::circuits::abis::NullifierLeafPreimage; +using aztec3::circuits::rollup::native_base_rollup::BaseOrMergeRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::BaseRollupInputs; -using aztec3::circuits::rollup::native_base_rollup::BaseRollupPublicInputs; using aztec3::circuits::rollup::native_base_rollup::ConstantRollupData; using aztec3::circuits::rollup::native_base_rollup::NT; @@ -305,14 +304,14 @@ TEST_F(root_rollup_tests, almost_full_root) AppendOnlyTreeSnapshot end_historic_contract_tree_snapshot = { .root = historic_contract_tree.root(), .next_available_leaf_index = 1 }; - BaseRollupPublicInputs base_outputs_1 = + BaseOrMergeRollupPublicInputs base_outputs_1 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(base_inputs_1); - BaseRollupPublicInputs base_outputs_2 = + BaseOrMergeRollupPublicInputs base_outputs_2 = aztec3::circuits::rollup::native_base_rollup::base_rollup_circuit(base_inputs_2); base_inputs_2.constants = base_inputs_1.constants; PreviousRollupData r1 = { - .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_outputs_1), + .base_or_merge_rollup_public_inputs = base_outputs_1, .proof = base_inputs_1.kernel_data[0].proof, // TODO: this is a hack, we should be able to use the proof from // base_outputs_1 .vk = base_inputs_1.kernel_data[0].vk, @@ -321,7 +320,7 @@ TEST_F(root_rollup_tests, almost_full_root) }; PreviousRollupData r2 = { - .merge_rollup_public_inputs = convert_base_public_inputs_to_merge_public_inputs(base_outputs_2), + .base_or_merge_rollup_public_inputs = base_outputs_2, .proof = base_inputs_1.kernel_data[0].proof, // TODO: this is a hack, we should be able to use the proof from // base_outputs_2 .vk = base_inputs_1.kernel_data[0].vk, 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 63fd7cd7..b88eaddc 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 @@ -35,20 +35,20 @@ bool verify_merge_proof(NT::Proof merge_proof) AggregationObject aggregate_proofs(RootRollupInputs const& rootRollupInputs) { // TODO: NOTE: for now we simply return the aggregation object from the first proof - return rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.end_aggregation_object; + return rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_aggregation_object; } void assert_both_input_proofs_of_same_rollup_type(RootRollupInputs rootRollupInputs) { - assert(rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs.rollup_type == - rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs.rollup_type); + assert(rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type == + rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type); (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); + assert(rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height == + rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height); (void)rootRollupInputs; } @@ -88,7 +88,7 @@ std::array compute_calldata_hash(RootRollupInputs const& rootRollupInputs std::array calldata_hash_input_bytes; for (uint8_t i = 0; i < 2; i++) { std::array calldata_hash_fr = - rootRollupInputs.previous_rollup_data[i].merge_rollup_public_inputs.calldata_hash; + rootRollupInputs.previous_rollup_data[i].base_or_merge_rollup_public_inputs.calldata_hash; auto high_buffer = calldata_hash_fr[0].to_buffer(); auto low_buffer = calldata_hash_fr[1].to_buffer(); @@ -156,8 +156,8 @@ RootRollupPublicInputs root_rollup_circuit(RootRollupInputs const& rootRollupInp assert(verify_merge_proof(proof)); } - auto left = rootRollupInputs.previous_rollup_data[0].merge_rollup_public_inputs; - auto right = rootRollupInputs.previous_rollup_data[1].merge_rollup_public_inputs; + auto left = rootRollupInputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs; + auto right = rootRollupInputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs; // Constants must be the same between left and right assert(is_constants_equal(left.constants, right.constants)); From caf1d864a322140478307fd45540a820447902d1 Mon Sep 17 00:00:00 2001 From: Rahul Kothari Date: Wed, 5 Apr 2023 15:49:31 +0000 Subject: [PATCH 8/8] this better work and ignore wasm tests --- cpp/src/aztec3/circuits/rollup/merge/.test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp index 6d4cd6f5..66440a81 100644 --- a/cpp/src/aztec3/circuits/rollup/merge/.test.cpp +++ b/cpp/src/aztec3/circuits/rollup/merge/.test.cpp @@ -15,6 +15,8 @@ namespace aztec3::circuits::rollup::merge::native_merge_rollup_circuit { class merge_rollup_tests : public ::testing::Test {}; +#ifndef __wasm__ // TODO: temporary hack. WASM doesn't support EXPECT_DEATH or try/catch or EXPECT_THROW so no way to + // test these in wasm. TEST_F(merge_rollup_tests, test_different_rollup_type_fails) { auto mergeInput = dummy_merge_rollup_inputs_with_vk_proof(); @@ -73,6 +75,7 @@ TEST_F(merge_rollup_tests, test_fail_if_previous_rollups_dont_follow_on) }; EXPECT_DEATH(merge_rollup_circuit(inputC), ".*ensure_prev_rollups_follow_on_from_each_other.*"); } +#endif TEST_F(merge_rollup_tests, test_rollup_fields_are_set_correctly) {