-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable merge and root rollup circuits in noir (#3248)
Enables the noir version of the merge and root rollup circuits. # 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. - [x] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [x] 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). --------- Co-authored-by: ludamad <adam.domurad@gmail.com> Co-authored-by: kevaundray <kevtheappdev@gmail.com>
- Loading branch information
1 parent
69dc616
commit 68555fc
Showing
34 changed files
with
1,168 additions
and
159 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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
src/crates | ||
src/target | ||
src/types |
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: 1 addition & 1 deletion
2
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "rollup_merge" | ||
name = "rollup_base" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.18.0" | ||
|
3 changes: 3 additions & 0 deletions
3
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/fixtures.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; | ||
mod root_rollup_inputs; | ||
mod previous_rollup_data; |
12 changes: 12 additions & 0 deletions
12
...-project/noir-protocol-circuits/src/crates/rollup-lib/src/fixtures/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,12 @@ | ||
use crate::merge::merge_rollup_inputs::MergeRollupInputs; | ||
use crate::abis::base_or_merge_rollup_public_inputs::BASE_ROLLUP_TYPE; | ||
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; | ||
use crate::fixtures::previous_rollup_data::default_previous_rollup_data; | ||
|
||
pub fn default_merge_rollup_inputs() -> MergeRollupInputs { | ||
let mut inputs: MergeRollupInputs = dep::std::unsafe::zeroed(); | ||
|
||
inputs.previous_rollup_data = default_previous_rollup_data(); | ||
|
||
inputs | ||
} |
72 changes: 72 additions & 0 deletions
72
...project/noir-protocol-circuits/src/crates/rollup-lib/src/fixtures/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,72 @@ | ||
use crate::abis::base_or_merge_rollup_public_inputs::BASE_ROLLUP_TYPE; | ||
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; | ||
use crate::abis::previous_rollup_data::PreviousRollupData; | ||
|
||
pub fn default_previous_rollup_data() -> [PreviousRollupData; 2] { | ||
let mut previous_rollup_data: [PreviousRollupData; 2] = dep::std::unsafe::zeroed(); | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 0, | ||
next_available_leaf_index: 0 | ||
}; | ||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_note_hash_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 2, | ||
next_available_leaf_index: 2 | ||
}; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 0, | ||
next_available_leaf_index: 0 | ||
}; | ||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_nullifier_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_nullifier_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 2, | ||
next_available_leaf_index: 2 | ||
}; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 0, | ||
next_available_leaf_index: 0 | ||
}; | ||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_contract_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 1, | ||
next_available_leaf_index: 1 | ||
}; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.end_contract_tree_snapshot = AppendOnlyTreeSnapshot { | ||
root: 2, | ||
next_available_leaf_index: 2 | ||
}; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.end_public_data_tree_root = 3; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.start_public_data_tree_root = 3; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_type = BASE_ROLLUP_TYPE; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_type = BASE_ROLLUP_TYPE; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.rollup_subtree_height = 1; | ||
|
||
previous_rollup_data[0].base_or_merge_rollup_public_inputs.calldata_hash = [0, 1]; | ||
previous_rollup_data[1].base_or_merge_rollup_public_inputs.calldata_hash = [2, 3]; | ||
|
||
previous_rollup_data | ||
} |
62 changes: 62 additions & 0 deletions
62
yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/fixtures/root_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,62 @@ | ||
use crate::{ | ||
root::{ | ||
root_rollup_inputs::RootRollupInputs, | ||
}, | ||
}; | ||
use dep::aztec::constants_gen::{ | ||
L1_TO_L2_MSG_TREE_HEIGHT, | ||
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, | ||
L1_TO_L2_MSG_SUBTREE_HEIGHT, | ||
HISTORIC_BLOCKS_TREE_HEIGHT, | ||
}; | ||
use crate::abis::append_only_tree_snapshot::AppendOnlyTreeSnapshot; | ||
use crate::fixtures::previous_rollup_data::default_previous_rollup_data; | ||
|
||
pub fn compute_zero_hashes<N>(mut hashes: [Field; N]) -> [Field; N] { | ||
hashes[0] = dep::std::hash::pedersen_hash([0, 0]); | ||
|
||
for i in 1..N { | ||
hashes[i] = dep::std::hash::pedersen_hash([hashes[i-1], hashes[i-1]]); | ||
} | ||
|
||
hashes | ||
} | ||
|
||
pub fn compute_l1_l2_empty_snapshot() -> (AppendOnlyTreeSnapshot, [Field; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH]) { | ||
let zero_hashes = compute_zero_hashes([0; L1_TO_L2_MSG_TREE_HEIGHT]); | ||
let mut new_l1_to_l2_messages_tree_root_sibling_path = [0; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH]; | ||
|
||
for i in 0..L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH { | ||
let index = L1_TO_L2_MSG_SUBTREE_HEIGHT + i - 1; | ||
new_l1_to_l2_messages_tree_root_sibling_path[i] = zero_hashes[index]; | ||
} | ||
|
||
(AppendOnlyTreeSnapshot{ root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, new_l1_to_l2_messages_tree_root_sibling_path) | ||
} | ||
|
||
pub fn compute_historic_blocks_tree_snapshot() -> (AppendOnlyTreeSnapshot, [Field; HISTORIC_BLOCKS_TREE_HEIGHT]) { | ||
let zero_hashes = compute_zero_hashes([0; HISTORIC_BLOCKS_TREE_HEIGHT]); | ||
let mut sibling_path = [0; HISTORIC_BLOCKS_TREE_HEIGHT]; | ||
for i in 1..HISTORIC_BLOCKS_TREE_HEIGHT { | ||
sibling_path[i] = zero_hashes[i-1]; | ||
} | ||
(AppendOnlyTreeSnapshot { root: zero_hashes[zero_hashes.len() - 1], next_available_leaf_index: 0 }, sibling_path) | ||
} | ||
|
||
|
||
pub fn default_root_rollup_inputs() -> RootRollupInputs { | ||
let mut inputs: RootRollupInputs = dep::std::unsafe::zeroed(); | ||
let (l1_l2_empty_snapshot, l1_l2_empty_sibling_path) = compute_l1_l2_empty_snapshot(); | ||
|
||
inputs.new_l1_to_l2_messages_tree_root_sibling_path = l1_l2_empty_sibling_path; | ||
inputs.start_l1_to_l2_messages_tree_snapshot = l1_l2_empty_snapshot; | ||
|
||
let (historic_blocks_snapshot, historic_blocks_sibling_path) = compute_historic_blocks_tree_snapshot(); | ||
|
||
inputs.start_historic_blocks_tree_snapshot = historic_blocks_snapshot; | ||
inputs.new_historic_blocks_tree_sibling_path = historic_blocks_sibling_path; | ||
|
||
inputs.previous_rollup_data = default_previous_rollup_data(); | ||
|
||
inputs | ||
} |
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 |
---|---|---|
|
@@ -13,4 +13,6 @@ mod components; | |
|
||
mod hash; | ||
|
||
mod merkle_tree; | ||
mod merkle_tree; | ||
|
||
mod fixtures; |
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
Oops, something went wrong.