Skip to content

Commit

Permalink
Update CREATE2 gas cost calculation
Browse files Browse the repository at this point in the history
Fixes #1346
  • Loading branch information
cburgdorf committed Oct 15, 2018
1 parent 740dc53 commit 128158c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion eth/vm/logic/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from eth.utils.hexadecimal import (
encode_hex,
)
from eth.utils.numeric import (
ceil32,
)
from eth.vm import mnemonics
from eth.vm.computation import (
BaseComputation
Expand Down Expand Up @@ -120,6 +123,9 @@ class Create(Opcode):
def max_child_gas_modifier(self, gas: int) -> int:
return gas

def get_gas_cost(self, data: CreateOpcodeStackData) -> int:
return self.gas_cost

def generate_contract_address(self,
stack_data: CreateOpcodeStackData,
call_data: bytes,
Expand All @@ -144,10 +150,12 @@ def get_stack_data(self, computation: BaseComputation) -> CreateOpcodeStackData:
return CreateOpcodeStackData(endowment, memory_start, memory_length)

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

stack_data = self.get_stack_data(computation)

gas_cost = self.get_gas_cost(stack_data)
computation.consume_gas(gas_cost, reason=self.mnemonic)

computation.extend_memory(stack_data.memory_start, stack_data.memory_length)

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

return CreateOpcodeStackData(endowment, memory_start, memory_length, salt)

def get_gas_cost(self, data: CreateOpcodeStackData) -> int:
return constants.GAS_SHA3WORD * ceil32(data.memory_length) // 32

def generate_contract_address(self,
stack_data: CreateOpcodeStackData,
call_data: bytes,
Expand Down

0 comments on commit 128158c

Please sign in to comment.