fix revert opcode at first level computation

This commit is contained in:
andri lim 2019-04-24 13:58:56 +07:00
parent c57295da0b
commit 90e3a4320a
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
7 changed files with 29 additions and 52 deletions

View File

@ -391,13 +391,13 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
CreateOOGafterInitCodeReturndata2.json Skip CreateOOGafterInitCodeReturndata2.json Skip
+ CreateOOGafterInitCodeReturndata3.json OK + CreateOOGafterInitCodeReturndata3.json OK
CreateOOGafterInitCodeReturndataSize.json Skip CreateOOGafterInitCodeReturndataSize.json Skip
CreateOOGafterInitCodeRevert.json Skip + CreateOOGafterInitCodeRevert.json OK
CreateOOGafterInitCodeRevert2.json Skip + CreateOOGafterInitCodeRevert2.json OK
+ TransactionCollisionToEmpty.json OK + TransactionCollisionToEmpty.json OK
+ TransactionCollisionToEmptyButCode.json OK + TransactionCollisionToEmptyButCode.json OK
+ TransactionCollisionToEmptyButNonce.json OK + TransactionCollisionToEmptyButNonce.json OK
``` ```
OK: 26/30 Fail: 0/30 Skip: 4/30 OK: 28/30 Fail: 0/30 Skip: 2/30
## stDelegatecallTestHomestead ## stDelegatecallTestHomestead
```diff ```diff
Call1024BalanceTooLow.json Skip Call1024BalanceTooLow.json Skip
@ -1573,9 +1573,9 @@ OK: 19/19 Fail: 0/19 Skip: 0/19
+ returndatacopy_initial_256.json OK + returndatacopy_initial_256.json OK
+ returndatacopy_initial_big_sum.json OK + returndatacopy_initial_big_sum.json OK
+ returndatacopy_overrun.json OK + returndatacopy_overrun.json OK
returndatasize_after_failing_callcode.json Skip + returndatasize_after_failing_callcode.json OK
returndatasize_after_failing_delegatecall.json Skip + returndatasize_after_failing_delegatecall.json OK
returndatasize_after_failing_staticcall.json Skip + returndatasize_after_failing_staticcall.json OK
+ returndatasize_after_oog_after_deeper.json OK + returndatasize_after_oog_after_deeper.json OK
+ returndatasize_after_successful_callcode.json OK + returndatasize_after_successful_callcode.json OK
+ returndatasize_after_successful_delegatecall.json OK + returndatasize_after_successful_delegatecall.json OK
@ -1585,7 +1585,7 @@ OK: 19/19 Fail: 0/19 Skip: 0/19
+ returndatasize_initial.json OK + returndatasize_initial.json OK
returndatasize_initial_zero_read.json Skip returndatasize_initial_zero_read.json Skip
``` ```
OK: 23/37 Fail: 0/37 Skip: 14/37 OK: 26/37 Fail: 0/37 Skip: 11/37
## stRevertTest ## stRevertTest
```diff ```diff
LoopCallsDepthThenRevert.json Skip LoopCallsDepthThenRevert.json Skip
@ -1601,18 +1601,18 @@ OK: 23/37 Fail: 0/37 Skip: 14/37
RevertInCallCode.json Skip RevertInCallCode.json Skip
RevertInCreateInInit.json Skip RevertInCreateInInit.json Skip
RevertInDelegateCall.json Skip RevertInDelegateCall.json Skip
RevertInStaticCall.json Skip + RevertInStaticCall.json OK
RevertOnEmptyStack.json Skip + RevertOnEmptyStack.json OK
RevertOpcode.json Skip + RevertOpcode.json OK
RevertOpcodeCalls.json Skip + RevertOpcodeCalls.json OK
RevertOpcodeCreate.json Skip + RevertOpcodeCreate.json OK
RevertOpcodeDirectCall.json Skip + RevertOpcodeDirectCall.json OK
RevertOpcodeInCallsOnNonEmptyReturnData.json Skip + RevertOpcodeInCallsOnNonEmptyReturnData.json OK
RevertOpcodeInCreateReturns.json Skip + RevertOpcodeInCreateReturns.json OK
RevertOpcodeInInit.json Skip + RevertOpcodeInInit.json OK
RevertOpcodeMultipleSubCalls.json Skip + RevertOpcodeMultipleSubCalls.json OK
RevertOpcodeReturn.json Skip + RevertOpcodeReturn.json OK
RevertOpcodeWithBigOutputInInit.json Skip + RevertOpcodeWithBigOutputInInit.json OK
+ RevertPrecompiledTouch.json OK + RevertPrecompiledTouch.json OK
+ RevertPrecompiledTouchCC.json OK + RevertPrecompiledTouchCC.json OK
+ RevertPrecompiledTouchDC.json OK + RevertPrecompiledTouchDC.json OK
@ -1632,7 +1632,7 @@ OK: 23/37 Fail: 0/37 Skip: 14/37
+ TouchToEmptyAccountRevert2.json OK + TouchToEmptyAccountRevert2.json OK
+ TouchToEmptyAccountRevert3.json OK + TouchToEmptyAccountRevert3.json OK
``` ```
OK: 22/43 Fail: 0/43 Skip: 21/43 OK: 34/43 Fail: 0/43 Skip: 9/43
## stShift ## stShift
```diff ```diff
+ sar00.json OK + sar00.json OK
@ -2520,4 +2520,4 @@ OK: 130/133 Fail: 0/133 Skip: 3/133
OK: 130/130 Fail: 0/130 Skip: 0/130 OK: 130/130 Fail: 0/130 Skip: 0/130
---TOTAL--- ---TOTAL---
OK: 2147/2334 Fail: 0/2334 Skip: 187/2334 OK: 2164/2334 Fail: 0/2334 Skip: 170/2334

