17
17
from eth .utils .hexadecimal import (
18
18
encode_hex ,
19
19
)
20
+ from eth .utils .numeric import (
21
+ ceil32 ,
22
+ )
20
23
from eth .vm import mnemonics
21
24
from eth .vm .computation import (
22
25
BaseComputation
@@ -120,6 +123,9 @@ class Create(Opcode):
120
123
def max_child_gas_modifier (self , gas : int ) -> int :
121
124
return gas
122
125
126
+ def get_gas_cost (self , data : CreateOpcodeStackData ) -> int :
127
+ return self .gas_cost
128
+
123
129
def generate_contract_address (self ,
124
130
stack_data : CreateOpcodeStackData ,
125
131
call_data : bytes ,
@@ -144,10 +150,12 @@ def get_stack_data(self, computation: BaseComputation) -> CreateOpcodeStackData:
144
150
return CreateOpcodeStackData (endowment , memory_start , memory_length )
145
151
146
152
def __call__ (self , computation : BaseComputation ) -> None :
147
- computation .consume_gas (self .gas_cost , reason = self .mnemonic )
148
153
149
154
stack_data = self .get_stack_data (computation )
150
155
156
+ gas_cost = self .get_gas_cost (stack_data )
157
+ computation .consume_gas (gas_cost , reason = self .mnemonic )
158
+
151
159
computation .extend_memory (stack_data .memory_start , stack_data .memory_length )
152
160
153
161
insufficient_funds = computation .state .account_db .get_balance (
@@ -219,6 +227,9 @@ def get_stack_data(self, computation: BaseComputation) -> CreateOpcodeStackData:
219
227
220
228
return CreateOpcodeStackData (endowment , memory_start , memory_length , salt )
221
229
230
+ def get_gas_cost (self , data : CreateOpcodeStackData ) -> int :
231
+ return constants .GAS_SHA3WORD * ceil32 (data .memory_length ) // 32
232
+
222
233
def generate_contract_address (self ,
223
234
stack_data : CreateOpcodeStackData ,
224
235
call_data : bytes ,
0 commit comments