-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add initial skeleton code for root/merge/mase rollups for Noir (…
…#3178) This adds the initial skeleton code for the root/merge and base rollup in Noir. Theres a bug in Noir with double re-exports which is why it looks quite janky. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist).
- Loading branch information
1 parent
daee2f9
commit 7b0d076
Showing
41 changed files
with
401 additions
and
5,541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
yarn-project/noir-protocol-circuits/src/crates/bug-collecting-crate/compile-lib.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
7 changes: 7 additions & 0 deletions
7
yarn-project/noir-protocol-circuits/src/crates/bug-collecting-crate/workspace.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
yarn-project/noir-protocol-circuits/src/crates/rollup-base/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } |
5 changes: 5 additions & 0 deletions
5
yarn-project/noir-protocol-circuits/src/crates/rollup-base/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
9 changes: 9 additions & 0 deletions
9
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
6 changes: 6 additions & 0 deletions
6
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
4 changes: 4 additions & 0 deletions
4
...roject/noir-protocol-circuits/src/crates/rollup-lib/src/abis/append_only_tree_snapshot.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
struct AppendOnlyTreeSnapshot { | ||
root : Field, | ||
next_available_leaf_index : u32 | ||
} |
36 changes: 36 additions & 0 deletions
36
...ir-protocol-circuits/src/crates/rollup-lib/src/abis/base_or_merge_rollup_public_inputs.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
} |
15 changes: 15 additions & 0 deletions
15
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/constant_rollup_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
23 changes: 23 additions & 0 deletions
23
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/global_variables.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/nullifier_leaf_preimage.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/abis/previous_rollup_data.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
4 changes: 4 additions & 0 deletions
4
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
64 changes: 64 additions & 0 deletions
64
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/lib.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
3 changes: 3 additions & 0 deletions
3
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
14 changes: 14 additions & 0 deletions
14
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/merge/merge_rollup_inputs.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/root.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.