View File

@ -44,7 +44,8 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
db.subBalance(sender, upfrontGasCost) db.subBalance(sender, upfrontGasCost)
if tx.isContractCreation and isCollision: break if tx.isContractCreation and isCollision: break
if execComputation(computation): execComputation(computation)
if not computation.shouldBurnGas:
gasUsed = computation.refundGas(tx, sender) gasUsed = computation.refundGas(tx, sender)
if computation.isSuicided(vmState.blockHeader.coinbase): if computation.isSuicided(vmState.blockHeader.coinbase):

View File

@ -325,7 +325,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
value = if call.value.isSome: call.value.get else: 0.u256 value = if call.value.isSome: call.value.get else: 0.u256
comp = setupComputation(vmState, header.blockNumber, value, data, sender, destination, gasLimit, gasPrice, call.to.isNone) comp = setupComputation(vmState, header.blockNumber, value, data, sender, destination, gasLimit, gasPrice, call.to.isNone)
discard comp.execComputation comp.execComputation
result = ("0x" & nimcrypto.toHex(comp.output)).HexDataStr result = ("0x" & nimcrypto.toHex(comp.output)).HexDataStr
rpcsrv.rpc("eth_estimateGas") do(call: EthCall, quantityTag: string) -> GasInt: rpcsrv.rpc("eth_estimateGas") do(call: EthCall, quantityTag: string) -> GasInt:

View File

@ -103,12 +103,6 @@ proc snapshot*(comp: BaseComputation) =
comp.dbsnapshot.intermediateRoot = comp.vmState.accountDb.rootHash comp.dbsnapshot.intermediateRoot = comp.vmState.accountDb.rootHash
comp.vmState.blockHeader.stateRoot = comp.vmState.accountDb.rootHash comp.vmState.blockHeader.stateRoot = comp.vmState.accountDb.rootHash
proc revert*(comp: BaseComputation, burnsGas = false) =
comp.dbsnapshot.transaction.rollback()
comp.vmState.accountDb.rootHash = comp.dbsnapshot.intermediateRoot
comp.vmState.blockHeader.stateRoot = comp.dbsnapshot.intermediateRoot
comp.error = Error(info: getCurrentExceptionMsg(), burnsGas: burnsGas)
proc commit*(comp: BaseComputation) = proc commit*(comp: BaseComputation) =
comp.dbsnapshot.transaction.commit() comp.dbsnapshot.transaction.commit()
comp.vmState.accountDb.rootHash = comp.vmState.blockHeader.stateRoot comp.vmState.accountDb.rootHash = comp.vmState.blockHeader.stateRoot

View File

