Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit 2b08e85

Browse files
committed
checkpoint
1 parent 1c6b23b commit 2b08e85

File tree

6 files changed

+108
-18
lines changed

6 files changed

+108
-18
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99

1010
# MdBook Artifacts
1111
book/book/
12+
13+
# Kurtosis Devnet
14+
devnet/

Justfile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,84 @@ build *args='':
5353
# Generates all test fixtures for scripts in examples/exec-scripts
5454
gen fork_url:
5555
@just ./examples/exec-scripts/gen {{fork_url}}
56+
57+
# Install the devnet
58+
install-devnet:
59+
#!/bin/bash
60+
61+
if [ -d "./devnet" ]; then
62+
exit 0
63+
fi
64+
65+
git clone https://github.com/ethpandaops/optimism-package && mv optimism-package devnet
66+
67+
T8N_NETWORK_PARAMS=$(cat <<- "EOM"
68+
optimism_package:
69+
participants:
70+
- el_type: op-geth
71+
cl_type: op-node
72+
network_params:
73+
seconds_per_slot: 2
74+
network_id: 1337
75+
ethereum_package:
76+
participants:
77+
- el_type: reth
78+
cl_type: lighthouse
79+
network_params:
80+
preset: minimal
81+
EOM
82+
)
83+
printf "%s" "$T8N_NETWORK_PARAMS" > ./devnet/network_params.yaml
84+
85+
# Start the devnet
86+
start-devnet:
87+
#!/bin/bash
88+
89+
SCRIPT_DIR=$( pwd )
90+
KURTOSIS_DIR="$SCRIPT_DIR/devnet"
91+
92+
# Exit if Kurtosis is already running
93+
kurtosis enclave inspect devnet && exit 0
94+
95+
echo "Starting Kurtosis network..."
96+
cd "$KURTOSIS_DIR" || exit 1
97+
kurtosis clean -a
98+
kurtosis run --enclave devnet . --args-file ./network_params.yaml
99+
100+
echo "Returning to opt8n..."
101+
cd "$SCRIPT_DIR" || exit 1
102+
103+
# Stop the devnet
104+
stop-devnet:
105+
#!/bin/bash
106+
kurtosis clean -a
107+
108+
# Run t8n
109+
t8n *args='': install-devnet start-devnet
110+
#!/bin/bash
111+
112+
SCRIPT_DIR=$( pwd )
113+
T8N_PATH="$SCRIPT_DIR/target/release/opt8n"
114+
115+
echo "Building opt8n..."
116+
cargo build --bin opt8n --release
117+
118+
# Download L2 genesis configs and contract addresses
119+
echo "Downloading L2 genesis configs and contract addresses from devnet..."
120+
kurtosis files download devnet op-genesis-configs
121+
122+
OPTIMISM_PORTAL_PROXY=$(jq -r .OptimismPortalProxy ./op-genesis-configs/kurtosis.json)
123+
GENESIS="./op-genesis-configs/genesis.json"
124+
125+
L1_PORT=$(kurtosis enclave inspect devnet | grep 'el-1-reth-lighthouse' -A5 | grep " rpc:" | awk -F ' -> ' '{print $2}' | awk -F ':' '{print $2}' | tr -d ' \n\r')
126+
L2_PORT=$(kurtosis enclave inspect devnet | grep 'op-el-1-op-geth-op-node' -A5 | grep " rpc:" | awk -F ' -> ' '{print $2}' | awk -F ':' '{print $3}' | tr -d ' \n\r')
127+
128+
$T8N_PATH \
129+
--l1-port "$L1_PORT" \
130+
--l2-port "$L2_PORT" \
131+
-o "$OPTIMISM_PORTAL_PROXY" \
132+
--l2-genesis "$GENESIS" \
133+
$@
134+
135+
echo "Cleaning up genesis + configs..."
136+
rm -rf ./op-genesis-configs

