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

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

View File

@ -61,6 +61,9 @@ template getDifficulty*(c: Computation): DifficultyInt =
template getGasLimit*(c: Computation): GasInt =
c.vmState.gasLimit
template getBaseFee*(c: Computation): Uint256 =
c.vmState.baseFee
template getChainId*(c: Computation): uint =
c.vmState.chaindb.config.chainId.uint

View File

@ -507,6 +507,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

@ -103,8 +103,9 @@ type
ChainIdOp = 0x46, ## Get current chains EIP-155 unique identifier.
SelfBalance = 0x47, ## Get current contract's balance.
BaseFee = 0x48, ## Get blocks base fee. EIP-3198
Nop0x48, Nop0x49, Nop0x4A, Nop0x4B, Nop0x4C, Nop0x4D,
Nop0x49, Nop0x4A, Nop0x4B, Nop0x4C, Nop0x4D,
Nop0x4E, Nop0x4F, ## ..
# 50s: Stack, Memory, Storage and Flow Operations

View File

@ -68,6 +68,11 @@ const
k.cpt.stack.push:
k.cpt.getBalance(k.cpt.msg.contractAddress)
baseFeeOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x48, Get the block's base fee.
k.cpt.stack.push:
k.cpt.getBaseFee
# ------------------------------------------------------------------------------
# Public, op exec table entries
# ------------------------------------------------------------------------------
@ -137,6 +142,14 @@ const
info: "Get current contract's balance",
exec: (prep: vm2OpIgnore,
run: selfBalanceOp,
post: vm2OpIgnore)),
(opCode: BaseFee, ## 0x48, EIP-1559 Block base fee.
forks: Vm2OpLondonAndLater,
name: "baseFee",
info: "Get current block's EIP-1559 base fee",
exec: (prep: vm2OpIgnore,
run: baseFeeOp,
post: vm2OpIgnore))]
# ------------------------------------------------------------------------------

View File

@ -129,6 +129,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