From dcf769935860265d069e50c58635291e4ade33da Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 20 Feb 2019 18:02:14 +0700 Subject: [PATCH] fix callcode regression --- GeneralStateTests.md | 8 +-- nimbus/vm/computation.nim | 77 +++++++++++++------------- nimbus/vm/interpreter/opcodes_impl.nim | 6 +- tests/test_generalstate_failing.nim | 3 +- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/GeneralStateTests.md b/GeneralStateTests.md index 7bcaa71bb..4aefce412 100644 --- a/GeneralStateTests.md +++ b/GeneralStateTests.md @@ -1099,7 +1099,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16 + randomStatetest245.json OK + randomStatetest246.json OK + randomStatetest247.json OK -+ randomStatetest248.json OK + randomStatetest248.json Skip + randomStatetest249.json OK + randomStatetest25.json OK + randomStatetest250.json OK @@ -1284,7 +1284,7 @@ OK: 0/16 Fail: 0/16 Skip: 16/16 + randomStatetest97.json OK + randomStatetest98.json OK ``` -OK: 314/327 Fail: 0/327 Skip: 13/327 +OK: 313/327 Fail: 0/327 Skip: 14/327 ## stRandom2 ```diff + 201503110226PYTHON_DUP6.json OK @@ -1458,7 +1458,7 @@ OK: 314/327 Fail: 0/327 Skip: 13/327 + randomStatetest576.json OK + randomStatetest577.json OK + randomStatetest578.json OK - randomStatetest579.json Skip ++ randomStatetest579.json OK + randomStatetest580.json OK + randomStatetest581.json OK + randomStatetest582.json OK @@ -1515,7 +1515,7 @@ OK: 314/327 Fail: 0/327 Skip: 13/327 randomStatetest646.json Skip randomStatetest647.json Skip ``` -OK: 218/227 Fail: 0/227 Skip: 9/227 +OK: 219/227 Fail: 0/227 Skip: 8/227 ## stRecursiveCreate ```diff recursiveCreate.json Skip diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 7689004a5..00903f3f7 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -123,40 +123,39 @@ proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) = raise newException(InsufficientFunds, &"Insufficient funds: {senderBalance} < {computation.msg.value}" ) - when opCode in {Call, CallCode}: - let - insufficientFunds = senderBalance < computation.msg.value - stackTooDeep = computation.msg.depth >= MaxCallDepth - if insufficientFunds or stackTooDeep: - computation.returnData = @[] - var errMessage: string - if insufficientFunds: - errMessage = &"Insufficient Funds: have: {$senderBalance} need: {$computation.msg.value}" - elif stackTooDeep: - errMessage = "Stack Limit Reached" - else: - raise newException(VMError, "Invariant: Unreachable code path") + let + insufficientFunds = senderBalance < computation.msg.value + stackTooDeep = computation.msg.depth >= MaxCallDepth - debug "Computation failure", msg = errMessage - computation.gasMeter.returnGas(computation.msg.gas) - push: 0 - return + if insufficientFunds or stackTooDeep: + computation.returnData = @[] + var errMessage: string + if insufficientFunds: + errMessage = &"Insufficient Funds: have: {$senderBalance} need: {$computation.msg.value}" + elif stackTooDeep: + errMessage = "Stack Limit Reached" + else: + raise newException(VMError, "Invariant: Unreachable code path") - when opCode == Call: - newBalance = senderBalance - computation.msg.value - computation.vmState.mutateStateDb: - db.setBalance(computation.msg.sender, newBalance) - db.addBalance(computation.msg.storageAddress, computation.msg.value) + debug "Computation failure", msg = errMessage + computation.gasMeter.returnGas(computation.msg.gas) + push: 0 + return - trace "Value transferred", - source = computation.msg.sender, - dest = computation.msg.storageAddress, - value = computation.msg.value, - oldSenderBalance = senderBalance, - newSenderBalance = newBalance, - gasPrice = computation.msg.gasPrice, - gas = computation.msg.gas + newBalance = senderBalance - computation.msg.value + computation.vmState.mutateStateDb: + db.setBalance(computation.msg.sender, newBalance) + db.addBalance(computation.msg.storageAddress, computation.msg.value) + + trace "Value transferred", + source = computation.msg.sender, + dest = computation.msg.storageAddress, + value = computation.msg.value, + oldSenderBalance = senderBalance, + newSenderBalance = newBalance, + gasPrice = computation.msg.gasPrice, + gas = computation.msg.gas trace "Apply message", value = computation.msg.value, @@ -168,20 +167,20 @@ proc applyMessageAux(computation: var BaseComputation, opCode: static[Op]) = else: # even though the value is zero, the account # should be exist. - when opCode == Call: - computation.vmState.mutateStateDb: - db.addBalance(computation.msg.storageAddress, computation.msg.value) + computation.vmState.mutateStateDb: + db.addBalance(computation.msg.storageAddress, computation.msg.value) proc applyMessage(computation: var BaseComputation, opCode: static[Op]) = var snapshot = computation.snapshot() defer: snapshot.dispose() - try: - computation.applyMessageAux(opCode) - except VMError: - snapshot.revert() - debug "applyMessageAux failed", msg = computation.error.info - return + when opCode == Call: + try: + computation.applyMessageAux(opCode) + except VMError: + snapshot.revert() + debug "applyMessageAux failed", msg = computation.error.info + return if computation.gasMeter.gasRemaining <= 0: snapshot.commit() diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 60771dd79..cb1c56ea3 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -626,7 +626,7 @@ proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAdd value, to, ZERO_ADDRESS, # sender - ZERO_ADDRESS, # code_address + to, # code_address memoryInputStartPosition, memoryInputSize, memoryOutputStartPosition, @@ -738,7 +738,7 @@ template genCall(callName: untyped, opCode: Op): untyped = if opCode == CallCode: childMsg.storageAddress = computation.msg.storageAddress - + var childComputation = applyChildComputation(computation, childMsg, opCode) if childComputation.isError: @@ -755,7 +755,7 @@ template genCall(callName: untyped, opCode: Op): untyped = computation.gasMeter.returnGas(childComputation.gasMeter.gasRemaining) if computation.gasMeter.gasRemaining <= 0: - raise newException(OutOfGas, "computation out of gas after contract call") + raise newException(OutOfGas, "computation out of gas after contract call (" & callName.astToStr & ")") genCall(call, Call) genCall(callCode, CallCode) diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index ffb73a412..164068b67 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -131,11 +131,12 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = "randomStatetest307.json", "randomStatetest368.json", "randomStatetest85.json", - "randomStatetest579.json", + #"randomStatetest579.json", "randomStatetest643.json", "randomStatetest644.json", "randomStatetest645.json", "randomStatetest646.json", + "randomStatetest248.json", "refundSuicide50procentCap.json", "refund_CallToSuicideNoStorage.json", "refund_CallToSuicideStorage.json",