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

🥢 Refactor #8

Merged
merged 4 commits into from
Sep 4, 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
109 changes: 68 additions & 41 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ authors = ["clabby"]
alloy-primitives = "0.7.7"

# kona
kona-preimage = { git = "https://github.com/ethereum-optimism/kona" }
kona-common = { git = "https://github.com/ethereum-optimism/kona" }
kona-preimage = { git = "https://github.com/ethereum-optimism/kona", rev = "e069eb4" }
kona-common = { git = "https://github.com/ethereum-optimism/kona", rev = "e069eb4" }

# ser
serde = { version = "1.0.204", features = ["derive"] }
Expand All @@ -29,6 +29,7 @@ tracing = "0.1.40"
opt-level = 3
lto = true
codegen-units = 1
debug = false

[profile.dev]
overflow-checks = false
Expand Down
5 changes: 5 additions & 0 deletions bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@ anyhow.workspace = true
alloy-primitives.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true

# External
clap = { version = "4.5.9", features = ["derive"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
async-trait = "0.1.81"

# Local
howitzer-kernel = { path = "../crates/kernel" }
howitzer-fpvm = { path = "../crates/fpvm" }

[features]
asm-keccak = ["howitzer-fpvm/asm-keccak"]

[[bin]]
name = "howitzer"
path = "src/howitzer.rs"
5 changes: 3 additions & 2 deletions bin/src/howitzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ struct Args {
subcommand: subcommands::HowitzerSubcommand,
}

fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
// Parse the command arguments
let Args { v, subcommand } = Args::parse();

// Initialize the tracing subscriber
init_tracing_subscriber(v)?;

tracing::debug!(target: "howitzer-cli", "Dispatching subcommand");
subcommand.dispatch()?;
subcommand.dispatch().await?;

Ok(())
}
Expand Down
21 changes: 13 additions & 8 deletions bin/src/subcommands/load_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use super::HowitzerSubcommandDispatcher;
use alloy_primitives::B256;
use anyhow::Result;
use async_trait::async_trait;
use clap::Args;
use howitzer_fpvm::{
memory::{Memory, TrieMemory},
state::state_hash,
utils::patch::{load_elf, patch_go, patch_stack},
};
Expand All @@ -22,16 +24,16 @@ use std::{
#[command(author, version, about)]
pub(crate) struct LoadElfArgs {
/// The path to the input 32-bit big-endian MIPS ELF file.
#[arg(long)]
path: PathBuf,
#[arg(long, short)]
input: PathBuf,

/// The type of patch to perform on the ELF file.
#[arg(long, default_values = ["go", "stack"])]
#[arg(long, short, default_values = ["go", "stack"])]
patch_kind: Vec<PatchKind>,

/// The output path to write the JSON state to. State will be dumped to stdout if set to `-`.
/// Not written if not provided.
#[arg(long)]
#[arg(long, short)]
output: Option<String>,
}

Expand Down Expand Up @@ -62,15 +64,16 @@ impl Display for PatchKind {
}
}

#[async_trait]
impl HowitzerSubcommandDispatcher for LoadElfArgs {
fn dispatch(self) -> Result<()> {
tracing::info!(target: "howitzer-cli::load-elf", "Loading ELF file @ {}", self.path.display());
let file = File::open(&self.path)?;
async fn dispatch(self) -> Result<()> {
tracing::info!(target: "howitzer-cli::load-elf", "Loading ELF file @ {}", self.input.display());
let file = File::open(&self.input)?;
let file_sz = file.metadata()?.len();
let mut reader = BufReader::new(file);
let mut elf_raw = Vec::with_capacity(file_sz as usize);
reader.read_to_end(&mut elf_raw)?;
let mut state = load_elf(&elf_raw)?;
let mut state = load_elf::<TrieMemory>(&elf_raw)?;
tracing::info!(target: "howitzer-cli::load-elf", "Loaded ELF file and constructed the State");

for p in self.patch_kind {
Expand All @@ -81,6 +84,8 @@ impl HowitzerSubcommandDispatcher for LoadElfArgs {
}?;
}

state.memory.flush_page_cache()?;

if let Some(ref path_str) = self.output {
if path_str == "-" {
println!("{}", serde_json::to_string(&state)?);
Expand Down
Loading