Skip to content

Commit 128158c

Browse files
committed
Update CREATE2 gas cost calculation
Fixes #1346
1 parent 740dc53 commit 128158c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

eth/vm/logic/system.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
from eth.utils.hexadecimal import (
1818
encode_hex,
1919
)
20+
from eth.utils.numeric import (
21+
ceil32,
22+
)
2023
from eth.vm import mnemonics
2124
from eth.vm.computation import (
2225
BaseComputation
@@ -120,6 +123,9 @@ class Create(Opcode):
120123
def max_child_gas_modifier(self, gas: int) -> int:
121124
return gas
122125

126+
def get_gas_cost(self, data: CreateOpcodeStackData) -> int:
127+
return self.gas_cost
128+
123129
def generate_contract_address(self,
124130
stack_data: CreateOpcodeStackData,
125131
call_data: bytes,
@@ -144,10 +150,12 @@ def get_stack_data(self, computation: BaseComputation) -> CreateOpcodeStackData:
144150
return CreateOpcodeStackData(endowment, memory_start, memory_length)
145151

146152
def __call__(self, computation: BaseComputation) -> None:
147-
computation.consume_gas(self.gas_cost, reason=self.mnemonic)
148153

149154
stack_data = self.get_stack_data(computation)
150155

156+
gas_cost = self.get_gas_cost(stack_data)
157+
computation.consume_gas(gas_cost, reason=self.mnemonic)
158+
151159
computation.extend_memory(stack_data.memory_start, stack_data.memory_length)
152160

153161
insufficient_funds = computation.state.account_db.get_balance(
@@ -219,6 +227,9 @@ def get_stack_data(self, computation: BaseComputation) -> CreateOpcodeStackData:
219227

220228
return CreateOpcodeStackData(endowment, memory_start, memory_length, salt)
221229

230+
def get_gas_cost(self, data: CreateOpcodeStackData) -> int:
231+
return constants.GAS_SHA3WORD * ceil32(data.memory_length) // 32
232+
222233
def generate_contract_address(self,
223234
stack_data: CreateOpcodeStackData,
224235
call_data: bytes,

0 commit comments

Comments
 (0)