EIP-4399 implementation of nim-vm2
new addition: - `RANDOM` opcode - `random` field of BlockHeader(previously `mixDigest`) - `PostMerge` temporary name of this new EVM version
This commit is contained in:
parent
71aa7e4b5c
commit
d7f1d698ce
|
@ -58,6 +58,9 @@ template getBlockNumber*(c: Computation): Uint256 =
|
|||
template getDifficulty*(c: Computation): DifficultyInt =
|
||||
c.vmState.difficulty
|
||||
|
||||
template getRandom*(c: Computation): Hash256 =
|
||||
c.vmState.random
|
||||
|
||||
template getGasLimit*(c: Computation): GasInt =
|
||||
c.vmState.gasLimit
|
||||
|
||||
|
|
|
@ -730,7 +730,8 @@ const
|
|||
FkPetersburg: SpuriousGasFees,
|
||||
FkIstanbul: IstanbulGasFees,
|
||||
FkBerlin: BerlinGasFees,
|
||||
FkLondon: LondonGasFees
|
||||
FkLondon: LondonGasFees,
|
||||
FkPostMerge: LondonGasFees
|
||||
]
|
||||
|
||||
|
||||
|
@ -742,6 +743,7 @@ gasCosts(FkConstantinople, constantinople, ConstantinopleGasCosts)
|
|||
gasCosts(FkIstanbul, istanbul, IstanbulGasCosts)
|
||||
gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
||||
gasCosts(FkLondon, london, LondonGasCosts)
|
||||
gasCosts(FkPostMerge, postMerge, PostMergeGasCosts)
|
||||
|
||||
proc forkToSchedule*(fork: Fork): GasCosts =
|
||||
if fork < FkHomestead:
|
||||
|
@ -758,8 +760,10 @@ proc forkToSchedule*(fork: Fork): GasCosts =
|
|||
IstanbulGasCosts
|
||||
elif fork < FkLondon:
|
||||
BerlinGasCosts
|
||||
else:
|
||||
elif fork < FkPostMerge:
|
||||
LondonGasCosts
|
||||
else:
|
||||
PostMergeGasCosts
|
||||
|
||||
const
|
||||
## Precompile costs
|
||||
|
|
|
@ -209,6 +209,10 @@ type
|
|||
SelfDestruct = 0xff ## Halt execution and register account for later
|
||||
## deletion.
|
||||
|
||||
const
|
||||
# EIP-4399 new opcode
|
||||
Random* = Difficulty
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Verify that Op is contiguous and sym names follow some standards
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -53,6 +53,11 @@ const
|
|||
k.cpt.stack.push:
|
||||
k.cpt.getDifficulty
|
||||
|
||||
randomOp: Vm2OpFn = proc (k: var Vm2Ctx) =
|
||||
## 0x44, Get the block's randomness
|
||||
k.cpt.stack.push:
|
||||
k.cpt.getRandom
|
||||
|
||||
gasLimitOp: Vm2OpFn = proc (k: var Vm2Ctx) =
|
||||
## 0x45, Get the block's gas limit
|
||||
k.cpt.stack.push:
|
||||
|
@ -113,7 +118,7 @@ const
|
|||
post: vm2OpIgnore)),
|
||||
|
||||
(opCode: Difficulty, ## 0x44, Block difficulty
|
||||
forks: Vm2OpAllForks,
|
||||
forks: Vm2OpAllForks - Vm2OpPostMergeAndLater,
|
||||
name: "difficulty",
|
||||
info: "Get the block's difficulty",
|
||||
exec: (prep: vm2OpIgnore,
|
||||
|
@ -144,12 +149,20 @@ const
|
|||
run: selfBalanceOp,
|
||||
post: vm2OpIgnore)),
|
||||
|
||||
(opCode: BaseFee, ## 0x48, EIP-1559 Block base fee.
|
||||
(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)),
|
||||
|
||||
(opCode: Random, ## 0x44, EIP-4399 Block randomness.
|
||||
forks: Vm2OpPostMergeAndLater,
|
||||
name: "random",
|
||||
info: "Get current block's EIP-4399 randomness",
|
||||
exec: (prep: vm2OpIgnore,
|
||||
run: randomOp,
|
||||
post: vm2OpIgnore))]
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -81,6 +81,9 @@ const
|
|||
Vm2OpLondonAndLater* =
|
||||
Vm2OpBerlinAndLater - {FkBerlin}
|
||||
|
||||
Vm2OpPostMergeAndLater* =
|
||||
Vm2OpLondonAndLater - {FkLondon}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# End
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
|
@ -58,6 +58,7 @@ proc init(
|
|||
timestamp: EthTime;
|
||||
gasLimit: GasInt;
|
||||
fee: Option[Uint256];
|
||||
random: Hash256;
|
||||
miner: EthAddress;
|
||||
chainDB: BaseChainDB;
|
||||
tracer: TransactionTracer)
|
||||
|
@ -69,6 +70,7 @@ proc init(
|
|||
self.timestamp = timestamp
|
||||
self.gasLimit = gasLimit
|
||||
self.fee = fee
|
||||
self.random = random
|
||||
self.chaindb = chainDB
|
||||
self.tracer = tracer
|
||||
self.logEntries = @[]
|
||||
|
@ -83,6 +85,7 @@ proc init(
|
|||
timestamp: EthTime;
|
||||
gasLimit: GasInt;
|
||||
fee: Option[Uint256];
|
||||
random: Hash256;
|
||||
miner: EthAddress;
|
||||
chainDB: BaseChainDB;
|
||||
tracerFlags: set[TracerFlags])
|
||||
|
@ -95,6 +98,7 @@ proc init(
|
|||
timestamp = timestamp,
|
||||
gasLimit = gasLimit,
|
||||
fee = fee,
|
||||
random = random,
|
||||
miner = miner,
|
||||
chainDB = chainDB,
|
||||
tracer = tracer)
|
||||
|
@ -116,6 +120,7 @@ proc new*(
|
|||
timestamp: EthTime; ## tx env: time stamp
|
||||
gasLimit: GasInt; ## tx env: gas limit
|
||||
fee: Option[Uint256]; ## tx env: optional base fee
|
||||
random: Hash256; ## tx env: POS block randomness
|
||||
miner: EthAddress; ## tx env: coinbase(PoW) or signer(PoA)
|
||||
chainDB: BaseChainDB; ## block chain database
|
||||
tracerFlags: set[TracerFlags] = {};
|
||||
|
@ -135,6 +140,7 @@ proc new*(
|
|||
timestamp = timestamp,
|
||||
gasLimit = gasLimit,
|
||||
fee = fee,
|
||||
random = random,
|
||||
miner = miner,
|
||||
chainDB = chainDB,
|
||||
tracerFlags = tracerFlags)
|
||||
|
@ -144,6 +150,7 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
|||
timestamp: EthTime; ## tx env: time stamp
|
||||
gasLimit: GasInt; ## tx env: gas limit
|
||||
fee: Option[Uint256]; ## tx env: optional base fee
|
||||
random: Hash256; ## tx env: POS block randomness
|
||||
miner: EthAddress; ## tx env: coinbase(PoW) or signer(PoA)
|
||||
pruneTrie: bool = true): bool
|
||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
||||
|
@ -168,6 +175,7 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
|||
timestamp = timestamp,
|
||||
gasLimit = gasLimit,
|
||||
fee = fee,
|
||||
random = random,
|
||||
miner = miner,
|
||||
chainDB = db,
|
||||
tracer = tracer)
|
||||
|
@ -190,6 +198,7 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
|||
timestamp = header.timestamp,
|
||||
gasLimit = header.gasLimit,
|
||||
fee = header.fee,
|
||||
random = header.random,
|
||||
miner = self.chainDB.getMinerAddress(header),
|
||||
pruneTrie = pruneTrie)
|
||||
|
||||
|
@ -226,6 +235,7 @@ proc init*(
|
|||
header.timestamp,
|
||||
header.gasLimit,
|
||||
header.fee,
|
||||
header.random,
|
||||
chainDB.getMinerAddress(header),
|
||||
chainDB,
|
||||
tracerFlags)
|
||||
|
|
|
@ -29,6 +29,7 @@ type
|
|||
timestamp* : EthTime
|
||||
gasLimit* : GasInt
|
||||
fee* : Option[Uint256]
|
||||
random* : Hash256
|
||||
name* : string
|
||||
flags* : set[VMFlag]
|
||||
tracer* : TransactionTracer
|
||||
|
|
Loading…
Reference in New Issue