Initial EVMC message type API matching: reorder overlapping fields to match EMVC; rename to to destination; replace isStatic with more general flags (with only one non-zero value); remove superfluous-seeming shouldTransferValue; keep internalFoo fields, which aren't in PyEVM either, so weren't per se part of PyEVM matching
This commit is contained in:
parent
3c0d27021e
commit
f91bb16bdd
|
@ -579,7 +579,7 @@ op create, inline = false, value, startPosition, size:
|
||||||
push: contractAddress
|
push: contractAddress
|
||||||
computation.gasMeter.returnGas(childComputation.gasMeter.gasRemaining)
|
computation.gasMeter.returnGas(childComputation.gasMeter.gasRemaining)
|
||||||
|
|
||||||
proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, bool, bool) =
|
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()
|
||||||
|
|
||||||
|
@ -599,10 +599,9 @@ proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress
|
||||||
memoryInputSize,
|
memoryInputSize,
|
||||||
memoryOutputStartPosition,
|
memoryOutputStartPosition,
|
||||||
memoryOutputSize,
|
memoryOutputSize,
|
||||||
true, # should_transfer_value,
|
computation.msg.flags)
|
||||||
computation.msg.isStatic)
|
|
||||||
|
|
||||||
proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, bool, bool) =
|
proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
|
||||||
let gas = computation.stack.popInt()
|
let gas = computation.stack.popInt()
|
||||||
let to = computation.stack.popAddress()
|
let to = computation.stack.popAddress()
|
||||||
|
|
||||||
|
@ -619,10 +618,9 @@ proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAdd
|
||||||
memoryInputSize,
|
memoryInputSize,
|
||||||
memoryOutputStartPosition,
|
memoryOutputStartPosition,
|
||||||
memoryOutputSize,
|
memoryOutputSize,
|
||||||
true, # should_transfer_value,
|
computation.msg.flags)
|
||||||
computation.msg.isStatic)
|
|
||||||
|
|
||||||
proc delegateCallParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, bool, bool) =
|
proc delegateCallParams(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()
|
||||||
|
|
||||||
|
@ -642,10 +640,9 @@ proc delegateCallParams(computation: var BaseComputation): (UInt256, UInt256, Et
|
||||||
memoryInputSize,
|
memoryInputSize,
|
||||||
memoryOutputStartPosition,
|
memoryOutputStartPosition,
|
||||||
memoryOutputSize,
|
memoryOutputSize,
|
||||||
false, # should_transfer_value,
|
computation.msg.flags)
|
||||||
computation.msg.isStatic)
|
|
||||||
|
|
||||||
proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, bool, bool) =
|
proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress, EthAddress, EthAddress, UInt256, UInt256, UInt256, UInt256, MsgFlags) =
|
||||||
let gas = computation.stack.popInt()
|
let gas = computation.stack.popInt()
|
||||||
let to = computation.stack.popAddress()
|
let to = computation.stack.popAddress()
|
||||||
|
|
||||||
|
@ -661,8 +658,7 @@ proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthA
|
||||||
memoryInputSize,
|
memoryInputSize,
|
||||||
memoryOutputStartPosition,
|
memoryOutputStartPosition,
|
||||||
memoryOutputSize,
|
memoryOutputSize,
|
||||||
false, # should_transfer_value,
|
emvcStatic) # is_static
|
||||||
true) # is_static
|
|
||||||
|
|
||||||
template genCall(callName: untyped): untyped =
|
template genCall(callName: untyped): untyped =
|
||||||
op callName, inline = false:
|
op callName, inline = false:
|
||||||
|
@ -676,8 +672,7 @@ template genCall(callName: untyped): untyped =
|
||||||
codeAddress,
|
codeAddress,
|
||||||
memoryInputStartPosition, memoryInputSize,
|
memoryInputStartPosition, memoryInputSize,
|
||||||
memoryOutputStartPosition, memoryOutputSize,
|
memoryOutputStartPosition, memoryOutputSize,
|
||||||
shouldTransferValue,
|
flags) = `callName Params`(computation)
|
||||||
isStatic) = `callName Params`(computation)
|
|
||||||
|
|
||||||
let (memInPos, memInLen, memOutPos, memOutLen) = (memoryInputStartPosition.cleanMemRef, memoryInputSize.cleanMemRef, memoryOutputStartPosition.cleanMemRef, memoryOutputSize.cleanMemRef)
|
let (memInPos, memInLen, memOutPos, memOutLen) = (memoryInputStartPosition.cleanMemRef, memoryInputSize.cleanMemRef, memoryOutputStartPosition.cleanMemRef, memoryOutputSize.cleanMemRef)
|
||||||
|
|
||||||
|
@ -734,9 +729,7 @@ template genCall(callName: untyped): untyped =
|
||||||
value,
|
value,
|
||||||
callData,
|
callData,
|
||||||
code,
|
code,
|
||||||
MessageOptions(
|
MessageOptions(flags: flags)
|
||||||
shouldTransferValue: shouldTransferValue,
|
|
||||||
isStatic: isStatic)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if sender != ZERO_ADDRESS:
|
if sender != ZERO_ADDRESS:
|
||||||
|
|
|
@ -23,16 +23,14 @@ proc newMessageOptions*(
|
||||||
depth: int = 0,
|
depth: int = 0,
|
||||||
createAddress = ZERO_ADDRESS,
|
createAddress = ZERO_ADDRESS,
|
||||||
codeAddress = ZERO_ADDRESS,
|
codeAddress = ZERO_ADDRESS,
|
||||||
shouldTransferValue: bool = true,
|
flags: MsgFlags = static(emvcNoFlags)): MessageOptions =
|
||||||
isStatic: bool = false): MessageOptions =
|
|
||||||
|
|
||||||
result = MessageOptions(
|
result = MessageOptions(
|
||||||
origin: origin,
|
origin: origin,
|
||||||
depth: depth,
|
depth: depth,
|
||||||
createAddress: createAddress,
|
createAddress: createAddress,
|
||||||
codeAddress: codeAddress,
|
codeAddress: codeAddress,
|
||||||
shouldTransferValue: shouldTransferValue,
|
flags: flags)
|
||||||
isStatic: isStatic)
|
|
||||||
|
|
||||||
proc newMessage*(
|
proc newMessage*(
|
||||||
gas: GasInt,
|
gas: GasInt,
|
||||||
|
@ -49,15 +47,14 @@ proc newMessage*(
|
||||||
new(result)
|
new(result)
|
||||||
result.gas = gas
|
result.gas = gas
|
||||||
result.gasPrice = gasPrice
|
result.gasPrice = gasPrice
|
||||||
result.to = to
|
result.destination = to
|
||||||
result.sender = sender
|
result.sender = sender
|
||||||
result.value = value
|
result.value = value
|
||||||
result.data = data
|
result.data = data
|
||||||
result.depth = options.depth
|
result.depth = options.depth
|
||||||
result.storageAddress = options.createAddress
|
result.storageAddress = options.createAddress
|
||||||
result.codeAddress = options.codeAddress
|
result.codeAddress = options.codeAddress
|
||||||
result.shouldTransferValue = options.shouldTransferValue
|
result.flags = options.flags
|
||||||
result.isStatic = options.isStatic
|
|
||||||
result.code = code
|
result.code = code
|
||||||
|
|
||||||
if options.origin != ZERO_ADDRESS:
|
if options.origin != ZERO_ADDRESS:
|
||||||
|
@ -78,13 +75,13 @@ proc codeAddress*(message: Message): EthAddress =
|
||||||
if message.internalCodeAddress != ZERO_ADDRESS:
|
if message.internalCodeAddress != ZERO_ADDRESS:
|
||||||
message.internalCodeAddress
|
message.internalCodeAddress
|
||||||
else:
|
else:
|
||||||
message.to
|
message.destination
|
||||||
|
|
||||||
proc `storageAddress`*(message: Message): EthAddress =
|
proc `storageAddress`*(message: Message): EthAddress =
|
||||||
if message.internalStorageAddress != ZERO_ADDRESS:
|
if message.internalStorageAddress != ZERO_ADDRESS:
|
||||||
message.internalStorageAddress
|
message.internalStorageAddress
|
||||||
else:
|
else:
|
||||||
message.to
|
message.destination
|
||||||
|
|
||||||
proc isCreate(message: Message): bool =
|
proc isCreate(message: Message): bool =
|
||||||
message.to == CREATE_CONTRACT_ADDRESS
|
message.destination == CREATE_CONTRACT_ADDRESS
|
||||||
|
|
|
@ -51,8 +51,20 @@ type
|
||||||
startGas*: GasInt
|
startGas*: GasInt
|
||||||
gasRemaining*: GasInt
|
gasRemaining*: GasInt
|
||||||
|
|
||||||
|
CallKind* = enum
|
||||||
|
evmcCall = 0, # CALL
|
||||||
|
evmcDelegateCall = 1, # DELEGATECALL
|
||||||
|
evmcCallCode = 2, # CALLCODE
|
||||||
|
evmcCreate = 3, # CREATE
|
||||||
|
evmcCreate2 = 4 # CREATE2
|
||||||
|
|
||||||
|
MsgFlags* = enum
|
||||||
|
emvcNoFlags = 0
|
||||||
|
emvcStatic = 1
|
||||||
|
|
||||||
Message* = ref object
|
Message* = ref object
|
||||||
# A message for VM computation
|
# A message for VM computation
|
||||||
|
# https://github.com/ethereum/evmc/blob/master/include/evmc/evmc.h
|
||||||
|
|
||||||
# depth = None
|
# depth = None
|
||||||
|
|
||||||
|
@ -61,30 +73,33 @@ type
|
||||||
|
|
||||||
# createAddress = None
|
# createAddress = None
|
||||||
|
|
||||||
# shouldTransferValue = None
|
|
||||||
# isStatic = None
|
|
||||||
|
|
||||||
# logger = logging.getLogger("evm.vm.message.Message")
|
# logger = logging.getLogger("evm.vm.message.Message")
|
||||||
|
|
||||||
gas*: GasInt
|
destination*: EthAddress
|
||||||
gasPrice*: GasInt
|
|
||||||
to*: EthAddress
|
|
||||||
sender*: EthAddress
|
sender*: EthAddress
|
||||||
value*: UInt256
|
value*: UInt256
|
||||||
data*: seq[byte]
|
data*: seq[byte]
|
||||||
|
# size_t input_size;
|
||||||
|
codeHash*: UInt256
|
||||||
|
create2Salt*: Uint256
|
||||||
|
gas*: GasInt
|
||||||
|
gasPrice*: GasInt
|
||||||
|
depth*: int
|
||||||
|
kind*: CallKind
|
||||||
|
flags*: MsgFlags
|
||||||
|
|
||||||
|
# Not in EVMC API
|
||||||
|
|
||||||
|
# TODO: Done via callback function (v)table in EVMC
|
||||||
code*: string # TODO: seq[byte] is probably a better representation
|
code*: string # TODO: seq[byte] is probably a better representation
|
||||||
|
|
||||||
internalOrigin*: EthAddress
|
internalOrigin*: EthAddress
|
||||||
internalCodeAddress*: EthAddress
|
internalCodeAddress*: EthAddress
|
||||||
depth*: int
|
|
||||||
internalStorageAddress*: EthAddress
|
internalStorageAddress*: EthAddress
|
||||||
shouldTransferValue*: bool
|
|
||||||
isStatic*: bool
|
|
||||||
isCreate*: bool
|
|
||||||
|
|
||||||
MessageOptions* = ref object
|
MessageOptions* = ref object
|
||||||
origin*: EthAddress
|
origin*: EthAddress
|
||||||
depth*: int
|
depth*: int
|
||||||
createAddress*: EthAddress
|
createAddress*: EthAddress
|
||||||
codeAddress*: EthAddress
|
codeAddress*: EthAddress
|
||||||
shouldTransferValue*: bool
|
flags*: MsgFlags
|
||||||
isStatic*: bool
|
|
||||||
|
|
Loading…
Reference in New Issue