Skip to content

Commit c699b79

Browse files
committed
Revert "refactor(handler): provide &CallInputstoPrecompileProvider::run (bluealloy#2921)"
This reverts commit 827d572.
1 parent acaed10 commit c699b79

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

crates/handler/src/frame.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ impl EthFrame<EthInterpreter> {
193193
let is_static = inputs.is_static;
194194
let gas_limit = inputs.gas_limit;
195195

196-
if let Some(result) = precompiles.run(ctx, &inputs).map_err(ERROR::from_string)? {
196+
if let Some(result) = precompiles
197+
.run(
198+
ctx,
199+
&inputs.bytecode_address,
200+
&interpreter_input,
201+
is_static,
202+
gas_limit,
203+
)
204+
.map_err(ERROR::from_string)?
205+
{
197206
if result.result.is_ok() {
198207
ctx.journal_mut().checkpoint_commit();
199208
} else {

crates/handler/src/precompile_provider.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use auto_impl::auto_impl;
22
use context::{Cfg, LocalContextTr};
33
use context_interface::ContextTr;
4-
use interpreter::{CallInput, CallInputs, Gas, InstructionResult, InterpreterResult};
4+
use interpreter::{CallInput, Gas, InputsImpl, InstructionResult, InterpreterResult};
55
use precompile::PrecompileError;
66
use precompile::{PrecompileSpecId, Precompiles};
77
use primitives::{hardfork::SpecId, Address, Bytes};
@@ -23,7 +23,10 @@ pub trait PrecompileProvider<CTX: ContextTr> {
2323
fn run(
2424
&mut self,
2525
context: &mut CTX,
26-
inputs: &CallInputs,
26+
address: &Address,
27+
inputs: &InputsImpl,
28+
is_static: bool,
29+
gas_limit: u64,
2730
) -> Result<Option<Self::Output>, String>;
2831

2932
/// Get the warm addresses.
@@ -90,15 +93,18 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> for EthPrecompiles {
9093
fn run(
9194
&mut self,
9295
context: &mut CTX,
93-
inputs: &CallInputs,
96+
address: &Address,
97+
inputs: &InputsImpl,
98+
_is_static: bool,
99+
gas_limit: u64,
94100
) -> Result<Option<InterpreterResult>, String> {
95-
let Some(precompile) = self.precompiles.get(&inputs.bytecode_address) else {
101+
let Some(precompile) = self.precompiles.get(address) else {
96102
return Ok(None);
97103
};
98104

99105
let mut result = InterpreterResult {
100106
result: InstructionResult::Return,
101-
gas: Gas::new(inputs.gas_limit),
107+
gas: Gas::new(gas_limit),
102108
output: Bytes::new(),
103109
};
104110

@@ -115,7 +121,7 @@ impl<CTX: ContextTr> PrecompileProvider<CTX> for EthPrecompiles {
115121
CallInput::Bytes(bytes) => bytes.0.iter().as_slice(),
116122
};
117123

118-
match precompile.execute(input_bytes, inputs.gas_limit) {
124+
match precompile.execute(input_bytes, gas_limit) {
119125
Ok(output) => {
120126
let underflow = result.gas.record_cost(output.gas_used);
121127
assert!(underflow, "Gas underflow is not possible");

crates/op-revm/src/precompiles.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use revm::{
44
context::Cfg,
55
context_interface::ContextTr,
66
handler::{EthPrecompiles, PrecompileProvider},
7-
interpreter::{CallInputs, InterpreterResult},
7+
interpreter::{InputsImpl, InterpreterResult},
88
precompile::{
99
self, bn254, secp256r1, Precompile, PrecompileError, PrecompileId, PrecompileResult,
1010
Precompiles,
@@ -111,9 +111,13 @@ where
111111
fn run(
112112
&mut self,
113113
context: &mut CTX,
114-
inputs: &CallInputs,
114+
address: &Address,
115+
inputs: &InputsImpl,
116+
is_static: bool,
117+
gas_limit: u64,
115118
) -> Result<Option<Self::Output>, String> {
116-
self.inner.run(context, inputs)
119+
self.inner
120+
.run(context, address, inputs, is_static, gas_limit)
117121
}
118122

119123
#[inline]

examples/custom_precompile_journal/src/precompile_provider.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use revm::{
44
context::Cfg,
55
context_interface::{ContextTr, JournalTr, LocalContextTr, Transaction},
66
handler::{EthPrecompiles, PrecompileProvider},
7-
interpreter::{CallInputs, Gas, InstructionResult, InterpreterResult},
7+
interpreter::{Gas, InputsImpl, InstructionResult, InterpreterResult},
88
precompile::{PrecompileError, PrecompileOutput, PrecompileResult},
99
primitives::{address, hardfork::SpecId, Address, Bytes, U256},
1010
};
@@ -52,15 +52,21 @@ where
5252
fn run(
5353
&mut self,
5454
context: &mut CTX,
55-
inputs: &CallInputs,
55+
address: &Address,
56+
inputs: &InputsImpl,
57+
is_static: bool,
58+
gas_limit: u64,
5659
) -> Result<Option<Self::Output>, String> {
5760
// Check if this is our custom precompile
58-
if inputs.bytecode_address == CUSTOM_PRECOMPILE_ADDRESS {
59-
return Ok(Some(run_custom_precompile(context, inputs)?));
61+
if *address == CUSTOM_PRECOMPILE_ADDRESS {
62+
return Ok(Some(run_custom_precompile(
63+
context, inputs, is_static, gas_limit,
64+
)?));
6065
}
6166

6267
// Otherwise, delegate to standard Ethereum precompiles
63-
self.inner.run(context, inputs)
68+
self.inner
69+
.run(context, address, inputs, is_static, gas_limit)
6470
}
6571

6672
fn warm_addresses(&self) -> Box<impl Iterator<Item = Address>> {
@@ -78,7 +84,9 @@ where
7884
/// Runs our custom precompile
7985
fn run_custom_precompile<CTX: ContextTr>(
8086
context: &mut CTX,
81-
inputs: &CallInputs,
87+
inputs: &InputsImpl,
88+
is_static: bool,
89+
gas_limit: u64,
8290
) -> Result<InterpreterResult, String> {
8391
let input_bytes = match &inputs.input {
8492
revm::interpreter::CallInput::SharedBuffer(range) => {
@@ -97,13 +105,13 @@ fn run_custom_precompile<CTX: ContextTr>(
97105

98106
let result = if input_bytes.is_empty() {
99107
// Read storage operation
100-
handle_read_storage(context, inputs.gas_limit)
108+
handle_read_storage(context, gas_limit)
101109
} else if input_bytes.len() == 32 {
102-
if inputs.is_static {
110+
if is_static {
103111
return Err("Cannot modify state in static context".to_string());
104112
}
105113
// Write storage operation
106-
handle_write_storage(context, &input_bytes, inputs.gas_limit)
114+
handle_write_storage(context, &input_bytes, gas_limit)
107115
} else {
108116
Err(PrecompileError::Other("Invalid input length".to_string()))
109117
};
@@ -116,7 +124,7 @@ fn run_custom_precompile<CTX: ContextTr>(
116124
} else {
117125
InstructionResult::Return
118126
},
119-
gas: Gas::new(inputs.gas_limit),
127+
gas: Gas::new(gas_limit),
120128
output: output.bytes,
121129
};
122130
let underflow = interpreter_result.gas.record_cost(output.gas_used);
@@ -131,7 +139,7 @@ fn run_custom_precompile<CTX: ContextTr>(
131139
} else {
132140
InstructionResult::PrecompileError
133141
},
134-
gas: Gas::new(inputs.gas_limit),
142+
gas: Gas::new(gas_limit),
135143
output: Bytes::new(),
136144
}),
137145
}

0 commit comments

Comments
 (0)