Skip to content
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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trevm"
version = "0.27.9"
version = "0.29.0"
rust-version = "1.83.0"
edition = "2021"
authors = ["init4"]
Expand Down Expand Up @@ -34,7 +34,7 @@ name = "fork_ref_transact"
required-features = ["alloy-db"]

[dependencies]
alloy = { version = "1.0.25", default-features = false, features = [
alloy = { version = "1.0.35", default-features = false, features = [
"consensus",
"rpc-types-mev",
"eips",
Expand All @@ -44,8 +44,8 @@ alloy = { version = "1.0.25", default-features = false, features = [
"sol-types",
] }

revm = { version = "27.1", default-features = false }
revm-inspectors = { version = "0.27.3", optional = true }
revm = { version = "29.0.1", default-features = false }
revm-inspectors = { version = "0.30", optional = true }

dashmap = { version = "6.1.0", optional = true }
tracing = { version = "0.1.41", optional = true }
Expand All @@ -54,10 +54,10 @@ thiserror = "2.0.11"
tokio = { version = "1.44", optional = true }

[dev-dependencies]
revm = { version = "27.0.1", features = ["serde-json", "std", "alloydb"] }
revm = { version = "29.0.1", features = ["serde-json", "std", "alloydb"] }
trevm = { path = ".", features = ["test-utils"] }

alloy = { version = "1.0.13", features = ["providers", "transports"] }
alloy = { version = "1.0.35", features = ["providers", "transports"] }

# misc
eyre = "0.6"
Expand Down
6 changes: 3 additions & 3 deletions src/evm/all_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ where
/// Disable an opcode by replacing it with unknown opcode behavior. This is
/// a shortcut for [`Self::override_opcode`] with [`crate::helpers::forbidden`].
pub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db> {
self.override_opcode(opcode, crate::helpers::forbidden)
self.override_opcode(opcode, Instruction::new(crate::helpers::forbidden, 0))
}

/// Run some closure with an opcode override, then restore the previous
Expand Down Expand Up @@ -278,7 +278,7 @@ where
/// Enable the prevrandao opcode. If the prevrandao opcode was not
/// previously disabled or replaced, this will have no effect on behavior.
pub fn enable_prevrandao(&mut self) -> Instruction<Db> {
self.override_opcode(DIFFICULTY, block_info::difficulty)
self.override_opcode(DIFFICULTY, Instruction::new(block_info::difficulty, 2))
}

/// Run some code with the prevrandao opcode disabled, then restore the
Expand All @@ -288,7 +288,7 @@ where
where
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
{
self.with_opcode_override(DIFFICULTY, crate::helpers::forbidden, f)
self.with_opcode_override(DIFFICULTY, Instruction::new(crate::helpers::forbidden, 0), f)
}

/// Set the precompiles for the EVM. This will replace the current
Expand Down
29 changes: 29 additions & 0 deletions src/evm/has_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,35 @@ where
self.set_code_size_limit(0x6000)
}

/// Disable the [EIP-155] chain ID check.
///
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
pub fn disable_chain_id_check(&mut self) {
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = false);
}

/// Enable the [EIP-155] chain ID check.
///
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
pub fn enable_chain_id_check(&mut self) {
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = true);
}

/// Run a closure with the chain ID check disabled, then restore the previous
/// setting.
///
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
pub fn without_chain_id_check<F, NewState: HasCfg>(mut self, f: F) -> Trevm<Db, Insp, NewState>
where
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
{
let previous = self.inner.cfg().tx_chain_id_check;
self.disable_chain_id_check();
let mut new = f(self);
new.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = previous);
new
}

/// Run a function with the provided configuration, then restore the
/// previous configuration. This will not affect the block and tx, if those
/// have been filled.
Expand Down
9 changes: 7 additions & 2 deletions src/evm/has_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ where
#[cfg(test)]
mod tests {
use crate::{
fillers::DisableChainIdCheck,
test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_DEPLOYED_BYTECODE},
NoopBlock, NoopCfg, TrevmBuilder,
};
Expand Down Expand Up @@ -285,8 +286,12 @@ mod tests {
.with_authorization_list(vec![signed_authorization])
.with_input(bytes!("0x7b3ab2d0")); // emitHello()

let (estimation, trevm) =
trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap();
let (estimation, trevm) = trevm
.fill_cfg(&DisableChainIdCheck)
.fill_block(&NoopBlock)
.fill_tx(&tx)
.estimate_gas()
.unwrap();

assert!(estimation.is_success());

Expand Down
13 changes: 13 additions & 0 deletions src/fill/fillers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ impl Cfg for DisableGasChecks {
}
}

/// A [`Cfg`] that disables the chain ID check, while leaving other [`CfgEnv`]
/// attributes untouched.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct DisableChainIdCheck;

impl Cfg for DisableChainIdCheck {
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
{
cfg_env.tx_chain_id_check = false;
}
}
}

/// A [`Cfg`] that disables the nonce check, while leaving other [`CfgEnv`]
/// attributes untouched.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
Expand Down
2 changes: 1 addition & 1 deletion src/fill/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ impl Block for NoopBlock {
pub struct NoopCfg;

impl Cfg for NoopCfg {
fn fill_cfg_env(&self, _: &mut CfgEnv) {}
fn fill_cfg_env(&self, _env: &mut CfgEnv) {}
}
36 changes: 36 additions & 0 deletions src/fill/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,40 @@ mod test {
*chain_id = 1;
}
}

// This test exists to ensure that if fields are added to BlockEnv or TxEnv,
// the compiler will emit an error to remind us to update the fillers to
// handle the new fields. The change canary is not present for [`CfgEnv`]
// because it is marked `#[non_exhaustive]`, which prevents compiler errors
// when fields are added. This is moderately annoying.
#[allow(unused_variables)]
fn _change_canary(block: &BlockEnv, tx: &TxEnv) {
let BlockEnv {
number,
beneficiary,
timestamp,
gas_limit,
basefee,
difficulty,
prevrandao,
blob_excess_gas_and_price,
} = block;

let TxEnv {
tx_type,
caller,
gas_limit,
gas_price,
kind,
value,
data,
nonce,
chain_id,
access_list,
gas_priority_fee,
blob_hashes,
max_fee_per_blob_gas,
authorization_list,
} = tx;
}
}