fix create2 gasCost

This commit is contained in:
andri lim 2019-05-08 18:41:25 +07:00 committed by zah
parent e51725d13b
commit a86979eaa3
5 changed files with 77 additions and 85 deletions

View File

@ -58,9 +58,9 @@ OK: 46/46 Fail: 0/46 Skip: 0/46
OK: 1/2 Fail: 0/2 Skip: 1/2
## stBadOpcode
```diff
badOpcodes.json Skip
+ badOpcodes.json OK
```
OK: 0/1 Fail: 0/1 Skip: 1/1
OK: 1/1 Fail: 0/1 Skip: 0/1
## stBugs
```diff
+ evmBytecode.json OK
@ -368,8 +368,8 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 3/3 Fail: 0/3 Skip: 0/3
## stCreate2
```diff
CREATE2_Bounds.json Skip
CREATE2_Bounds2.json Skip
+ CREATE2_Bounds.json OK
+ CREATE2_Bounds2.json OK
+ CREATE2_Bounds3.json OK
+ CREATE2_ContractSuicideDuringInit_ThenStoreThenReturn.json OK
+ CREATE2_Suicide.json OK
@ -392,7 +392,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
+ RevertOpcodeInCreateReturnsCreate2.json OK
+ call_outsize_then_create2_successful_then_returndatasize.json OK
+ call_then_create2_successful_then_returndatasize.json OK
create2InitCodes.json Skip
+ create2InitCodes.json OK
+ create2SmartInitCode.json OK
create2callPrecompiles.json Skip
+ create2checkFieldsInInitcode.json OK
@ -413,7 +413,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
+ returndatacopy_following_successful_create.json OK
+ returndatasize_following_successful_create.json OK
```
OK: 38/44 Fail: 0/44 Skip: 6/44
OK: 41/44 Fail: 0/44 Skip: 3/44
## stCreateTest
```diff
+ CREATE_AcreateB_BSuicide_BStore.json OK
@ -2645,4 +2645,4 @@ OK: 133/133 Fail: 0/133 Skip: 0/133
OK: 130/130 Fail: 0/130 Skip: 0/130
---TOTAL---
OK: 2338/2447 Fail: 0/2447 Skip: 109/2447
OK: 2342/2447 Fail: 0/2447 Skip: 105/2447

View File

@ -353,8 +353,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
result.gasCost += static(FeeSchedule[GasNewAccount])
func `prefix gasCreate2`(currentMemSize, memOffset, memLength: Natural): GasInt {.nimcall.} =
result = static(FeeSchedule[GasCreate]) +
static(FeeSchedule[GasSha3Word]) * (memLength).wordCount
result = static(FeeSchedule[GasSha3Word]) * (memLength).wordCount
# ###################################################################################################

View File

