From 490d2c4697fe3ad9eeeee65cfaf418df4e0a9d55 Mon Sep 17 00:00:00 2001 From: refcell Date: Thu, 22 Aug 2024 10:46:58 -0400 Subject: [PATCH 1/4] feat(optv): generic derivation test fixtures --- bin/opdn/src/cmd/fixtures.rs | 3 +- crates/op-test-vectors/Cargo.toml | 2 +- crates/op-test-vectors/src/derivation.rs | 35 ++++++++++++++++++------ crates/op-test-vectors/src/lib.rs | 4 --- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/bin/opdn/src/cmd/fixtures.rs b/bin/opdn/src/cmd/fixtures.rs index 8e2a589..9680ddd 100644 --- a/bin/opdn/src/cmd/fixtures.rs +++ b/bin/opdn/src/cmd/fixtures.rs @@ -8,6 +8,7 @@ use kona_derive::online::{ AlloyChainProvider, OnlineBeaconClient, OnlineBlobProviderWithFallback, SimpleSlotDerivation, }; use kona_derive::traits::ChainProvider; +use kona_derive::types::Blob; use op_test_vectors::derivation::FixtureBlock; /// Constructs [FixtureBlock]s for the given L1 blocks. @@ -21,7 +22,7 @@ pub async fn build_fixture_blocks( OnlineBeaconClient, SimpleSlotDerivation, >, -) -> Result> { +) -> Result>> { let mut fixtures = Vec::with_capacity(blocks.len()); for b in blocks { let block_info = l1_provider diff --git a/crates/op-test-vectors/Cargo.toml b/crates/op-test-vectors/Cargo.toml index b5923c5..7898626 100644 --- a/crates/op-test-vectors/Cargo.toml +++ b/crates/op-test-vectors/Cargo.toml @@ -26,7 +26,7 @@ alloy-consensus.workspace = true # OP Types op-alloy-rpc-types.workspace = true op-alloy-consensus.workspace = true -kona-derive.workspace = true [dev-dependencies] serde_json.workspace = true +kona-derive.workspace = true diff --git a/crates/op-test-vectors/src/derivation.rs b/crates/op-test-vectors/src/derivation.rs index 4540bfb..a8f4433 100644 --- a/crates/op-test-vectors/src/derivation.rs +++ b/crates/op-test-vectors/src/derivation.rs @@ -3,18 +3,26 @@ use alloy_consensus::{Header, Receipt}; use alloy_primitives::Bytes; use hashbrown::HashMap; -use kona_derive::types::{Blob, L2BlockInfo, L2PayloadAttributes, RollupConfig, SystemConfig}; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; /// The derivation fixture is the top-level object that contains /// everything needed to run a derivation test. #[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] +#[serde( + bound = "RollupConfig: Serialize + DeserializeOwned, L2PayloadAttributes: Serialize + DeserializeOwned, SystemConfig: Serialize + DeserializeOwned, L2BlockInfo: Serialize + DeserializeOwned, Blob: Serialize + DeserializeOwned" +)] #[serde(rename_all = "camelCase")] -pub struct DerivationFixture { +pub struct DerivationFixture< + RollupConfig: DeserializeOwned, + L2PayloadAttributes: DeserializeOwned, + SystemConfig: DeserializeOwned, + L2BlockInfo: DeserializeOwned, + Blob: DeserializeOwned, +> { /// The rollup config. pub rollup_config: RollupConfig, /// A list of L1 Blocks to derive from. - pub l1_blocks: Vec, + pub l1_blocks: Vec>, /// A map of L2 block number to l2 payload attributes. pub l2_payloads: HashMap, /// A map of l2 block number to reference payloads. @@ -36,8 +44,9 @@ pub struct DerivationFixture { /// A fixture block is a minimal block with associated data including blobs /// to derive from. #[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] +#[serde(bound = "Blob: Serialize + DeserializeOwned")] #[serde(rename_all = "camelCase")] -pub struct FixtureBlock { +pub struct FixtureBlock { /// The block header. /// The entire header is required to generate the block hash when deriving the l1 block info /// tx. @@ -55,9 +64,11 @@ pub struct FixtureBlock { mod tests { use super::*; use alloy_primitives::{address, b256, bytes, uint}; - use kona_derive::types::{BlockID, BlockInfo}; + use kona_derive::types::{ + Blob, BlockID, BlockInfo, L2BlockInfo, L2PayloadAttributes, RollupConfig, SystemConfig, + }; - fn ref_blocks() -> Vec { + fn ref_blocks() -> Vec> { vec![ FixtureBlock { header: Header { @@ -336,7 +347,13 @@ mod tests { #[test] fn test_derivation_fixture() { let fixture_str = include_str!("./testdata/derivation_fixture.json"); - let fixture: DerivationFixture = serde_json::from_str(fixture_str).unwrap(); + let fixture: DerivationFixture< + RollupConfig, + L2PayloadAttributes, + SystemConfig, + L2BlockInfo, + Blob, + > = serde_json::from_str(fixture_str).unwrap(); let expected = DerivationFixture { rollup_config: ref_rollup_config(), l1_blocks: ref_blocks(), @@ -353,7 +370,7 @@ mod tests { #[test] fn test_fixture_block() { let fixture_str = include_str!("./testdata/fixture_block.json"); - let fixture: FixtureBlock = serde_json::from_str(fixture_str).unwrap(); + let fixture: FixtureBlock = serde_json::from_str(fixture_str).unwrap(); assert_eq!(fixture.header.number, 1); assert_eq!( fixture.header.parent_hash, diff --git a/crates/op-test-vectors/src/lib.rs b/crates/op-test-vectors/src/lib.rs index 83a95d3..b11d233 100644 --- a/crates/op-test-vectors/src/lib.rs +++ b/crates/op-test-vectors/src/lib.rs @@ -8,10 +8,6 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -// Re-export `kona-derive` since its types are used in derivation fixtures -// and the crate is pinned to a specific version. -pub use kona_derive; - pub mod derivation; pub mod execution; From 26a133d79f1f86a8bdf01ee896f61cdf9674c07c Mon Sep 17 00:00:00 2001 From: refcell Date: Thu, 22 Aug 2024 11:55:20 -0400 Subject: [PATCH 2/4] fix: bind types to serializable --- crates/op-test-vectors/src/derivation.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/op-test-vectors/src/derivation.rs b/crates/op-test-vectors/src/derivation.rs index a8f4433..7f9fba4 100644 --- a/crates/op-test-vectors/src/derivation.rs +++ b/crates/op-test-vectors/src/derivation.rs @@ -13,11 +13,11 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize}; )] #[serde(rename_all = "camelCase")] pub struct DerivationFixture< - RollupConfig: DeserializeOwned, - L2PayloadAttributes: DeserializeOwned, - SystemConfig: DeserializeOwned, - L2BlockInfo: DeserializeOwned, - Blob: DeserializeOwned, + RollupConfig: DeserializeOwned + Serialize, + L2PayloadAttributes: DeserializeOwned + Serialize, + SystemConfig: DeserializeOwned + Serialize, + L2BlockInfo: DeserializeOwned + Serialize, + Blob: DeserializeOwned + Serialize, > { /// The rollup config. pub rollup_config: RollupConfig, @@ -46,7 +46,7 @@ pub struct DerivationFixture< #[derive(Serialize, Deserialize, Clone, Debug, Default, Eq, PartialEq)] #[serde(bound = "Blob: Serialize + DeserializeOwned")] #[serde(rename_all = "camelCase")] -pub struct FixtureBlock { +pub struct FixtureBlock { /// The block header. /// The entire header is required to generate the block hash when deriving the l1 block info /// tx. From d923447df96f6bb33537f44b9067cc69ad0470fd Mon Sep 17 00:00:00 2001 From: refcell Date: Fri, 23 Aug 2024 16:15:48 -0400 Subject: [PATCH 3/4] fix: update to use refactored kona types in kona-primitives --- Cargo.lock | 97 +++++++++++++----------- Cargo.toml | 3 +- bin/opdn/Cargo.toml | 1 + bin/opdn/src/cmd/blobs.rs | 2 +- bin/opdn/src/cmd/fixtures.rs | 2 +- bin/opdn/src/cmd/from_l1.rs | 6 +- bin/opdn/src/cmd/from_l2.rs | 6 +- bin/opdn/src/cmd/util.rs | 2 +- bin/range-finder/Cargo.toml | 1 + bin/range-finder/src/cli.rs | 6 +- crates/op-test-vectors/Cargo.toml | 2 +- crates/op-test-vectors/src/derivation.rs | 2 +- 12 files changed, 67 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc9934b..0f15190 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4067,8 +4067,8 @@ dependencies = [ [[package]] name = "kona-derive" -version = "0.0.2" -source = "git+https://github.com/ethereum-optimism/kona?rev=4e57dd35ea08b31d0baa293c7a12165f28e6cd92#4e57dd35ea08b31d0baa293c7a12165f28e6cd92" +version = "0.0.3" +source = "git+https://github.com/ethereum-optimism/kona#19b00f3cf456775197a320aed9e900f110057d2f" dependencies = [ "alloc-no-stdlib", "alloy-consensus", @@ -4077,8 +4077,6 @@ dependencies = [ "alloy-provider", "alloy-rlp", "alloy-rpc-client", - "alloy-rpc-types", - "alloy-sol-types", "alloy-transport", "alloy-transport-http", "anyhow", @@ -4091,9 +4089,8 @@ dependencies = [ "miniz_oxide", "op-alloy-consensus", "reqwest", - "revm 10.0.0", + "revm 13.0.0", "serde", - "serde_json", "sha2", "spin", "tracing", @@ -4102,18 +4099,23 @@ dependencies = [ [[package]] name = "kona-primitives" -version = "0.0.1" -source = "git+https://github.com/ethereum-optimism/kona?rev=4e57dd35ea08b31d0baa293c7a12165f28e6cd92#4e57dd35ea08b31d0baa293c7a12165f28e6cd92" +version = "0.0.2" +source = "git+https://github.com/ethereum-optimism/kona#19b00f3cf456775197a320aed9e900f110057d2f" dependencies = [ "alloy-consensus", "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-sol-types", "anyhow", + "c-kzg", + "hashbrown", "op-alloy-consensus", + "revm 13.0.0", "serde", + "sha2", + "spin", "superchain-primitives", + "tracing", ] [[package]] @@ -4589,7 +4591,7 @@ dependencies = [ "anvil-core", "color-eyre", "hashbrown", - "kona-derive", + "kona-primitives", "op-alloy-consensus", "op-alloy-rpc-types", "serde", @@ -4608,6 +4610,7 @@ dependencies = [ "futures", "hashbrown", "kona-derive", + "kona-primitives", "op-test-vectors", "reqwest", "serde", @@ -5266,6 +5269,7 @@ dependencies = [ "color-eyre", "futures", "kona-derive", + "kona-primitives", "reqwest", "superchain-registry", "tokio", @@ -5441,19 +5445,6 @@ dependencies = [ "winreg", ] -[[package]] -name = "revm" -version = "10.0.0" -source = "git+https://github.com/bluealloy/revm?tag=v37#99367b1db2c436359c0155ed8965c19fc5503a1b" -dependencies = [ - "auto_impl", - "cfg-if", - "dyn-clone", - "revm-interpreter 6.0.0", - "revm-precompile 8.0.0", - "serde", -] - [[package]] name = "revm" version = "12.1.0" @@ -5473,6 +5464,19 @@ dependencies = [ "tokio", ] +[[package]] +name = "revm" +version = "13.0.0" +source = "git+https://github.com/bluealloy/revm#1ad860469755e3cf71383f45d71c3faaf61d3029" +dependencies = [ + "auto_impl", + "cfg-if", + "dyn-clone", + "revm-interpreter 9.0.0", + "revm-precompile 10.0.0", + "serde", +] + [[package]] name = "revm-inspectors" version = "0.5.5" @@ -5492,63 +5496,66 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "6.0.0" -source = "git+https://github.com/bluealloy/revm?tag=v37#99367b1db2c436359c0155ed8965c19fc5503a1b" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b0daddea06fc6da5346acc39b32a357bbe3579e9e3d94117d9ae125cd596fc" dependencies = [ - "revm-primitives 5.0.0", + "revm-primitives 7.1.0", "serde", ] [[package]] name = "revm-interpreter" -version = "8.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6b0daddea06fc6da5346acc39b32a357bbe3579e9e3d94117d9ae125cd596fc" +version = "9.0.0" +source = "git+https://github.com/bluealloy/revm#1ad860469755e3cf71383f45d71c3faaf61d3029" dependencies = [ - "revm-primitives 7.1.0", + "revm-primitives 8.0.0", "serde", ] [[package]] name = "revm-precompile" -version = "8.0.0" -source = "git+https://github.com/bluealloy/revm?tag=v37#99367b1db2c436359c0155ed8965c19fc5503a1b" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef55228211251d7b6c7707c3ee13bb70dea4d2fd81ec4034521e4fe31010b2ea" dependencies = [ "aurora-engine-modexp", + "blst", "c-kzg", + "cfg-if", "k256", "once_cell", - "revm-primitives 5.0.0", + "p256", + "revm-primitives 7.1.0", "ripemd", + "secp256k1", "sha2", "substrate-bn", ] [[package]] name = "revm-precompile" -version = "9.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef55228211251d7b6c7707c3ee13bb70dea4d2fd81ec4034521e4fe31010b2ea" +version = "10.0.0" +source = "git+https://github.com/bluealloy/revm#1ad860469755e3cf71383f45d71c3faaf61d3029" dependencies = [ "aurora-engine-modexp", - "blst", "c-kzg", "cfg-if", "k256", "once_cell", - "p256", - "revm-primitives 7.1.0", + "revm-primitives 8.0.0", "ripemd", - "secp256k1", "sha2", "substrate-bn", ] [[package]] name = "revm-primitives" -version = "5.0.0" -source = "git+https://github.com/bluealloy/revm?tag=v37#99367b1db2c436359c0155ed8965c19fc5503a1b" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc4311037ee093ec50ec734e1424fcb3e12d535c6cef683b75d1c064639630c" dependencies = [ + "alloy-eips", "alloy-primitives", "auto_impl", "bitflags 2.6.0", @@ -5560,15 +5567,15 @@ dependencies = [ "enumn", "hashbrown", "hex", + "kzg-rs", "once_cell", "serde", ] [[package]] name = "revm-primitives" -version = "7.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fc4311037ee093ec50ec734e1424fcb3e12d535c6cef683b75d1c064639630c" +version = "8.0.0" +source = "git+https://github.com/bluealloy/revm#1ad860469755e3cf71383f45d71c3faaf61d3029" dependencies = [ "alloy-eips", "alloy-primitives", diff --git a/Cargo.toml b/Cargo.toml index e691754..73df50b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,8 @@ revm = { version = "12.1", features = ["alloydb", "optimism"] } # Kona + OP Types superchain-registry = "0.2.6" -kona-derive = { git = "https://github.com/ethereum-optimism/kona", rev = "4e57dd35ea08b31d0baa293c7a12165f28e6cd92", features = ["online"] } +kona-primitives = { git = "https://github.com/ethereum-optimism/kona", version = "0.0.2", features = ["online"] } +kona-derive = { git = "https://github.com/ethereum-optimism/kona", version = "0.0.3", features = ["online"] } # Internal op-test-vectors = { path = "crates/op-test-vectors" } diff --git a/bin/opdn/Cargo.toml b/bin/opdn/Cargo.toml index 3614ebc..3356704 100644 --- a/bin/opdn/Cargo.toml +++ b/bin/opdn/Cargo.toml @@ -30,5 +30,6 @@ alloy-eips.workspace = true # OP Types + Kona op-test-vectors.workspace = true +kona-primitives.workspace = true kona-derive.workspace = true superchain-registry.workspace = true diff --git a/bin/opdn/src/cmd/blobs.rs b/bin/opdn/src/cmd/blobs.rs index 03b759f..c3cdd6d 100644 --- a/bin/opdn/src/cmd/blobs.rs +++ b/bin/opdn/src/cmd/blobs.rs @@ -9,7 +9,7 @@ use kona_derive::online::{ OnlineBeaconClient, OnlineBlobProviderWithFallback, SimpleSlotDerivation, }; use kona_derive::traits::BlobProvider; -use kona_derive::types::{Blob, BlockInfo, IndexedBlobHash}; +use kona_primitives::{Blob, BlockInfo, IndexedBlobHash}; /// Loads blobs for the given block number. pub async fn load( diff --git a/bin/opdn/src/cmd/fixtures.rs b/bin/opdn/src/cmd/fixtures.rs index 9680ddd..4a3103a 100644 --- a/bin/opdn/src/cmd/fixtures.rs +++ b/bin/opdn/src/cmd/fixtures.rs @@ -8,7 +8,7 @@ use kona_derive::online::{ AlloyChainProvider, OnlineBeaconClient, OnlineBlobProviderWithFallback, SimpleSlotDerivation, }; use kona_derive::traits::ChainProvider; -use kona_derive::types::Blob; +use kona_primitives::Blob; use op_test_vectors::derivation::FixtureBlock; /// Constructs [FixtureBlock]s for the given L1 blocks. diff --git a/bin/opdn/src/cmd/from_l1.rs b/bin/opdn/src/cmd/from_l1.rs index 63579c2..5045367 100644 --- a/bin/opdn/src/cmd/from_l1.rs +++ b/bin/opdn/src/cmd/from_l1.rs @@ -6,10 +6,8 @@ use color_eyre::{ Result, }; use hashbrown::HashMap; -use kona_derive::{ - online::*, - types::{L2BlockInfo, StageError}, -}; +use kona_derive::{errors::StageError, online::*}; +use kona_primitives::L2BlockInfo; use op_test_vectors::derivation::DerivationFixture; use reqwest::Url; use std::path::PathBuf; diff --git a/bin/opdn/src/cmd/from_l2.rs b/bin/opdn/src/cmd/from_l2.rs index 84cce1a..a662506 100644 --- a/bin/opdn/src/cmd/from_l2.rs +++ b/bin/opdn/src/cmd/from_l2.rs @@ -6,10 +6,8 @@ use color_eyre::{ Result, }; use hashbrown::HashMap; -use kona_derive::{ - online::*, - types::{L2BlockInfo, StageError}, -}; +use kona_derive::{errors::StageError, online::*}; +use kona_primitives::L2BlockInfo; use op_test_vectors::derivation::DerivationFixture; use reqwest::Url; use std::path::PathBuf; diff --git a/bin/opdn/src/cmd/util.rs b/bin/opdn/src/cmd/util.rs index eaa4e1c..41ee004 100644 --- a/bin/opdn/src/cmd/util.rs +++ b/bin/opdn/src/cmd/util.rs @@ -1,6 +1,6 @@ //! Utilities -use kona_derive::types::{L2ExecutionPayloadEnvelope, L2PayloadAttributes, RawTransaction}; +use kona_primitives::{L2ExecutionPayloadEnvelope, L2PayloadAttributes, RawTransaction}; /// Converts an [L2ExecutionPayloadEnvelope] to an [L2PayloadAttributes]. pub fn to_payload_attributes(payload: L2ExecutionPayloadEnvelope) -> L2PayloadAttributes { diff --git a/bin/range-finder/Cargo.toml b/bin/range-finder/Cargo.toml index 0f9e7b5..5d513f4 100644 --- a/bin/range-finder/Cargo.toml +++ b/bin/range-finder/Cargo.toml @@ -27,4 +27,5 @@ alloy-eips.workspace = true # OP Types + Kona kona-derive.workspace = true +kona-primitives.workspace = true superchain-registry.workspace = true diff --git a/bin/range-finder/src/cli.rs b/bin/range-finder/src/cli.rs index 6c71790..a35396a 100644 --- a/bin/range-finder/src/cli.rs +++ b/bin/range-finder/src/cli.rs @@ -2,10 +2,8 @@ use clap::{ArgAction, Parser}; use color_eyre::eyre::{eyre, Result}; -use kona_derive::{ - online::*, - types::{L2BlockInfo, StageError}, -}; +use kona_derive::{errors::StageError, online::*}; +use kona_primitives::L2BlockInfo; use reqwest::Url; use std::sync::Arc; use superchain_registry::ROLLUP_CONFIGS; diff --git a/crates/op-test-vectors/Cargo.toml b/crates/op-test-vectors/Cargo.toml index 7898626..5f2850c 100644 --- a/crates/op-test-vectors/Cargo.toml +++ b/crates/op-test-vectors/Cargo.toml @@ -29,4 +29,4 @@ op-alloy-consensus.workspace = true [dev-dependencies] serde_json.workspace = true -kona-derive.workspace = true +kona-primitives.workspace = true diff --git a/crates/op-test-vectors/src/derivation.rs b/crates/op-test-vectors/src/derivation.rs index 7f9fba4..4d39fad 100644 --- a/crates/op-test-vectors/src/derivation.rs +++ b/crates/op-test-vectors/src/derivation.rs @@ -64,7 +64,7 @@ pub struct FixtureBlock { mod tests { use super::*; use alloy_primitives::{address, b256, bytes, uint}; - use kona_derive::types::{ + use kona_primitives::{ Blob, BlockID, BlockInfo, L2BlockInfo, L2PayloadAttributes, RollupConfig, SystemConfig, }; From 3494a197ff168cb727b6ee2fded5de7f89a3039c Mon Sep 17 00:00:00 2001 From: refcell Date: Fri, 23 Aug 2024 16:25:14 -0400 Subject: [PATCH 4/4] chore(docs): Update top-level readme --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1792dcb..5a64100 100644 --- a/README.md +++ b/README.md @@ -38,14 +38,32 @@ Each has it's own cli tool to generate test fixtures. [opt8n](./bin/opt8n) can b **`op-test-vectors`** +A rust crate exposing types used to generate test fixtures in [./fixtures](./fixtures/). + +`op-test-vectors` contains two primary modules: + - [`execution`](./crates/op-test-vectors/src/execution.rs): Rust types for the execution test fixtures. - [`derivation`](./crates/op-test-vectors/src/derivation.rs): Rust types for the derivation test fixtures. -**`opt8n` Commands** +**`opt8n`** + +A binary to generate execution test fixtures. + +`opt8n` has two subcommands: - `repl`: Spins up a REPL that allows the user to send transactions to and generate a test fixture from those transactions. - `script`: Executes a forge script against an anvil instance and generates the test fixture. +**`opdn`** + +A binary to generate derivation test fixtures. + +`opdn` has the following subcommands: + +- `from-l2`: Generates a derivation test fixture from the specified range of L2 blocks. +- `from-l1`: Generates a derivation test fixture from the specified range of L1 blocks. +- `info`: Outputs the L2 block info including the L1 origin for the given L2 block number. + ## Book The [book][book] contains an in-depth overview of the project, contributor guidelines, and tutorials for creating your own test fixtures as well as you own test runners.