-
Notifications
You must be signed in to change notification settings - Fork 2
General interface for creating proofs with nozzle (and likely other parties interested in VE) #80
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
Draft
pedrohba1
wants to merge
7
commits into
main
Choose a base branch
from
nve-integration
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6803758
feat: adds proof gen interface
pedrohba1 173eb3e
feat: generic block trait to implement
pedrohba1 e0dec2d
Merge remote-tracking branch 'origin/main' into nve-integration
pedrohba1 38e2d4a
feat: EVM block match, filter capella block num
pedrohba1 dee9120
refactor: separates between evm and non evm
pedrohba1 ccbd863
refactor: mock eth block use
pedrohba1 f833579
Merge remote-tracking branch 'origin/main' into nve-integration
pedrohba1 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,253 @@ | ||
| // Copyright 2024-, Semiotic AI, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Generates proof for block based on its relation to the Merge and Capella upgrades | ||
| //! in case of Ethereum BLocks. For Arbitrum, Optimism, it uses other methods to generate proofs | ||
|
|
||
| //use crate::protos::EthBlock; | ||
| use alloy_primitives::B256; | ||
| use ethportal_api::types::execution::header_with_proof::{ | ||
| BlockHeaderProof, | ||
| // HistoricalRootsBlockProof, HistoricalSummariesBlockProof, | ||
| PreMergeAccumulatorProof, | ||
| }; | ||
|
|
||
| /// The merge block, inclusive, i.e., the block number below already counts as post-merge. | ||
| pub const MERGE_BLOCK: u64 = 15537394; | ||
| /// The first block after Shanghai-Capella block | ||
| pub const CAPELLA_START_BLOCK: u64 = 17_034_870; | ||
|
|
||
| /// A trait for EVM-based blockchains (Ethereum, Arbitrum, Optimism, etc.). | ||
| pub trait AnyBlock { | ||
| /// return height of given block | ||
| fn block_number(&self) -> u64; | ||
| /// Returns the chain id | ||
| fn chain_id(&self) -> EvmChain; | ||
| /// Generates a proof for the block | ||
| fn prove_block(&self) -> BlockHeaderProof; | ||
| } | ||
|
|
||
| /// Enum to differentiate which EVM chain it is. | ||
| #[derive(Debug)] | ||
| pub enum EvmChain { | ||
| /// layer 1 ethereum | ||
| Ethereum, | ||
| ///arbiturm, layer 2 | ||
| Arbitrum, | ||
| ///optimism layer 2 | ||
| Optimism, | ||
| } | ||
|
|
||
| /// Enum to differentiate Non-EVM chains. | ||
| /// Currently only Solana, but can be extended to include more. | ||
| #[derive(Debug)] | ||
| pub enum NonEvmChain { | ||
| ///Solana type | ||
| Solana, | ||
| // Future chains can be added here (e.g., Aptos, Sui) | ||
| } | ||
|
|
||
| /// Represents a blockchain block that can be either an EVM block or a Non-EVM block. | ||
| /// | ||
| /// This enum allows for storing different blockchain block types while maintaining a common interface. | ||
| /// It uses generics to store any type that implements the `AnyBlock` trait and provides | ||
| /// a separate variant for Non-EVM chains. | ||
| /// | ||
| /// # Variants | ||
| /// - `Evm(E)`: Stores an EVM-based block (Ethereum, Arbitrum, Optimism, etc.). | ||
| /// - `NonEvm(NonEvmChain)`: Represents a block from a non-EVM chain. | ||
| pub enum Block<E: AnyBlock> { | ||
| /// An EVM-based block, such as Ethereum, Arbitrum, or Optimism. | ||
| Evm(E), | ||
| /// A Non-EVM blockchain block (e.g., Solana, Sui, Aptos). | ||
| NonEvm(NonEvmChain), | ||
| } | ||
|
|
||
| impl<E: AnyBlock> Block<E> { | ||
| /// Retrieves the block number of the stored block. | ||
| /// | ||
| /// - Returns `Some(block_number)` for EVM-based blocks. | ||
| /// - Returns `None` for Non-EVM blocks, as they may not have numeric block heights. | ||
| /// | ||
| /// # Example | ||
| /// ``` | ||
| /// let eth_block = Block::Evm(EthereumBlock { number: 15537394 }); | ||
| /// assert_eq!(eth_block.block_number(), Some(15537394)); | ||
| /// | ||
| /// let solana_block = Block::NonEvm(NonEvmChain::Solana); | ||
| /// assert_eq!(solana_block.block_number(), None); | ||
| /// ``` | ||
| pub fn block_number(&self) -> Option<u64> { | ||
| match self { | ||
| Block::Evm(block) => Some(block.block_number()), | ||
| Block::NonEvm(_) => None, // Non-EVM chains don't necessarily use block numbers. | ||
| } | ||
| } | ||
|
|
||
| /// Generates a proof for the stored block. | ||
| /// | ||
| /// - Returns `Some(BlockHeaderProof)` for EVM-based blocks. | ||
| /// - Returns `None` for Non-EVM blocks, as proof mechanisms differ. | ||
| /// | ||
| /// # Example | ||
| /// ``` | ||
| /// let eth_block = Block::Evm(EthereumBlock { number: 15537394 }); | ||
| /// let proof = eth_block.prove_block(); | ||
| /// assert!(proof.is_some()); | ||
| /// | ||
| /// let solana_block = Block::NonEvm(NonEvmChain::Solana); | ||
| /// let proof = solana_block.prove_block(); | ||
| /// assert!(proof.is_none()); | ||
| /// ``` | ||
| pub fn prove_block(&self) -> Option<BlockHeaderProof> { | ||
| match self { | ||
| Block::Evm(block) => Some(block.prove_block()), | ||
| Block::NonEvm(_) => None, // Non-EVM proof logic would go here. | ||
| } | ||
| } | ||
|
|
||
| /// Retrieves the chain type of the stored block. | ||
| /// | ||
| /// - Returns `Some(EvmChain)` for EVM blocks (Ethereum, Arbitrum, Optimism). | ||
| /// - Returns `None` for Non-EVM chains. | ||
| /// | ||
| /// # Example | ||
| /// ``` | ||
| /// let eth_block = Block::Evm(EthereumBlock { number: 15537394 }); | ||
| /// assert_eq!(eth_block.chain_id(), Some(EvmChain::Ethereum)); | ||
| /// | ||
| /// let solana_block = Block::NonEvm(NonEvmChain::Solana); | ||
| /// assert_eq!(solana_block.chain_id(), None); | ||
| /// ``` | ||
| pub fn chain_id(&self) -> Option<EvmChain> { | ||
| match self { | ||
| Block::Evm(block) => Some(block.chain_id()), | ||
| Block::NonEvm(_) => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Implement AnyBlock for EthereumBlock | ||
| struct EthereumBlock { | ||
| pub number: u64, | ||
| } | ||
|
|
||
| impl AnyBlock for EthereumBlock { | ||
| fn block_number(&self) -> u64 { | ||
| self.number | ||
| } | ||
|
|
||
| fn chain_id(&self) -> EvmChain { | ||
| EvmChain::Ethereum | ||
| } | ||
|
|
||
| fn prove_block(&self) -> BlockHeaderProof { | ||
| let execution_block_number = self.block_number(); | ||
|
|
||
| if execution_block_number < MERGE_BLOCK { | ||
| println!("Pre-Merge Ethereum block: {:?}", execution_block_number); | ||
| todo!() | ||
| } else if execution_block_number < CAPELLA_START_BLOCK { | ||
| println!( | ||
| "Post-Merge, Pre-Capella Ethereum block: {:?}", | ||
| execution_block_number | ||
| ); | ||
| todo!() | ||
| } else { | ||
| println!("Post-Capella Ethereum block: {:?}", execution_block_number); | ||
| todo!() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Implement AnyBlock for ArbBlock | ||
| struct ArbBlock { | ||
| pub number: u64, | ||
| } | ||
|
|
||
| impl AnyBlock for ArbBlock { | ||
| fn block_number(&self) -> u64 { | ||
| self.number | ||
| } | ||
|
|
||
| fn chain_id(&self) -> EvmChain { | ||
| EvmChain::Arbitrum | ||
| } | ||
|
|
||
| fn prove_block(&self) -> BlockHeaderProof { | ||
| println!("Proving Arbitrum block: {:?}", self.number); | ||
| BlockHeaderProof::PreMergeAccumulatorProof(PreMergeAccumulatorProof { | ||
| proof: [B256::default(); 15], | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| /// Implement AnyBlock for OptimismBlock | ||
| struct OptimismBlock { | ||
| pub number: u64, | ||
| } | ||
|
|
||
| impl AnyBlock for OptimismBlock { | ||
| fn block_number(&self) -> u64 { | ||
| self.number | ||
| } | ||
|
|
||
| fn chain_id(&self) -> EvmChain { | ||
| EvmChain::Optimism | ||
| } | ||
|
|
||
| fn prove_block(&self) -> BlockHeaderProof { | ||
| println!("Proving Optimism block: {:?}", self.number); | ||
| BlockHeaderProof::PreMergeAccumulatorProof(PreMergeAccumulatorProof { | ||
| proof: [B256::default(); 15], | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TODO: implement receipt trait | ||
| // where we can retrieve specific block data | ||
| // for generating the proof | ||
| // tip: check parquet nozzle files, for receipt related matadata that | ||
| // is filled in each row | ||
| // tip 2: metadata_db can have additional receipt information if configure to. | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
|
|
||
| use super::*; | ||
|
|
||
| fn mock_eth_block() -> EthereumBlock { | ||
| EthereumBlock { | ||
| number: MERGE_BLOCK, | ||
| } | ||
| } | ||
|
|
||
| fn mock_arb_block() -> ArbBlock { | ||
| ArbBlock { number: 15537395 } | ||
| } | ||
|
|
||
| fn mock_optimism_block() -> OptimismBlock { | ||
| OptimismBlock { number: 15537400 } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prove_eth_block_pre_merge() { | ||
| let arb_block = mock_eth_block(); | ||
| let block = Block::Evm(arb_block); | ||
| block.prove_block(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prove_arb_block_post_merge_pre_capella() { | ||
| let arb_block = mock_arb_block(); | ||
| let block = Block::Evm(arb_block); | ||
| block.prove_block(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_prove_optimism_block_post_capella() { | ||
| let optimism_block = mock_optimism_block(); | ||
| let block = Block::Evm(optimism_block); | ||
| block.prove_block(); | ||
| } | ||
| } | ||
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.
Generating this proof is going to require the block headers for all other blocks in the same era. How is this function going to get the required data?