revm_interpreter/interpreter_action/
eof_create_inputs.rs

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