From 112d2219df4fa5936c1b2839b32cfbb956304924 Mon Sep 17 00:00:00 2001 From: andri lim Date: Tue, 2 Apr 2019 12:13:18 +0700 Subject: [PATCH] reduce indirect call in EVM --- nimbus/vm/computation.nim | 10 ++++------ nimbus/vm/interpreter/opcodes_impl.nim | 14 ++++---------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 9905ed7c9..a4ebc1717 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -200,7 +200,7 @@ proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) = else: computation.rollback() -proc addChildComputation(computation: var BaseComputation, child: BaseComputation) = +proc addChildComputation*(computation: var BaseComputation, child: BaseComputation) = if child.isError: if child.msg.isCreate: computation.returnData = child.output @@ -216,12 +216,10 @@ proc addChildComputation(computation: var BaseComputation, child: BaseComputatio for k, v in child.accountsToDelete: computation.accountsToDelete[k] = v computation.logEntries.add child.logEntries - computation.children.add(child) -proc applyChildComputation*(parentComp, childComp: var BaseComputation, opCode: static[Op]) = - ## Apply the vm message childMsg as a child computation. - childComp.applyMessage(opCode) - parentComp.addChildComputation(childComp) + if not child.shouldBurnGas: + computation.gasMeter.returnGas(child.gasMeter.gasRemaining) + computation.children.add(child) proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) = if c.msg.storageAddress in c.accountsToDelete: diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 9ccbebb51..576a8489d 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -593,16 +593,14 @@ op create, inline = false, value, startPosition, size: var childComp = setupCreate(computation, memPos, len, value) if childComp.isNil: return - computation.applyChildComputation(childComp, Create) + childComp.applyMessage(Create) + computation.addChildComputation(childComp) if childComp.isError: push: 0 else: push: childComp.msg.storageAddress - if not childComp.shouldBurnGas: - computation.gasMeter.returnGas(childComp.gasMeter.gasRemaining) - proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) = let gas = computation.stack.popInt() let codeAddress = computation.stack.popAddress() @@ -761,7 +759,8 @@ template genCall(callName: untyped, opCode: Op): untyped = ## STATICCALL, 0xfa, Static message-call into an account. var (childComp, memOutPos, memOutLen) = `callName Setup`(computation, callName.astToStr) - applyChildComputation(computation, childComp, opCode) + childComp.applyMessage(opCode) + addChildComputation(computation, childComp) if childComp.isError: push: 0 @@ -773,11 +772,6 @@ template genCall(callName: untyped, opCode: Op): untyped = computation.memory.write( memOutPos, childComp.output.toOpenArray(0, actualOutputSize - 1)) - if not childComp.shouldBurnGas: - computation.gasMeter.returnGas(childComp.gasMeter.gasRemaining) - - if computation.gasMeter.gasRemaining <= 0: - raise newException(OutOfGas, "computation out of gas after contract call (" & callName.astToStr & ")") genCall(call, Call) genCall(callCode, CallCode)