reduce indirect call in EVM

This commit is contained in:
andri lim 2019-04-02 12:13:18 +07:00
parent 0f8affb7c9
commit 112d2219df
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 8 additions and 16 deletions

View File

@ -200,7 +200,7 @@ proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) =
else: else:
computation.rollback() computation.rollback()
proc addChildComputation(computation: var BaseComputation, child: BaseComputation) = proc addChildComputation*(computation: var BaseComputation, child: BaseComputation) =
if child.isError: if child.isError:
if child.msg.isCreate: if child.msg.isCreate:
computation.returnData = child.output computation.returnData = child.output
@ -216,12 +216,10 @@ proc addChildComputation(computation: var BaseComputation, child: BaseComputatio
for k, v in child.accountsToDelete: for k, v in child.accountsToDelete:
computation.accountsToDelete[k] = v computation.accountsToDelete[k] = v
computation.logEntries.add child.logEntries computation.logEntries.add child.logEntries
computation.children.add(child)
proc applyChildComputation*(parentComp, childComp: var BaseComputation, opCode: static[Op]) = if not child.shouldBurnGas:
## Apply the vm message childMsg as a child computation. computation.gasMeter.returnGas(child.gasMeter.gasRemaining)
childComp.applyMessage(opCode) computation.children.add(child)
parentComp.addChildComputation(childComp)
proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) = proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) =
if c.msg.storageAddress in c.accountsToDelete: if c.msg.storageAddress in c.accountsToDelete:

View File

@ -593,16 +593,14 @@ op create, inline = false, value, startPosition, size:
var childComp = setupCreate(computation, memPos, len, value) var childComp = setupCreate(computation, memPos, len, value)
if childComp.isNil: return if childComp.isNil: return
computation.applyChildComputation(childComp, Create) childComp.applyMessage(Create)
computation.addChildComputation(childComp)
if childComp.isError: if childComp.isError:
push: 0 push: 0
else: else:
push: childComp.msg.storageAddress 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) = proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
let gas = computation.stack.popInt() let gas = computation.stack.popInt()
let codeAddress = computation.stack.popAddress() let codeAddress = computation.stack.popAddress()
@ -761,7 +759,8 @@ template genCall(callName: untyped, opCode: Op): untyped =
## STATICCALL, 0xfa, Static message-call into an account. ## STATICCALL, 0xfa, Static message-call into an account.
var (childComp, memOutPos, memOutLen) = `callName Setup`(computation, callName.astToStr) var (childComp, memOutPos, memOutLen) = `callName Setup`(computation, callName.astToStr)
applyChildComputation(computation, childComp, opCode) childComp.applyMessage(opCode)
addChildComputation(computation, childComp)
if childComp.isError: if childComp.isError:
push: 0 push: 0
@ -773,11 +772,6 @@ template genCall(callName: untyped, opCode: Op): untyped =
computation.memory.write( computation.memory.write(
memOutPos, memOutPos,
childComp.output.toOpenArray(0, actualOutputSize - 1)) 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(call, Call)
genCall(callCode, CallCode) genCall(callCode, CallCode)