-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
782 additions
and
453 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! This module contains the implementation of the [crate::TraceProvider] trait for serving mock output commitments. | ||
|
||
use crate::{Gindex, Position, TraceProvider}; | ||
use alloy_primitives::U256; | ||
use anyhow::Result; | ||
use durin_primitives::Claim; | ||
use std::sync::Arc; | ||
|
||
/// The [MockOutputTraceProvider] is a [TraceProvider] that provides mock L2 output commitments for a [Position]. | ||
pub struct MockOutputTraceProvider { | ||
pub starting_block_number: u64, | ||
pub leaf_depth: u8, | ||
} | ||
|
||
impl MockOutputTraceProvider { | ||
pub fn new(starting_block_number: u64, leaf_depth: u8) -> Self { | ||
Self { | ||
starting_block_number, | ||
leaf_depth, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl TraceProvider for MockOutputTraceProvider { | ||
async fn absolute_prestate(&self, _: Position) -> Result<Arc<[u8]>> { | ||
Ok(Arc::<[u8; 32]>::new( | ||
U256::from(self.starting_block_number).to_be_bytes(), | ||
)) | ||
} | ||
|
||
async fn absolute_prestate_hash(&self, position: Position) -> Result<Claim> { | ||
// The raw state is equivalent to the state hash in the output trace provider. It must be 32 bytes in size. | ||
Ok((*self.absolute_prestate(position).await?).try_into()?) | ||
} | ||
|
||
async fn state_at(&self, position: Position) -> Result<Arc<[u8]>> { | ||
let state = | ||
U256::from(position.trace_index(self.leaf_depth) + self.starting_block_number + 1); | ||
Ok(Arc::<[u8; 32]>::new(state.to_be_bytes())) | ||
} | ||
|
||
async fn state_hash(&self, position: Position) -> Result<Claim> { | ||
// The raw state is equivalent to the state hash in the output trace provider. It must be 32 bytes in size. | ||
Ok((*self.state_at(position).await?).try_into()?) | ||
} | ||
|
||
async fn proof_at(&self, _: Position) -> Result<Arc<[u8]>> { | ||
unimplemented!("Proofs are not supported for the OutputTraceProvider") | ||
} | ||
} |
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,7 @@ | ||
//! Mock implementations of the [crate::TraceProvider] trait for testing. | ||
|
||
mod alphabet; | ||
pub use self::alphabet::AlphabetTraceProvider; | ||
|
||
mod mock_output; | ||
pub use self::mock_output::MockOutputTraceProvider; |
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,13 +1,13 @@ | ||
//! This modules contains trace providers for the variants of the [crate::FaultDisputeGame]. | ||
|
||
mod alphabet; | ||
pub use self::alphabet::AlphabetTraceProvider; | ||
mod split; | ||
pub use self::split::SplitTraceProvider; | ||
|
||
mod output; | ||
pub use self::output::OutputTraceProvider; | ||
|
||
mod split; | ||
pub use self::split::SplitTraceProvider; | ||
|
||
mod cannon; | ||
pub use self::cannon::CannonTraceProvider; | ||
|
||
mod mocks; | ||
pub use self::mocks::{AlphabetTraceProvider, MockOutputTraceProvider}; |
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.