bin/opt8n/src/cli/state.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use alloy_provider::{
1010
};
1111
use color_eyre::eyre::{bail, eyre, Result};
1212
use hashbrown::HashMap;
13-
use kona_primitives::L1BlockInfoTx;
1413
use reqwest::Url;
1514
use serde::{Deserialize, Serialize};
1615
use tracing::info;
@@ -44,7 +43,7 @@ impl<'a> StateCapture<'a> {
4443
/// ## Returns
4544
/// - `Ok(L1BlockInfoTx)` - Successfully captured the prestate / test block environment.
4645
/// - `Err(_)` - Error capturing prestate / test block environment.
47-
pub(crate) async fn capture_state(&mut self) -> Result<(L1BlockInfoTx, Bytes)> {
46+
pub(crate) async fn capture_state(&mut self) -> Result<Bytes> {
4847
// Set up the providers.
4948
let l2_rpc_url = format!("http://localhost:{}", self.cli.l2_port);
5049
let l2_provider: RootProvider<_, Ethereum> =
@@ -78,7 +77,7 @@ impl<'a> StateCapture<'a> {
7877

7978
// Fetch the latest and parent block.
8079
let latest_block = l2_provider
81-
.get_block_by_number(latest_block_number.into(), true)
80+
.get_block_by_number(latest_block_number.into(), false)
8281
.await?
8382
.ok_or(eyre!("Latest block not found."))?;
8483
let parent_block = l2_provider
@@ -89,23 +88,20 @@ impl<'a> StateCapture<'a> {
8988
self.header = latest_block.header.try_into()?;
9089
self.pre_header = parent_block.header.try_into()?;
9190

92-
let BlockTransactions::Full(transactions) = latest_block.transactions else {
91+
let BlockTransactions::Hashes(transactions) = latest_block.transactions else {
9392
bail!("Could not fetch L1 info transaction.")
9493
};
9594

9695
let l1_info_tx = transactions
9796
.get(0)
9897
.ok_or(eyre!("L1 info transaction not present"))?;
99-
let l1_info = L1BlockInfoTx::decode_calldata(l1_info_tx.input.as_ref())
100-
.map_err(|e| eyre!("Error decoding L1 info tx: {e}"))?;
101-
10298
let raw_tx = l2_provider
103-
.raw_request::<[B256; 1], Bytes>("debug_getRawTransaction".into(), [l1_info_tx.hash])
99+
.raw_request::<[B256; 1], Bytes>("debug_getRawTransaction".into(), [*l1_info_tx])
104100
.await?;
105101

106102
info!(target: "state-capture", "Captured prestate / test block environment successfully.");
107103

108-
Ok((l1_info, raw_tx))
104+
Ok(raw_tx)
109105
}
110106
}
111107

bin/opt8n/src/cli/t8n.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::{deposits::DepositCapture, state::StateCapture, Cli};
44
use crate::generator::STF;
55
use alloy_genesis::Genesis;
66
use alloy_primitives::Bytes;
7-
use color_eyre::{eyre::ensure, Result, owo_colors::OwoColorize};
7+
use color_eyre::{eyre::ensure, owo_colors::OwoColorize, Result};
88
use futures::{future::BoxFuture, FutureExt};
99
use inquire::Select;
1010
use std::{fmt::Display, path::PathBuf};
@@ -44,7 +44,7 @@ impl<'a> T8n<'a> {
4444
let options = [
4545
MainMenuOption::SetupEnvironment,
4646
MainMenuOption::CaptureDeposits,
47-
MainMenuOption::ModifyBlock,
47+
MainMenuOption::CaptureTransactions,
4848
MainMenuOption::GenerateFixture,
4949
MainMenuOption::Exit,
5050
];
@@ -53,7 +53,7 @@ impl<'a> T8n<'a> {
5353
match choice {
5454
MainMenuOption::SetupEnvironment => {
5555
// Capture prestate and test block environment.
56-
let (_, l1_info_encoded) = self.state_cfg.capture_state().await?;
56+
let l1_info_encoded = self.state_cfg.capture_state().await?;
5757
self.deposits.transactions.push(l1_info_encoded);
5858

5959
// Return to the main menu.
@@ -66,7 +66,7 @@ impl<'a> T8n<'a> {
6666
// Return to the main menu.
6767
self.run().await?;
6868
}
69-
MainMenuOption::ModifyBlock => {
69+
MainMenuOption::CaptureTransactions => {
7070
// Capture the transactions sent to the L2 node.
7171
let transactions = crate::proxy::capture_transactions(
7272
3000,
@@ -129,7 +129,7 @@ impl<'a> T8n<'a> {
129129
enum MainMenuOption {
130130
SetupEnvironment,
131131
CaptureDeposits,
132-
ModifyBlock,
132+
CaptureTransactions,
133133
GenerateFixture,
134134
Exit,
135135
}
@@ -142,7 +142,7 @@ impl Display for MainMenuOption {
142142
"Setup environment (capture prestate and test block environment)"
143143
),
144144
Self::CaptureDeposits => write!(f, "Set deposit transactions"),
145-
Self::ModifyBlock => write!(f, "Set user-space transactions"),
145+
Self::CaptureTransactions => write!(f, "Set user-space transactions"),
146146
Self::GenerateFixture => write!(f, "Generate execution fixture"),
147147
Self::Exit => write!(f, "Exit"),
148148
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//! TODO: Custom EVM config.

bin/opt8n/src/generator/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! The reference state transition function.
22
3+
use crate::cli::state::{DumpBlockResponse, GenesisAccountExt};
34
use alloy_consensus::{constants::KECCAK_EMPTY, Header};
45
use alloy_genesis::{Genesis, GenesisAccount};
56
use alloy_primitives::B256;
67
use alloy_rlp::{Decodable, Encodable};
78
use alloy_trie::{HashBuilder, HashMap, Nibbles};
8-
use color_eyre::{eyre::eyre, Result};
9+
use color_eyre::{eyre::eyre, owo_colors::OwoColorize, Result};
910
use itertools::Itertools;
1011
use kona_mpt::TrieAccount;
1112
use op_test_vectors::execution::{ExecutionEnvironment, ExecutionFixture, ExecutionResult};
@@ -22,8 +23,7 @@ use revm::{
2223
primitives::{AccountInfo, Bytecode},
2324
};
2425
use std::{collections::BTreeMap, sync::Arc};
25-
26-
use crate::cli::state::{DumpBlockResponse, GenesisAccountExt};
26+
use tracing::info;
2727

2828
/// The database for [STF].
2929
type STFDB = CacheDB<EmptyDBTyped<ProviderError>>;
@@ -159,12 +159,14 @@ impl STF {
159159
.collect::<Result<Vec<_>>>()?;
160160

161161
// Execute the block.
162+
info!(target: "stf", "Executing block with {} transactions...", txs.len().cyan());
162163
let block_with_senders = BlockWithSenders::new(block, senders)
163164
.ok_or(eyre!("Error creating block with senders"))?;
164165
let execution_input = BlockExecutionInput::new(&block_with_senders, header.difficulty);
165166
let BlockExecutionOutput {
166167
state, receipts, ..
167168
} = executor.execute(execution_input)?;
169+
info!(target: "stf", "✅ Block successfully executed.");
168170

169171
// Flush the bundle state updates to the in-memory database.
170172
let alloc_db = self.db.clone();
@@ -207,6 +209,13 @@ impl STF {
207209
.expect("Number is in range");
208210
let transactions_root = reth_primitives::proofs::calculate_transaction_root(&txs);
209211

212+
// Log the execution fixture results.
213+
let ind = "~>".magenta().italic().to_string();
214+
info!(target: "stf", "{} State root: {}", ind, root.cyan());
215+
info!(target: "stf", "{} Transactions root: {}", ind, transactions_root.cyan());
216+
info!(target: "stf", "{} Receipts root: {}", ind, receipts_root.cyan());
217+
info!(target: "stf", "{} Logs bloom: {}", ind, logs_bloom.cyan());
218+
210219
Ok(ExecutionFixture {
211220
env: ExecutionEnvironment {
212221
current_coinbase: header.beneficiary,

0 commit comments

Comments
 (0)