Skip to content

Commit

Permalink
feat(base_rollup_circuit): base rollup impl (wip) (#99)
Browse files Browse the repository at this point in the history
* add basic contract deployment test for private kernel

* chore(base_rollup): scaffold

* feat(base_rollup): scaffold

* fix(base_rollup): var name changes

* feat(base_rollup): historical subtree membership checks

* feat(merge_rollup) merge rollup types

* clean(merge): clean types and scaffold

* refactor(merge): seperate merge and base rollup

* fix(base): rename messup

* clean(merge): pr review

* initial test setup

* fix: paths and prints

* deleted deps

* minor tweaks

* fix(merge|base): aggregation object naming issue

* fix: change interface of base rollup

* fix witness init

* fix(ts): update bindings (#108)

* refactor(merge): seperate merge and base rollup

* initial test setup

* fix(ts-bindings): reduce roots to calldatahash

* fix: remove prover id

* fix: base rollup pub inputs ts tests

* remove deps

* rm gtest

* fix: scuffed rebase

* fix: scuffed rebase cont.

* fix: update tests

---------

Co-authored-by: cheethas <[email protected]>
Co-authored-by: LHerskind <[email protected]>

* fix(ts): update incorrect constant parity

* fix(base): update vk pointer handling (#111)

* fix: bb update

* fix: update head

* fix:(base): remove subtrees from interface (#110)

* update inputs and outputs of base per new miro dg

* update types and bindings

* fix ts bindings for base

* Adding tests for base rollup + sha256 (#114)

* tests: tiny tests added

* fix: insert zero-leaf in contract + use sha256 + change calldata hash -> 2 fields

* fix: run tests in ci + remove log

* fix: fix tests

* fix: fix comments

* fix: better comment

* feat(base): insert commitments and contracts into end trees (#116)

* insert commitments and contracts into end trees

* fix merkle membership refactoring

* add new root to snapshot

* fix per pr comments

* update ts constants

* fix per pr comments

* fix: Update rollup sha256 input + add test with "meaningful" input (#118)

* feat(base): nullifier tree impl (#119)

* chore(bb): update branch

* feat: impl nullifier logic

* fix(base): naming and miscalculations

* fix: update subtree sibling path depth constants

* fix: more nits

---------

Co-authored-by: cheethas <[email protected]>

---------

Co-authored-by: dbanks12 <[email protected]>
Co-authored-by: cheethas <[email protected]>
Co-authored-by: LHerskind <[email protected]>
Co-authored-by: David Banks <[email protected]>
Co-authored-by: Rahul Kothari <[email protected]>
Co-authored-by: Lasse Herskind <[email protected]>
  • Loading branch information
7 people authored Mar 28, 2023
1 parent c2fa51a commit 5b275db
Show file tree
Hide file tree
Showing 36 changed files with 1,345 additions and 373 deletions.
2 changes: 1 addition & 1 deletion cpp/barretenberg
Submodule barretenberg updated 20 files
+12 −4 cpp/src/barretenberg/plonk/proof_system/types/proof.hpp
+12 −3 cpp/src/barretenberg/stdlib/merkle_tree/hash.hpp
+1 −4 cpp/src/barretenberg/stdlib/merkle_tree/hash.test.cpp
+3 −3 cpp/src/barretenberg/stdlib/merkle_tree/hash_path.hpp
+29 −0 cpp/src/barretenberg/stdlib/merkle_tree/membership.hpp
+70 −0 cpp/src/barretenberg/stdlib/merkle_tree/membership.test.cpp
+2 −2 cpp/src/barretenberg/stdlib/merkle_tree/memory_tree.cpp
+1 −1 cpp/src/barretenberg/stdlib/merkle_tree/memory_tree.hpp
+3 −3 cpp/src/barretenberg/stdlib/merkle_tree/memory_tree.test.cpp
+1 −1 cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.bench.cpp
+7 −7 cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.cpp
+2 −2 cpp/src/barretenberg/stdlib/merkle_tree/merkle_tree.hpp
+65 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_leaf.hpp
+65 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.cpp
+93 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp
+203 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_memory_tree.test.cpp
+85 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.cpp
+45 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.hpp
+140 −0 cpp/src/barretenberg/stdlib/merkle_tree/nullifier_tree/nullifier_tree.test.cpp
+1 −1 cpp/src/barretenberg/stdlib/recursion/aggregation_state/native_aggregation_state.hpp
1 change: 1 addition & 0 deletions cpp/scripts/a3-tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
aztec3_circuits_abis_tests
aztec3_circuits_apps_tests
aztec3_circuits_kernel_tests
aztec3_circuits_rollup_tests
aztec3_circuits_recursion_tests
5 changes: 3 additions & 2 deletions cpp/src/aztec3/circuits/abis/c_bind.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "c_bind.h"
#include "aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp"
#include "barretenberg/srs/reference_string/mem_reference_string.hpp"
#include "aztec3/circuits/abis/function_data.hpp"
#include "aztec3/circuits/abis/private_kernel/new_contract_data.hpp"
#include "private_circuit_public_inputs.hpp"
#include "tx_request.hpp"
#include "tx_context.hpp"
#include "function_leaf_preimage.hpp"
#include "base_rollup/base_rollup_inputs.hpp"
#include "base_rollup/base_rollup_public_inputs.hpp"
#include "rollup/base/base_rollup_inputs.hpp"
#include "rollup/base/base_rollup_public_inputs.hpp"
#include "private_kernel/previous_kernel_data.hpp"
#include "private_kernel/private_inputs.hpp"

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/aztec3/circuits/abis/membership_witness.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ template <typename NCT, unsigned int N> struct MembershipWitness {

bool operator==(MembershipWitness<NCT, N> const&) const = default;

static MembershipWitness<NCT, N> empty() { return { 0, std::array<fr, N>(N) }; };
static MembershipWitness<NCT, N> empty() { return { 0, std::array<fr, N>({ 0, { 0 } }) }; };

template <typename Composer> MembershipWitness<CircuitTypes<Composer>, N> to_circuit_type(Composer& composer) const
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "aztec3/constants.hpp"
#include "aztec3/utils/types/circuit_types.hpp"
#include "aztec3/utils/types/convert.hpp"
#include "barretenberg/stdlib/primitives/witness/witness.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using aztec3::utils::types::NativeTypes;
using plonk::stdlib::witness_t;
using std::is_same;

// @todo Naming should not be previous. Annoying.
template <typename NCT> struct PreviousKernelData {
typedef typename NCT::fr fr;
typedef typename NCT::VK VK;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#pragma once
#include "../append_only_tree_snapshot.hpp"
#include "../private_kernel/previous_kernel_data.hpp"
#include "../membership_witness.hpp"
#include "./nullifier_leaf_preimage.hpp"
#include "./constant_base_rollup_data.hpp"
#include "../../append_only_tree_snapshot.hpp"
#include "../../private_kernel/previous_kernel_data.hpp"
#include "../../membership_witness.hpp"
#include "../nullifier_leaf_preimage.hpp"
#include "../constant_rollup_data.hpp"
#include "aztec3/constants.hpp"
#include <math.h>

namespace aztec3::circuits::abis {

Expand All @@ -17,19 +19,26 @@ template <typename NCT> struct BaseRollupInputs {

std::array<private_kernel::PreviousKernelData<NCT>, 2> kernel_data;

AppendOnlyTreeSnapshot<NCT> start_private_data_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> start_nullifier_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> start_contract_tree_snapshot;

std::array<NullifierLeafPreimage<NCT>, 2 * KERNEL_NEW_NULLIFIERS_LENGTH> low_nullifier_leaf_preimages;
std::array<MembershipWitness<NCT, NULLIFIER_TREE_HEIGHT>, 2 * KERNEL_NEW_NULLIFIERS_LENGTH>
low_nullifier_membership_witness;

// For inserting the new subtrees into their respective trees:
// Note: the insertion leaf index can be derived from the above snapshots' `next_available_leaf_index` values.
std::array<fr, PRIVATE_DATA_SUBTREE_INCLUSION_CHECK_DEPTH> new_commitments_subtree_sibling_path;
std::array<fr, NULLIFIER_SUBTREE_INCLUSION_CHECK_DEPTH> new_nullifiers_subtree_sibling_path;
std::array<fr, NULLIFIER_SUBTREE_INCLUSION_CHECK_DEPTH> new_contracts_subtree_sibling_path;

std::array<MembershipWitness<NCT, PRIVATE_DATA_TREE_ROOTS_TREE_HEIGHT>, 2>
historic_private_data_tree_root_membership_witnesses;
std::array<MembershipWitness<NCT, CONTRACT_TREE_ROOTS_TREE_HEIGHT>, 2>
historic_contract_tree_root_membership_witnesses;

ConstantBaseRollupData<NCT> constants;

fr prover_id;
ConstantRollupData<NCT> constants;

bool operator==(BaseRollupInputs<NCT> const&) const = default;
};
Expand All @@ -39,27 +48,35 @@ template <typename NCT> void read(uint8_t const*& it, BaseRollupInputs<NCT>& obj
using serialize::read;

read(it, obj.kernel_data);
read(it, obj.start_private_data_tree_snapshot);
read(it, obj.start_nullifier_tree_snapshot);
read(it, obj.start_contract_tree_snapshot);
read(it, obj.low_nullifier_leaf_preimages);
read(it, obj.low_nullifier_membership_witness);
read(it, obj.new_commitments_subtree_sibling_path);
read(it, obj.new_nullifiers_subtree_sibling_path);
read(it, obj.new_contracts_subtree_sibling_path);
read(it, obj.historic_private_data_tree_root_membership_witnesses);
read(it, obj.historic_contract_tree_root_membership_witnesses);
read(it, obj.constants);
read(it, obj.prover_id);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, BaseRollupInputs<NCT> const& obj)
{
using serialize::write;

write(buf, obj.kernel_data);
write(buf, obj.start_private_data_tree_snapshot);
write(buf, obj.start_nullifier_tree_snapshot);
write(buf, obj.start_contract_tree_snapshot);
write(buf, obj.low_nullifier_leaf_preimages);
write(buf, obj.low_nullifier_membership_witness);
write(buf, obj.new_commitments_subtree_sibling_path);
write(buf, obj.new_nullifiers_subtree_sibling_path);
write(buf, obj.new_contracts_subtree_sibling_path);
write(buf, obj.historic_private_data_tree_root_membership_witnesses);
write(buf, obj.historic_contract_tree_root_membership_witnesses);
write(buf, obj.constants);
write(buf, obj.prover_id);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, BaseRollupInputs<NCT> const& obj)
Expand All @@ -72,13 +89,18 @@ template <typename NCT> std::ostream& operator<<(std::ostream& os, BaseRollupInp
<< obj.low_nullifier_leaf_preimages << "\n"
<< "low_nullifier_membership_witness:\n"
<< obj.low_nullifier_membership_witness << "\n"
<< "new_commitments_subtree_sibling_path:\n"
<< obj.new_commitments_subtree_sibling_path << "\n"
<< "new_nullifiers_subtree_sibling_path:\n"
<< obj.new_nullifiers_subtree_sibling_path << "\n"
<< "new_contracts_subtree_sibling_path:\n"
<< obj.new_contracts_subtree_sibling_path << "\n"
<< "historic_private_data_tree_root_membership_witnesses:\n"
<< obj.historic_private_data_tree_root_membership_witnesses << "\n"
<< "historic_contract_tree_root_membership_witnesses:\n"
<< obj.historic_contract_tree_root_membership_witnesses << "\n"
<< "constants:\n"
<< obj.constants << "\n"
<< "prover_id: " << obj.prover_id << "\n";
<< obj.constants << "\n";
}

} // namespace aztec3::circuits::abis
102 changes: 102 additions & 0 deletions cpp/src/aztec3/circuits/abis/rollup/base/base_rollup_public_inputs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#pragma once
#include <barretenberg/stdlib/recursion/aggregation_state/aggregation_state.hpp>
#include <aztec3/utils/types/native_types.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include "../../append_only_tree_snapshot.hpp"
#include "../../append_only_tree_snapshot.hpp"
#include "../constant_rollup_data.hpp"

namespace aztec3::circuits::abis {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct BaseRollupPublicInputs {
typedef typename NCT::fr fr;
typedef typename NCT::AggregationObject AggregationObject;

AggregationObject end_aggregation_object;
ConstantRollupData<NCT> constants;

AppendOnlyTreeSnapshot<NCT> start_private_data_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> end_private_data_tree_snapshot;

AppendOnlyTreeSnapshot<NCT> start_nullifier_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> end_nullifier_tree_snapshot;

AppendOnlyTreeSnapshot<NCT> start_contract_tree_snapshot;
AppendOnlyTreeSnapshot<NCT> 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.
std::array<fr, 2> calldata_hash;

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

template <typename NCT> void read(uint8_t const*& it, BaseRollupPublicInputs<NCT>& obj)
{
using serialize::read;

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 <typename NCT> void write(std::vector<uint8_t>& buf, BaseRollupPublicInputs<NCT> const& obj)
{
using serialize::write;

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 <typename NCT> std::ostream& operator<<(std::ostream& os, BaseRollupPublicInputs<NCT> const& obj)
{
return os << "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.start_private_data_tree_snapshot
<< "\n"
"start_nullifier_tree_snapshot:\n"
<< obj.start_nullifier_tree_snapshot
<< "\n"
"end_nullifier_tree_snapshots:\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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct ConstantBaseRollupData {
template <typename NCT> struct ConstantRollupData {

typedef typename NCT::fr fr;

Expand All @@ -22,9 +22,9 @@ template <typename NCT> struct ConstantBaseRollupData {
fr base_rollup_vk_hash;
fr merge_rollup_vk_hash;

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

static ConstantBaseRollupData<NCT> empty()
static ConstantRollupData<NCT> empty()
{
return { AppendOnlyTreeSnapshot<NCT>::empty(),
AppendOnlyTreeSnapshot<NCT>::empty(),
Expand All @@ -36,7 +36,7 @@ template <typename NCT> struct ConstantBaseRollupData {
};
};

template <typename NCT> void read(uint8_t const*& it, ConstantBaseRollupData<NCT>& obj)
template <typename NCT> void read(uint8_t const*& it, ConstantRollupData<NCT>& obj)
{
using serialize::read;

Expand All @@ -49,7 +49,7 @@ template <typename NCT> void read(uint8_t const*& it, ConstantBaseRollupData<NCT
read(it, obj.merge_rollup_vk_hash);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, ConstantBaseRollupData<NCT> const& obj)
template <typename NCT> void write(std::vector<uint8_t>& buf, ConstantRollupData<NCT> const& obj)
{
using serialize::write;

Expand All @@ -62,7 +62,7 @@ template <typename NCT> void write(std::vector<uint8_t>& buf, ConstantBaseRollup
write(buf, obj.merge_rollup_vk_hash);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, ConstantBaseRollupData<NCT> const& obj)
template <typename NCT> std::ostream& operator<<(std::ostream& os, ConstantRollupData<NCT> const& obj)
{
return os << "start_tree_of_historic_private_data_tree_roots_snapshot:\n "
<< obj.start_tree_of_historic_private_data_tree_roots_snapshot << "\n"
Expand Down
40 changes: 40 additions & 0 deletions cpp/src/aztec3/circuits/abis/rollup/merge/merge_rollup_inputs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once
#include "aztec3/circuits/abis/append_only_tree_snapshot.hpp"
#include <aztec3/circuits/abis/rollup/merge/previous_rollup_data.hpp>
#include <aztec3/utils/types/native_types.hpp>
#include <aztec3/utils/types/circuit_types.hpp>
#include <aztec3/utils/types/convert.hpp>
#include <type_traits>

namespace aztec3::circuits::abis {

using aztec3::utils::types::CircuitTypes;
using aztec3::utils::types::NativeTypes;
using std::is_same;

template <typename NCT> struct MergeRollupInputs {
std::array<PreviousRollupData<NCT>, 2> previous_rollup_data;

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

template <typename NCT> void read(uint8_t const*& it, MergeRollupInputs<NCT>& obj)
{
using serialize::read;

read(it, obj.previous_rollup_data);
};

template <typename NCT> void write(std::vector<uint8_t>& buf, MergeRollupInputs<NCT> const& obj)
{
using serialize::write;

write(buf, obj.previous_rollup_data);
};

template <typename NCT> std::ostream& operator<<(std::ostream& os, MergeRollupInputs<NCT> const& obj)
{
return os << "previous_rollup_data: " << obj.previous_rollup_data << "\n";
};

} // namespace aztec3::circuits::abis
Loading

0 comments on commit 5b275db

Please sign in to comment.