Skip to content

Commit

Permalink
boilerplate + nits
Browse files Browse the repository at this point in the history
  • Loading branch information
hashcashier committed Jan 17, 2025
1 parent 9cb22a3 commit c3b072e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
21 changes: 8 additions & 13 deletions bin/client/src/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use alloy_primitives::B256;
use core::fmt::Debug;
use kona_driver::{Driver, DriverError};
use kona_executor::{ExecutorError, KonaHandleRegister, TrieDBProvider};
use kona_preimage::{
CommsClient, HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient,
};
use kona_preimage::{CommsClient, HintWriterClient, PreimageKeyType, PreimageOracleClient};
use kona_proof::{
errors::OracleProviderError,
executor::KonaExecutor,
Expand Down Expand Up @@ -154,25 +152,22 @@ where

/// Fetches the safe head hash of the L2 chain based on the agreed upon L2 output root in the
/// [BootInfo].
async fn fetch_safe_head_hash<O>(
pub async fn fetch_safe_head_hash<O>(
caching_oracle: &O,
boot_info: &BootInfo,
) -> Result<B256, OracleProviderError>
where
O: CommsClient,
{
caching_oracle
.write(&HintType::StartingL2Output.encode_with(&[boot_info.agreed_l2_output_root.as_ref()]))
.await
.map_err(OracleProviderError::Preimage)?;
let mut output_preimage = [0u8; 128];
caching_oracle
.get_exact(
PreimageKey::new(*boot_info.agreed_l2_output_root, PreimageKeyType::Keccak256),
HintType::StartingL2Output
.get_exact_preimage(
caching_oracle,
boot_info.agreed_l2_output_root,
PreimageKeyType::Keccak256,
&mut output_preimage,
)
.await
.map_err(OracleProviderError::Preimage)?;
.await?;

output_preimage[96..128].try_into().map_err(OracleProviderError::SliceConversion)
}
12 changes: 6 additions & 6 deletions crates/proof-sdk/proof/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,32 @@ impl HintType {
pub async fn get_preimage<T: CommsClient>(
&self,
oracle: &T,
preimage: B256,
image: B256,
preimage_key_type: PreimageKeyType,
) -> Result<Vec<u8>, OracleProviderError> {
oracle
.write(&self.encode_with(&[preimage.as_ref()]))
.write(&self.encode_with(&[image.as_ref()]))
.await
.map_err(OracleProviderError::Preimage)?;
oracle
.get(PreimageKey::new(*preimage, preimage_key_type))
.get(PreimageKey::new(*image, preimage_key_type))
.await
.map_err(OracleProviderError::Preimage)
}
/// Retrieves a preimage through an oracle
pub async fn get_exact_preimage<T: CommsClient>(
&self,
oracle: &T,
preimage: B256,
image: B256,
preimage_key_type: PreimageKeyType,
buf: &mut [u8],
) -> Result<(), OracleProviderError> {
oracle
.write(&self.encode_with(&[preimage.as_ref()]))
.write(&self.encode_with(&[image.as_ref()]))
.await
.map_err(OracleProviderError::Preimage)?;
oracle
.get_exact(PreimageKey::new(*preimage, preimage_key_type), buf)
.get_exact(PreimageKey::new(*image, preimage_key_type), buf)
.await
.map_err(OracleProviderError::Preimage)
}
Expand Down

0 comments on commit c3b072e

Please sign in to comment.