Skip to content

Commit

Permalink
revert until wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Sep 17, 2024
1 parent acf1a70 commit f8f1b30
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 172 deletions.
256 changes: 151 additions & 105 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ alloy-rlp = { version = "0.3", default-features = false, features = [
] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
clap = { version = "4", features = ["derive"] }
structopt = "0.3"
thiserror = "1.0"
triehash = "0.8"
walkdir = "2.5"
Expand Down
16 changes: 9 additions & 7 deletions bins/revme/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ pub mod eofvalidation;
pub mod evmrunner;
pub mod statetest;

use clap::Parser;
use structopt::{clap::AppSettings, StructOpt};

#[derive(Parser, Debug)]
#[command(infer_subcommands = true)]
#[derive(StructOpt, Debug)]
#[structopt(setting = AppSettings::InferSubcommands)]
#[allow(clippy::large_enum_variant)]
pub enum MainCmd {
/// Execute Ethereum state tests.
#[structopt(about = "Execute Ethereum state tests")]
Statetest(statetest::Cmd),
/// Execute eof validation tests.
#[structopt(about = "Execute eof validation tests")]
EofValidation(eofvalidation::Cmd),
/// Run arbitrary EVM bytecode.
#[structopt(
about = "Evm runner command allows running arbitrary evm bytecode.\nBytecode can be provided from cli or from file with --path option."
)]
Evm(evmrunner::Cmd),
/// Print the structure of an EVM bytecode.
#[structopt(alias = "bc", about = "Prints the opcodes of an hex Bytecodes.")]
Bytecode(bytecode::Cmd),
}

