Skip to content

Commit 3033df3

Browse files
prestwichEvalir
andauthored
chore: bump revm to 29.0.1 (#127)
* chore: bump revm to 29.0.1 * feat: change canary * feat(has_cfg): chain id check enabling / disabling --------- Co-authored-by: evalir <[email protected]>
1 parent d2f2443 commit 3033df3

File tree

7 files changed

+95
-12
lines changed

7 files changed

+95
-12
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.27.9"
3+
version = "0.29.0"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]
@@ -34,7 +34,7 @@ name = "fork_ref_transact"
3434
required-features = ["alloy-db"]
3535

3636
[dependencies]
37-
alloy = { version = "1.0.25", default-features = false, features = [
37+
alloy = { version = "1.0.35", default-features = false, features = [
3838
"consensus",
3939
"rpc-types-mev",
4040
"eips",
@@ -44,8 +44,8 @@ alloy = { version = "1.0.25", default-features = false, features = [
4444
"sol-types",
4545
] }
4646

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

5050
dashmap = { version = "6.1.0", optional = true }
5151
tracing = { version = "0.1.41", optional = true }
@@ -54,10 +54,10 @@ thiserror = "2.0.11"
5454
tokio = { version = "1.44", optional = true }
5555

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

60-
alloy = { version = "1.0.13", features = ["providers", "transports"] }
60+
alloy = { version = "1.0.35", features = ["providers", "transports"] }
6161

6262
# misc
6363
eyre = "0.6"

src/evm/all_states.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ where
247247
/// Disable an opcode by replacing it with unknown opcode behavior. This is
248248
/// a shortcut for [`Self::override_opcode`] with [`crate::helpers::forbidden`].
249249
pub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db> {
250-
self.override_opcode(opcode, crate::helpers::forbidden)
250+
self.override_opcode(opcode, Instruction::new(crate::helpers::forbidden, 0))
251251
}
252252

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

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

294294
/// Set the precompiles for the EVM. This will replace the current

src/evm/has_cfg.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,35 @@ where
5757
self.set_code_size_limit(0x6000)
5858
}
5959

60+
/// Disable the [EIP-155] chain ID check.
61+
///
62+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
63+
pub fn disable_chain_id_check(&mut self) {
64+
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = false);
65+
}
66+
67+
/// Enable the [EIP-155] chain ID check.
68+
///
69+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
70+
pub fn enable_chain_id_check(&mut self) {
71+
self.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = true);
72+
}
73+
74+
/// Run a closure with the chain ID check disabled, then restore the previous
75+
/// setting.
76+
///
77+
/// [`EIP-155`]: https://eips.ethereum.org/EIPS/eip-155
78+
pub fn without_chain_id_check<F, NewState: HasCfg>(mut self, f: F) -> Trevm<Db, Insp, NewState>
79+
where
80+
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
81+
{
82+
let previous = self.inner.cfg().tx_chain_id_check;
83+
self.disable_chain_id_check();
84+
let mut new = f(self);
85+
new.inner.ctx.modify_cfg(|cfg| cfg.tx_chain_id_check = previous);
86+
new
87+
}
88+
6089
/// Run a function with the provided configuration, then restore the
6190
/// previous configuration. This will not affect the block and tx, if those
6291
/// have been filled.

src/evm/has_tx.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ where
219219
#[cfg(test)]
220220
mod tests {
221221
use crate::{
222+
fillers::DisableChainIdCheck,
222223
test_utils::{test_trevm_with_funds, ALICE, BOB, LOG_DEPLOYED_BYTECODE},
223224
NoopBlock, NoopCfg, TrevmBuilder,
224225
};
@@ -285,8 +286,12 @@ mod tests {
285286
.with_authorization_list(vec![signed_authorization])
286287
.with_input(bytes!("0x7b3ab2d0")); // emitHello()
287288

288-
let (estimation, trevm) =
289-
trevm.fill_cfg(&NoopCfg).fill_block(&NoopBlock).fill_tx(&tx).estimate_gas().unwrap();
289+
let (estimation, trevm) = trevm
290+
.fill_cfg(&DisableChainIdCheck)
291+
.fill_block(&NoopBlock)
292+
.fill_tx(&tx)
293+
.estimate_gas()
294+
.unwrap();
290295

291296
assert!(estimation.is_success());
292297

src/fill/fillers.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ impl Cfg for DisableGasChecks {
3131
}
3232
}
3333

34+
/// A [`Cfg`] that disables the chain ID check, while leaving other [`CfgEnv`]
35+
/// attributes untouched.
36+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
37+
pub struct DisableChainIdCheck;
38+
39+
impl Cfg for DisableChainIdCheck {
40+
fn fill_cfg_env(&self, cfg_env: &mut CfgEnv) {
41+
{
42+
cfg_env.tx_chain_id_check = false;
43+
}
44+
}
45+
}
46+
3447
/// A [`Cfg`] that disables the nonce check, while leaving other [`CfgEnv`]
3548
/// attributes untouched.
3649
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]

src/fill/noop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ impl Block for NoopBlock {
1515
pub struct NoopCfg;
1616

1717
impl Cfg for NoopCfg {
18-
fn fill_cfg_env(&self, _: &mut CfgEnv) {}
18+
fn fill_cfg_env(&self, _env: &mut CfgEnv) {}
1919
}

src/fill/traits.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,40 @@ mod test {
230230
*chain_id = 1;
231231
}
232232
}
233+
234+
// This test exists to ensure that if fields are added to BlockEnv or TxEnv,
235+
// the compiler will emit an error to remind us to update the fillers to
236+
// handle the new fields. The change canary is not present for [`CfgEnv`]
237+
// because it is marked `#[non_exhaustive]`, which prevents compiler errors
238+
// when fields are added. This is moderately annoying.
239+
#[allow(unused_variables)]
240+
fn _change_canary(block: &BlockEnv, tx: &TxEnv) {
241+
let BlockEnv {
242+
number,
243+
beneficiary,
244+
timestamp,
245+
gas_limit,
246+
basefee,
247+
difficulty,
248+
prevrandao,
249+
blob_excess_gas_and_price,
250+
} = block;
251+
252+
let TxEnv {
253+
tx_type,
254+
caller,
255+
gas_limit,
256+
gas_price,
257+
kind,
258+
value,
259+
data,
260+
nonce,
261+
chain_id,
262+
access_list,
263+
gas_priority_fee,
264+
blob_hashes,
265+
max_fee_per_blob_gas,
266+
authorization_list,
267+
} = tx;
268+
}
233269
}

0 commit comments

Comments
 (0)