EIP-3198: add baseFee op code in nim-evm

This commit is contained in:
jangko 2021-06-27 20:18:17 +07:00
parent 1cdb30df90
commit 05e9b891f0
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
7 changed files with 17 additions and 0 deletions

View File

@ -63,6 +63,7 @@ proc setupTxContext(host: TransactionHost) =
# vmState.difficulty now unused
host.txContext.block_difficulty = vmState.blockHeader.difficulty.toEvmc
host.txContext.chain_id = vmState.chaindb.config.chainId.uint.u256.toEvmc
host.txContext.block_base_fee = vmState.blockHeader.baseFee.toEvmc
const use_evmc_glue = defined(evmc_enabled)

View File

@ -57,6 +57,12 @@ template getGasLimit*(c: Computation): GasInt =
else:
c.vmState.gasLimit
template getBaseFee*(c: Computation): Uint256 =
when evmc_enabled:
Uint256.fromEvmc c.host.getTxContext().block_base_fee
else:
c.vmState.baseFee
template getChainId*(c: Computation): uint =
when evmc_enabled:
Uint256.fromEvmc(c.host.getTxContext().chain_id).truncate(uint)

View File

@ -537,6 +537,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
GasLimit: fixed GasBase,
ChainIdOp: fixed GasBase,
SelfBalance: fixed GasLow,
BaseFee: fixed GasBase,
# 50s: Stack, Memory, Storage and Flow Operations
Pop: fixed GasBase,

View File

@ -81,6 +81,7 @@ fill_enum_holes:
ChainIdOp = 0x46, # Get current chains EIP-155 unique identifier.
SelfBalance = 0x47, # Get current contract's balance.
BaseFee = 0x48, # Get blocks base fee. EIP-3198
# 50s: Stack, Memory, Storage and Flow Operations
Pop = 0x50, # Remove item from stack.

View File

@ -384,6 +384,10 @@ op gasLimit, inline = true:
## 0x45, Get the block's gas limit
push: c.getGasLimit()
op baseFee, inline = true:
## 0x45, Get the block's gas limit
push: c.getBaseFee()
op chainId, inline = true:
## 0x46, Get current chains EIP-155 unique identifier.
push: c.getChainId()

View File

@ -251,6 +251,7 @@ let BerlinOpDispatch {.compileTime.}: array[Op, NimNode] = genBerlinJumpTable(Is
proc genLondonJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} =
result = ops
# incoming EIP-3198 and EIP-3529
result[BaseFee] = newIdentNode "baseFee"
let LondonOpDispatch {.compileTime.}: array[Op, NimNode] = genLondonJumpTable(BerlinOpDispatch)

View File

@ -141,6 +141,9 @@ method difficulty*(vmState: BaseVMState): UInt256 {.base, gcsafe.} =
method gasLimit*(vmState: BaseVMState): GasInt {.base, gcsafe.} =
vmState.blockHeader.gasLimit
method baseFee*(vmState: BaseVMState): Uint256 {.base, gcsafe.} =
vmState.blockHeader.baseFee
when defined(geth):
import db/geth_db