revm_interpreter/interpreter_action/
eof_create_inputs.rs

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