From b7bb3a26284b45aa2ab289d7c2666e5977c188cc Mon Sep 17 00:00:00 2001 From: jangko Date: Wed, 28 Dec 2022 09:48:41 +0700 Subject: [PATCH] introduce runtime EIPs management --- nimbus/common/common.nim | 25 ++++++++++- nimbus/common/eips.nim | 91 ++++++++++++++++++++++++++-------------- 2 files changed, 83 insertions(+), 33 deletions(-) diff --git a/nimbus/common/common.nim b/nimbus/common/common.nim index a09ca8bc89..cf0f31e52d 100644 --- a/nimbus/common/common.nim +++ b/nimbus/common/common.nim @@ -15,6 +15,7 @@ import ./hardforks, ./evmforks, ./genesis, + ./eips, ../utils/[utils, ec_recover], ../db/[db_chain, storage_types], ../core/[pow, clique, casper] @@ -26,7 +27,8 @@ export evmforks, hardforks, genesis, - utils + utils, + eips.EIP type SyncProgress = object @@ -75,6 +77,8 @@ type pos: CasperRef ## Proof Of Stake descriptor + eips: ForkToEIP + # ------------------------------------------------------------------------------ # Forward declarations # ------------------------------------------------------------------------------ @@ -150,6 +154,9 @@ proc init(com : CommonRef, com.pow = PowRef.new com.pos = CasperRef.new + # allow runtime configuration of EIPs + com.eips = ForkToEipList + # ------------------------------------------------------------------------------ # Public constructors # ------------------------------------------------------------------------------ @@ -204,7 +211,8 @@ proc clone*(com: CommonRef, db: TrieDatabaseRef): CommonRef = consensusType: com.consensusType, pow : com.pow, poa : com.poa, - pos : com.pos + pos : com.pos, + eips : com.eips ) proc clone*(com: CommonRef): CommonRef = @@ -462,3 +470,16 @@ proc setFork*(com: CommonRef, fork: HardFork): Hardfork = result = com.currentFork com.currentFork = fork com.consensusTransition(fork) + +# ------------------------------------------------------------------------------ +# EIPs procs +# ------------------------------------------------------------------------------ + +proc activate*(com: CommonRef, fork: HardFork, eip: EIP) = + com.eips[fork].incl eip + +proc deactivate*(com: CommonRef, fork: HardFork, eip: EIP) = + com.eips[fork].excl eip + +func activated*(com: CommonRef, eip: EIP): bool = + eip in com.eips[com.currentFork] diff --git a/nimbus/common/eips.nim b/nimbus/common/eips.nim index 9d5c169470..af114fde48 100644 --- a/nimbus/common/eips.nim +++ b/nimbus/common/eips.nim @@ -8,46 +8,75 @@ # those terms. import + stew/bitseqs, ./hardforks -#[ - * - [EIP-1153](https://eips.ethereum.org/EIPS/eip-1153) - Transient Storage Opcodes (`experimental`) - * - [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) - EIP-1559 Fee Market - * - [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315) - VM simple subroutines (`experimental`) - * - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) - BLS12-381 precompiles (`experimental`) - * - [EIP-2565](https://eips.ethereum.org/EIPS/eip-2565) - ModExp Gas Cost - * - [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) - Typed Transactions - * - [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929) - Gas cost increases for state access opcodes - * - [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) - Access List Transaction Type - * - [EIP-3198](https://eips.ethereum.org/EIPS/eip-3198) - BASEFEE opcode - * - [EIP-3529](https://eips.ethereum.org/EIPS/eip-3529) - Reduction in refunds - * - [EIP-3540](https://eips.ethereum.org/EIPS/eip-3541) - EVM Object Format (EOF) v1 (`experimental`) - * - [EIP-3541](https://eips.ethereum.org/EIPS/eip-3541) - Reject new contracts starting with the 0xEF byte - * [EIP-3651](https://eips.ethereum.org/EIPS/eip-3651) - Warm COINBASE (`experimental`) - * - [EIP-3670](https://eips.ethereum.org/EIPS/eip-3670) - EOF - Code Validation (`experimental`) - * - [EIP-3855](https://eips.ethereum.org/EIPS/eip-3855) - PUSH0 instruction (`experimental`) - * - [EIP-3860](https://eips.ethereum.org/EIPS/eip-3860) - Limit and meter initcode (`experimental`) - * - [EIP-4399](https://eips.ethereum.org/EIPS/eip-4399) - Supplant DIFFICULTY opcode with PREVRANDAO (Merge) - * [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895) - Beacon chain push withdrawals as operations (`experimental`) - * - [EIP-5133](https://eips.ethereum.org/EIPS/eip-5133) - Delaying Difficulty Bomb to mid-September 2022 -]# - type EIP* = enum - EIP3541 - EIP3670 - EIP1559 - EIP2537 - EIP4895 + EIP3540 # EVM Object Format (EOF) v1 + EIP3651 # Warm COINBASE + EIP3670 # EOF - Code Validation + EIP3855 # PUSH0 instruction + EIP3860 # Limit and meter initcode + EIP4200 # EOF - Static relative jumps + EIP4750 # EOF - Functions + EIP4895 # Beacon chain push withdrawals as operations + EIP5450 # EOF - Stack Validation + +template len(x: type EIP): int = + 1+EIP.high.int + +type + EipSet* = BitArray[EIP.len] + ForkToEIP* = array[HardFork, EipSet] + +proc incl*(x: var EipSet, y: EipSet) = + for i in 0..