-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(client): Interop consolidation sub-problem (#913)
- Loading branch information
Showing
17 changed files
with
382 additions
and
74 deletions.
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 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 +1,70 @@ | ||
//! Consolidation phase of the interop proof program. | ||
use super::FaultProofProgramError; | ||
use alloc::{sync::Arc, vec::Vec}; | ||
use core::fmt::Debug; | ||
use kona_interop::MessageGraph; | ||
use kona_preimage::{HintWriterClient, PreimageOracleClient}; | ||
use kona_proof::CachingOracle; | ||
use kona_proof_interop::{BootInfo, OracleInteropProvider, PreState}; | ||
use revm::primitives::HashMap; | ||
use tracing::info; | ||
|
||
/// Executes the consolidation phase of the interop proof with the given [PreimageOracleClient] and | ||
/// [HintWriterClient]. | ||
/// | ||
/// This phase is responsible for checking the dependencies between [OptimisticBlock]s in the | ||
/// superchain and ensuring that all dependencies are satisfied. | ||
/// | ||
/// [OptimisticBlock]: kona_proof_interop::OptimisticBlock | ||
pub(crate) async fn consolidate_dependencies<P, H>( | ||
oracle: Arc<CachingOracle<P, H>>, | ||
boot: BootInfo, | ||
pre: PreState, | ||
) -> Result<(), FaultProofProgramError> | ||
where | ||
P: PreimageOracleClient + Send + Sync + Debug + Clone, | ||
H: HintWriterClient + Send + Sync + Debug + Clone, | ||
{ | ||
let provider = OracleInteropProvider::new(oracle, pre.clone()); | ||
|
||
info!(target: "client_interop", "Deriving local-safe headers from prestate"); | ||
|
||
// Ensure that the pre-state is a transition state. | ||
let PreState::TransitionState(ref transition_state) = pre else { | ||
return Err(FaultProofProgramError::StateTransitionFailed); | ||
}; | ||
|
||
let block_hashes = transition_state | ||
.pending_progress | ||
.iter() | ||
.zip(transition_state.pre_state.output_roots.iter()) | ||
.map(|(optimistic_block, pre_state)| (pre_state.chain_id, optimistic_block.block_hash)) | ||
.collect::<HashMap<_, _>>(); | ||
|
||
let mut headers = Vec::with_capacity(block_hashes.len()); | ||
for (chain_id, block_hash) in block_hashes { | ||
let header = provider.header_by_hash(chain_id, block_hash).await?; | ||
headers.push((chain_id, header.seal(block_hash))); | ||
} | ||
|
||
info!(target: "client_interop", "Loaded {} local-safe headers", headers.len()); | ||
|
||
// TODO: Re-execution w/ bad blocks. Not complete, we just panic if any deps are invalid atm. | ||
let graph = MessageGraph::derive(headers.as_slice(), provider).await.unwrap(); | ||
graph.resolve().await.unwrap(); | ||
|
||
// Transition to the Super Root at the next timestamp. | ||
// | ||
// TODO: This won't work if we replace blocks, `transition` doesn't allow replacement of pending | ||
// progress just yet. | ||
let post = pre.transition(None).ok_or(FaultProofProgramError::StateTransitionFailed)?; | ||
let post_commitment = post.hash(); | ||
|
||
// Ensure that the post-state matches the claimed post-state. | ||
if post_commitment != boot.claimed_post_state { | ||
return Err(FaultProofProgramError::InvalidClaim(boot.claimed_post_state, post_commitment)); | ||
} | ||
|
||
Ok(()) | ||
} |
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
Oops, something went wrong.