revm_interpreter/interpreter_action/
eof_create_inputs.rs

1use std::sync::Arc;
2
3use bytecode::Eof;
4use primitives::{Address, Bytes, U256};
5
6use super::CallInput;
7
8/// EOF create can be called from two places:
9/// * EOFCREATE opcode
10/// * Creation transaction.
11///
12/// Creation transaction uses initdata and packs EOF and initdata inside it,
13/// and this eof bytecode needs to be validated.
14///
15/// Opcode creation uses already validated EOF bytecode, and input from Interpreter memory.
16///
17/// Address is already known and is passed as an argument.
18#[derive(Debug, Clone, PartialEq, Eq)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
20pub enum EOFCreateKind {
21    Tx {
22        initdata: Bytes,
23    },
24    Opcode {
25        initcode: Arc<Eof>,
26        input: CallInput,
27        created_address: Address,
28    },
29}
30
31impl EOFCreateKind {
32    /// Returns created address
33    pub fn created_address(&self) -> Option<&Address> {
34        match self {
35            EOFCreateKind::Opcode {
36                created_address, ..
37            } => Some(created_address),
38            EOFCreateKind::Tx { .. } => None,
39        }
40    }
41}
42
43impl Default for EOFCreateKind {
44    fn default() -> Self {
45        EOFCreateKind::Opcode {
46            initcode: Arc::new(Eof::default()),
47            input: CallInput::Bytes(Bytes::default()),
48            created_address: Address::default(),
49        }
50    }
51}
52
53/// Inputs for EOF Create call
54#[derive(Debug, Default, Clone, PartialEq, Eq)]
55#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
56pub struct EOFCreateInputs {
57    /// Caller of EOF Create
58    pub caller: Address,
59    /// Values of ether transferred
60    pub value: U256,
61    /// Gas limit for the create call
62    pub gas_limit: u64,
63    /// EOF Create kind
64    pub kind: EOFCreateKind,
65}
66
67impl EOFCreateInputs {
68    /// Creates new EOF Create input from transaction that has concatenated eof init code and calldata.
69    ///
70    /// Legacy transaction still have optional nonce so we need to obtain it.
71    pub fn new(caller: Address, value: U256, gas_limit: u64, kind: EOFCreateKind) -> Self {
72        //let (eof_init_code, input) = Eof::decode_dangling(tx.data.clone())?;
73        EOFCreateInputs {
74            caller,
75            value,
76            gas_limit,
77            kind,
78        }
79    }
80
81    /// Returns a new instance of EOFCreateInput.
82    pub fn new_opcode(
83        caller: Address,
84        created_address: Address,
85        value: U256,
86        eof_init_code: Eof,
87        gas_limit: u64,
88        input: CallInput,
89    ) -> EOFCreateInputs {
90        EOFCreateInputs::new(
91            caller,
92            value,
93            gas_limit,
94            EOFCreateKind::Opcode {
95                initcode: Arc::new(eof_init_code),
96                input,
97                created_address,
98            },
99        )
100    }
101}