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
|
||||
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 codeAddress = computation.stack.popAddress()
|
||||
|
||||
|
@ -599,10 +599,9 @@ proc callParams(computation: var BaseComputation): (UInt256, UInt256, EthAddress
|
|||
memoryInputSize,
|
||||
memoryOutputStartPosition,
|
||||
memoryOutputSize,
|
||||
true, # should_transfer_value,
|
||||
computation.msg.isStatic)
|
||||
computation.msg.flags)
|
||||
|
||||
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 to = computation.stack.popAddress()
|
||||
|
||||
|
@ -619,10 +618,9 @@ proc callCodeParams(computation: var BaseComputation): (UInt256, UInt256, EthAdd
|
|||
memoryInputSize,
|
||||
memoryOutputStartPosition,
|
||||
memoryOutputSize,
|
||||
true, # should_transfer_value,
|
||||
computation.msg.isStatic)
|
||||
computation.msg.flags)
|
||||
|
||||
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 codeAddress = computation.stack.popAddress()
|
||||
|
||||
|
@ -642,10 +640,9 @@ proc delegateCallParams(computation: var BaseComputation): (UInt256, UInt256, Et
|
|||
memoryInputSize,
|
||||
memoryOutputStartPosition,
|
||||
memoryOutputSize,
|
||||
false, # should_transfer_value,
|
||||
computation.msg.isStatic)
|
||||
computation.msg.flags)
|
||||
|
||||
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 to = computation.stack.popAddress()
|
||||
|
||||
|
@ -661,8 +658,7 @@ proc staticCallParams(computation: var BaseComputation): (UInt256, UInt256, EthA
|
|||
memoryInputSize,
|
||||
memoryOutputStartPosition,
|
||||
memoryOutputSize,
|
||||
false, # should_transfer_value,
|
||||
true) # is_static
|
||||
emvcStatic) # is_static
|
||||
|
||||
template genCall(callName: untyped): untyped =
|
||||
op callName, inline = false:
|
||||
|
@ -676,8 +672,7 @@ template genCall(callName: untyped): untyped =
|
|||
codeAddress,
|
||||
memoryInputStartPosition, memoryInputSize,
|
||||
memoryOutputStartPosition, memoryOutputSize,
|
||||
shouldTransferValue,
|
||||
isStatic) = `callName Params`(computation)
|
||||
flags) = `callName Params`(computation)
|
||||
|
||||
let (memInPos, memInLen, memOutPos, memOutLen) = (memoryInputStartPosition.cleanMemRef, memoryInputSize.cleanMemRef, memoryOutputStartPosition.cleanMemRef, memoryOutputSize.cleanMemRef)
|
||||
|
||||
|
@ -734,9 +729,7 @@ template genCall(callName: untyped): untyped =
|
|||
value,
|
||||
callData,
|
||||
code,
|
||||
MessageOptions(
|
||||
shouldTransferValue: shouldTransferValue,
|
||||
isStatic: isStatic)
|
||||
MessageOptions(flags: flags)
|
||||
)
|
||||
|
||||
if sender != ZERO_ADDRESS:
|
||||
|
|
|
@ -23,16 +23,14 @@ proc newMessageOptions*(
|
|||
depth: int = 0,
|
||||
createAddress = ZERO_ADDRESS,
|
||||
codeAddress = ZERO_ADDRESS,
|
||||
shouldTransferValue: bool = true,
|
||||
isStatic: bool = false): MessageOptions =
|
||||
flags: MsgFlags = static(emvcNoFlags)): MessageOptions =
|
||||
|
||||
result = MessageOptions(
|
||||
origin: origin,
|
||||
depth: depth,
|
||||
createAddress: createAddress,
|
||||
codeAddress: codeAddress,
|
||||
shouldTransferValue: shouldTransferValue,
|
||||
isStatic: isStatic)
|
||||
flags: flags)
|
||||
|
||||
proc newMessage*(
|
||||
gas: GasInt,
|
||||
|
@ -49,15 +47,14 @@ proc newMessage*(
|
|||
new(result)
|
||||
result.gas = gas
|
||||
result.gasPrice = gasPrice
|
||||
result.to = to
|
||||
result.destination = to
|
||||
result.sender = sender
|
||||
result.value = value
|
||||
result.data = data
|
||||
result.depth = options.depth
|
||||
result.storageAddress = options.createAddress
|
||||
result.codeAddress = options.codeAddress
|
||||
result.shouldTransferValue = options.shouldTransferValue
|
||||
result.isStatic = options.isStatic
|
||||
result.flags = options.flags
|
||||
result.code = code
|
||||
|
||||
if options.origin != ZERO_ADDRESS:
|
||||
|
@ -78,13 +75,13 @@ proc codeAddress*(message: Message): EthAddress =
|
|||
if message.internalCodeAddress != ZERO_ADDRESS:
|
||||
message.internalCodeAddress
|
||||
else:
|
||||
message.to
|
||||
message.destination
|
||||
|
||||
proc `storageAddress`*(message: Message): EthAddress =
|
||||
if message.internalStorageAddress != ZERO_ADDRESS:
|
||||
message.internalStorageAddress
|
||||
else:
|
||||
message.to
|
||||
message.destination
|
||||
|
||||
proc isCreate(message: Message): bool =
|
||||
message.to == CREATE_CONTRACT_ADDRESS
|
||||
message.destination == CREATE_CONTRACT_ADDRESS
|
||||
|
|
|
@ -51,8 +51,20 @@ type
|
|||
startGas*: 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
|
||||
# A message for VM computation
|
||||
# https://github.com/ethereum/evmc/blob/master/include/evmc/evmc.h
|
||||
|
||||
# depth = None
|
||||
|
||||
|
@ -61,30 +73,33 @@ type
|
|||
|
||||
# createAddress = None
|
||||
|
||||
# shouldTransferValue = None
|
||||
# isStatic = None
|
||||
|
||||
# logger = logging.getLogger("evm.vm.message.Message")
|
||||
|
||||
gas*: GasInt
|
||||
gasPrice*: GasInt
|
||||
to*: EthAddress
|
||||
destination*: EthAddress
|
||||
sender*: EthAddress
|
||||
value*: UInt256
|
||||
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
|
||||
|
||||
internalOrigin*: EthAddress
|
||||
internalCodeAddress*: EthAddress
|
||||
depth*: int
|
||||
internalStorageAddress*: EthAddress
|
||||
shouldTransferValue*: bool
|
||||
isStatic*: bool
|
||||
isCreate*: bool
|
||||
|
||||
MessageOptions* = ref object
|
||||
origin*: EthAddress
|
||||
depth*: int
|
||||
createAddress*: EthAddress
|
||||
codeAddress*: EthAddress
|
||||
shouldTransferValue*: bool
|
||||
isStatic*: bool
|
||||
flags*: MsgFlags
|
||||
|
|
Loading…
Reference in New Issue