Skip to content
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

chore(client): Isolate FPVM-specific constructs #435

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! [OracleReader]: kona_preimage::OracleReader

use crate::{HINT_WRITER, ORACLE_READER};
use super::{HINT_WRITER, ORACLE_READER};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use anyhow::Result;
use async_trait::async_trait;
Expand All @@ -17,7 +17,7 @@ use spin::Mutex;
///
/// [OracleReader]: kona_preimage::OracleReader
#[derive(Debug, Clone)]
pub struct CachingOracle {
pub(crate) struct CachingOracle {
/// The spin-locked cache that stores the responses from the oracle.
cache: Arc<Mutex<LruCache<PreimageKey, Vec<u8>>>>,
}
Expand All @@ -27,7 +27,7 @@ impl CachingOracle {
/// responses in the cache.
///
/// [OracleReader]: kona_preimage::OracleReader
pub fn new(cache_size: usize) -> Self {
pub(crate) fn new(cache_size: usize) -> Self {
Self {
cache: Arc::new(Mutex::new(LruCache::new(
NonZeroUsize::new(cache_size).expect("N must be greater than 0"),
Expand Down
11 changes: 7 additions & 4 deletions bin/client/src/comms/mod.rs → bin/client/src/fault/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! Contains the host <-> client communication utilities.
//! Contains FPVM-specific constructs for the `kona-client` program.

use kona_common::FileDescriptor;
use kona_preimage::{HintWriter, OracleReader, PipeHandle};

mod caching_oracle;
pub use caching_oracle::CachingOracle;
pub(crate) use caching_oracle::CachingOracle;

mod precompiles;
pub(crate) use precompiles::FPVMPrecompileOverride;

/// The global preimage oracle reader pipe.
static ORACLE_READER_PIPE: PipeHandle =
Expand All @@ -15,7 +18,7 @@ static HINT_WRITER_PIPE: PipeHandle =
PipeHandle::new(FileDescriptor::HintRead, FileDescriptor::HintWrite);

/// The global preimage oracle reader.
pub static ORACLE_READER: OracleReader = OracleReader::new(ORACLE_READER_PIPE);
pub(crate) static ORACLE_READER: OracleReader = OracleReader::new(ORACLE_READER_PIPE);

/// The global hint writer.
pub static HINT_WRITER: HintWriter = HintWriter::new(HINT_WRITER_PIPE);
pub(crate) static HINT_WRITER: HintWriter = HintWriter::new(HINT_WRITER_PIPE);
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! Contains the accelerated version of the `ecPairing` precompile.

use crate::fault::{HINT_WRITER, ORACLE_READER};
use alloc::{string::ToString, vec::Vec};
use alloy_primitives::{keccak256, Address, Bytes};
use anyhow::ensure;
use kona_client::HintType;
use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient};
use revm::{
precompile::{
Expand All @@ -12,8 +14,6 @@ use revm::{
primitives::{Precompile, PrecompileOutput, PrecompileResult},
};

use crate::{HintType, HINT_WRITER, ORACLE_READER};

const ECPAIRING_ADDRESS: Address = u64_to_address(8);
const PAIR_ELEMENT_LEN: usize = 64 + 128;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! Contains the accelerated version of the `ecrecover` precompile.

use crate::fault::{HINT_WRITER, ORACLE_READER};
use alloc::{string::ToString, vec::Vec};
use alloy_primitives::{keccak256, Address, Bytes};
use anyhow::ensure;
use kona_client::HintType;
use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient};
use revm::{
precompile::{u64_to_address, Error as PrecompileError, PrecompileWithAddress},
primitives::{Precompile, PrecompileOutput, PrecompileResult},
};

use crate::{HintType, HINT_WRITER, ORACLE_READER};

const ECRECOVER_ADDRESS: Address = u64_to_address(1);

pub(crate) const FPVM_ECRECOVER: PrecompileWithAddress =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//! Contains the accelerated version of the KZG point evaluation precompile.

use crate::fault::{HINT_WRITER, ORACLE_READER};
use alloc::{string::ToString, vec::Vec};
use alloy_primitives::{keccak256, Address, Bytes};
use anyhow::ensure;
use kona_client::HintType;
use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient};
use revm::{
precompile::{u64_to_address, Error as PrecompileError, PrecompileWithAddress},
primitives::{Precompile, PrecompileOutput, PrecompileResult},
};

use crate::{HintType, HINT_WRITER, ORACLE_READER};

const POINT_EVAL_ADDRESS: Address = u64_to_address(0x0A);

pub(crate) const FPVM_KZG_POINT_EVAL: PrecompileWithAddress =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod kzg_point_eval;

/// The [PrecompileOverride] implementation for the FPVM-accelerated precompiles.
#[derive(Debug)]
pub struct FPVMPrecompileOverride<F, H>
pub(crate) struct FPVMPrecompileOverride<F, H>
where
F: TrieDBFetcher,
H: TrieDBHinter,
Expand Down
9 changes: 6 additions & 3 deletions bin/client/src/kona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
#![no_std]
#![cfg_attr(any(target_arch = "mips", target_arch = "riscv64"), no_main)]

extern crate alloc;

use alloc::sync::Arc;
use alloy_consensus::Header;
use kona_client::{
l1::{DerivationDriver, OracleBlobProvider, OracleL1ChainProvider},
l2::{FPVMPrecompileOverride, OracleL2ChainProvider},
BootInfo, CachingOracle,
l2::OracleL2ChainProvider,
BootInfo,
};
use kona_common_proc::client_entry;
use kona_executor::StatelessL2BlockExecutor;
use kona_primitives::L2AttributesWithParent;

extern crate alloc;
pub(crate) mod fault;
use fault::{CachingOracle, FPVMPrecompileOverride};

/// The size of the LRU cache in the oracle.
const ORACLE_LRU_SIZE: usize = 1024;
Expand Down
3 changes: 0 additions & 3 deletions bin/client/src/l2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@

mod chain_provider;
pub use chain_provider::OracleL2ChainProvider;

mod precompiles;
pub use precompiles::FPVMPrecompileOverride;
12 changes: 3 additions & 9 deletions bin/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,8 @@ pub mod l1;

pub mod l2;

pub mod hint;
mod hint;
pub use hint::HintType;

mod comms;
pub use comms::{CachingOracle, HINT_WRITER, ORACLE_READER};

mod boot;
pub use boot::{
BootInfo, L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY,
L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY,
};
pub mod boot;
pub use boot::BootInfo;
2 changes: 1 addition & 1 deletion bin/host/src/kv/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::KeyValueStore;
use crate::cli::HostCli;
use alloy_primitives::B256;
use kona_client::{
use kona_client::boot::{
L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY,
L2_ROLLUP_CONFIG_KEY,
};
Expand Down