Expand Down
12 changes: 6 additions & 6 deletions bins/revme/src/cmd/bytecode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use clap::Parser;
use revm::{
interpreter::{
analysis::{validate_eof_inner, CodeType, EofError},
Expand All @@ -7,20 +6,21 @@ use revm::{
primitives::{Bytes, Eof, MAX_INITCODE_SIZE},
};
use std::io;
use structopt::StructOpt;

/// `bytecode` subcommand.
#[derive(Parser, Debug)]
/// Statetest command
#[derive(StructOpt, Debug)]
pub struct Cmd {
/// Is EOF code in INITCODE mode.
#[arg(long)]
#[structopt(long)]
eof_initcode: bool,
/// Is EOF code in RUNTIME mode.
#[arg(long)]
#[structopt(long)]
eof_runtime: bool,
/// Bytecode in hex format. If bytes start with 0xFE it will be interpreted as a EOF.
/// Otherwise, it will be interpreted as a EOF bytecode.
/// If not provided, it will operate in interactive EOF validation mode.
#[arg()]
#[structopt()]
bytes: Option<String>,
}

Expand Down
14 changes: 7 additions & 7 deletions bins/revme/src/cmd/eofvalidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ mod test_suite;
pub use test_suite::{PragueTestResult, TestResult, TestSuite, TestUnit, TestVector};

use crate::{cmd::Error, dir_utils::find_all_json_tests};
use clap::Parser;
use revm::interpreter::analysis::{validate_raw_eof_inner, CodeType, EofError};
use std::collections::BTreeMap;
use std::path::{Path, PathBuf};
use structopt::StructOpt;

/// `eof-validation` subcommand.
#[derive(Parser, Debug)]
/// Eof validation command.
#[derive(StructOpt, Debug)]
pub struct Cmd {
/// Input paths to EOF validation tests.
#[arg(required = true, num_args = 1..)]
paths: Vec<PathBuf>,
/// Input path to eof validation test
#[structopt(required = true)]
path: Vec<PathBuf>,
}

impl Cmd {
/// Run statetest command.
pub fn run(&self) -> Result<(), Error> {
// check if path exists.
for path in &self.paths {
for path in &self.path {
if !path.exists() {
return Err(Error::Custom("The specified path does not exist"));
}
Expand Down
34 changes: 17 additions & 17 deletions bins/revme/src/cmd/evmrunner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use clap::Parser;
use revm::{
db::BenchmarkDB,
inspector_handle_register,
Expand All @@ -10,6 +9,9 @@ use std::io::Error as IoError;
use std::path::PathBuf;
use std::time::Duration;
use std::{borrow::Cow, fs};
use structopt::StructOpt;

extern crate alloc;

#[derive(Debug, thiserror::Error)]
pub enum Errors {
Expand All @@ -29,26 +31,26 @@ pub enum Errors {

/// Evm runner command allows running arbitrary evm bytecode.
/// Bytecode can be provided from cli or from file with --path option.
#[derive(Parser, Debug)]
#[derive(StructOpt, Debug)]
pub struct Cmd {
/// Hex-encoded EVM bytecode to be executed.
#[arg(required_unless_present = "path")]
bytecode: Option<String>,
/// Path to a file containing the hex-encoded EVM bytecode to be executed.
/// Overrides the positional `bytecode` argument.
#[arg(long)]
/// Bytecode to be executed.
#[structopt(default_value = "")]
bytecode: String,
/// Path to file containing the evm bytecode.
/// Overrides the bytecode option.
#[structopt(long)]
path: Option<PathBuf>,
/// Run in benchmarking mode.
#[arg(long)]
#[structopt(long)]
bench: bool,
/// Hex-encoded input/calldata bytes.
#[arg(long, default_value = "")]
/// Input bytes.
#[structopt(long, default_value = "")]
input: String,
/// Print the state.
#[arg(long)]
#[structopt(long)]
state: bool,
/// Print the trace.
#[arg(long)]
#[structopt(long)]
trace: bool,
}

Expand All @@ -62,11 +64,9 @@ impl Cmd {
if !path.exists() {
return Err(Errors::PathNotExists);
}
fs::read_to_string(path)?.into()
} else if let Some(bytecode) = &self.bytecode {
bytecode.as_str().into()
fs::read_to_string(path)?.to_owned().into()
} else {
unreachable!()
self.bytecode.as_str().into()
};

let bytecode = hex::decode(bytecode_str.trim()).map_err(|_| Errors::InvalidBytecode)?;
Expand Down
25 changes: 12 additions & 13 deletions bins/revme/src/cmd/statetest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,38 @@ pub mod utils;

pub use runner::TestError as Error;

use clap::Parser;
use runner::{find_all_json_tests, run, TestError};
use std::path::PathBuf;
use structopt::StructOpt;

/// `statetest` subcommand.
#[derive(Parser, Debug)]
/// Statetest command
#[derive(StructOpt, Debug)]
pub struct Cmd {
/// Path to folder or file containing the tests. If multiple paths are specified
/// they will be run in sequence.
///
/// Folders will be searched recursively for files with the extension `.json`.
#[clap(required = true, num_args = 1..)]
paths: Vec<PathBuf>,
#[structopt(required = true)]
path: Vec<PathBuf>,
/// Run tests in a single thread.
#[clap(short = 's', long)]
#[structopt(short = "s", long)]
single_thread: bool,
/// Output results in JSON format.
/// It will stop second run of evm on failure.
#[clap(long)]
#[structopt(long)]
json: bool,
/// Output outcome in JSON format. If `--json` is true, this is implied.
/// It will stop second run of EVM on failure.
#[clap(short = 'o', long)]
/// Output outcome in JSON format. If json is true, this is implied.
/// It will stop second run of evm on failure.
#[structopt(short = "o", long)]
json_outcome: bool,
/// Keep going after a test failure.
#[clap(long, alias = "no-fail-fast")]
#[structopt(long, alias = "no-fail-fast")]
keep_going: bool,
}

impl Cmd {
/// Run statetest command.
pub fn run(&self) -> Result<(), TestError> {
for path in &self.paths {
for path in &self.path {
println!("\nRunning tests in {}...", path.display());
let test_files = find_all_json_tests(path);
run(
Expand Down
2 changes: 0 additions & 2 deletions bins/revme/src/cmd/statetest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@ pub fn execute_test_suite(
.with_external_context(
TracerEip3155::new(Box::new(stderr())).without_summary(),
)
.with_spec_id(spec_id)
.append_handler_register(inspector_handle_register)
.build();

Expand Down Expand Up @@ -467,7 +466,6 @@ pub fn execute_test_suite(
.with_env(env.clone())
.reset_handler_with_external_context::<EthereumWiring<_, TracerEip3155>>()
.with_external_context(TracerEip3155::new(Box::new(stdout())).without_summary())
.with_spec_id(spec_id)
.append_handler_register(inspector_handle_register)
.build();
let _ = evm.transact_commit();
Expand Down
11 changes: 8 additions & 3 deletions bins/revme/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use clap::Parser;
use revme::cmd::{Error, MainCmd};
use structopt::StructOpt;

fn main() -> Result<(), Error> {
MainCmd::parse().run().inspect_err(|e| eprintln!("{e:?}"))
pub fn main() -> Result<(), Error> {
let cmd = MainCmd::from_args();
if let Err(e) = cmd.run() {
println!("{:?}", e);
return Err(e);
}
Ok(())
}
16 changes: 9 additions & 7 deletions crates/interpreter/src/instruction_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use core::fmt::Debug;

use revm_primitives::HaltReasonTrait;
use derive_where::derive_where;
use revm_primitives::EvmWiring;

use crate::primitives::{HaltReason, OutOfGasError, SuccessReason};

Expand Down Expand Up @@ -235,16 +236,17 @@ pub enum InternalResult {
InvalidExtDelegateCallTarget,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum SuccessOrHalt<HaltReasonT: HaltReasonTrait> {
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[derive_where(Debug; EvmWiringT::HaltReason)]
pub enum SuccessOrHalt<EvmWiringT: EvmWiring> {
Success(SuccessReason),
Revert,
Halt(HaltReasonT),
Halt(EvmWiringT::HaltReason),
FatalExternalError,
Internal(InternalResult),
}

impl<HaltReasonT: HaltReasonTrait> SuccessOrHalt<HaltReasonT> {
impl<EvmWiringT: EvmWiring> SuccessOrHalt<EvmWiringT> {
/// Returns true if the transaction returned successfully without halts.
#[inline]
pub fn is_success(self) -> bool {
Expand Down Expand Up @@ -274,15 +276,15 @@ impl<HaltReasonT: HaltReasonTrait> SuccessOrHalt<HaltReasonT> {

/// Returns the [HaltReason] value the EVM has experienced an exceptional halt
#[inline]
pub fn to_halt(self) -> Option<HaltReasonT> {
pub fn to_halt(self) -> Option<EvmWiringT::HaltReason> {
match self {
SuccessOrHalt::Halt(reason) => Some(reason),
_ => None,
}
}
}

impl<HaltReasonT: HaltReasonTrait> From<InstructionResult> for SuccessOrHalt<HaltReasonT> {
impl<EvmWiringT: EvmWiring> From<InstructionResult> for SuccessOrHalt<EvmWiringT> {
fn from(result: InstructionResult) -> Self {
match result {
InstructionResult::Continue => Self::Internal(InternalResult::InternalContinue), // used only in interpreter loop
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ serde = { version = "1.0", default-features = false, features = [


[dev-dependencies]
anyhow = "1.0.89"
anyhow = "1.0.83"
criterion = "0.5"
indicatif = "0.17"
rstest = "0.22.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ all = "warn"

[dependencies]
revm-primitives = { path = "../primitives", version = "9.0.1", default-features = false }
once_cell = { version = "1.20", default-features = false, features = ["alloc"] }
once_cell = { version = "1.19", default-features = false, features = ["alloc"] }

# ecRecover
k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ alloy-sol-types = { version = "0.8.2", default-features = false, features = [
"std",
] }
ethers-contract = { version = "2.0.14", default-features = false }
anyhow = "1.0.89"
anyhow = "1.0.87"
criterion = "0.5"
indicatif = "0.17"
reqwest = { version = "0.12" }
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/mainnet/post_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn output<EvmWiringT: EvmWiring>(
// reset journal and return present state.
let (state, logs) = context.evm.journaled_state.finalize();

let result = match SuccessOrHalt::<EvmWiringT::HaltReason>::from(instruction_result.result) {
let result = match SuccessOrHalt::<EvmWiringT>::from(instruction_result.result) {
SuccessOrHalt::Success(reason) => ExecutionResult::Success {
reason,
gas_used: final_gas_used,
Expand Down

0 comments on commit f8f1b30

Please sign in to comment.