-
Notifications
You must be signed in to change notification settings - Fork 106
feat(AggLayer): implement verify_leaf
#2295
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
Open
mmagician
wants to merge
5
commits into
mmagician-verify-leaf-bridge
Choose a base branch
from
mmagician-verify-leaf
base: mmagician-verify-leaf-bridge
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
| extern crate alloc; | ||
|
|
||
| use alloc::sync::Arc; | ||
|
|
||
| use miden_agglayer::agglayer_library; | ||
| use miden_agglayer::errors::{ | ||
| ERR_BRIDGE_NOT_MAINNET, | ||
| ERR_LEADING_BITS_NON_ZERO, | ||
| ERR_ROLLUP_INDEX_NON_ZERO, | ||
| }; | ||
| use miden_assembly::{Assembler, DefaultSourceManager}; | ||
| use miden_core_lib::CoreLibrary; | ||
| use miden_processor::Program; | ||
| use miden_testing::assert_execution_error; | ||
|
|
||
| use crate::agglayer::test_utils::execute_program_with_default_host; | ||
|
|
||
| fn assemble_process_global_index_program(global_index_be_u32_limbs: [u32; 8]) -> Program { | ||
| let [g0, g1, g2, g3, g4, g5, g6, g7] = global_index_be_u32_limbs; | ||
|
|
||
| let script_code = format!( | ||
| r#" | ||
| use miden::core::sys | ||
| use miden::agglayer::bridge_in | ||
| begin | ||
| push.{g7}.{g6}.{g5}.{g4}.{g3}.{g2}.{g1}.{g0} | ||
| exec.bridge_in::process_global_index_mainnet | ||
| exec.sys::truncate_stack | ||
| end | ||
| "# | ||
| ); | ||
|
|
||
| Assembler::new(Arc::new(DefaultSourceManager::default())) | ||
| .with_dynamic_library(CoreLibrary::default()) | ||
| .unwrap() | ||
| .with_dynamic_library(agglayer_library()) | ||
| .unwrap() | ||
| .assemble_program(&script_code) | ||
| .unwrap() | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_process_global_index_mainnet_returns_leaf_index() -> anyhow::Result<()> { | ||
| // 256-bit globalIndex encoded as 8 u32 limbs (big-endian): | ||
mmagician marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // [top 191 bits = 0, mainnet flag = 1, rollup_index = 0, leaf_index = 2] | ||
| let global_index = [0, 0, 0, 0, 0, 1, 0, 2]; | ||
| let program = assemble_process_global_index_program(global_index); | ||
|
|
||
| let exec_output = execute_program_with_default_host(program, None).await?; | ||
|
|
||
| assert_eq!(exec_output.stack[0].as_int(), 2); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_process_global_index_mainnet_rejects_non_zero_leading_bits() { | ||
| let global_index = [1, 0, 0, 0, 0, 1, 0, 2]; | ||
| let program = assemble_process_global_index_program(global_index); | ||
|
|
||
| let err = execute_program_with_default_host(program, None).await; | ||
| assert_execution_error!(err, ERR_LEADING_BITS_NON_ZERO); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_process_global_index_mainnet_rejects_flag_limb_upper_bits() { | ||
| // limb5 is the mainent flag; only the lowest bit is allowed | ||
| let global_index = [0, 0, 0, 0, 0, 3, 0, 2]; | ||
| let program = assemble_process_global_index_program(global_index); | ||
|
|
||
| let err = execute_program_with_default_host(program, None).await; | ||
| assert_execution_error!(err, ERR_BRIDGE_NOT_MAINNET); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_process_global_index_mainnet_rejects_non_zero_rollup_index() { | ||
| let global_index = [0, 0, 0, 0, 0, 1, 7, 2]; | ||
| let program = assemble_process_global_index_program(global_index); | ||
|
|
||
| let err = execute_program_with_default_host(program, None).await; | ||
| assert_execution_error!(err, ERR_ROLLUP_INDEX_NON_ZERO); | ||
| } | ||
This file contains hidden or 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,4 +1,6 @@ | ||
| pub mod asset_conversion; | ||
| mod bridge_in; | ||
| mod bridge_out; | ||
| mod global_index; | ||
| mod solidity_miden_address_conversion; | ||
| mod test_utils; |
|
Contributor
Author
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. copied from #2262, they'll eventually be merged |
This file contains hidden or 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,35 @@ | ||
| extern crate alloc; | ||
|
|
||
| use miden_agglayer::agglayer_library; | ||
| use miden_core_lib::CoreLibrary; | ||
| use miden_processor::fast::{ExecutionOutput, FastProcessor}; | ||
| use miden_processor::{AdviceInputs, DefaultHost, ExecutionError, Program, StackInputs}; | ||
| use miden_protocol::transaction::TransactionKernel; | ||
|
|
||
| /// Execute a program with default host and optional advice inputs | ||
| pub async fn execute_program_with_default_host( | ||
| program: Program, | ||
| advice_inputs: Option<AdviceInputs>, | ||
| ) -> Result<ExecutionOutput, ExecutionError> { | ||
| let mut host = DefaultHost::default(); | ||
|
|
||
| let test_lib = TransactionKernel::library(); | ||
| host.load_library(test_lib.mast_forest()).unwrap(); | ||
|
|
||
| let std_lib = CoreLibrary::default(); | ||
| host.load_library(std_lib.mast_forest()).unwrap(); | ||
|
|
||
| // Register handlers from std_lib | ||
| for (event_name, handler) in std_lib.handlers() { | ||
| host.register_handler(event_name, handler)?; | ||
| } | ||
|
|
||
| let agglayer_lib = agglayer_library(); | ||
| host.load_library(agglayer_lib.mast_forest()).unwrap(); | ||
|
|
||
| let stack_inputs = StackInputs::new(vec![]).unwrap(); | ||
| let advice_inputs = advice_inputs.unwrap_or_default(); | ||
|
|
||
| let processor = FastProcessor::new_debug(stack_inputs.as_slice(), advice_inputs); | ||
| processor.execute(&program, &mut host).await | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.