2024-04-16 12:52:07 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2024 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
# at your option.
|
|
|
|
# This file may not be copied, modified, or distributed except according to
|
|
|
|
# those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
chronicles,
|
2024-10-16 01:34:12 +00:00
|
|
|
eth/common/[addresses, headers],
|
|
|
|
web3/eth_api_types,
|
2024-04-16 12:52:07 +00:00
|
|
|
../transaction/call_common,
|
2024-06-17 07:56:39 +00:00
|
|
|
../evm/types,
|
2024-06-07 08:24:32 +00:00
|
|
|
../evm/evm_errors,
|
2024-10-16 01:34:12 +00:00
|
|
|
../constants
|
2024-04-16 12:52:07 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
from ../beacon/web3_eth_conv import ethAccessList
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
const
|
2024-10-16 01:34:12 +00:00
|
|
|
ZeroAddr = ZERO_ADDRESS
|
2024-04-16 12:52:07 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
func sender*(args: TransactionArgs): Address =
|
|
|
|
args.source.get(ZeroAddr)
|
2024-04-16 12:52:07 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
func destination*(args: TransactionArgs): Address =
|
|
|
|
args.to.get(ZeroAddr)
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
proc toCallParams*(vmState: BaseVMState, args: TransactionArgs,
|
2024-07-04 13:48:36 +00:00
|
|
|
globalGasCap: GasInt, baseFee: Opt[UInt256]): EvmResult[CallParams] =
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
# Reject invalid combinations of pre- and post-1559 fee styles
|
|
|
|
if args.gasPrice.isSome and
|
|
|
|
(args.maxFeePerGas.isSome or args.maxPriorityFeePerGas.isSome):
|
2024-06-07 08:24:32 +00:00
|
|
|
return err(evmErr(EvmInvalidParam))
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
# Set default gas & gas price if none were set
|
|
|
|
var gasLimit = globalGasCap
|
|
|
|
if gasLimit == 0:
|
2024-10-16 01:34:12 +00:00
|
|
|
gasLimit = high(uint64) div 2
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
if args.gas.isSome:
|
|
|
|
gasLimit = GasInt args.gas.get()
|
|
|
|
|
|
|
|
if globalGasCap != 0 and globalGasCap < gasLimit:
|
|
|
|
warn "Caller gas above allowance, capping",
|
|
|
|
requested = gasLimit,
|
|
|
|
cap = globalGasCap,
|
|
|
|
gasLimit = globalGasCap
|
|
|
|
|
|
|
|
var gasPrice = GasInt args.gasPrice.get(0.Quantity)
|
|
|
|
if baseFee.isSome:
|
|
|
|
# A basefee is provided, necessitating EIP-1559-type execution
|
|
|
|
let maxPriorityFee = GasInt args.maxPriorityFeePerGas.get(0.Quantity)
|
|
|
|
let maxFee = GasInt args.maxFeePerGas.get(0.Quantity)
|
|
|
|
|
|
|
|
# Backfill the legacy gasPrice for EVM execution, unless we're all zeroes
|
|
|
|
if maxPriorityFee > 0 or maxFee > 0:
|
|
|
|
let baseFee = baseFee.get().truncate(GasInt)
|
|
|
|
let priorityFee = min(maxPriorityFee, maxFee - baseFee)
|
|
|
|
gasPrice = priorityFee + baseFee
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
template versionedHashes(args: TransactionArgs): seq[VersionedHash] =
|
2024-04-16 12:52:07 +00:00
|
|
|
if args.blobVersionedHashes.isSome:
|
2024-10-16 01:34:12 +00:00
|
|
|
args.blobVersionedHashes.get
|
2024-04-16 12:52:07 +00:00
|
|
|
else:
|
|
|
|
@[]
|
|
|
|
|
2024-06-07 08:24:32 +00:00
|
|
|
ok(CallParams(
|
2024-04-16 12:52:07 +00:00
|
|
|
vmState: vmState,
|
|
|
|
sender: args.sender,
|
|
|
|
to: args.destination,
|
|
|
|
isCreate: args.to.isNone,
|
|
|
|
gasLimit: gasLimit,
|
|
|
|
gasPrice: gasPrice,
|
|
|
|
value: args.value.get(0.u256),
|
|
|
|
input: args.payload(),
|
|
|
|
accessList: ethAccessList args.accessList,
|
|
|
|
versionedHashes: args.versionedHashes,
|
2024-06-07 08:24:32 +00:00
|
|
|
))
|
2024-04-16 12:52:07 +00:00
|
|
|
|
|
|
|
{.pop.}
|