Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: Add initial skeleton code for root/merge/mase rollups for Noir #3178

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions yarn-project/noir-protocol-circuits/src/Nargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ members = [
"crates/private-kernel-inner-simulated",
"crates/private-kernel-ordering",
"crates/private-kernel-ordering-simulated",
"crates/rollup-lib",
"crates/rollup-merge",
"crates/rollup-base",
"crates/rollup-root",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Seems that if we have errors in a library that is in the workspace
it doesn't get checked.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Have a workspace with multiple members.

Comment out the members in the workspace Nargo.toml file, except for one member.

Then compile that member using `nargo compile --package {member}

You will get warnings about the other members having unused members
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_init_simulated"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_init"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_inner_simulated"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_inner"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_lib"
type = "lib"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
aztec = { path="../../../../aztec-nr/aztec" }
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use dep::aztec::constants_gen::{
CONTRACT_TREE_HEIGHT,
FUNCTION_TREE_HEIGHT,
ROLLUP_VK_TREE_HEIGHT,
MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP,
KERNELS_PER_BASE_ROLLUP
};

struct MembershipWitness<N> {
Expand All @@ -21,3 +24,18 @@ struct ContractLeafMembershipWitness{
leaf_index : Field,
sibling_path : [Field; CONTRACT_TREE_HEIGHT]
}

struct VKMembershipWitness{
leaf_index : Field,
sibling_path : [Field; ROLLUP_VK_TREE_HEIGHT]
}

struct NullifierMembershipWitness{
leaf_index : Field,
sibling_path : [Field; MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP]
}

struct HistoricBlocksTreeRootMembershipWitness{
leaf_index : Field,
sibling_path : [Field; KERNELS_PER_BASE_ROLLUP]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_ordering_simulated"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "private_kernel_ordering"
type = "bin"
authors = [""]
compiler_version = "0.16.0"
compiler_version = ">=0.18.0"

[dependencies]
private_kernel_lib = { path = "../private-kernel-lib" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rollup_merge"
type = "bin"
authors = [""]
compiler_version = ">=0.18.0"

[dependencies]
rollup_lib = { path = "../rollup-lib" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use dep::rollup_lib::base::{BaseRollupInputs,BaseOrMergeRollupPublicInputs};

fn main(inputs : BaseRollupInputs) -> pub BaseOrMergeRollupPublicInputs {
inputs.base_rollup_circuit()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rollup_lib"
type = "lib"
authors = [""]
compiler_version = ">=0.18.0"

[dependencies]
aztec = { path="../../../../aztec-nr/aztec" }
private_kernel_lib = {path = "../private-kernel-lib"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod nullifier_leaf_preimage;
mod append_only_tree_snapshot;
mod global_variables;
mod constant_rollup_data;
mod base_or_merge_rollup_public_inputs;
mod previous_rollup_data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct AppendOnlyTreeSnapshot {
root : Field,
next_available_leaf_index : u32
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// TODO(Kev): This constant is also defined in private-kernel-lib
use dep::aztec::constants_gen::NUM_FIELDS_PER_SHA256;
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot;
use crate::abis::constant_rollup_data::ConstantRollupData;

// Re-export bug 3384
// use dep::private_kernel_lib::mocked::AggregationObject;
struct AggregationObject;

global BASE_ROLLUP_TYPE = 0;
global MERGE_ROLLUP_TYPE = 1;

struct BaseOrMergeRollupPublicInputs {
// rollup_type is either 0 (base) or 1 (merge)
// TODO(Kev): Why is this a u32 instead of a u8/u16?
rollup_type : u32,
// 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
rollup_subtree_height : Field,
end_aggregation_object : AggregationObject,
constants : ConstantRollupData,

start_note_hash_tree_snapshot : AppendOnlyTreeSnapshot,
end_note_hash_tree_snapshot : AppendOnlyTreeSnapshot,

start_nullifier_tree_snapshot : AppendOnlyTreeSnapshot,
end_nullifier_tree_snapshot : AppendOnlyTreeSnapshot,

start_contract_tree_snapshot : AppendOnlyTreeSnapshot,
end_contract_tree_snapshot : AppendOnlyTreeSnapshot,

start_public_data_tree_root : Field,
end_public_data_tree_root : Field,
// // We hash public inputs to make them constant-sized (to then be unpacked on-chain)
calldata_hash : [Field; 2],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::abis::global_variables::GlobalVariables;
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot;

struct ConstantRollupData {
// The very latest roots as at the very beginning of the entire rollup:
start_historic_blocks_tree_roots_snapshot : AppendOnlyTreeSnapshot,

// TODO(Sean): Some members of this struct tbd
private_kernel_vk_tree_root : Field,
public_kernel_vk_tree_root : Field,
base_rollup_vk_hash : Field,
merge_rollup_vk_hash : Field,

global_variables : GlobalVariables,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use dep::aztec::constants_gen;

struct GlobalVariables {
chain_id : Field,
version : Field,
block_number : Field,
timestamp : Field,
}

impl GlobalVariables {

pub fn hash(self) -> Field {
dep::std::hash::pedersen_hash_with_separator([
self.chain_id,
self.version,
self.block_number,
self.timestamp
],
constants_gen::GENERATOR_INDEX__GLOBAL_VARIABLES,
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
struct NullifierLeafPreimage {
leaf_value : Field,
next_value :Field,
next_index : u32,
}

impl NullifierLeafPreimage {
// TODO(Kev): Check if this is needed.
fn is_empty(self) -> bool {
(self.leaf_value == 0) & (self.next_index == 0) & (self.next_value == 0)
}

fn hash(self) -> Field {
if self.is_empty() {
0
} else {
dep::std::hash::pedersen_hash([self.leaf_value, (self.next_index as Field), self.next_value])
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;

// Reexport bug (3384)
// use dep::private_kernel_lib::abis::membership_witness::VKMembershipWitness;
use dep::aztec::constants_gen::ROLLUP_VK_TREE_HEIGHT;
struct VKMembershipWitness{
leaf_index : Field,
sibling_path : [Field; ROLLUP_VK_TREE_HEIGHT]
}

// Reexport bug (3384)
// use dep::private_kernel_lib::mocked::{Proof, VerificationKey};
struct Proof;
struct VerificationKey;

struct PreviousRollupData{
base_or_merge_rollup_public_inputs : BaseOrMergeRollupPublicInputs,
proof : Proof,
vk : VerificationKey,
vk_index : u32,
vk_sibling_path : VKMembershipWitness,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod base_rollup_inputs;

use base_rollup_inputs::BaseRollupInputs;
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use crate::abis::nullifier_leaf_preimage::NullifierLeafPreimage;
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot;
use crate::abis::constant_rollup_data::ConstantRollupData;
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
use dep::aztec::constants_gen::{
MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP,
NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH,
NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH,
CONTRACT_SUBTREE_SIBLING_PATH_LENGTH,
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_BASE_ROLLUP,
MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP,
PUBLIC_DATA_TREE_HEIGHT,
KERNELS_PER_BASE_ROLLUP,
};

// Reexport bug (3384)
// use dep::private_kernel_lib::abis::previous_kernel_data::PreviousKernelData;
// Note: I have not implemented the fields for this, it would be a mess to do so.
struct PreviousKernelData;

// Reexport bug (3384)
// use dep::private_kernel_lib::abis::membership_witness::NullifierMembershipWitness;
struct NullifierMembershipWitness{
leaf_index : Field,
sibling_path : [Field; MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP]
}

// Reexport bug (3384)
// use dep::private_kernel_lib::abis::membership_witness::HistoricBlocksTreeRootMembershipWitness;
struct HistoricBlocksTreeRootMembershipWitness{
leaf_index : Field,
sibling_path : [Field; KERNELS_PER_BASE_ROLLUP]
}

struct BaseRollupInputs {
kernel_data: [PreviousKernelData; KERNELS_PER_BASE_ROLLUP],
start_note_hash_tree_snapshot: AppendOnlyTreeSnapshot,
start_nullifier_tree_snapshot: AppendOnlyTreeSnapshot,
start_contract_tree_snapshot: AppendOnlyTreeSnapshot,
start_public_data_tree_root: Field,
start_historic_blocks_tree_snapshot: AppendOnlyTreeSnapshot,

low_nullifier_leaf_preimages: [NullifierLeafPreimage; MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP],
low_nullifier_membership_witness: [NullifierMembershipWitness; MAX_NEW_NULLIFIERS_PER_BASE_ROLLUP],

// 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.
new_commitments_subtree_sibling_path: [Field; NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH],
new_nullifiers_subtree_sibling_path: [Field; NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH],
new_contracts_subtree_sibling_path: [Field; CONTRACT_SUBTREE_SIBLING_PATH_LENGTH],
new_public_data_update_requests_sibling_paths: [[Field; PUBLIC_DATA_TREE_HEIGHT]; MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_BASE_ROLLUP],
new_public_data_reads_sibling_paths: [[Field; PUBLIC_DATA_TREE_HEIGHT]; MAX_PUBLIC_DATA_READS_PER_BASE_ROLLUP],

historic_blocks_tree_root_membership_witnesses: [HistoricBlocksTreeRootMembershipWitness; KERNELS_PER_BASE_ROLLUP],

constants: ConstantRollupData,
}

impl BaseRollupInputs {
pub fn base_rollup_circuit(self) -> BaseOrMergeRollupPublicInputs {
let zeroed = dep::std::unsafe::zeroed();
zeroed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod abis;

// Base rollup
mod base;

// Merge rollup
mod merge;

// Root rollup
mod root;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod merge_rollup_inputs;
use merge_rollup_inputs::MergeRollupInputs;
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::abis::previous_rollup_data::PreviousRollupData;
use crate::abis::base_or_merge_rollup_public_inputs::BaseOrMergeRollupPublicInputs;

struct MergeRollupInputs{
// TODO(Kev): Why is this 2?
previous_rollup_data : [PreviousRollupData; 2]
}

impl MergeRollupInputs {
pub fn merge_rollup_circuit(self) -> BaseOrMergeRollupPublicInputs {
let zeroed = dep::std::unsafe::zeroed();
zeroed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod root_rollup_inputs;
use root_rollup_inputs::RootRollupInputs;
mod root_rollup_public_inputs;
use root_rollup_public_inputs::RootRollupPublicInputs;


impl RootRollupInputs {
pub fn root_rollup_circuit(self) -> RootRollupPublicInputs {
let zeroed = dep::std::unsafe::zeroed();
zeroed
}
}
Loading