Skip to main content

revm_handler/
execution.rs

1use context::{ContextTr, Database, JournalTr};
2use context_interface::Transaction;
3use interpreter::{
4    CallInput, CallInputs, CallScheme, CallValue, CreateInputs, CreateScheme, FrameInput,
5};
6use primitives::TxKind;
7use state::Bytecode;
8use std::boxed::Box;
9
10/// Creates the first [`FrameInput`] from the transaction, spec and gas limit.
11#[inline]
12pub fn create_init_frame<CTX: ContextTr>(
13    ctx: &mut CTX,
14    gas_limit: u64,
15) -> Result<FrameInput, <<CTX::Journal as JournalTr>::Database as Database>::Error> {
16    let (tx, journal) = ctx.tx_journal_mut();
17    let input = tx.input().clone();
18
19    match tx.kind() {
20        TxKind::Call(target_address) => {
21            let account = &journal.load_account_with_code(target_address)?.info;
22
23            let known_bytecode = if let Some(delegated_address) =
24                account.code.as_ref().and_then(Bytecode::eip7702_address)
25            {
26                let account = &journal.load_account_with_code(delegated_address)?.info;
27                (
28                    account.code_hash(),
29                    account.code.clone().unwrap_or_default(),
30                )
31            } else {
32                (
33                    account.code_hash(),
34                    account.code.clone().unwrap_or_default(),
35                )
36            };
37            Ok(FrameInput::Call(Box::new(CallInputs {
38                input: CallInput::Bytes(input),
39                gas_limit,
40                target_address,
41                bytecode_address: target_address,
42                known_bytecode,
43                caller: tx.caller(),
44                value: CallValue::Transfer(tx.value()),
45                scheme: CallScheme::Call,
46                is_static: false,
47                return_memory_offset: 0..0,
48                reservoir: 0,
49            })))
50        }
51        TxKind::Create => Ok(FrameInput::Create(Box::new(CreateInputs::new(
52            tx.caller(),
53            CreateScheme::Create,
54            tx.value(),
55            input,
56            gas_limit,
57        )))),
58    }
59}