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:
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:

View File

@ -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)