Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit c280839

Browse files
committed
spec_to_generic for cacl_call_gas
1 parent 85f95bd commit c280839

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

crates/instructions/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,13 @@ secp256k1 = { version = "0.28.2", default-features = false, features = [
2222
"rand-std"
2323
] }
2424

25+
[features]
26+
optimism = [
27+
"revm/optimism",
28+
"revm-interpreter/optimism",
29+
"revm-precompile/optimism",
30+
"revm-primitives/optimism",
31+
]
32+
2533
[lints]
2634
workspace = true

crates/instructions/src/eip3074.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use crate::{context::InstructionsContext, BoxedInstructionWithOpCode};
22
use revm::{Database, Evm};
33
use revm_interpreter::{
4-
gas, instructions::host::get_memory_input_and_out_ranges, pop, pop_address, resize_memory,
5-
CallContext, CallInputs, CallScheme, InstructionResult, Interpreter, InterpreterAction,
6-
Transfer,
4+
gas,
5+
instructions::host::{calc_call_gas, get_memory_input_and_out_ranges},
6+
pop, pop_address, resize_memory, CallContext, CallInputs, CallScheme, InstructionResult,
7+
Interpreter, InterpreterAction, Transfer,
78
};
89
use revm_precompile::secp256k1::ecrecover;
9-
use revm_primitives::{alloy_primitives::B512, keccak256, Address, B256, U256};
10+
use revm_primitives::{
11+
alloy_primitives::B512, keccak256, spec_to_generic, Address, SpecId, B256, U256,
12+
};
1013

1114
const AUTH_OPCODE: u8 = 0xF6;
1215
const AUTHCALL_OPCODE: u8 = 0xF7;
@@ -123,7 +126,7 @@ fn auth_instruction<EXT, DB: Database>(
123126

124127
fn authcall_instruction<EXT, DB: Database>(
125128
interp: &mut Interpreter,
126-
_evm: &mut Evm<'_, EXT, DB>,
129+
evm: &mut Evm<'_, EXT, DB>,
127130
ctx: &InstructionsContext,
128131
) {
129132
let authorized = match ctx.get(AUTHORIZED_VAR_NAME) {
@@ -137,7 +140,7 @@ fn authcall_instruction<EXT, DB: Database>(
137140
pop!(interp, local_gas_limit);
138141
pop_address!(interp, to);
139142
// max gas limit is not possible in real ethereum situation.
140-
let _local_gas_limit = u64::try_from(local_gas_limit).unwrap_or(u64::MAX);
143+
let local_gas_limit = u64::try_from(local_gas_limit).unwrap_or(u64::MAX);
141144

142145
pop!(interp, value);
143146
if interp.is_static && value != U256::ZERO {
@@ -149,11 +152,18 @@ fn authcall_instruction<EXT, DB: Database>(
149152
return;
150153
};
151154

152-
let Some(mut gas_limit) =
153-
// TODO: calc_call_gas requires SPEC.
154-
//calc_call_gas(interp, evm, to, value != U256::ZERO, local_gas_limit, true, true)
155-
Some(100)
156-
else {
155+
let Some(mut gas_limit) = spec_to_generic!(
156+
evm.spec_id(),
157+
calc_call_gas::<Evm<'_, EXT, DB>, SPEC>(
158+
interp,
159+
evm,
160+
to,
161+
value != U256::ZERO,
162+
local_gas_limit,
163+
true,
164+
true
165+
)
166+
) else {
157167
return;
158168
};
159169

0 commit comments

Comments
 (0)