From 4a3b9289942ec8084a41b62bd122de9922c1af72 Mon Sep 17 00:00:00 2001 From: clabby Date: Fri, 15 Nov 2024 15:49:12 -0500 Subject: [PATCH] feat(workspace): `kona-proof` (#818) * feat(workspace): Introduce `kona-proof` crate * ignore `kona-proof` fix --- .github/codecov.yml | 3 +- Cargo.lock | 28 ++++++++++ Cargo.toml | 1 + bin/client/Cargo.toml | 1 + bin/client/src/fault/mod.rs | 22 -------- .../src/{fault => }/handler/bn128_pair.rs | 4 +- .../src/{fault => }/handler/ecrecover.rs | 4 +- .../src/{fault => }/handler/kzg_point_eval.rs | 4 +- bin/client/src/{fault => }/handler/mod.rs | 0 bin/client/src/kona.rs | 30 +++++++--- bin/client/src/lib.rs | 19 ------- bin/host/Cargo.toml | 1 + bin/host/src/fetcher/mod.rs | 2 +- bin/host/src/kv/local.rs | 4 +- bin/host/src/util.rs | 2 +- crates/proof-sdk/proof/CHANGELOG.md | 55 +++++++++++++++++++ crates/proof-sdk/proof/Cargo.toml | 41 ++++++++++++++ crates/proof-sdk/proof/README.md | 8 +++ .../proof-sdk/proof/src/blocking_runtime.rs | 52 ++++++++++++++++++ .../proof-sdk/proof}/src/boot.rs | 3 +- .../proof-sdk/proof}/src/caching_oracle.rs | 0 .../proof-sdk/proof}/src/errors.rs | 0 .../proof-sdk/proof}/src/executor.rs | 2 +- .../proof-sdk/proof}/src/hint.rs | 27 +++++---- .../proof-sdk/proof}/src/l1/blob_provider.rs | 2 +- .../proof-sdk/proof}/src/l1/chain_provider.rs | 6 +- .../proof-sdk/proof}/src/l1/mod.rs | 2 +- .../proof-sdk/proof}/src/l1/pipeline.rs | 3 +- .../proof-sdk/proof}/src/l2/chain_provider.rs | 14 ++--- .../proof-sdk/proof}/src/l2/mod.rs | 0 crates/proof-sdk/proof/src/lib.rs | 30 ++++++++++ .../proof-sdk/proof}/src/sync.rs | 0 32 files changed, 279 insertions(+), 91 deletions(-) delete mode 100644 bin/client/src/fault/mod.rs rename bin/client/src/{fault => }/handler/bn128_pair.rs (96%) rename bin/client/src/{fault => }/handler/ecrecover.rs (95%) rename bin/client/src/{fault => }/handler/kzg_point_eval.rs (96%) rename bin/client/src/{fault => }/handler/mod.rs (100%) create mode 100644 crates/proof-sdk/proof/CHANGELOG.md create mode 100644 crates/proof-sdk/proof/Cargo.toml create mode 100644 crates/proof-sdk/proof/README.md create mode 100644 crates/proof-sdk/proof/src/blocking_runtime.rs rename {bin/client => crates/proof-sdk/proof}/src/boot.rs (99%) rename {bin/client => crates/proof-sdk/proof}/src/caching_oracle.rs (100%) rename {bin/client => crates/proof-sdk/proof}/src/errors.rs (100%) rename {bin/client => crates/proof-sdk/proof}/src/executor.rs (97%) rename {bin/client => crates/proof-sdk/proof}/src/hint.rs (80%) rename {bin/client => crates/proof-sdk/proof}/src/l1/blob_provider.rs (98%) rename {bin/client => crates/proof-sdk/proof}/src/l1/chain_provider.rs (97%) rename {bin/client => crates/proof-sdk/proof}/src/l1/mod.rs (74%) rename {bin/client => crates/proof-sdk/proof}/src/l1/pipeline.rs (99%) rename {bin/client => crates/proof-sdk/proof}/src/l2/chain_provider.rs (96%) rename {bin/client => crates/proof-sdk/proof}/src/l2/mod.rs (100%) create mode 100644 crates/proof-sdk/proof/src/lib.rs rename {bin/client => crates/proof-sdk/proof}/src/sync.rs (100%) diff --git a/.github/codecov.yml b/.github/codecov.yml index 1d835ab63..d9d6e086a 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -23,8 +23,7 @@ ignore: - "**/test_utils*" - "**/test_util*" - "**/tests*" - - "crates/derive-alloy/src/alloy_providers.rs" - - "crates/derive-alloy/src/beacon_client.rs" + - "crates/proof-sdk/proof" - "crates/mpt/src/noop.rs" # Make comments less noisy diff --git a/Cargo.lock b/Cargo.lock index e8112fb7a..bba5fdedd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2304,6 +2304,7 @@ dependencies = [ "kona-executor", "kona-mpt", "kona-preimage", + "kona-proof", "lru", "op-alloy-consensus", "op-alloy-genesis", @@ -2431,6 +2432,7 @@ dependencies = [ "kona-derive", "kona-mpt", "kona-preimage", + "kona-proof", "op-alloy-genesis", "op-alloy-protocol", "os_pipe", @@ -2481,6 +2483,32 @@ dependencies = [ "tracing", ] +[[package]] +name = "kona-proof" +version = "0.0.1" +dependencies = [ + "alloy-consensus", + "alloy-eips", + "alloy-primitives", + "alloy-rlp", + "async-trait", + "kona-derive", + "kona-driver", + "kona-executor", + "kona-mpt", + "kona-preimage", + "lru", + "op-alloy-consensus", + "op-alloy-genesis", + "op-alloy-protocol", + "op-alloy-rpc-types-engine", + "serde", + "serde_json", + "spin", + "thiserror 2.0.3", + "tracing", +] + [[package]] name = "lazy_static" version = "1.5.0" diff --git a/Cargo.toml b/Cargo.toml index 659fdc27c..3572d1a96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,6 +70,7 @@ kona-executor = { path = "crates/executor", version = "0.0.5", default-features kona-common = { path = "crates/proof-sdk/common", version = "0.0.4", default-features = false } kona-common-proc = { path = "crates/proof-sdk/common-proc", version = "0.0.5", default-features = false } kona-preimage = { path = "crates/proof-sdk/preimage", version = "0.0.4", default-features = false } +kona-proof = { path = "crates/proof-sdk/proof", version = "0.0.1", default-features = false } # Alloy alloy-rlp = { version = "0.3.9", default-features = false } diff --git a/bin/client/Cargo.toml b/bin/client/Cargo.toml index 6eb5ba4f6..b522e3d13 100644 --- a/bin/client/Cargo.toml +++ b/bin/client/Cargo.toml @@ -17,6 +17,7 @@ kona-driver.workspace = true kona-preimage.workspace = true kona-executor.workspace = true kona-common-proc.workspace = true +kona-proof.workspace = true # Alloy alloy-rlp.workspace = true diff --git a/bin/client/src/fault/mod.rs b/bin/client/src/fault/mod.rs deleted file mode 100644 index 8773f68d6..000000000 --- a/bin/client/src/fault/mod.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Contains FPVM-specific constructs for the `kona-client` program. - -use kona_client::PipeHandle; -use kona_common::FileDescriptor; -use kona_preimage::{HintWriter, OracleReader}; - -mod handler; -pub(crate) use handler::fpvm_handle_register; - -/// The global preimage oracle reader pipe. -static ORACLE_READER_PIPE: PipeHandle = - PipeHandle::new(FileDescriptor::PreimageRead, FileDescriptor::PreimageWrite); - -/// The global hint writer pipe. -static HINT_WRITER_PIPE: PipeHandle = - PipeHandle::new(FileDescriptor::HintRead, FileDescriptor::HintWrite); - -/// The global preimage oracle reader. -pub(crate) static ORACLE_READER: OracleReader = OracleReader::new(ORACLE_READER_PIPE); - -/// The global hint writer. -pub(crate) static HINT_WRITER: HintWriter = HintWriter::new(HINT_WRITER_PIPE); diff --git a/bin/client/src/fault/handler/bn128_pair.rs b/bin/client/src/handler/bn128_pair.rs similarity index 96% rename from bin/client/src/fault/handler/bn128_pair.rs rename to bin/client/src/handler/bn128_pair.rs index 0be0f2264..fb9e62cc1 100644 --- a/bin/client/src/fault/handler/bn128_pair.rs +++ b/bin/client/src/handler/bn128_pair.rs @@ -1,13 +1,13 @@ //! Contains the accelerated version of the `ecPairing` precompile. -use crate::fault::{HINT_WRITER, ORACLE_READER}; +use crate::{HINT_WRITER, ORACLE_READER}; use alloc::{string::ToString, vec::Vec}; use alloy_primitives::{keccak256, Address, Bytes}; -use kona_client::{errors::OracleProviderError, HintType}; use kona_preimage::{ errors::PreimageOracleError, HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient, }; +use kona_proof::{errors::OracleProviderError, HintType}; use revm::{ precompile::{ bn128::pair::{ISTANBUL_PAIR_BASE, ISTANBUL_PAIR_PER_POINT}, diff --git a/bin/client/src/fault/handler/ecrecover.rs b/bin/client/src/handler/ecrecover.rs similarity index 95% rename from bin/client/src/fault/handler/ecrecover.rs rename to bin/client/src/handler/ecrecover.rs index 9ac11d9e7..0e3a1cf5c 100644 --- a/bin/client/src/fault/handler/ecrecover.rs +++ b/bin/client/src/handler/ecrecover.rs @@ -1,13 +1,13 @@ //! Contains the accelerated version of the `ecrecover` precompile. -use crate::fault::{HINT_WRITER, ORACLE_READER}; +use crate::{HINT_WRITER, ORACLE_READER}; use alloc::{string::ToString, vec::Vec}; use alloy_primitives::{keccak256, Address, Bytes}; -use kona_client::{errors::OracleProviderError, HintType}; use kona_preimage::{ errors::PreimageOracleError, HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient, }; +use kona_proof::{errors::OracleProviderError, HintType}; use revm::{ precompile::{u64_to_address, Error as PrecompileError, PrecompileWithAddress}, primitives::{Precompile, PrecompileOutput, PrecompileResult}, diff --git a/bin/client/src/fault/handler/kzg_point_eval.rs b/bin/client/src/handler/kzg_point_eval.rs similarity index 96% rename from bin/client/src/fault/handler/kzg_point_eval.rs rename to bin/client/src/handler/kzg_point_eval.rs index 9f9c3d4f4..5447af1cf 100644 --- a/bin/client/src/fault/handler/kzg_point_eval.rs +++ b/bin/client/src/handler/kzg_point_eval.rs @@ -1,13 +1,13 @@ //! Contains the accelerated version of the KZG point evaluation precompile. -use crate::fault::{HINT_WRITER, ORACLE_READER}; +use crate::{HINT_WRITER, ORACLE_READER}; use alloc::{string::ToString, vec::Vec}; use alloy_primitives::{keccak256, Address, Bytes}; -use kona_client::{errors::OracleProviderError, HintType}; use kona_preimage::{ errors::PreimageOracleError, HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient, }; +use kona_proof::{errors::OracleProviderError, HintType}; use revm::{ precompile::{u64_to_address, Error as PrecompileError, PrecompileWithAddress}, primitives::{Precompile, PrecompileOutput, PrecompileResult}, diff --git a/bin/client/src/fault/handler/mod.rs b/bin/client/src/handler/mod.rs similarity index 100% rename from bin/client/src/fault/handler/mod.rs rename to bin/client/src/handler/mod.rs diff --git a/bin/client/src/kona.rs b/bin/client/src/kona.rs index 434ca1794..3ba6e120b 100644 --- a/bin/client/src/kona.rs +++ b/bin/client/src/kona.rs @@ -8,21 +8,37 @@ extern crate alloc; use alloc::{string::String, sync::Arc}; -use kona_client::{ +use kona_client::PipeHandle; +use kona_common::{io, FileDescriptor}; +use kona_common_proc::client_entry; +use kona_driver::{Driver, DriverError}; +use kona_preimage::{HintWriter, OracleReader}; +use kona_proof::{ executor::KonaExecutorConstructor, l1::{OracleBlobProvider, OracleL1ChainProvider, OraclePipeline}, l2::OracleL2ChainProvider, sync::new_pipeline_cursor, BootInfo, CachingOracle, }; -use kona_common::io; -use kona_common_proc::client_entry; -use kona_driver::{Driver, DriverError}; - -pub(crate) mod fault; -use fault::{fpvm_handle_register, HINT_WRITER, ORACLE_READER}; use tracing::{error, info, warn}; +mod handler; +use handler::fpvm_handle_register; + +/// The global preimage oracle reader pipe. +static ORACLE_READER_PIPE: PipeHandle = + PipeHandle::new(FileDescriptor::PreimageRead, FileDescriptor::PreimageWrite); + +/// The global hint writer pipe. +static HINT_WRITER_PIPE: PipeHandle = + PipeHandle::new(FileDescriptor::HintRead, FileDescriptor::HintWrite); + +/// The global preimage oracle reader. +static ORACLE_READER: OracleReader = OracleReader::new(ORACLE_READER_PIPE); + +/// The global hint writer. +static HINT_WRITER: HintWriter = HintWriter::new(HINT_WRITER_PIPE); + /// The size of the LRU cache in the oracle. const ORACLE_LRU_SIZE: usize = 1024; diff --git a/bin/client/src/lib.rs b/bin/client/src/lib.rs index 36c706377..f32ecd6ea 100644 --- a/bin/client/src/lib.rs +++ b/bin/client/src/lib.rs @@ -6,24 +6,5 @@ extern crate alloc; -pub mod l1; - -pub mod l2; - -pub mod sync; - -pub mod errors; - -pub mod executor; - -mod hint; -pub use hint::HintType; - -pub mod boot; -pub use boot::BootInfo; - mod pipe; pub use pipe::PipeHandle; - -mod caching_oracle; -pub use caching_oracle::{CachingOracle, FlushableCache}; diff --git a/bin/host/Cargo.toml b/bin/host/Cargo.toml index 96ac0dfc8..66058f0e1 100644 --- a/bin/host/Cargo.toml +++ b/bin/host/Cargo.toml @@ -18,6 +18,7 @@ kona-client.workspace = true kona-derive.workspace = true kona-common.workspace = true kona-preimage.workspace = true +kona-proof.workspace = true # Alloy alloy-rlp.workspace = true diff --git a/bin/host/src/fetcher/mod.rs b/bin/host/src/fetcher/mod.rs index 453eb09bb..6801db698 100644 --- a/bin/host/src/fetcher/mod.rs +++ b/bin/host/src/fetcher/mod.rs @@ -15,9 +15,9 @@ use alloy_rpc_types::{ Block, BlockNumberOrTag, BlockTransactions, BlockTransactionsKind, Transaction, }; use anyhow::{anyhow, Result}; -use kona_client::HintType; use kona_derive::sources::IndexedBlobHash; use kona_preimage::{PreimageKey, PreimageKeyType}; +use kona_proof::HintType; use op_alloy_protocol::BlockInfo; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/bin/host/src/kv/local.rs b/bin/host/src/kv/local.rs index f529c1992..ace48fbef 100644 --- a/bin/host/src/kv/local.rs +++ b/bin/host/src/kv/local.rs @@ -4,11 +4,11 @@ use super::KeyValueStore; use crate::cli::HostCli; use alloy_primitives::B256; use anyhow::Result; -use kona_client::boot::{ +use kona_preimage::PreimageKey; +use kona_proof::boot::{ L1_HEAD_KEY, L2_CHAIN_ID_KEY, L2_CLAIM_BLOCK_NUMBER_KEY, L2_CLAIM_KEY, L2_OUTPUT_ROOT_KEY, L2_ROLLUP_CONFIG_KEY, }; -use kona_preimage::PreimageKey; /// The default chain ID to use if none is provided. const DEFAULT_CHAIN_ID: u64 = 0xbeefbabe; diff --git a/bin/host/src/util.rs b/bin/host/src/util.rs index 355a93fa3..5053e1bc0 100644 --- a/bin/host/src/util.rs +++ b/bin/host/src/util.rs @@ -5,7 +5,7 @@ use alloy_provider::ReqwestProvider; use alloy_rpc_client::RpcClient; use alloy_transport_http::Http; use anyhow::{anyhow, Result}; -use kona_client::HintType; +use kona_proof::HintType; use os_pipe::{PipeReader, PipeWriter}; use reqwest::Client; use tokio::task::JoinHandle; diff --git a/crates/proof-sdk/proof/CHANGELOG.md b/crates/proof-sdk/proof/CHANGELOG.md new file mode 100644 index 000000000..c9fe9ccaf --- /dev/null +++ b/crates/proof-sdk/proof/CHANGELOG.md @@ -0,0 +1,55 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.0.4](https://github.com/anton-rs/kona/compare/kona-common-v0.0.3...kona-common-v0.0.4) - 2024-10-25 + +### Added + +- remove thiserror ([#735](https://github.com/anton-rs/kona/pull/735)) +- *(preimage/common)* Migrate to `thiserror` ([#543](https://github.com/anton-rs/kona/pull/543)) + +### Fixed + +- *(workspace)* hoist and fix lints ([#577](https://github.com/anton-rs/kona/pull/577)) + +### Other + +- re-org imports ([#711](https://github.com/anton-rs/kona/pull/711)) +- *(preimage)* Test Coverage ([#634](https://github.com/anton-rs/kona/pull/634)) +- test coverage for common ([#629](https://github.com/anton-rs/kona/pull/629)) +- doc logos ([#609](https://github.com/anton-rs/kona/pull/609)) +- *(workspace)* Allow stdlib in `cfg(test)` ([#548](https://github.com/anton-rs/kona/pull/548)) + +## [0.0.3](https://github.com/anton-rs/kona/compare/kona-common-v0.0.2...kona-common-v0.0.3) - 2024-09-04 + +### Added +- add zkvm target for io ([#394](https://github.com/anton-rs/kona/pull/394)) + +### Other +- *(workspace)* Update for `anton-rs` org transfer ([#474](https://github.com/anton-rs/kona/pull/474)) +- *(workspace)* Hoist Dependencies ([#466](https://github.com/anton-rs/kona/pull/466)) +- *(bin)* Remove `kt` ([#461](https://github.com/anton-rs/kona/pull/461)) +- *(common)* Remove need for cursors in `NativeIO` ([#416](https://github.com/anton-rs/kona/pull/416)) + +## [0.0.2](https://github.com/anton-rs/kona/compare/kona-common-v0.0.1...kona-common-v0.0.2) - 2024-06-22 + +### Added +- *(client)* Derivation integration ([#257](https://github.com/anton-rs/kona/pull/257)) +- *(client/host)* Oracle-backed Blob fetcher ([#255](https://github.com/anton-rs/kona/pull/255)) +- *(host)* Host program scaffold ([#184](https://github.com/anton-rs/kona/pull/184)) +- *(preimage)* `OracleServer` + `HintReader` ([#96](https://github.com/anton-rs/kona/pull/96)) +- *(common)* Move from `RegisterSize` to native ptr size type ([#95](https://github.com/anton-rs/kona/pull/95)) +- *(workspace)* Add `rustfmt.toml` + +### Fixed +- *(common)* Pipe IO support ([#282](https://github.com/anton-rs/kona/pull/282)) + +### Other +- *(common)* Use `Box::leak` rather than `mem::forget` ([#180](https://github.com/anton-rs/kona/pull/180)) +- Add simple blocking async executor ([#38](https://github.com/anton-rs/kona/pull/38)) +- Make versions of packages independent ([#36](https://github.com/anton-rs/kona/pull/36)) diff --git a/crates/proof-sdk/proof/Cargo.toml b/crates/proof-sdk/proof/Cargo.toml new file mode 100644 index 000000000..dedc7c3d7 --- /dev/null +++ b/crates/proof-sdk/proof/Cargo.toml @@ -0,0 +1,41 @@ +[package] +name = "kona-proof" +description = "OP Stack Proof SDK" +version = "0.0.1" +edition.workspace = true +authors.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true + +[lints] +workspace = true + +[dependencies] +# Workspace +kona-mpt.workspace = true +kona-derive.workspace = true +kona-driver.workspace = true +kona-preimage.workspace = true +kona-executor.workspace = true + +# Alloy +alloy-rlp.workspace = true +alloy-eips.workspace = true +alloy-consensus.workspace = true +alloy-primitives.workspace = true + +# Op Alloy +op-alloy-protocol.workspace = true +op-alloy-consensus.workspace = true +op-alloy-rpc-types-engine.workspace = true +op-alloy-genesis = { workspace = true, features = ["serde"] } + +# General +lru.workspace = true +spin.workspace = true +serde.workspace = true +tracing.workspace = true +serde_json.workspace = true +async-trait.workspace = true +thiserror.workspace = true diff --git a/crates/proof-sdk/proof/README.md b/crates/proof-sdk/proof/README.md new file mode 100644 index 000000000..32348f546 --- /dev/null +++ b/crates/proof-sdk/proof/README.md @@ -0,0 +1,8 @@ +# `kona-proof` + +CI +Kona Proof SDK +License +Codecov + +`kona-proof` is an OP Stack state transition proof SDK. diff --git a/crates/proof-sdk/proof/src/blocking_runtime.rs b/crates/proof-sdk/proof/src/blocking_runtime.rs new file mode 100644 index 000000000..f04ad4385 --- /dev/null +++ b/crates/proof-sdk/proof/src/blocking_runtime.rs @@ -0,0 +1,52 @@ +//! This module contains a blocking runtime for futures, allowing for synchronous execution of async +//! code in an embedded environment. + +use alloc::boxed::Box; +use core::{ + future::Future, + task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, +}; + +/// This function busy waits on a future until it is ready. It uses a no-op waker to poll the future +/// in a thread-blocking loop. +pub fn block_on(f: impl Future) -> T { + let mut f = Box::pin(f); + + // Construct a no-op waker. + fn noop_clone(_: *const ()) -> RawWaker { + noop_raw_waker() + } + const fn noop(_: *const ()) {} + fn noop_raw_waker() -> RawWaker { + let vtable = &RawWakerVTable::new(noop_clone, noop, noop, noop); + RawWaker::new(core::ptr::null(), vtable) + } + let waker = unsafe { Waker::from_raw(noop_raw_waker()) }; + let mut context = Context::from_waker(&waker); + + loop { + // Safety: This is safe because we only poll the future once per loop iteration, + // and we do not move the future after pinning it. + if let Poll::Ready(v) = f.as_mut().poll(&mut context) { + return v; + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use core::future::ready; + + #[test] + fn test_block_on() { + let f = async { 42 }; + assert_eq!(block_on(f), 42); + } + + #[test] + fn test_block_on_ready() { + let f = ready(42); + assert_eq!(block_on(f), 42); + } +} diff --git a/bin/client/src/boot.rs b/crates/proof-sdk/proof/src/boot.rs similarity index 99% rename from bin/client/src/boot.rs rename to crates/proof-sdk/proof/src/boot.rs index 4330dac9b..f46a30f78 100644 --- a/bin/client/src/boot.rs +++ b/crates/proof-sdk/proof/src/boot.rs @@ -1,14 +1,13 @@ //! This module contains the prologue phase of the client program, pulling in the boot information //! through the `PreimageOracle` ABI as local keys. +use crate::errors::OracleProviderError; use alloy_primitives::{B256, U256}; use kona_preimage::{PreimageKey, PreimageOracleClient}; use op_alloy_genesis::RollupConfig; use serde::{Deserialize, Serialize}; use tracing::warn; -use crate::errors::OracleProviderError; - /// The local key ident for the L1 head hash. pub const L1_HEAD_KEY: U256 = U256::from_be_slice(&[1]); diff --git a/bin/client/src/caching_oracle.rs b/crates/proof-sdk/proof/src/caching_oracle.rs similarity index 100% rename from bin/client/src/caching_oracle.rs rename to crates/proof-sdk/proof/src/caching_oracle.rs diff --git a/bin/client/src/errors.rs b/crates/proof-sdk/proof/src/errors.rs similarity index 100% rename from bin/client/src/errors.rs rename to crates/proof-sdk/proof/src/errors.rs diff --git a/bin/client/src/executor.rs b/crates/proof-sdk/proof/src/executor.rs similarity index 97% rename from bin/client/src/executor.rs rename to crates/proof-sdk/proof/src/executor.rs index a8a035b56..1859ff254 100644 --- a/bin/client/src/executor.rs +++ b/crates/proof-sdk/proof/src/executor.rs @@ -22,7 +22,7 @@ where H: TrieHinter + Send + Sync + Clone, { /// Creates a new executor. - pub fn new(executor: StatelessL2BlockExecutor<'a, P, H>) -> Self { + pub const fn new(executor: StatelessL2BlockExecutor<'a, P, H>) -> Self { Self(executor) } } diff --git a/bin/client/src/hint.rs b/crates/proof-sdk/proof/src/hint.rs similarity index 80% rename from bin/client/src/hint.rs rename to crates/proof-sdk/proof/src/hint.rs index b35c7831b..fce3218ca 100644 --- a/bin/client/src/hint.rs +++ b/crates/proof-sdk/proof/src/hint.rs @@ -1,5 +1,6 @@ //! This module contains the [HintType] enum. +use crate::errors::HintParsingError; use alloc::{ string::{String, ToString}, vec::Vec, @@ -7,8 +8,6 @@ use alloc::{ use alloy_primitives::hex; use core::fmt::Display; -use crate::errors::HintParsingError; - /// The [HintType] enum is used to specify the type of hint that was received. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum HintType { @@ -52,18 +51,18 @@ impl TryFrom<&str> for HintType { fn try_from(value: &str) -> Result { match value { - "l1-block-header" => Ok(HintType::L1BlockHeader), - "l1-transactions" => Ok(HintType::L1Transactions), - "l1-receipts" => Ok(HintType::L1Receipts), - "l1-blob" => Ok(HintType::L1Blob), - "l1-precompile" => Ok(HintType::L1Precompile), - "l2-block-header" => Ok(HintType::L2BlockHeader), - "l2-transactions" => Ok(HintType::L2Transactions), - "l2-code" => Ok(HintType::L2Code), - "starting-l2-output" => Ok(HintType::StartingL2Output), - "l2-state-node" => Ok(HintType::L2StateNode), - "l2-account-proof" => Ok(HintType::L2AccountProof), - "l2-account-storage-proof" => Ok(HintType::L2AccountStorageProof), + "l1-block-header" => Ok(Self::L1BlockHeader), + "l1-transactions" => Ok(Self::L1Transactions), + "l1-receipts" => Ok(Self::L1Receipts), + "l1-blob" => Ok(Self::L1Blob), + "l1-precompile" => Ok(Self::L1Precompile), + "l2-block-header" => Ok(Self::L2BlockHeader), + "l2-transactions" => Ok(Self::L2Transactions), + "l2-code" => Ok(Self::L2Code), + "starting-l2-output" => Ok(Self::StartingL2Output), + "l2-state-node" => Ok(Self::L2StateNode), + "l2-account-proof" => Ok(Self::L2AccountProof), + "l2-account-storage-proof" => Ok(Self::L2AccountStorageProof), _ => Err(HintParsingError(value.to_string())), } } diff --git a/bin/client/src/l1/blob_provider.rs b/crates/proof-sdk/proof/src/l1/blob_provider.rs similarity index 98% rename from bin/client/src/l1/blob_provider.rs rename to crates/proof-sdk/proof/src/l1/blob_provider.rs index 31698d1bb..57dd967c9 100644 --- a/bin/client/src/l1/blob_provider.rs +++ b/crates/proof-sdk/proof/src/l1/blob_provider.rs @@ -18,7 +18,7 @@ pub struct OracleBlobProvider { impl OracleBlobProvider { /// Constructs a new `OracleBlobProvider`. - pub fn new(oracle: Arc) -> Self { + pub const fn new(oracle: Arc) -> Self { Self { oracle } } diff --git a/bin/client/src/l1/chain_provider.rs b/crates/proof-sdk/proof/src/l1/chain_provider.rs similarity index 97% rename from bin/client/src/l1/chain_provider.rs rename to crates/proof-sdk/proof/src/l1/chain_provider.rs index 655e4b578..9f9cfb8bc 100644 --- a/bin/client/src/l1/chain_provider.rs +++ b/crates/proof-sdk/proof/src/l1/chain_provider.rs @@ -1,4 +1,4 @@ -//! Contains the concrete implementation of the [ChainProvider] trait for the client program. +//! Contains the concrete implementation of the [ChainProvider] trait for the proof. use crate::{errors::OracleProviderError, BootInfo, HintType}; use alloc::{boxed::Box, sync::Arc, vec::Vec}; @@ -23,7 +23,7 @@ pub struct OracleL1ChainProvider { impl OracleL1ChainProvider { /// Creates a new [OracleL1ChainProvider] with the given boot information and oracle client. - pub fn new(boot_info: Arc, oracle: Arc) -> Self { + pub const fn new(boot_info: Arc, oracle: Arc) -> Self { Self { boot_info, oracle } } } @@ -141,7 +141,7 @@ impl TrieProvider for OracleL1ChainProvider { fn trie_node_by_hash(&self, key: B256) -> Result { // On L1, trie node preimages are stored as keccak preimage types in the oracle. We assume // that a hint for these preimages has already been sent, prior to this call. - kona_common::block_on(async move { + crate::block_on(async move { TrieNode::decode( &mut self .oracle diff --git a/bin/client/src/l1/mod.rs b/crates/proof-sdk/proof/src/l1/mod.rs similarity index 74% rename from bin/client/src/l1/mod.rs rename to crates/proof-sdk/proof/src/l1/mod.rs index cf884f816..936877168 100644 --- a/bin/client/src/l1/mod.rs +++ b/crates/proof-sdk/proof/src/l1/mod.rs @@ -1,4 +1,4 @@ -//! Contains the L1 constructs of the client program. +//! Contains the L1 constructs of the proof, backed by the preimage oracle ABI as a data source. mod pipeline; pub use pipeline::{ diff --git a/bin/client/src/l1/pipeline.rs b/crates/proof-sdk/proof/src/l1/pipeline.rs similarity index 99% rename from bin/client/src/l1/pipeline.rs rename to crates/proof-sdk/proof/src/l1/pipeline.rs index 2c60f53df..540279b6a 100644 --- a/bin/client/src/l1/pipeline.rs +++ b/crates/proof-sdk/proof/src/l1/pipeline.rs @@ -1,5 +1,6 @@ //! Contains an oracle-backed pipeline. +use crate::{l1::OracleL1ChainProvider, l2::OracleL2ChainProvider, FlushableCache}; use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use core::fmt::Debug; @@ -21,8 +22,6 @@ use op_alloy_genesis::{RollupConfig, SystemConfig}; use op_alloy_protocol::{BlockInfo, L2BlockInfo}; use op_alloy_rpc_types_engine::OpAttributesWithParent; -use crate::{l1::OracleL1ChainProvider, l2::OracleL2ChainProvider, FlushableCache}; - /// An oracle-backed derivation pipeline. pub type OracleDerivationPipeline = DerivationPipeline< OracleAttributesQueue, O>, diff --git a/bin/client/src/l2/chain_provider.rs b/crates/proof-sdk/proof/src/l2/chain_provider.rs similarity index 96% rename from bin/client/src/l2/chain_provider.rs rename to crates/proof-sdk/proof/src/l2/chain_provider.rs index f35eb5e2f..224eedba1 100644 --- a/bin/client/src/l2/chain_provider.rs +++ b/crates/proof-sdk/proof/src/l2/chain_provider.rs @@ -26,7 +26,7 @@ pub struct OracleL2ChainProvider { impl OracleL2ChainProvider { /// Creates a new [OracleL2ChainProvider] with the given boot information and oracle client. - pub fn new(boot_info: Arc, oracle: Arc) -> Self { + pub const fn new(boot_info: Arc, oracle: Arc) -> Self { Self { boot_info, oracle } } } @@ -148,7 +148,7 @@ impl TrieProvider for OracleL2ChainProvider { fn trie_node_by_hash(&self, key: B256) -> Result { // On L2, trie node preimages are stored as keccak preimage types in the oracle. We assume // that a hint for these preimages has already been sent, prior to this call. - kona_common::block_on(async move { + crate::block_on(async move { TrieNode::decode( &mut self .oracle @@ -165,7 +165,7 @@ impl TrieProvider for OracleL2ChainProvider { impl TrieDBProvider for OracleL2ChainProvider { fn bytecode_by_hash(&self, hash: B256) -> Result { // Fetch the bytecode preimage from the caching oracle. - kona_common::block_on(async move { + crate::block_on(async move { self.oracle .write(&HintType::L2Code.encode_with(&[hash.as_ref()])) .await @@ -181,7 +181,7 @@ impl TrieDBProvider for OracleL2ChainProvider { fn header_by_hash(&self, hash: B256) -> Result { // Fetch the header from the caching oracle. - kona_common::block_on(async move { + crate::block_on(async move { self.oracle .write(&HintType::L2BlockHeader.encode_with(&[hash.as_ref()])) .await @@ -201,7 +201,7 @@ impl TrieHinter for OracleL2ChainProvider { type Error = OracleProviderError; fn hint_trie_node(&self, hash: B256) -> Result<(), Self::Error> { - kona_common::block_on(async move { + crate::block_on(async move { self.oracle .write(&HintType::L2StateNode.encode_with(&[hash.as_slice()])) .await @@ -210,7 +210,7 @@ impl TrieHinter for OracleL2ChainProvider { } fn hint_account_proof(&self, address: Address, block_number: u64) -> Result<(), Self::Error> { - kona_common::block_on(async move { + crate::block_on(async move { self.oracle .write( &HintType::L2AccountProof @@ -227,7 +227,7 @@ impl TrieHinter for OracleL2ChainProvider { slot: alloy_primitives::U256, block_number: u64, ) -> Result<(), Self::Error> { - kona_common::block_on(async move { + crate::block_on(async move { self.oracle .write(&HintType::L2AccountStorageProof.encode_with(&[ block_number.to_be_bytes().as_ref(), diff --git a/bin/client/src/l2/mod.rs b/crates/proof-sdk/proof/src/l2/mod.rs similarity index 100% rename from bin/client/src/l2/mod.rs rename to crates/proof-sdk/proof/src/l2/mod.rs diff --git a/crates/proof-sdk/proof/src/lib.rs b/crates/proof-sdk/proof/src/lib.rs new file mode 100644 index 000000000..27ed3b29d --- /dev/null +++ b/crates/proof-sdk/proof/src/lib.rs @@ -0,0 +1,30 @@ +#![doc = include_str!("../README.md")] +#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)] +#![deny(unused_must_use, rust_2018_idioms)] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![no_std] + +extern crate alloc; + +pub mod l1; + +pub mod l2; + +pub mod sync; + +pub mod errors; + +pub mod executor; + +mod hint; +pub use hint::HintType; + +pub mod boot; +pub use boot::BootInfo; + +mod caching_oracle; +pub use caching_oracle::{CachingOracle, FlushableCache}; + +mod blocking_runtime; +pub use blocking_runtime::block_on; diff --git a/bin/client/src/sync.rs b/crates/proof-sdk/proof/src/sync.rs similarity index 100% rename from bin/client/src/sync.rs rename to crates/proof-sdk/proof/src/sync.rs