@ -504,17 +504,16 @@ genLog()
# f0s: System operations.
proc canTransfer(computation: BaseComputation, memPos, memLen: int, value: Uint256, opCode: static[Op]): bool =
when opCode == Create:
let gasParams = GasParams(kind: Create,
cr_currentMemSize: computation.memory.len,
cr_memOffset: memPos,
cr_memLength: memLen
)
let gasCost = computation.gasCosts[Create].c_handler(1.u256, gasParams).gasCost
let reason = &"CREATE: GasCreate + {memLen} * memory expansion"
else:
let gasCost = computation.gasCosts[Create2].m_handler(0, 0, memLen)
let reason = &"CREATE2: GasCreate + {memLen} * GasSha3Word"
let gasParams = GasParams(kind: Create,
cr_currentMemSize: computation.memory.len,
cr_memOffset: memPos,
cr_memLength: memLen
)
var gasCost = computation.gasCosts[Create].c_handler(1.u256, gasParams).gasCost
let reason = &"CREATE: GasCreate + {memLen} * memory expansion"
when opCode == Create2:
gasCost = gasCost + computation.gasCosts[Create2].m_handler(0, 0, memLen)
computation.gasMeter.consumeGas(gasCost, reason = reason)
computation.memory.extend(memPos, memLen)
@ -599,7 +598,7 @@ proc setupCreate(computation: BaseComputation, memPos, len: int, value: Uint256,
template genCreate(callName: untyped, opCode: Op): untyped =
op callName, inline = false, value, startPosition, size:
## 0xf0, Create a new account with associated code.
let (memPos, len) = (startPosition.cleanMemRef, size.cleanMemRef)
let (memPos, len) = (startPosition.safeInt, size.safeInt)
if not computation.canTransfer(memPos, len, value, opCode):
push: 0
return

View File

@ -14,70 +14,7 @@
func allowedFailingGeneralStateTest*(folder, name: string): bool =
let allowedFailingGeneralStateTests = @[
"modexp.json",
"CREATE2_Bounds.json",
"CREATE2_Bounds2.json",
"create2callPrecompiles.json",
"create2InitCodes.json",
"create2noCash.json",
"badOpcodes.json",
# all these tests below actually pass
# but they are very slow
# constantinople slow tests
"Create2Recursive.json",
# byzantium slow tests
"LoopCallsDepthThenRevert3.json",
"LoopCallsDepthThenRevert2.json",
"LoopCallsDepthThenRevert.json",
"static_Call50000.json",
"static_Call50000_ecrec.json",
"static_Call50000_identity.json",
"static_Call50000_identity2.json",
"static_Call50000_rip160.json",
"static_Call50000_sha256.json",
"LoopCallsThenRevert.json",
"LoopDelegateCallsDepthThenRevert.json",
"recursiveCreateReturnValue.json",
"static_Call1024PreCalls2.json",
"Callcode1024BalanceTooLow.json",
"static_Call1024BalanceTooLow.json",
"static_Call1024BalanceTooLow2.json",
"static_Call1024OOG.json",
"static_Call1024PreCalls3.json",
"static_Call1024PreCalls.json",
"static_Call1MB1024Calldepth.json",
# Homestead recursives
"ContractCreationSpam.json",
"Call1024OOG.json",
"Call1024PreCalls.json",
"CallRecursiveBombPreCall.json",
"Delegatecall1024.json",
"Delegatecall1024OOG.json",
"JUMPDEST_Attack.json",
"JUMPDEST_AttackwithJump.json",
"ABAcalls1.json",
"ABAcalls2.json",
"CallRecursiveBomb0.json",
"CallRecursiveBomb0_OOG_atMaxCallDepth.json",
"CallRecursiveBomb1.json",
"CallRecursiveBomb2.json",
"CallRecursiveBombLog.json",
"CallRecursiveBombLog2.json",
"Call1024BalanceTooLow.json",
# Frontier recursives
"Callcode1024OOG.json",
"callcallcodecall_ABCB_RECURSIVE.json",
"callcallcodecallcode_ABCB_RECURSIVE.json",
"callcodecallcall_ABCB_RECURSIVE.json",
"callcodecallcallcode_ABCB_RECURSIVE.json",
"callcodecallcodecall_ABCB_RECURSIVE.json",
"callcodecallcodecallcode_ABCB_RECURSIVE.json",
"callcallcallcode_ABCB_RECURSIVE.json"
]
result = name in allowedFailingGeneralStateTests

View File

@ -43,7 +43,64 @@ func slowTest*(folder: string, name: string): bool =
"DELEGATECALL_Bounds.json", "CALL_Bounds2a.json",
"CALL_Bounds2.json",
"CallToNameRegistratorMemOOGAndInsufficientBalance.json",
"CallToNameRegistratorTooMuchMemory0.json"]
"CallToNameRegistratorTooMuchMemory0.json",
# all these tests below actually pass
# but they are very slow
# constantinople slow tests
"Create2Recursive.json",
# byzantium slow tests
"LoopCallsDepthThenRevert3.json",
"LoopCallsDepthThenRevert2.json",
"LoopCallsDepthThenRevert.json",
"static_Call50000.json",
"static_Call50000_ecrec.json",
"static_Call50000_identity.json",
"static_Call50000_identity2.json",
"static_Call50000_rip160.json",
"static_Call50000_sha256.json",
"LoopCallsThenRevert.json",
"LoopDelegateCallsDepthThenRevert.json",
"recursiveCreateReturnValue.json",
"static_Call1024PreCalls2.json",
"Callcode1024BalanceTooLow.json",
"static_Call1024BalanceTooLow.json",
"static_Call1024BalanceTooLow2.json",
"static_Call1024OOG.json",
"static_Call1024PreCalls3.json",
"static_Call1024PreCalls.json",
"static_Call1MB1024Calldepth.json",
# Homestead recursives
"ContractCreationSpam.json",
"Call1024OOG.json",
"Call1024PreCalls.json",
"CallRecursiveBombPreCall.json",
"Delegatecall1024.json",
"Delegatecall1024OOG.json",
"JUMPDEST_Attack.json",
"JUMPDEST_AttackwithJump.json",
"ABAcalls1.json",
"ABAcalls2.json",
"CallRecursiveBomb0.json",
"CallRecursiveBomb0_OOG_atMaxCallDepth.json",
"CallRecursiveBomb1.json",
"CallRecursiveBomb2.json",
"CallRecursiveBombLog.json",
"CallRecursiveBombLog2.json",
"Call1024BalanceTooLow.json",
# Frontier recursives
"Callcode1024OOG.json",
"callcallcodecall_ABCB_RECURSIVE.json",
"callcallcodecallcode_ABCB_RECURSIVE.json",
"callcodecallcall_ABCB_RECURSIVE.json",
"callcodecallcallcode_ABCB_RECURSIVE.json",
"callcodecallcodecall_ABCB_RECURSIVE.json",
"callcodecallcodecallcode_ABCB_RECURSIVE.json",
"callcallcallcode_ABCB_RECURSIVE.json"]
func failIn32Bits(folder, name: string): bool =
return name in @[