@ -60,7 +60,7 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient:
result = newBaseComputation(vmState, vmState.blockNumber, msg, some(fork)) result = newBaseComputation(vmState, vmState.blockNumber, msg, some(fork))
doAssert result.isOriginComputation doAssert result.isOriginComputation
proc execComputation*(computation: var BaseComputation): bool = proc execComputation*(computation: var BaseComputation) =
if computation.msg.isCreate: if computation.msg.isCreate:
computation.applyMessage(Create) computation.applyMessage(Create)
else: else:
@ -79,9 +79,8 @@ proc execComputation*(computation: var BaseComputation): bool =
if computation.getFork >= FkSpurious: if computation.getFork >= FkSpurious:
computation.collectTouchedAccounts(computation.vmState.touchedAccounts) computation.collectTouchedAccounts(computation.vmState.touchedAccounts)
result = computation.isSuccess computation.vmstate.status = computation.isSuccess
computation.vmstate.status = result if computation.isSuccess:
if result:
computation.vmState.addLogs(computation.logEntries) computation.vmState.addLogs(computation.logEntries)
proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt = proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt =

View File

@ -233,10 +233,10 @@ proc runVM*(blockNumber: Uint256, chainDB: BaseChainDB, boa: Assembler): bool =
var computation = initComputation(blockNumber, chainDB, boa.code, boa.data) var computation = initComputation(blockNumber, chainDB, boa.code, boa.data)
let gas = computation.gasMeter.gasRemaining let gas = computation.gasMeter.gasRemaining
let computationResult = execComputation(computation) execComputation(computation)
let gasUsed = gas - computation.gasMeter.gasRemaining let gasUsed = gas - computation.gasMeter.gasRemaining
if computationResult: if computation.isSuccess:
if boa.success == false: if boa.success == false:
error "different success value", expected=boa.success, actual=true error "different success value", expected=boa.success, actual=true
return false return false

View File

@ -25,40 +25,23 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool =
"sha3_deja.json", "sha3_deja.json",
"delegatecallNonConst.json", "delegatecallNonConst.json",
"returndatasize_after_failing_delegatecall.json",
"returndatacopy_following_revert_in_create.json", "returndatacopy_following_revert_in_create.json",
"returndatasize_initial_zero_read.json", "returndatasize_initial_zero_read.json",
"returndatacopy_after_successful_callcode.json", "returndatacopy_after_successful_callcode.json",
"returndatacopy_afterFailing_create.json", "returndatacopy_afterFailing_create.json",
"returndatacopy_after_successful_delegatecall.json", "returndatacopy_after_successful_delegatecall.json",
"returndatacopy_following_revert.json", "returndatacopy_following_revert.json",
"returndatasize_after_failing_staticcall.json",
"returndatacopy_after_successful_staticcall.json", "returndatacopy_after_successful_staticcall.json",
"returndatacopy_following_call.json", "returndatacopy_following_call.json",
"returndatacopy_after_revert_in_staticcall.json", "returndatacopy_after_revert_in_staticcall.json",
"returndatasize_after_failing_callcode.json",
"CreateOOGafterInitCodeRevert.json",
"CreateOOGafterInitCodeReturndataSize.json", "CreateOOGafterInitCodeReturndataSize.json",
"CreateOOGafterInitCodeRevert2.json",
"static_RevertOpcodeCalls.json", "static_RevertOpcodeCalls.json",
"PythonRevertTestTue201814-1430.json", "PythonRevertTestTue201814-1430.json",
"RevertOpcodeDirectCall.json",
"RevertInCallCode.json", "RevertInCallCode.json",
"RevertOpcodeReturn.json",
"RevertOnEmptyStack.json",
"RevertInDelegateCall.json", "RevertInDelegateCall.json",
"RevertOpcodeCalls.json",
"RevertOpcode.json",
"RevertOpcodeInInit.json",
"RevertOpcodeWithBigOutputInInit.json",
"RevertOpcodeInCreateReturns.json",
"RevertOpcodeCreate.json",
"RevertOpcodeMultipleSubCalls.json",
"RevertOpcodeInCallsOnNonEmptyReturnData.json",
"RevertInCreateInInit.json", "RevertInCreateInInit.json",
"RevertInStaticCall.json",
"modexpRandomInput.json", "modexpRandomInput.json",
"modexp_9_37111_37111_1000000.json", "modexp_9_37111_37111_1000000.json",