Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita committed Sep 6, 2024
1 parent de4e89c commit 492c27a
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 144 deletions.
4 changes: 0 additions & 4 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ asm-keccak = ["revm-primitives/asm-keccak"]
portable = ["revm-primitives/portable"]
parse = ["dep:paste", "dep:phf"]

optimism = ["revm-primitives/optimism"]

dev = [
"memory_limit",
"optional_balance_check",
Expand All @@ -61,7 +59,6 @@ dev = [
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
"optional_nonce_check",
]
memory_limit = ["revm-primitives/memory_limit"]
optional_balance_check = ["revm-primitives/optional_balance_check"]
Expand All @@ -70,6 +67,5 @@ optional_eip3607 = ["revm-primitives/optional_eip3607"]
optional_gas_refund = ["revm-primitives/optional_gas_refund"]
optional_no_base_fee = ["revm-primitives/optional_no_base_fee"]
optional_beneficiary_reward = ["revm-primitives/optional_beneficiary_reward"]
optional_nonce_check = ["revm-primitives/optional_nonce_check"]

kzg-rs = ["revm-primitives/kzg-rs"]
2 changes: 0 additions & 2 deletions crates/optimism/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ dev = [
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
"optional_nonce_check",
]
memory_limit = ["revm/memory_limit"]
optional_balance_check = ["revm/optional_balance_check"]
Expand All @@ -87,7 +86,6 @@ optional_eip3607 = ["revm/optional_eip3607"]
optional_gas_refund = ["revm/optional_gas_refund"]
optional_no_base_fee = ["revm/optional_no_base_fee"]
optional_beneficiary_reward = ["revm/optional_beneficiary_reward"]
optional_nonce_check = ["revm/optional_nonce_check"]

# See comments in `revm-precompile`
secp256k1 = ["revm/secp256k1"]
Expand Down
2 changes: 0 additions & 2 deletions crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ std = [
hashbrown = ["revm-primitives/hashbrown"]
asm-keccak = ["revm-primitives/asm-keccak"]

optimism = ["revm-primitives/optimism", "secp256r1"]

# Enables the p256verify precompile.
secp256r1 = ["dep:p256"]

Expand Down
4 changes: 0 additions & 4 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ arbitrary = [
asm-keccak = ["alloy-primitives/asm-keccak"]
portable = ["c-kzg?/portable"]

optimism = []

dev = [
"memory_limit",
"optional_balance_check",
Expand All @@ -93,7 +91,6 @@ dev = [
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
"optional_nonce_check",
]
memory_limit = []
optional_balance_check = []
Expand All @@ -102,7 +99,6 @@ optional_eip3607 = []
optional_gas_refund = []
optional_no_base_fee = []
optional_beneficiary_reward = []
optional_nonce_check = []
rand = ["alloy-primitives/rand"]

# See comments in `revm-precompile`
Expand Down
18 changes: 5 additions & 13 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ pub struct CfgEnv {
/// If some it will effects EIP-170: Contract code size limit. Useful to increase this because of tests.
/// By default it is 0x6000 (~25kb).
pub limit_contract_code_size: Option<usize>,
/// Skips the nonce validation against the account's nonce:
/// [`crate::InvalidTransaction::NonceTooHigh`] and
/// [`crate::InvalidTransaction::NonceTooLow`]
pub disable_nonce_check: bool,
/// A hard memory limit in bytes beyond which [crate::result::OutOfGasError::Memory] cannot be resized.
///
/// In cases where the gas limit may be extraordinarily high, it is recommended to set this to
Expand Down Expand Up @@ -341,11 +345,6 @@ pub struct CfgEnv {
/// By default, it is set to `false`.
#[cfg(feature = "optional_beneficiary_reward")]
pub disable_beneficiary_reward: bool,
/// Skips the nonce validation against the account's nonce:
/// [`crate::InvalidTransaction::NonceTooHigh`] and
/// [`crate::InvalidTransaction::NonceTooLow`]
#[cfg(feature = "optional_nonce_check")]
pub disable_nonce_check: bool,
}

impl CfgEnv {
Expand Down Expand Up @@ -420,15 +419,9 @@ impl CfgEnv {
false
}

#[cfg(feature = "optional_nonce_check")]
pub const fn is_nonce_check_disabled(&self) -> bool {
self.disable_nonce_check
}

#[cfg(not(feature = "optional_nonce_check"))]
pub const fn is_nonce_check_disabled(&self) -> bool {
false
}
}

impl Default for CfgEnv {
Expand All @@ -437,6 +430,7 @@ impl Default for CfgEnv {
chain_id: 1,
perf_analyse_created_bytecodes: AnalysisKind::default(),
limit_contract_code_size: None,
disable_nonce_check: false,
#[cfg(any(feature = "c-kzg", feature = "kzg-rs"))]
kzg_settings: crate::kzg::EnvKzgSettings::Default,
#[cfg(feature = "memory_limit")]
Expand All @@ -453,8 +447,6 @@ impl Default for CfgEnv {
disable_base_fee: false,
#[cfg(feature = "optional_beneficiary_reward")]
disable_beneficiary_reward: false,
#[cfg(feature = "optional_nonce_check")]
disable_nonce_check: false,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ impl Output {
}
}

pub type EVMErrorWiring<EvmWiringT> = EVMError<
<<EvmWiringT as EvmWiring>::Database as Database>::Error,
<<EvmWiringT as EvmWiring>::Transaction as TransactionValidation>::ValidationError,
>;

/// Main EVM error.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down
7 changes: 0 additions & 7 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ dev = [
"optional_gas_refund",
"optional_no_base_fee",
"optional_beneficiary_reward",
"optional_nonce_check",
]
memory_limit = ["revm-interpreter/memory_limit"]
optional_balance_check = ["revm-interpreter/optional_balance_check"]
Expand All @@ -111,7 +110,6 @@ optional_eip3607 = ["revm-interpreter/optional_eip3607"]
optional_gas_refund = ["revm-interpreter/optional_gas_refund"]
optional_no_base_fee = ["revm-interpreter/optional_no_base_fee"]
optional_beneficiary_reward = ["revm-interpreter/optional_beneficiary_reward"]
optional_nonce_check = ["revm-interpreter/optional_nonce_check"]

# See comments in `revm-precompile`
secp256k1 = ["revm-precompile/secp256k1"]
Expand Down Expand Up @@ -140,11 +138,6 @@ required-features = ["std", "serde-json"]
#path = "../../examples/uniswap_v2_usdc_swap.rs"
#required-features = ["alloydb"]

#[[example]]
#name = "custom_opcodes"
#path = "../../examples/custom_opcodes.rs"
#required-features = []

[[bench]]
name = "bench"
path = "benches/bench.rs"
Expand Down
28 changes: 16 additions & 12 deletions crates/revm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use revm_interpreter::Host as _;
use crate::{
builder::{EvmBuilder, SetGenericStage},
db::{Database, DatabaseCommit},
handler::{EnvWithEvmWiring, Handler},
handler::Handler,
interpreter::{CallInputs, CreateInputs, EOFCreateInputs, InterpreterAction, SharedMemory},
primitives::{
CfgEnv, EVMError, EVMResult, EVMResultGeneric, ExecutionResult, ResultAndState, SpecId,
Transaction, TxKind, EOF_MAGIC_BYTES,
CfgEnv, EVMError, EVMResult, EVMResultGeneric, EnvWiring, ExecutionResult, ResultAndState,
SpecId, Transaction, TxKind, EOF_MAGIC_BYTES,
},
Context, ContextWithEvmWiring, EvmContext, EvmWiring, Frame, FrameOrResult, FrameResult,
InnerEvmContext,
Expand Down Expand Up @@ -91,10 +91,6 @@ impl<'a, EvmWiringT: EvmWiring> Evm<'a, EvmWiringT> {
},
handler,
} = self;
// let handler = self.handler;
// let db = self.context.evm.db;
// let ext = self.context.external;
// let env = self.context.evm.env;
EvmBuilder::<'a>::new_with(db, external, env, handler)
}

Expand Down Expand Up @@ -316,6 +312,12 @@ impl<EvmWiringT: EvmWiring> Evm<'_, EvmWiringT> {
&mut self.context.evm.env.block
}

/// Modify spec id, this will create new EVM that matches this spec id.
pub fn modify_spec_id(&mut self, spec_id: EvmWiringT::Hardfork) {
self.context.evm.journaled_state.set_spec_id(spec_id.into());
self.handler.modify_spec_id(spec_id);
}

/// Returns internal database and external struct.
#[inline]
pub fn into_context(self) -> Context<EvmWiringT> {
Expand All @@ -326,13 +328,15 @@ impl<EvmWiringT: EvmWiring> Evm<'_, EvmWiringT> {
#[inline]
pub fn into_db_and_env_with_handler_cfg(
self,
) -> (EvmWiringT::Database, EnvWithEvmWiring<EvmWiringT>) {
) -> (
EvmWiringT::Database,
Box<EnvWiring<EvmWiringT>>,
EvmWiringT::Hardfork,
) {
(
self.context.evm.inner.db,
EnvWithEvmWiring {
env: self.context.evm.inner.env,
spec_id: self.handler.spec_id,
},
self.context.evm.inner.env,
self.handler.spec_id,
)
}

Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions crates/revm/src/handler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
// Modules.
pub mod cfg;
mod handle_types;
pub mod mainnet;
pub mod register;

// Exports.
pub use cfg::{CfgEnvWithEvmWiring, EnvWithEvmWiring};
pub use handle_types::*;

// Includes.
Expand Down
94 changes: 0 additions & 94 deletions crates/revm/src/handler/cfg.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/revm/src/handler/handle_types/pre_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub type ApplyEIP7702AuthListHandle<'a, EvmWiringT> = GenericContextHandleRet<'a
pub struct PreExecutionHandler<'a, EvmWiringT: EvmWiring> {
/// Load precompiles
pub load_precompiles: LoadPrecompilesHandle<'a, EvmWiringT>,
// /// Main load handle
/// Main load handle
pub load_accounts: LoadAccountsHandle<'a, EvmWiringT>,
/// Deduct max value from the caller.
pub deduct_caller: DeductCallerHandle<'a, EvmWiringT>,
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/handler/mainnet/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub fn insert_eofcreate_outcome<EvmWiringT: EvmWiring>(
frame: &mut Frame,
outcome: CreateOutcome,
) -> EVMResultGeneric<(), EvmWiringT> {
core::mem::replace(&mut context.evm.error, Ok(())).map_err(EVMError::Database)?;
context.evm.take_error().map_err(EVMError::Database)?;

frame
.frame_data_mut()
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ mod context;
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;

mod chain_spec;
pub mod db;
mod evm;
mod evm_wiring;
mod frame;
pub mod handler;
mod inspector;
Expand All @@ -25,7 +25,6 @@ mod journaled_state;
// Export items.

pub use builder::EvmBuilder;
pub use chain_spec::EvmWiring;
pub use context::{
Context, ContextPrecompile, ContextPrecompiles, ContextStatefulPrecompile,
ContextStatefulPrecompileArc, ContextStatefulPrecompileBox, ContextStatefulPrecompileMut,
Expand All @@ -36,6 +35,7 @@ pub use db::{
};
pub use db::{Database, DatabaseCommit, DatabaseRef, InMemoryDB};
pub use evm::{Evm, CALL_STACK_LIMIT};
pub use evm_wiring::EvmWiring;
pub use frame::{CallFrame, CreateFrame, Frame, FrameData, FrameOrResult, FrameResult};
pub use handler::{register::EvmHandler, Handler};
pub use inspector::{inspector_handle_register, inspectors, GetInspector, Inspector};
Expand Down

0 comments on commit 492c27a

Please sign in to comment.