Skip to content

Commit

Permalink
add versioned state and make compatible with latest optimism
Browse files Browse the repository at this point in the history
  • Loading branch information
jjtny1 committed Jan 23, 2025
1 parent 9004b40 commit 8ca43a2
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 56 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ clap = { version = "4", features = ["derive"] }
shellwords = "1"
reqwest = { version = "0.12", features = ["stream"] }
tracing-subscriber = "0.3.18"
byteorder = "1.5.0"

# Alloy Dependencies
alloy-primitives = { version = "0.8" }
Expand Down
1 change: 1 addition & 0 deletions bin/opfp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ reqwest.workspace = true
futures.workspace = true
color-eyre.workspace = true
tracing-subscriber.workspace = true
byteorder.workspace = true

# CLI
clap.workspace = true
Expand Down
62 changes: 33 additions & 29 deletions bin/opfp/src/cmd/from_op_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,40 +179,44 @@ impl FromOpProgram {
let entry = entry?;
let prefix = entry.path();
debug!(target: TARGET, "Found dir: {:?}", prefix);
prefix.read_dir()?.try_for_each(|entry| -> Result<()> {
let entry = entry?;
let filename = entry.path();
debug!(target: TARGET, "Found file: {:?}", filename);

let contents = std::fs::read_to_string(&filename)?;
debug!(target: TARGET, "File contents: {}", contents);

let key_prefix = prefix
.file_name()
.ok_or(eyre!("Failed to get directory name"))?
.to_os_string()
.into_string()
.map_err(|_| eyre!("Failed to convert directory name into string"))?;

// strip the .txt suffix from the file path
let key: String = key_prefix
+ filename
if prefix.is_dir() {
prefix.read_dir()?.try_for_each(|entry| -> Result<()> {
let entry = entry?;
let filename = entry.path();
debug!(target: TARGET, "Found file: {:?}", filename);

let contents = std::fs::read_to_string(&filename)?;
debug!(target: TARGET, "File contents: {}", contents);

let key_prefix = prefix
.file_name()
.ok_or(eyre!("Failed to get file name"))?
.to_str()
.ok_or(eyre!("Failed to convert file name to string"))?
.split('.')
.next()
.ok_or(eyre!("Failed to strip file extension"))?;
.ok_or(eyre!("Failed to get directory name"))?
.to_os_string()
.into_string()
.map_err(|_| eyre!("Failed to convert directory name into string"))?;

// strip the .txt suffix from the file path
let key: String = key_prefix
+ filename
.file_name()
.ok_or(eyre!("Failed to get file name"))?
.to_str()
.ok_or(eyre!("Failed to convert file name to string"))?
.split('.')
.next()
.ok_or(eyre!("Failed to strip file extension"))?;

debug!(target: TARGET, "Key: {}", key);
debug!(target: TARGET, "Key: {}", key);

let key: B256 = FromHex::from_hex(key)?;
let witness = FromHex::from_hex(contents)?;
let key: B256 = FromHex::from_hex(key)?;
let witness = FromHex::from_hex(contents)?;

witness_data.insert(key, witness);
witness_data.insert(key, witness);
Ok(())
})
} else {
Ok(())
})
}
})?;

let fixture = FaultProofFixture {
Expand Down
15 changes: 10 additions & 5 deletions bin/opfp/src/cmd/run_op_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, path::PathBuf};
use tracing::{debug, error, info, trace, warn};

use super::util::RollupConfig;
use super::util::{RollupConfig, VersionedState};

