remove 'var' modifier from 'computation: var BaseComputation'

This commit is contained in:
andri lim 2019-04-04 10:20:00 +07:00
parent e8f6eeca43
commit 07ac4620d9
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 42 additions and 42 deletions

View File

@ -61,7 +61,7 @@ func output*(c: BaseComputation): seq[byte] =
else:
c.rawOutput
func `output=`*(c: var BaseComputation, value: openarray[byte]) =
func `output=`*(c: BaseComputation, value: openarray[byte]) =
c.rawOutput = @value
proc outputHex*(c: BaseComputation): string =
@ -69,11 +69,11 @@ proc outputHex*(c: BaseComputation): string =
return "0x"
c.rawOutput.bytesToHex
proc isSuicided*(c: var BaseComputation, address: EthAddress): bool =
proc isSuicided*(c: BaseComputation, address: EthAddress): bool =
result = address in c.accountsToDelete
proc prepareChildMessage*(
c: var BaseComputation,
c: BaseComputation,
gas: GasInt,
to: EthAddress,
value: UInt256,
@ -126,7 +126,7 @@ proc getFork*(computation: BaseComputation): Fork =
else:
computation.vmState.blockNumber.toFork
proc writeContract*(computation: var BaseComputation, fork: Fork): bool =
proc writeContract*(computation: BaseComputation, fork: Fork): bool =
result = true
let contractCode = computation.output
@ -150,7 +150,7 @@ proc writeContract*(computation: var BaseComputation, fork: Fork): bool =
if fork < FkHomestead: computation.output = @[]
result = false
proc transferBalance(computation: var BaseComputation, opCode: static[Op]) =
proc transferBalance(computation: BaseComputation, opCode: static[Op]) =
if computation.msg.depth > MaxCallDepth:
computation.setError(&"Stack depth limit reached depth={computation.msg.depth}")
return
@ -167,9 +167,9 @@ proc transferBalance(computation: var BaseComputation, opCode: static[Op]) =
db.subBalance(computation.msg.sender, computation.msg.value)
db.addBalance(computation.msg.storageAddress, computation.msg.value)
proc executeOpcodes*(computation: var BaseComputation) {.gcsafe.}
proc executeOpcodes*(computation: BaseComputation) {.gcsafe.}
proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) =
proc applyMessage*(computation: BaseComputation, opCode: static[Op]) =
computation.snapshot()
defer: computation.dispose()
@ -202,7 +202,7 @@ proc applyMessage*(computation: var BaseComputation, opCode: static[Op]) =
else:
computation.rollback()
proc addChildComputation*(computation: var BaseComputation, child: BaseComputation) =
proc addChildComputation*(computation: BaseComputation, child: BaseComputation) =
if child.isError:
if child.msg.isCreate:
computation.returnData = child.output
@ -223,14 +223,14 @@ proc addChildComputation*(computation: var BaseComputation, child: BaseComputati
computation.gasMeter.returnGas(child.gasMeter.gasRemaining)
computation.children.add(child)
proc registerAccountForDeletion*(c: var BaseComputation, beneficiary: EthAddress) =
proc registerAccountForDeletion*(c: BaseComputation, beneficiary: EthAddress) =
if c.msg.storageAddress in c.accountsToDelete:
raise newException(ValueError,
"invariant: should be impossible for an account to be " &
"registered for deletion multiple times")
c.accountsToDelete[c.msg.storageAddress] = beneficiary
proc addLogEntry*(c: var BaseComputation, log: Log) {.inline.} =
proc addLogEntry*(c: BaseComputation, log: Log) {.inline.} =
c.logEntries.add(log)
# many methods are basically TODO, but they still return valid values

View File

@ -452,7 +452,7 @@ op sstore, inline = false, slot, value:
computation.vmState.mutateStateDB:
db.setStorage(computation.msg.storageAddress, slot, value)
proc jumpImpl(computation: var BaseComputation, jumpTarget: UInt256) =
proc jumpImpl(computation: BaseComputation, jumpTarget: UInt256) =
if jumpTarget >= computation.code.len.u256:
raise newException(InvalidJumpDestination, "Invalid Jump Destination")
@ -537,7 +537,7 @@ proc canTransfer(computation: BaseComputation, memPos, memLen: int, value: Uint2
result = true
proc setupCreate(computation: var BaseComputation, memPos, len: int, value: Uint256): BaseComputation =
proc setupCreate(computation: BaseComputation, memPos, len: int, value: Uint256): BaseComputation =
let
callData = computation.memory.read(memPos, len)
createMsgGas = computation.getGasRemaining()
@ -601,7 +601,7 @@ op create, inline = false, value, startPosition, size:
else:
push: childComp.msg.storageAddress
proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
proc callParams(computation: BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
let gas = computation.stack.popInt()
let codeAddress = computation.stack.popAddress()
@ -623,7 +623,7 @@ proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress
memoryOutputSize,
computation.msg.flags)
proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
proc callCodeParams(computation: BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
let gas = computation.stack.popInt()
let to = computation.stack.popAddress()
@ -642,7 +642,7 @@ proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAdd
memoryOutputSize,
computation.msg.flags)
proc delegateCallParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
proc delegateCallParams(computation: BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
let gas = computation.stack.popInt()
let codeAddress = computation.stack.popAddress()
@ -664,7 +664,7 @@ proc delegateCallParams(computation: var BaseComputation): (UInt256, UInt256, Et
memoryOutputSize,
computation.msg.flags)
proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
proc staticCallParams(computation: BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
let gas = computation.stack.popInt()
let to = computation.stack.popAddress()
@ -683,7 +683,7 @@ proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthA
emvcStatic) # is_static
template genCall(callName: untyped, opCode: Op): untyped =
proc `callName Setup`(computation: var BaseComputation, callNameStr: string): (BaseComputation, int, int) =
proc `callName Setup`(computation: BaseComputation, callNameStr: string): (BaseComputation, int, int) =
let (gas, value, to, sender,
codeAddress,
memoryInputStartPosition, memoryInputSize,

View File

@ -59,12 +59,12 @@ macro op*(procname: untyped, inline: static[bool], stackParams_body: varargs[unt
# TODO: replace by func to ensure no side effects
if inline:
result = quote do:
proc `procname`*(`computation`: var BaseComputation) {.inline.} =
proc `procname`*(`computation`: BaseComputation) {.inline.} =
`popStackStmt`
`body`
else:
result = quote do:
proc `procname`*(`computation`: var BaseComputation) =
proc `procname`*(`computation`: BaseComputation) =
`popStackStmt`
`body`
@ -76,7 +76,7 @@ macro genPush*(): untyped =
for size in 1 .. 32:
let name = genName(size)
result.add quote do:
func `name`*(computation: var BaseComputation) {.inline.}=
func `name`*(computation: BaseComputation) {.inline.}=
## Push `size`-byte(s) on the stack
computation.stack.push computation.code.readVmWord(`size`)
@ -87,7 +87,7 @@ macro genDup*(): untyped =
for pos in 1 .. 16:
let name = genName(pos)
result.add quote do:
func `name`*(computation: var BaseComputation) {.inline.}=
func `name`*(computation: BaseComputation) {.inline.}=
computation.stack.dup(`pos`)
macro genSwap*(): untyped =
@ -97,10 +97,10 @@ macro genSwap*(): untyped =
for pos in 1 .. 16:
let name = genName(pos)
result.add quote do:
func `name`*(computation: var BaseComputation) {.inline.}=
func `name`*(computation: BaseComputation) {.inline.}=
computation.stack.swap(`pos`)
proc logImpl(c: var BaseComputation, opcode: Op, topicCount: int) =
proc logImpl(c: BaseComputation, opcode: Op, topicCount: int) =
doAssert(topicCount in 0 .. 4)
let (memStartPosition, size) = c.stack.popInt(2)
let (memPos, len) = (memStartPosition.cleanMemRef, size.cleanMemRef)
@ -122,8 +122,8 @@ proc logImpl(c: var BaseComputation, opcode: Op, topicCount: int) =
c.addLogEntry(log)
template genLog*() =
proc log0*(c: var BaseComputation) {.inline.} = logImpl(c, Log0, 0)
proc log1*(c: var BaseComputation) {.inline.} = logImpl(c, Log1, 1)
proc log2*(c: var BaseComputation) {.inline.} = logImpl(c, Log2, 2)
proc log3*(c: var BaseComputation) {.inline.} = logImpl(c, Log3, 3)
proc log4*(c: var BaseComputation) {.inline.} = logImpl(c, Log4, 4)
proc log0*(c: BaseComputation) {.inline.} = logImpl(c, Log0, 0)
proc log1*(c: BaseComputation) {.inline.} = logImpl(c, Log1, 1)
proc log2*(c: BaseComputation) {.inline.} = logImpl(c, Log2, 2)
proc log3*(c: BaseComputation) {.inline.} = logImpl(c, Log3, 3)
proc log4*(c: BaseComputation) {.inline.} = logImpl(c, Log4, 4)

View File

@ -16,7 +16,7 @@ import
logScope:
topics = "vm opcode"
func invalidInstruction*(computation: var BaseComputation) {.inline.} =
func invalidInstruction*(computation: BaseComputation) {.inline.} =
raise newException(InvalidInstruction, "Invalid instruction, received an opcode not implemented in the current fork.")
let FrontierOpDispatch {.compileTime.}: array[Op, NimNode] = block:
@ -246,13 +246,13 @@ macro genFrontierDispatch(computation: BaseComputation): untyped =
macro genHomesteadDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(HomesteadOpDispatch, computation)
proc frontierVM(computation: var BaseComputation) =
proc frontierVM(computation: BaseComputation) =
genFrontierDispatch(computation)
proc homesteadVM(computation: var BaseComputation) =
proc homesteadVM(computation: BaseComputation) =
genHomesteadDispatch(computation)
proc executeOpcodes(computation: var BaseComputation) =
proc executeOpcodes(computation: BaseComputation) =
# TODO: Optimise getting fork and updating opCodeExec only when necessary
let fork = computation.getFork

View File

@ -63,7 +63,7 @@ proc getFR(data: openarray[byte]): FR =
if not result.fromBytes2(data):
raise newException(ValidationError, "Could not get FR value")
proc ecRecover*(computation: var BaseComputation) =
proc ecRecover*(computation: BaseComputation) =
computation.gasMeter.consumeGas(
GasECRecover,
reason="ECRecover Precompile")
@ -79,7 +79,7 @@ proc ecRecover*(computation: var BaseComputation) =
computation.rawOutput[12..31] = pubKey.toCanonicalAddress()
trace "ECRecover precompile", derivedKey = pubKey.toCanonicalAddress()
proc sha256*(computation: var BaseComputation) =
proc sha256*(computation: BaseComputation) =
let
wordCount = wordCount(computation.msg.data.len)
gasFee = GasSHA256 + wordCount * GasSHA256Word
@ -88,7 +88,7 @@ proc sha256*(computation: var BaseComputation) =
computation.rawOutput = @(nimcrypto.sha_256.digest(computation.msg.data).data)
trace "SHA256 precompile", output = computation.rawOutput.toHex
proc ripemd160*(computation: var BaseComputation) =
proc ripemd160*(computation: BaseComputation) =
let
wordCount = wordCount(computation.msg.data.len)
gasFee = GasRIPEMD160 + wordCount * GasRIPEMD160Word
@ -98,7 +98,7 @@ proc ripemd160*(computation: var BaseComputation) =
computation.rawOutput[12..31] = @(nimcrypto.ripemd160.digest(computation.msg.data).data)
trace "RIPEMD160 precompile", output = computation.rawOutput.toHex
proc identity*(computation: var BaseComputation) =
proc identity*(computation: BaseComputation) =
let
wordCount = wordCount(computation.msg.data.len)
gasFee = GasIdentity + wordCount * GasIdentityWord
@ -107,7 +107,7 @@ proc identity*(computation: var BaseComputation) =
computation.rawOutput = computation.msg.data
trace "Identity precompile", output = computation.rawOutput.toHex
proc modExpInternal(computation: var BaseComputation, base_len, exp_len, mod_len: int, T: type StUint) =
proc modExpInternal(computation: BaseComputation, base_len, exp_len, mod_len: int, T: type StUint) =
template rawMsg: untyped {.dirty.} =
computation.msg.data
@ -171,7 +171,7 @@ proc modExpInternal(computation: var BaseComputation, base_len, exp_len, mod_len
else:
computation.rawOutput = @(powmod(base, exp, modulo).toByteArrayBE)
proc modExp*(computation: var BaseComputation) =
proc modExp*(computation: BaseComputation) =
## Modular exponentiation precompiled contract
## Yellow Paper Appendix E
## EIP-198 - https://github.com/ethereum/EIPs/blob/master/EIPS/eip-198.md
@ -200,7 +200,7 @@ proc modExp*(computation: var BaseComputation) =
else:
raise newException(ValueError, "The Nimbus VM doesn't support modular exponentiation with numbers larger than uint8192")
proc bn256ecAdd*(computation: var BaseComputation) =
proc bn256ecAdd*(computation: BaseComputation) =
var
input: array[128, byte]
output: array[64, byte]
@ -220,7 +220,7 @@ proc bn256ecAdd*(computation: var BaseComputation) =
# computation.gasMeter.consumeGas(gasFee, reason = "ecAdd Precompile")
computation.rawOutput = @output
proc bn256ecMul*(computation: var BaseComputation) =
proc bn256ecMul*(computation: BaseComputation) =
var
input: array[96, byte]
output: array[64, byte]
@ -242,7 +242,7 @@ proc bn256ecMul*(computation: var BaseComputation) =
# computation.gasMeter.consumeGas(gasFee, reason="ecMul Precompile")
computation.rawOutput = @output
proc bn256ecPairing*(computation: var BaseComputation) =
proc bn256ecPairing*(computation: BaseComputation) =
var output: array[32, byte]
let msglen = len(computation.msg.data)
@ -275,7 +275,7 @@ proc bn256ecPairing*(computation: var BaseComputation) =
# computation.gasMeter.consumeGas(gasFee, reason="ecPairing Precompile")
computation.rawOutput = @output
proc execPrecompiles*(computation: var BaseComputation, fork: Fork): bool {.inline.} =
proc execPrecompiles*(computation: BaseComputation, fork: Fork): bool {.inline.} =
for i in 0..18:
if computation.msg.codeAddress[i] != 0: return