simplify CREATE gasCost

This commit is contained in:
andri lim 2019-02-20 09:53:05 +07:00 committed by zah
parent 8884627d07
commit 2e8176eb15
3 changed files with 6 additions and 5 deletions

View File

@ -208,6 +208,7 @@ proc applyCreateMessage(fork: Fork, computation: var BaseComputation, opCode: st
raise newException(OutOfGas, &"Contract code size exceeds EIP170 limit of {EIP170_CODE_SIZE_LIMIT}. Got code of size: {contractCode.len}")
try:
# tricky gasCost: 1,0,0 -> createCost. 0,0,x -> depositCost
let gasCost = computation.gasCosts[Create].m_handler(0, 0, contractCode.len)
computation.gasMeter.consumeGas(gasCost,
reason = "Write contract code for CREATE")

View File

@ -170,10 +170,9 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
result += static(FeeSchedule[GasExpByte]) * (1 + log256(value))
func `prefix gasCreate`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
if currentMemSize + memOffset + memLength == 0:
result = static(FeeSchedule[GasCreate])
else:
result = static(FeeSchedule[GasCodeDeposit]) * memLength
# tricky gasCost: 1,0,0 -> createCost. 0,0,x -> depositCost
result = currentMemSize * static(FeeSchedule[GasCreate]) +
static(FeeSchedule[GasCodeDeposit]) * memLength
func `prefix gasSha3`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =

View File

@ -510,7 +510,8 @@ op create, inline = false, value, startPosition, size:
# TODO: Forked create for Homestead
let (memPos, len) = (startPosition.cleanMemRef, size.cleanMemRef)
let gasCost = computation.gasCosts[Create].m_handler(0, 0, 0)
# tricky gasCost: 1,0,0 -> createCost. 0,0,x -> depositCost
let gasCost = computation.gasCosts[Create].m_handler(1, 0, 0)
let reason = &"CREATE: GasCreate + {len} * memory expansion"
computation.gasMeter.consumeGas(gasCost, reason = reason)