Skip to content

Commit 51eb790

Browse files
committed
fix: forbid handler
1 parent 5eecb99 commit 51eb790

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/evm.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use revm::{
1919
},
2020
database::{states::bundle_state::BundleRetention, BundleState, TryDatabaseCommit},
2121
inspector::NoOpInspector,
22-
interpreter::{
23-
gas::calculate_initial_tx_gas_for_tx,
24-
instructions::{block_info, control},
25-
},
22+
interpreter::{gas::calculate_initial_tx_gas_for_tx, instructions::block_info},
2623
primitives::{hardfork::SpecId, TxKind},
2724
state::{AccountInfo, Bytecode, EvmState},
2825
Database, DatabaseCommit, DatabaseRef, InspectEvm, Inspector,
@@ -195,9 +192,9 @@ where
195192
}
196193

197194
/// Disable an opcode by replacing it with unknown opcode behavior. This is
198-
/// a shortcut for [`Self::override_opcode`] with [`control::unknown`].
195+
/// a shortcut for [`Self::override_opcode`] with [`crate::helpers::forbidden`].
199196
pub fn disable_opcode(&mut self, opcode: u8) -> Instruction<Db> {
200-
self.override_opcode(opcode, control::unknown)
197+
self.override_opcode(opcode, crate::helpers::forbidden)
201198
}
202199

203200
/// Run some closure with an opcode override, then restore the previous
@@ -238,7 +235,7 @@ where
238235
where
239236
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
240237
{
241-
self.with_opcode_override(DIFFICULTY, control::unknown, f)
238+
self.with_opcode_override(DIFFICULTY, crate::helpers::forbidden, f)
242239
}
243240
}
244241

src/helpers.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use revm::{
22
context::{BlockEnv, CfgEnv, TxEnv},
3+
context_interface::context::ContextError,
34
handler::{instructions::EthInstructions, EthPrecompiles},
45
inspector::NoOpInspector,
5-
interpreter::interpreter::EthInterpreter,
6-
Context, Journal,
6+
interpreter::{interpreter::EthInterpreter, Interpreter, InterpreterTypes},
7+
Context, Database, Journal,
78
};
89

910
/// [`revm::Context`] with default env types and adjustable DB
@@ -18,3 +19,12 @@ pub type Instructions<Db> = EthInstructions<EthInterpreter, Ctx<Db>>;
1819

1920
/// The handler type for an EVM opcode.
2021
pub type Instruction<Db> = revm::interpreter::Instruction<EthInterpreter, Ctx<Db>>;
22+
23+
/// An [`Instruction`] that sets a [`ContextError`] in the [`Ctx`]. whenever it
24+
/// is executed.
25+
pub fn forbidden<Db: Database, Int: InterpreterTypes>(
26+
_interpreter: &mut Interpreter<Int>,
27+
ctx: &mut Ctx<Db>,
28+
) {
29+
ctx.error = Err(ContextError::Custom("forbidden opcode".to_string()));
30+
}

src/inspectors/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
mod layer;
2+
pub use layer::Layered;
3+
14
mod timeout;
25
pub use timeout::TimeLimit;
36

@@ -7,9 +10,6 @@ pub use set::InspectorSet;
710
mod spanning;
811
pub use spanning::SpanningInspector;
912

10-
mod layer;
11-
pub use layer::Layered;
12-
1313
#[cfg(test)]
1414
mod test {
1515
use super::*;

0 commit comments

Comments
 (0)