From 90e3a4320a3705d8ef75ccf6edc7c3b2758622e0 Mon Sep 17 00:00:00 2001 From: andri lim Date: Wed, 24 Apr 2019 13:58:56 +0700 Subject: [PATCH] fix revert opcode at first level computation --- GeneralStateTests.md | 42 ++++++++++++++--------------- nimbus/p2p/executor.nim | 3 ++- nimbus/rpc/p2p.nim | 2 +- nimbus/vm/computation.nim | 6 ----- nimbus/vm_state_transactions.nim | 7 +++-- tests/macro_assembler.nim | 4 +-- tests/test_generalstate_failing.nim | 17 ------------ 7 files changed, 29 insertions(+), 52 deletions(-) diff --git a/GeneralStateTests.md b/GeneralStateTests.md index b9f120d40..415a85c83 100644 --- a/GeneralStateTests.md +++ b/GeneralStateTests.md @@ -391,13 +391,13 @@ OK: 3/3 Fail: 0/3 Skip: 0/3 CreateOOGafterInitCodeReturndata2.json Skip + CreateOOGafterInitCodeReturndata3.json OK CreateOOGafterInitCodeReturndataSize.json Skip - CreateOOGafterInitCodeRevert.json Skip - CreateOOGafterInitCodeRevert2.json Skip ++ CreateOOGafterInitCodeRevert.json OK ++ CreateOOGafterInitCodeRevert2.json OK + TransactionCollisionToEmpty.json OK + TransactionCollisionToEmptyButCode.json OK + TransactionCollisionToEmptyButNonce.json OK ``` -OK: 26/30 Fail: 0/30 Skip: 4/30 +OK: 28/30 Fail: 0/30 Skip: 2/30 ## stDelegatecallTestHomestead ```diff Call1024BalanceTooLow.json Skip @@ -1573,9 +1573,9 @@ OK: 19/19 Fail: 0/19 Skip: 0/19 + returndatacopy_initial_256.json OK + returndatacopy_initial_big_sum.json OK + returndatacopy_overrun.json OK - returndatasize_after_failing_callcode.json Skip - returndatasize_after_failing_delegatecall.json Skip - returndatasize_after_failing_staticcall.json Skip ++ returndatasize_after_failing_callcode.json OK ++ returndatasize_after_failing_delegatecall.json OK ++ returndatasize_after_failing_staticcall.json OK + returndatasize_after_oog_after_deeper.json OK + returndatasize_after_successful_callcode.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_zero_read.json Skip ``` -OK: 23/37 Fail: 0/37 Skip: 14/37 +OK: 26/37 Fail: 0/37 Skip: 11/37 ## stRevertTest ```diff LoopCallsDepthThenRevert.json Skip @@ -1601,18 +1601,18 @@ OK: 23/37 Fail: 0/37 Skip: 14/37 RevertInCallCode.json Skip RevertInCreateInInit.json Skip RevertInDelegateCall.json Skip - RevertInStaticCall.json Skip - RevertOnEmptyStack.json Skip - RevertOpcode.json Skip - RevertOpcodeCalls.json Skip - RevertOpcodeCreate.json Skip - RevertOpcodeDirectCall.json Skip - RevertOpcodeInCallsOnNonEmptyReturnData.json Skip - RevertOpcodeInCreateReturns.json Skip - RevertOpcodeInInit.json Skip - RevertOpcodeMultipleSubCalls.json Skip - RevertOpcodeReturn.json Skip - RevertOpcodeWithBigOutputInInit.json Skip ++ RevertInStaticCall.json OK ++ RevertOnEmptyStack.json OK ++ RevertOpcode.json OK ++ RevertOpcodeCalls.json OK ++ RevertOpcodeCreate.json OK ++ RevertOpcodeDirectCall.json OK ++ RevertOpcodeInCallsOnNonEmptyReturnData.json OK ++ RevertOpcodeInCreateReturns.json OK ++ RevertOpcodeInInit.json OK ++ RevertOpcodeMultipleSubCalls.json OK ++ RevertOpcodeReturn.json OK ++ RevertOpcodeWithBigOutputInInit.json OK + RevertPrecompiledTouch.json OK + RevertPrecompiledTouchCC.json OK + RevertPrecompiledTouchDC.json OK @@ -1632,7 +1632,7 @@ OK: 23/37 Fail: 0/37 Skip: 14/37 + TouchToEmptyAccountRevert2.json OK + TouchToEmptyAccountRevert3.json OK ``` -OK: 22/43 Fail: 0/43 Skip: 21/43 +OK: 34/43 Fail: 0/43 Skip: 9/43 ## stShift ```diff + 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 ---TOTAL--- -OK: 2147/2334 Fail: 0/2334 Skip: 187/2334 +OK: 2164/2334 Fail: 0/2334 Skip: 170/2334 diff --git a/nimbus/p2p/executor.nim b/nimbus/p2p/executor.nim index 910e9ed3e..b7d76b8a2 100644 --- a/nimbus/p2p/executor.nim +++ b/nimbus/p2p/executor.nim @@ -44,7 +44,8 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta db.subBalance(sender, upfrontGasCost) if tx.isContractCreation and isCollision: break - if execComputation(computation): + execComputation(computation) + if not computation.shouldBurnGas: gasUsed = computation.refundGas(tx, sender) if computation.isSuicided(vmState.blockHeader.coinbase): diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 2c952cdee..56f2107bf 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -325,7 +325,7 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) = 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) - discard comp.execComputation + comp.execComputation result = ("0x" & nimcrypto.toHex(comp.output)).HexDataStr rpcsrv.rpc("eth_estimateGas") do(call: EthCall, quantityTag: string) -> GasInt: diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 04c27c081..7e40df8f9 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -103,12 +103,6 @@ proc snapshot*(comp: BaseComputation) = comp.dbsnapshot.intermediateRoot = 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) = comp.dbsnapshot.transaction.commit() comp.vmState.accountDb.rootHash = comp.vmState.blockHeader.stateRoot diff --git a/nimbus/vm_state_transactions.nim b/nimbus/vm_state_transactions.nim index a62fe973b..5aa8bf2c5 100644 --- a/nimbus/vm_state_transactions.nim +++ b/nimbus/vm_state_transactions.nim @@ -60,7 +60,7 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient: result = newBaseComputation(vmState, vmState.blockNumber, msg, some(fork)) doAssert result.isOriginComputation -proc execComputation*(computation: var BaseComputation): bool = +proc execComputation*(computation: var BaseComputation) = if computation.msg.isCreate: computation.applyMessage(Create) else: @@ -79,9 +79,8 @@ proc execComputation*(computation: var BaseComputation): bool = if computation.getFork >= FkSpurious: computation.collectTouchedAccounts(computation.vmState.touchedAccounts) - result = computation.isSuccess - computation.vmstate.status = result - if result: + computation.vmstate.status = computation.isSuccess + if computation.isSuccess: computation.vmState.addLogs(computation.logEntries) proc refundGas*(computation: BaseComputation, tx: Transaction, sender: EthAddress): GasInt = diff --git a/tests/macro_assembler.nim b/tests/macro_assembler.nim index 66b2a2154..1cbbc2045 100644 --- a/tests/macro_assembler.nim +++ b/tests/macro_assembler.nim @@ -233,10 +233,10 @@ proc runVM*(blockNumber: Uint256, chainDB: BaseChainDB, boa: Assembler): bool = var computation = initComputation(blockNumber, chainDB, boa.code, boa.data) let gas = computation.gasMeter.gasRemaining - let computationResult = execComputation(computation) + execComputation(computation) let gasUsed = gas - computation.gasMeter.gasRemaining - if computationResult: + if computation.isSuccess: if boa.success == false: error "different success value", expected=boa.success, actual=true return false diff --git a/tests/test_generalstate_failing.nim b/tests/test_generalstate_failing.nim index 246da8d79..76ccd3f46 100644 --- a/tests/test_generalstate_failing.nim +++ b/tests/test_generalstate_failing.nim @@ -25,40 +25,23 @@ func allowedFailingGeneralStateTest*(folder, name: string): bool = "sha3_deja.json", "delegatecallNonConst.json", - "returndatasize_after_failing_delegatecall.json", "returndatacopy_following_revert_in_create.json", "returndatasize_initial_zero_read.json", "returndatacopy_after_successful_callcode.json", "returndatacopy_afterFailing_create.json", "returndatacopy_after_successful_delegatecall.json", "returndatacopy_following_revert.json", - "returndatasize_after_failing_staticcall.json", "returndatacopy_after_successful_staticcall.json", "returndatacopy_following_call.json", "returndatacopy_after_revert_in_staticcall.json", - "returndatasize_after_failing_callcode.json", - "CreateOOGafterInitCodeRevert.json", "CreateOOGafterInitCodeReturndataSize.json", - "CreateOOGafterInitCodeRevert2.json", "static_RevertOpcodeCalls.json", "PythonRevertTestTue201814-1430.json", - "RevertOpcodeDirectCall.json", "RevertInCallCode.json", - "RevertOpcodeReturn.json", - "RevertOnEmptyStack.json", "RevertInDelegateCall.json", - "RevertOpcodeCalls.json", - "RevertOpcode.json", - "RevertOpcodeInInit.json", - "RevertOpcodeWithBigOutputInInit.json", - "RevertOpcodeInCreateReturns.json", - "RevertOpcodeCreate.json", - "RevertOpcodeMultipleSubCalls.json", - "RevertOpcodeInCallsOnNonEmptyReturnData.json", "RevertInCreateInInit.json", - "RevertInStaticCall.json", "modexpRandomInput.json", "modexp_9_37111_37111_1000000.json",