-
Notifications
You must be signed in to change notification settings - Fork 296
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
feat: Prepare protocol circuits for batch rollup #7727
Merged
Merged
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c49bd33
feat: first run at nr changes for batch rollup
MirandaWood 358c7b3
feat: add ts types, structs, tests (not yet impl in orch)
MirandaWood 9b288e3
feat: handle vks for block root and block merge circuits
MirandaWood c740c10
chore: small fixes, cleanup, inject prev block hash
MirandaWood 8859550
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood c031a20
chore: fmt, cleanup after adding prover_id via merge
MirandaWood 6b97c3a
chore: better comments, more root -> block_root renaming, add new cir…
MirandaWood 56c01ac
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood df113ce
feat: clean fee throw, add prev_block_hash to root pub inputs
MirandaWood b064be0
chore: fix for tests, more root -> block root renaming, comments
MirandaWood 951981f
feat: accumulate fees, test, add more clarity comments
MirandaWood d84984e
feat: verify block root proofs on L1, add prover id to PIs
MirandaWood 381da05
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood 930ebea
feat: add vk root to final root rollup inputs, fix typo
MirandaWood 82aa39a
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood abfca2b
feat: L1 process stores block hash, remove unused code
MirandaWood b23e646
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood 605e192
fix: update eth log handlers, revert fee acc, some comments
MirandaWood 644173b
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood eb3e283
fix: add epoch to block root/merge methods post merge
MirandaWood bb4815d
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood 1f114aa
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood 6d37433
feat: fixes after merge, use blockroot artifact, add proving todos
MirandaWood 117d9d3
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood ef2a883
fix: post merge fixes
MirandaWood 3127243
chore: forge fmt
MirandaWood 3e2f55f
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood a657e05
fix: post merge fixes to publisher
MirandaWood bc17e45
chore: cleanup opt chaining in orchestrator
MirandaWood 99064a1
Merge remote-tracking branch 'origin' into mw/batch-rollup
MirandaWood 388bce3
chore: fmt + fix post merge
MirandaWood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions
9
noir-projects/noir-protocol-circuits/crates/rollup-block-merge/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_block_merge" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.18.0" | ||
|
||
[dependencies] | ||
rollup_lib = { path = "../rollup-lib" } | ||
types = { path = "../types" } |
5 changes: 5 additions & 0 deletions
5
noir-projects/noir-protocol-circuits/crates/rollup-block-merge/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::block_merge::{BlockMergeRollupInputs, BlockRootOrBlockMergePublicInputs}; | ||
|
||
fn main(inputs: BlockMergeRollupInputs) -> pub BlockRootOrBlockMergePublicInputs { | ||
inputs.block_merge_rollup_circuit() | ||
} |
9 changes: 9 additions & 0 deletions
9
noir-projects/noir-protocol-circuits/crates/rollup-block-root/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_block_root" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.18.0" | ||
|
||
[dependencies] | ||
rollup_lib = { path = "../rollup-lib" } | ||
types = { path = "../types" } |
5 changes: 5 additions & 0 deletions
5
noir-projects/noir-protocol-circuits/crates/rollup-block-root/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::block_root::{BlockRootRollupInputs, BlockRootOrBlockMergePublicInputs}; | ||
|
||
fn main(inputs: BlockRootRollupInputs) -> pub BlockRootOrBlockMergePublicInputs { | ||
inputs.block_root_rollup_circuit() | ||
} |
135 changes: 135 additions & 0 deletions
135
...r-protocol-circuits/crates/rollup-lib/src/abis/block_root_or_block_merge_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,135 @@ | ||
use dep::types::{ | ||
abis::{append_only_tree_snapshot::AppendOnlyTreeSnapshot, global_variables::GlobalVariables}, | ||
constants::BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH, | ||
partial_state_reference::PartialStateReference, traits::{Empty, Serialize, Deserialize}, | ||
utils::reader::Reader, address::EthAddress | ||
}; | ||
use crate::abis::constant_rollup_data::ConstantRollupData; | ||
|
||
struct FeeRecipient { | ||
recipient: EthAddress, | ||
value: Field, | ||
} | ||
|
||
impl Empty for FeeRecipient { | ||
fn empty() -> Self { | ||
FeeRecipient { | ||
recipient: EthAddress::zero(), | ||
value: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Serialize<2> for FeeRecipient { | ||
fn serialize(self) -> [Field; 2] { | ||
[self.recipient.to_field(), self.value] | ||
} | ||
} | ||
|
||
impl Deserialize<2> for FeeRecipient { | ||
fn deserialize(values: [Field; 2]) -> Self { | ||
Self { | ||
recipient: EthAddress::from_field(values[0]), | ||
value: values[1] | ||
} | ||
} | ||
} | ||
|
||
impl Eq for FeeRecipient { | ||
fn eq(self, other: Self) -> bool { | ||
(self.recipient.eq(other.recipient)) & (self.value == other.value) | ||
} | ||
} | ||
|
||
// TODO: instead of archives + global vars, use ConstantRollupData x2? It also includes vk root | ||
// may be confusing as new_constant.last_archive would actually be the new_archive | ||
struct BlockRootOrBlockMergePublicInputs { | ||
previous_archive: AppendOnlyTreeSnapshot, // Archive tree root immediately before this block range | ||
new_archive: AppendOnlyTreeSnapshot, // Archive tree root after adding this block range | ||
previous_block_hash: Field, // Identifier of the previous block before the range | ||
end_block_hash: Field, // Identifier of the last block in the range | ||
start_global_variables: GlobalVariables, // Global variables for the first block in the range | ||
end_global_variables: GlobalVariables, // Global variables for the last block in the range | ||
out_hash: Field, // Merkle node of the L2-to-L1 messages merkle roots in the block range | ||
fees: [FeeRecipient; 32], // Concatenation of all coinbase and fees for the block range | ||
vk_tree_root: Field, // Root of allowed vk tree | ||
} | ||
|
||
impl Empty for BlockRootOrBlockMergePublicInputs { | ||
fn empty() -> Self { | ||
BlockRootOrBlockMergePublicInputs { | ||
previous_archive: AppendOnlyTreeSnapshot::zero(), | ||
new_archive: AppendOnlyTreeSnapshot::zero(), | ||
previous_block_hash: 0, | ||
end_block_hash: 0, | ||
start_global_variables: GlobalVariables::empty(), | ||
end_global_variables: GlobalVariables::empty(), | ||
out_hash: 0, | ||
fees: [FeeRecipient::empty(); 32], | ||
vk_tree_root: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Eq for BlockRootOrBlockMergePublicInputs { | ||
fn eq(self, other: Self) -> bool { | ||
(self.previous_archive.eq(other.previous_archive)) & | ||
(self.new_archive.eq(other.new_archive)) & | ||
(self.previous_block_hash == other.previous_block_hash) & | ||
(self.end_block_hash == other.end_block_hash) & | ||
(self.start_global_variables.eq(other.start_global_variables)) & | ||
(self.end_global_variables.eq(other.end_global_variables)) & | ||
(self.out_hash == other.out_hash) & | ||
(self.fees.eq(other.fees)) & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know that Noir handled array equality, nice! |
||
(self.vk_tree_root == other.vk_tree_root) | ||
} | ||
} | ||
|
||
impl Serialize<BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> for BlockRootOrBlockMergePublicInputs { | ||
fn serialize(self) -> [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH] { | ||
let mut fields: BoundedVec<Field, BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> = BoundedVec::new(); | ||
|
||
fields.extend_from_array(self.previous_archive.serialize()); | ||
fields.extend_from_array(self.new_archive.serialize()); | ||
fields.push(self.previous_block_hash as Field); | ||
fields.push(self.end_block_hash as Field); | ||
fields.extend_from_array(self.start_global_variables.serialize()); | ||
fields.extend_from_array(self.end_global_variables.serialize()); | ||
fields.push(self.out_hash as Field); | ||
for i in 0..32 { | ||
fields.extend_from_array(self.fees[i].serialize()); | ||
} | ||
fields.push(self.vk_tree_root as Field); | ||
assert_eq(fields.len(), BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH); | ||
|
||
fields.storage | ||
} | ||
} | ||
|
||
impl Deserialize<BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH> for BlockRootOrBlockMergePublicInputs { | ||
fn deserialize(fields: [Field; BLOCK_ROOT_OR_BLOCK_MERGE_PUBLIC_INPUTS_LENGTH]) -> BlockRootOrBlockMergePublicInputs { | ||
let mut reader = Reader::new(fields); | ||
let item = Self { | ||
previous_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), | ||
new_archive: reader.read_struct(AppendOnlyTreeSnapshot::deserialize), | ||
previous_block_hash: reader.read(), | ||
end_block_hash: reader.read(), | ||
start_global_variables: reader.read_struct(GlobalVariables::deserialize), | ||
end_global_variables: reader.read_struct(GlobalVariables::deserialize), | ||
out_hash: reader.read(), | ||
fees: reader.read_struct_array(FeeRecipient::deserialize, [FeeRecipient::empty(); 32]), | ||
vk_tree_root: reader.read(), | ||
}; | ||
|
||
reader.finish(); | ||
item | ||
} | ||
} | ||
|
||
#[test] | ||
fn serialization_of_empty() { | ||
let item = BlockRootOrBlockMergePublicInputs::empty(); | ||
let serialized = item.serialize(); | ||
let deserialized = BlockRootOrBlockMergePublicInputs::deserialize(serialized); | ||
assert(item.eq(deserialized)); | ||
} |
2 changes: 2 additions & 0 deletions
2
noir-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/mod.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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod constant_rollup_data; | ||
mod base_or_merge_rollup_public_inputs; | ||
mod block_root_or_block_merge_public_inputs; | ||
mod previous_rollup_data; | ||
mod previous_rollup_block_data; |
51 changes: 51 additions & 0 deletions
51
...-projects/noir-protocol-circuits/crates/rollup-lib/src/abis/previous_rollup_block_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,51 @@ | ||
use crate::abis::block_root_or_block_merge_public_inputs::BlockRootOrBlockMergePublicInputs; | ||
use dep::types::{ | ||
constants::VK_TREE_HEIGHT, | ||
recursion::{proof::NestedRecursiveProof, verification_key::VerificationKey, traits::Verifiable}, | ||
traits::Empty, merkle_tree::MembershipWitness, merkle_tree::membership::assert_check_membership, | ||
utils::arrays::find_index_hint | ||
}; | ||
|
||
struct PreviousRollupBlockData { | ||
block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs, | ||
proof: NestedRecursiveProof, | ||
vk: VerificationKey, | ||
vk_witness: MembershipWitness<VK_TREE_HEIGHT>, | ||
} | ||
|
||
impl Verifiable for PreviousRollupBlockData { | ||
fn verify(self) { | ||
let inputs = BlockRootOrBlockMergePublicInputs::serialize(self.block_root_or_block_merge_public_inputs); | ||
std::verify_proof( | ||
self.vk.key.as_slice(), | ||
self.proof.fields.as_slice(), | ||
inputs.as_slice(), | ||
self.vk.hash | ||
); | ||
} | ||
} | ||
|
||
impl Empty for PreviousRollupBlockData { | ||
fn empty() -> Self { | ||
PreviousRollupBlockData { | ||
block_root_or_block_merge_public_inputs: BlockRootOrBlockMergePublicInputs::empty(), | ||
proof: NestedRecursiveProof::empty(), | ||
vk: VerificationKey::empty(), | ||
vk_witness: MembershipWitness::empty(), | ||
} | ||
} | ||
} | ||
|
||
impl PreviousRollupBlockData { | ||
fn validate_in_vk_tree<N>(self, allowed_indices: [u32; N]) { | ||
let index_hint = find_index_hint(allowed_indices, self.vk_witness.leaf_index as u32); | ||
assert_eq(allowed_indices[index_hint], self.vk_witness.leaf_index as u32, "Invalid vk index"); | ||
|
||
assert_check_membership( | ||
self.vk.hash, | ||
self.vk_witness.leaf_index, | ||
self.vk_witness.sibling_path, | ||
self.block_root_or_block_merge_public_inputs.vk_tree_root | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not mentioned in engineering-designs doc - added the vk tree root to check for allowed circuits in future.