2021-04-30 09:33:14 +00:00
|
|
|
# Nimbus - Various ways of calling the EVM
|
|
|
|
#
|
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import
|
2021-05-17 11:39:52 +00:00
|
|
|
eth/common/eth_types, stint, options, stew/byteutils,
|
2021-05-31 10:36:40 +00:00
|
|
|
".."/[vm_types, vm_types2, vm_state, utils],
|
|
|
|
".."/[db/db_chain, config, rpc/hexstrings, utils],
|
|
|
|
".."/[db/accounts_cache, utils, transaction, vm_gas_costs], eth/trie/db,
|
2021-05-17 09:23:59 +00:00
|
|
|
".."/vm_internals,
|
2021-05-17 11:39:52 +00:00
|
|
|
./call_common
|
2021-04-30 09:33:14 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
RpcCallData* = object
|
|
|
|
source*: EthAddress
|
|
|
|
to*: EthAddress
|
|
|
|
gas*: GasInt
|
|
|
|
gasPrice*: GasInt
|
|
|
|
value*: UInt256
|
|
|
|
data*: seq[byte]
|
|
|
|
contractCreation*: bool
|
|
|
|
|
2021-05-17 14:27:28 +00:00
|
|
|
proc rpcRunComputation(vmState: BaseVMState, rpc: RpcCallData,
|
2021-05-29 04:22:53 +00:00
|
|
|
gasLimit: GasInt, forkOverride = none(Fork),
|
|
|
|
forEstimateGas: bool = false): CallResult =
|
2021-05-17 14:27:28 +00:00
|
|
|
return runComputation(CallParams(
|
2021-05-17 10:03:39 +00:00
|
|
|
vmState: vmState,
|
|
|
|
forkOverride: forkOverride,
|
|
|
|
gasPrice: rpc.gasPrice,
|
|
|
|
gasLimit: gasLimit,
|
|
|
|
sender: rpc.source,
|
|
|
|
to: rpc.to,
|
|
|
|
isCreate: rpc.contractCreation,
|
|
|
|
value: rpc.value,
|
2021-05-17 14:27:28 +00:00
|
|
|
input: rpc.data,
|
|
|
|
# This matches historical behaviour. It might be that not all these steps
|
|
|
|
# should be disabled for RPC/GraphQL `call`. But until we investigate what
|
|
|
|
# RPC/GraphQL clients are expecting, keep the same behaviour.
|
2021-05-29 04:22:53 +00:00
|
|
|
noIntrinsic: not forEstimateGas, # Don't charge intrinsic gas.
|
|
|
|
noAccessList: not forEstimateGas, # Don't initialise EIP-2929 access list.
|
|
|
|
noGasCharge: not forEstimateGas, # Don't charge sender account for gas.
|
|
|
|
noRefund: not forEstimateGas # Don't apply gas refund/burn rule.
|
2021-05-17 10:03:39 +00:00
|
|
|
))
|
2021-05-03 08:08:03 +00:00
|
|
|
|
|
|
|
proc rpcDoCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): HexDataStr =
|
|
|
|
# TODO: handle revert and error
|
|
|
|
# TODO: handle contract ABI
|
2021-05-17 14:27:28 +00:00
|
|
|
# we use current header stateRoot, unlike block validation
|
|
|
|
# which use previous block stateRoot
|
|
|
|
# TODO: ^ Check it's correct to use current header stateRoot, not parent
|
|
|
|
let vmState = newBaseVMState(header.stateRoot, header, chain)
|
|
|
|
let callResult = rpcRunComputation(vmState, call, call.gas)
|
|
|
|
return hexDataStr(callResult.output)
|
2021-05-03 08:08:11 +00:00
|
|
|
|
2021-05-03 08:07:56 +00:00
|
|
|
proc rpcMakeCall*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB): (string, GasInt, bool) =
|
|
|
|
# TODO: handle revert
|
2021-05-17 14:27:28 +00:00
|
|
|
let parent = chain.getBlockHeader(header.parentHash)
|
|
|
|
let vmState = newBaseVMState(parent.stateRoot, header, chain)
|
|
|
|
let callResult = rpcRunComputation(vmState, call, call.gas)
|
|
|
|
return (callResult.output.toHex, callResult.gasUsed, callResult.isError)
|
2021-05-03 08:07:56 +00:00
|
|
|
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
func rpcIntrinsicGas(call: RpcCallData, fork: Fork): GasInt =
|
|
|
|
var intrinsicGas = call.data.intrinsicGas(fork)
|
|
|
|
if call.contractCreation:
|
|
|
|
intrinsicGas = intrinsicGas + gasFees[fork][GasTXCreate]
|
|
|
|
return intrinsicGas
|
|
|
|
|
|
|
|
func rpcValidateCall(call: RpcCallData, vmState: BaseVMState, gasLimit: GasInt,
|
2021-05-29 04:22:53 +00:00
|
|
|
fork: Fork): bool =
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
# This behaviour matches `validateTransaction`, used by `processTransaction`.
|
|
|
|
if vmState.cumulativeGasUsed + gasLimit > vmState.blockHeader.gasLimit:
|
|
|
|
return false
|
|
|
|
let balance = vmState.readOnlyStateDB.getBalance(call.source)
|
2021-05-29 04:22:53 +00:00
|
|
|
let gasCost = gasLimit.u256 * call.gasPrice.u256
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
if gasCost > balance or call.value > balance - gasCost:
|
|
|
|
return false
|
2021-05-29 04:22:53 +00:00
|
|
|
let intrinsicGas = rpcIntrinsicGas(call, fork)
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
if intrinsicGas > gasLimit:
|
|
|
|
return false
|
|
|
|
return true
|
|
|
|
|
2021-05-03 08:08:11 +00:00
|
|
|
proc rpcEstimateGas*(call: RpcCallData, header: BlockHeader, chain: BaseChainDB, haveGasLimit: bool): GasInt =
|
|
|
|
# TODO: handle revert and error
|
|
|
|
var
|
|
|
|
# we use current header stateRoot, unlike block validation
|
|
|
|
# which use previous block stateRoot
|
|
|
|
vmState = newBaseVMState(header.stateRoot, header, chain)
|
|
|
|
fork = toFork(chain.config, header.blockNumber)
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
gasLimit = if haveGasLimit: call.gas else: header.gasLimit - vmState.cumulativeGasUsed
|
|
|
|
|
|
|
|
# Nimbus `estimateGas` has historically checked against remaining gas in the
|
|
|
|
# current block, balance in the sender account (even if the sender is default
|
|
|
|
# account 0x00), and other limits, and returned 0 as the gas estimate if any
|
|
|
|
# checks failed. This behaviour came from how it used `processTransaction`
|
|
|
|
# which calls `validateTransaction`. For now, keep this behaviour the same.
|
|
|
|
# Compare this code with `validateTransaction`.
|
|
|
|
#
|
|
|
|
# TODO: This historically differs from `rpcDoCall` and `rpcMakeCall`. There
|
|
|
|
# are other differences in rpc_utils.nim `callData` too. Are the different
|
|
|
|
# behaviours intended, and is 0 the correct return value to mean "not enough
|
|
|
|
# gas to start"? Probably not.
|
2021-05-29 04:22:53 +00:00
|
|
|
if not rpcValidateCall(call, vmState, gasLimit, fork):
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
return 0
|
2021-05-03 08:08:11 +00:00
|
|
|
|
2021-05-29 04:22:53 +00:00
|
|
|
# Use a db transaction to save and restore the state of the database.
|
2021-05-03 08:08:11 +00:00
|
|
|
var dbTx = chain.db.beginTransaction()
|
|
|
|
defer: dbTx.dispose()
|
RPC: Change rpcEstimateGas to use the EVM without a fake transaction
Change `rpcEstimateGas` to setup and execute a computation directly, in a
similar way to `rpcDoCall` and `rpcMakeCall`, instead of constructing a fake
transaction and then validating it.
This patch does not (or should not) change any behaviour.
Although this looks a bit messy as it duplicates parts of `validateTransaction`
and `processTransaction`, proc names have been used to hopefully keep the
meanings clear, and it's just a stepping stone as those transaction functions
will be changed next. Also the behaviour of RPC `estimateGas` may not be
correct (although this patch is careful not to change it), so it's good to make
it explicit so we can see how it differs from other RPCs.
Doing this change exposed some interesting behaviour differences between the
`call` RPC and `estimateGas` RPC, which may be bugs, or may be intentional.
These differences are now obvious and explicit.
The unclear areas are not well documented by any of the clients, even Infura
which says a bit more than the others. So to find out if they are intended,
we'll have to run tests against other Ethereum services.
Guessing, on the face of it, it looks likely that RPC `call` should:
- Setup EIP2929 access lists
- Account for intrinsic gas (maybe not because zero-gas transactions are ok)
And it looks likely that RPC `estimateGas` should:
- Not return zero when an account has insufficient balance
- Maybe use a different gas cost estimate when one isn't supplied in the RPC
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-03 06:58:45 +00:00
|
|
|
|
2021-05-29 04:22:53 +00:00
|
|
|
let callResult = rpcRunComputation(vmState, call, gasLimit, some(fork), true)
|
|
|
|
return callResult.gasUsed
|
2021-05-03 16:50:47 +00:00
|
|
|
|
2021-05-17 13:01:41 +00:00
|
|
|
proc txCallEvm*(tx: Transaction, sender: EthAddress, vmState: BaseVMState, fork: Fork): GasInt =
|
|
|
|
var call = CallParams(
|
2021-05-17 09:36:34 +00:00
|
|
|
vmState: vmState,
|
|
|
|
forkOverride: some(fork),
|
|
|
|
gasPrice: tx.gasPrice,
|
2021-05-17 13:01:41 +00:00
|
|
|
gasLimit: tx.gasLimit,
|
2021-05-17 09:36:34 +00:00
|
|
|
sender: sender,
|
|
|
|
to: tx.to,
|
|
|
|
isCreate: tx.isContractCreation,
|
|
|
|
value: tx.value,
|
|
|
|
input: tx.payload
|
2021-05-17 13:01:41 +00:00
|
|
|
)
|
|
|
|
if tx.txType == AccessListTxType:
|
|
|
|
shallowCopy(call.accessList, tx.accessListTx.accessList)
|
|
|
|
return runComputation(call).gasUsed
|
2021-05-03 19:35:29 +00:00
|
|
|
|
2021-05-17 15:33:46 +00:00
|
|
|
type
|
|
|
|
AsmResult* = object
|
|
|
|
isSuccess*: bool
|
|
|
|
gasUsed*: GasInt
|
|
|
|
output*: seq[byte]
|
|
|
|
stack*: Stack
|
|
|
|
memory*: Memory
|
|
|
|
vmState*: BaseVMState
|
|
|
|
contractAddress*: EthAddress
|
|
|
|
|
|
|
|
proc asmCallEvm*(blockNumber: Uint256, chainDB: BaseChainDB, code, data: seq[byte], fork: Fork): AsmResult =
|
2021-05-03 20:31:45 +00:00
|
|
|
let
|
|
|
|
parentNumber = blockNumber - 1
|
|
|
|
parent = chainDB.getBlockHeader(parentNumber)
|
|
|
|
header = chainDB.getBlockHeader(blockNumber)
|
|
|
|
headerHash = header.blockHash
|
|
|
|
body = chainDB.getBlockBody(headerHash)
|
|
|
|
vmState = newBaseVMState(parent.stateRoot, header, chainDB)
|
|
|
|
tx = body.transactions[0]
|
|
|
|
sender = transaction.getSender(tx)
|
2021-05-17 10:02:22 +00:00
|
|
|
gasLimit = 500000000
|
|
|
|
gasUsed = 0 #tx.payload.intrinsicGas.GasInt + gasFees[fork][GasTXCreate]
|
|
|
|
|
|
|
|
# This is an odd sort of test, where some fields are taken from
|
|
|
|
# `body.transactions[0]` but other fields (like `gasLimit`) are not. Also it
|
|
|
|
# creates the new contract using `code` like `CREATE`, but then executes the
|
|
|
|
# contract like it's `CALL`.
|
|
|
|
|
|
|
|
doAssert tx.isContractCreation
|
|
|
|
let contractAddress = generateAddress(sender, vmState.readOnlyStateDB.getNonce(sender))
|
|
|
|
vmState.mutateStateDB:
|
|
|
|
db.setCode(contractAddress, code)
|
2021-05-03 20:31:45 +00:00
|
|
|
|
2021-05-17 15:33:46 +00:00
|
|
|
let callResult = runComputation(CallParams(
|
2021-05-17 10:02:22 +00:00
|
|
|
vmState: vmState,
|
2021-05-17 15:33:46 +00:00
|
|
|
forkOverride: some(fork),
|
2021-05-17 10:02:22 +00:00
|
|
|
gasPrice: tx.gasPrice,
|
|
|
|
gasLimit: gasLimit - gasUsed,
|
|
|
|
sender: sender,
|
|
|
|
to: contractAddress,
|
|
|
|
isCreate: false,
|
|
|
|
value: tx.value,
|
2021-05-17 15:33:46 +00:00
|
|
|
input: data,
|
|
|
|
noIntrinsic: true, # Don't charge intrinsic gas.
|
|
|
|
noAccessList: true, # Don't initialise EIP-2929 access list.
|
|
|
|
noGasCharge: true, # Don't charge sender account for gas.
|
|
|
|
noRefund: true # Don't apply gas refund/burn rule.
|
2021-05-17 10:02:22 +00:00
|
|
|
))
|
2021-05-03 23:34:51 +00:00
|
|
|
|
|
|
|
# Some of these are extra returned state, for testing, that a normal EVMC API
|
|
|
|
# computation doesn't return. We'll have to obtain them outside EVMC.
|
2021-05-17 15:33:46 +00:00
|
|
|
result.isSuccess = not callResult.isError
|
|
|
|
result.gasUsed = callResult.gasUsed
|
|
|
|
result.output = callResult.output
|
|
|
|
result.stack = callResult.stack
|
|
|
|
result.memory = callResult.memory
|
|
|
|
result.vmState = vmState
|
|
|
|
result.contractAddress = contractAddress
|
2021-05-04 04:54:39 +00:00
|
|
|
|
2021-05-04 14:02:16 +00:00
|
|
|
type
|
|
|
|
FixtureResult* = object
|
|
|
|
isError*: bool
|
|
|
|
error*: Error
|
Precompiles: Change precompile tests to use fixtureCallEvm
Move the EVM setup and call in precompile tests to `fixtureCallEvm` in
`call_evm`. Extra return values needed for testing are returned specially, and
the convention for reporting gas used is changed to match `asmCallEvm`.
Although the precompile tests used `execPrecompiles` before, `executeOpcodes`
does perfectly well as a substitute, allowing `fixtureCallEvm` to be shared.
_Significantly, this patch also makes `Computation` more or less an internal
type of the EVM now._
Nothing outside the EVM (except `call_evm`) needs access any more to
`Computation`, `execComputation`, `executeOpcodes` or `execPrecompiles`.
Many imports can be trimmed, some files removed, and EVMC is much closer.
(As a bonus, the functions in `call_evm` reveal what capabilities parts of the
program have needed over time, makes certain bugs and inconsistencies clearer,
and suggests how to refactor into a more useful shared entry point.)
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-05 00:55:49 +00:00
|
|
|
gasUsed*: GasInt
|
2021-05-04 14:02:16 +00:00
|
|
|
output*: seq[byte]
|
|
|
|
vmState*: BaseVMState
|
|
|
|
logEntries*: seq[Log]
|
|
|
|
|
2021-05-04 23:55:04 +00:00
|
|
|
proc fixtureCallEvm*(vmState: BaseVMState, call: RpcCallData,
|
|
|
|
origin: EthAddress, forkOverride = none(Fork)): FixtureResult =
|
2021-05-17 16:27:20 +00:00
|
|
|
let callResult = runComputation(CallParams(
|
|
|
|
vmState: vmState,
|
|
|
|
forkOverride: forkOverride,
|
|
|
|
origin: some(origin), # Differs from `rpcSetupComputation`.
|
|
|
|
gasPrice: call.gasPrice,
|
|
|
|
gasLimit: call.gas, # Differs from `rpcSetupComputation`.
|
|
|
|
sender: call.source,
|
|
|
|
to: call.to,
|
|
|
|
isCreate: call.contractCreation,
|
|
|
|
value: call.value,
|
|
|
|
input: call.data,
|
|
|
|
noIntrinsic: true, # Don't charge intrinsic gas.
|
|
|
|
noAccessList: true, # Don't initialise EIP-2929 access list.
|
|
|
|
noGasCharge: true, # Don't charge sender account for gas.
|
|
|
|
noRefund: true, # Don't apply gas refund/burn rule.
|
|
|
|
noTransfer: true, # Don't update balances, nonces, code.
|
|
|
|
))
|
2021-05-04 14:02:16 +00:00
|
|
|
|
|
|
|
# Some of these are extra returned state, for testing, that a normal EVMC API
|
|
|
|
# computation doesn't return. We'll have to obtain them outside EVMC.
|
2021-05-17 16:27:20 +00:00
|
|
|
result.isError = callResult.isError
|
|
|
|
result.error = callResult.error
|
|
|
|
result.gasUsed = callResult.gasUsed
|
|
|
|
result.output = callResult.output
|
|
|
|
result.vmState = vmState
|
|
|
|
shallowCopy(result.logEntries, callResult.logEntries)
|