/// The logging target to use for [tracing].
const TARGET: &str = "run-op-program";
Expand Down Expand Up @@ -155,7 +155,7 @@ impl CannonCommand {
meta: PathBuf,
op_program: OpProgramCommand,
) -> Self {
let output = op_program.data_dir.join("cannon-output.json");
let output = op_program.data_dir.join("cannon-output.bin");
let debug = op_program.data_dir.join("cannon-debug.json");

Self {
Expand Down Expand Up @@ -185,9 +185,14 @@ impl CannonCommand {

let runtime = start.elapsed().as_millis();

let output = std::fs::read_to_string(&self.output)
.map_err(|e| eyre!("Failed to read output file: {}", e))?;
let output: CannonOutput = serde_json::from_str(&output)?;
let data =
std::fs::read(&self.output).map_err(|e| eyre!("Failed to read output file: {}", e))?;

let versioned_state = VersionedState::try_from(data)
.map_err(|e| eyre!("Failed to decode versioned state: {}", e))?;
let output: CannonOutput = CannonOutput {
step: versioned_state.single_threaded_fpvmstate.step,
};

let debug_output = std::fs::read_to_string(&self.debug)
.map_err(|e| eyre!("Failed to read debug output file: {}", e))?;
Expand Down
187 changes: 186 additions & 1 deletion bin/opfp/src/cmd/util.rs

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions devnet/minimal.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
optimism_package:
participants:
- el_type: op-geth
cl_type: op-node
network_params:
granite_time_offset: 0
chains:
- participants:
- el_type: op-geth
cl_type: op-node
network_params:
granite_time_offset: 0
ethereum_package:
network_params:
preset: minimal
additional_preloaded_contracts: '
{
"0x4e59b44847b379578588920cA78FbF26c0B4956C": {
"balance": "0ETH",
"code": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3",
"storage": {},
"nonce": "1"
}
}
'
26 changes: 20 additions & 6 deletions devnet/standard.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
optimism_package:
participants:
- el_type: op-geth
cl_type: op-node
network_params:
granite_time_offset: 0
chains:
- participants:
- el_type: op-geth
cl_type: op-node
network_params:
network_id: "18446744073709551615"
granite_time_offset: 0
op_contract_deployer_params:
image: local-op-deployer
ethereum_package:
network_params:
preset: minimal
additional_preloaded_contracts: '
{
"0x4e59b44847b379578588920cA78FbF26c0B4956C": {
"balance": "0ETH",
"code": "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3",
"storage": {},
"nonce": "1"
}
}
'
additional_services:
- tx_spammer
- blob_spammer
- blob_spammer
18 changes: 9 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ opfp := if `which opfp || true` != "" { `which opfp` } else { "target/debug/opfp
op-program := if `which op-program || true` != "" { `which op-program` } else { join(env("OPTIMISM_DIR"), "op-program/bin/op-program") }
cannon-dir := if `which cannon || true` != "" { parent_directory(parent_directory(`which cannon`)) } else { join(env("OPTIMISM_DIR"), "cannon") }
cannon-bin := join(cannon-dir, "bin/cannon")
cannon-state := join(cannon-dir, "state.json")
cannon-state := join(cannon-dir, "state.bin.gz")
cannon-meta := join(cannon-dir, "meta.json")
enclave := "devnet"
devnet-config-file := "devnet/standard.yaml"
Expand All @@ -21,8 +21,8 @@ fixture-file := join("fixtures", expanded-name + ".json")
op-program-output := join("output", "op-program", file_name(fixture-file))
cannon-output := join("output", "cannon", file_name(fixture-file))
verbosity := "-vv"
genesis-path := "op-genesis-configs/genesis.json"
rollup-path := "op-genesis-configs/rollup.json"
genesis-path := "op-deployer-configs/genesis-18446744073709551615.json"
rollup-path := "op-deployer-configs/rollup-18446744073709551615.json"

# default recipe to display help information
default:
Expand Down Expand Up @@ -53,7 +53,7 @@ cleanup-devnet:

# Creates a new local devnet
create-devnet:
kurtosis run github.com/ethpandaops/optimism-package \
kurtosis run github.com/jjtny1/optimism-package \
--args-file {{ devnet-config-file }} \
--enclave {{ enclave }}

Expand All @@ -62,8 +62,8 @@ generate-fixture:
#!/bin/bash
set -e

L2_RPC_URL={{ shell("kurtosis service inspect " + enclave + " op-el-1-op-geth-op-node | grep -- ' rpc: ' | sed 's/.*-> //'") }}
ROLLUP_URL={{ shell("kurtosis service inspect " + enclave + " op-cl-1-op-node-op-geth | grep -- ' http: ' | sed 's/.*-> //'") }}
L2_RPC_URL={{ shell("kurtosis service inspect " + enclave + " op-el-1-op-geth-op-node-op-kurtosis | grep -- ' rpc: ' | sed 's/.*-> //'") }}
ROLLUP_URL={{ shell("kurtosis service inspect " + enclave + " op-cl-1-op-node-op-geth-op-kurtosis | grep -- ' http: ' | sed 's/.*-> //'") }}

forge script \
--non-interactive \
Expand All @@ -75,10 +75,10 @@ generate-fixture:
script/{{ script-file }} \
{{ script-args }}

rm -rf op-genesis-configs
kurtosis files download {{ enclave }} op-genesis-configs
rm -rf op-deployer-configs
kurtosis files download {{ enclave }} op-deployer-configs

L2_BLOCK_NUM=$(($(jq < broadcast/{{ script-file }}/2151908/run-latest.json '.receipts[0].blockNumber' -r)))
L2_BLOCK_NUM=$(($(jq < broadcast/{{ script-file }}/18446744073709551615/run-latest.json '.receipts[0].blockNumber' -r)))

while true; do
SYNC_STATUS=$(cast rpc optimism_syncStatus --rpc-url $ROLLUP_URL)
Expand Down

0 comments on commit 8ca43a2

Please sign in to comment.