Skip to content

Commit

Permalink
Master branch - Gray Glacier Support (#1988)
Browse files Browse the repository at this point in the history
* common: add GrayGlacier HF and EIP-5133

* block/test: add grayGlacier tests

* VM, EVM: added EIP-5133 and GrayGlacier HF support

* VM, EVM -> Simplification: limit supported EIP check and EIP docs to inner EVM (will deterministically throw on instantiation)

* EVM, VM: moved supported HF check to EVM to cover both EVM and VM

Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com>
  • Loading branch information
ScottyPoi and holgerd77 authored Jun 28, 2022
1 parent 5bcd389 commit 932f4f9
Show file tree
Hide file tree
Showing 16 changed files with 21,465 additions and 63 deletions.
2 changes: 2 additions & 0 deletions packages/block/test/difficulty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const hardforkTestData: TestData = {
arrowGlacier:
require('../../ethereum-tests/DifficultyTests/dfArrowGlacier/difficultyArrowGlacier.json')
.difficultyArrowGlacier.ArrowGlacier,
grayGlacier: require('./testdata/dfGrayGlacier/difficultyGrayGlacier.json').difficultyGrayGlacier
.GrayGlacier,
}

const chainTestData: TestData = {
Expand Down
7,056 changes: 7,056 additions & 0 deletions packages/block/test/testdata/dfGrayGlacier/difficultyGrayGlacier.json

Large diffs are not rendered by default.

4,016 changes: 4,016 additions & 0 deletions packages/block/test/testdata/dfGrayGlacier/difficultyGrayGlacierForkBlock.json

Large diffs are not rendered by default.

7,056 changes: 7,056 additions & 0 deletions packages/block/test/testdata/dfGrayGlacier/difficultyGrayGlacierMinus1.json

Large diffs are not rendered by default.

1,632 changes: 1,632 additions & 0 deletions packages/block/test/testdata/dfGrayGlacier/difficultyGrayGlacierTimeDiff1.json

Large diffs are not rendered by default.

1,632 changes: 1,632 additions & 0 deletions packages/block/test/testdata/dfGrayGlacier/difficultyGrayGlacierTimeDiff2.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/common/src/chains/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
"block": 13773000,
"forkHash": "0x20c327fc"
},
{
"name": "grayGlacier",
"block": 15050000,
"forkHash": "0xf0afd0e3"
},
{
"name": "mergeForkIdTransition",
"block": null,
Expand Down
17 changes: 17 additions & 0 deletions packages/common/src/eips/5133.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "EIP-5133",
"number": 5133,
"comment": "Delaying Difficulty Bomb to mid-September 2022",
"url": "https://eips.ethereum.org/EIPS/eip-5133",
"status": "Draft",
"minimumHardfork": "grayGlacier",
"gasConfig": {},
"gasPrices": {},
"vm": {},
"pow": {
"difficultyBombDelay": {
"v": 11400000,
"d": "the amount of blocks to delay the difficulty bomb with"
}
}
}
1 change: 1 addition & 0 deletions packages/common/src/eips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export const EIPs: { [key: number]: any } = {
3860: require('./3860.json'),
4345: require('./4345.json'),
4399: require('./4399.json'),
5133: require('./5133.json'),
}
3 changes: 2 additions & 1 deletion packages/common/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ export enum Hardfork {
Berlin = 'berlin',
London = 'london',
ArrowGlacier = 'arrowGlacier',
Shanghai = 'shanghai',
GrayGlacier = 'grayGlacier',
MergeForkIdTransition = 'mergeForkIdTransition',
Merge = 'merge',
Shanghai = 'shanghai',
}

export enum ConsensusType {
Expand Down
11 changes: 11 additions & 0 deletions packages/common/src/hardforks/grayGlacier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "grayGlacier",
"comment": "Delaying the difficulty bomb to Mid September 2022",
"url": "https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/gray-glacier.md",
"status": "Draft",
"eips": [5133],
"gasConfig": {},
"gasPrices": {},
"vm": {},
"pow": {}
}
1 change: 1 addition & 0 deletions packages/common/src/hardforks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const hardforks = [
['london', require('./london.json')],
['shanghai', require('./shanghai.json')],
['arrowGlacier', require('./arrowGlacier.json')],
['grayGlacier', require('./grayGlacier.json')],
['mergeForkIdTransition', require('./mergeForkIdTransition.json')],
['merge', require('./merge.json')],
]
8 changes: 5 additions & 3 deletions packages/common/tests/hardforks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) {
Hardfork.Berlin,
Hardfork.London,
Hardfork.ArrowGlacier,
Hardfork.GrayGlacier,
Hardfork.Shanghai,
Hardfork.Merge,
]
Expand All @@ -41,8 +42,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) {
st.equal(c.getHardforkByBlockNumber(12244000), Hardfork.Berlin, msg)
st.equal(c.getHardforkByBlockNumber(12965000), Hardfork.London, msg)
st.equal(c.getHardforkByBlockNumber(13773000), Hardfork.ArrowGlacier, msg)
st.equal(c.getHardforkByBlockNumber(999999999999), Hardfork.ArrowGlacier, msg)

st.equal(c.getHardforkByBlockNumber(15050000), Hardfork.GrayGlacier, msg)
st.equal(c.getHardforkByBlockNumber(999999999999), Hardfork.GrayGlacier, msg)
msg = 'should set HF correctly'

st.equal(c.setHardforkByBlockNumber(0), Hardfork.Chainstart, msg)
Expand All @@ -52,7 +53,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) {
st.equal(c.setHardforkByBlockNumber(12244000), Hardfork.Berlin, msg)
st.equal(c.setHardforkByBlockNumber(12965000), Hardfork.London, msg)
st.equal(c.setHardforkByBlockNumber(13773000), Hardfork.ArrowGlacier, msg)
st.equal(c.setHardforkByBlockNumber(999999999999), Hardfork.ArrowGlacier, msg)
st.equal(c.setHardforkByBlockNumber(15050000), Hardfork.GrayGlacier, msg)
st.equal(c.setHardforkByBlockNumber(999999999999), Hardfork.GrayGlacier, msg)

c = new Common({ chain: Chain.Ropsten })
st.equal(c.setHardforkByBlockNumber(0), 'tangerineWhistle', msg)
Expand Down
27 changes: 26 additions & 1 deletion packages/evm/src/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface EVMOpts {
* - [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) (`experimental`)
* - [EIP-5133](https://eips.ethereum.org/EIPS/eip-5133) - Delaying Difficulty Bomb to mid-September 2022
*
* *Annotations:*
*
Expand Down Expand Up @@ -233,7 +234,7 @@ export default class EVM extends AsyncEventEmitter<EVMEvents> implements EVMInte
// Supported EIPs
const supportedEIPs = [
1153, 1559, 2315, 2537, 2565, 2718, 2929, 2930, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
3670, 3855, 3860, 4399,
3670, 3855, 3860, 4399, 5133,
]

for (const eip of this._common.eips()) {
Expand All @@ -242,6 +243,30 @@ export default class EVM extends AsyncEventEmitter<EVMEvents> implements EVMInte
}
}

const supportedHardforks = [
Hardfork.Chainstart,
Hardfork.Homestead,
Hardfork.Dao,
Hardfork.TangerineWhistle,
Hardfork.SpuriousDragon,
Hardfork.Byzantium,
Hardfork.Constantinople,
Hardfork.Petersburg,
Hardfork.Istanbul,
Hardfork.MuirGlacier,
Hardfork.Berlin,
Hardfork.London,
Hardfork.ArrowGlacier,
Hardfork.GrayGlacier,
Hardfork.MergeForkIdTransition,
Hardfork.Merge,
]
if (!supportedHardforks.includes(this._common.hardfork() as Hardfork)) {
throw new Error(
`Hardfork ${this._common.hardfork()} not set as supported in supportedHardforks`
)
}

this._allowUnlimitedContractSize = opts.allowUnlimitedContractSize ?? false
this._customOpcodes = opts.customOpcodes
this._customPrecompiles = opts.customPrecompiles
Expand Down
26 changes: 2 additions & 24 deletions packages/vm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,8 @@ export interface VMOpts {
* - `hardfork`: `mainnet` hardforks up to the `London` hardfork
* - `eips`: `2537` (usage e.g. `eips: [ 2537, ]`)
*
* ### Supported EIPs
*
* - [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-3074](https://eips.ethereum.org/EIPS/eip-3074) - AUTH and AUTHCALL opcodes
* - [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) (`experimental`)
*
* *Annotations:*
*
* - `experimental`: behaviour can change on patch versions
* Note: check the associated `@ethereumjs/evm` instance options
* documentation for supported EIPs.
*
* ### Default Setup
*
Expand Down
35 changes: 1 addition & 34 deletions packages/vm/src/vm.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Account, Address, toType, TypeOutput } from '@ethereumjs/util'
import Blockchain from '@ethereumjs/blockchain'
import Common, { Chain, Hardfork } from '@ethereumjs/common'
import Common, { Chain } from '@ethereumjs/common'
import { StateManager, DefaultStateManager } from '@ethereumjs/statemanager'
import { default as runTx } from './runTx'
import { default as runBlock } from './runBlock'
Expand Down Expand Up @@ -86,45 +86,12 @@ export class VM extends AsyncEventEmitter<VMEvents> {
this._opts = opts

if (opts.common) {
// Supported EIPs
const supportedEIPs = [
1153, 1559, 2315, 2537, 2565, 2718, 2929, 2930, 3074, 3198, 3529, 3540, 3541, 3607, 3651,
3670, 3855, 3860, 4399,
]
for (const eip of opts.common.eips()) {
if (!supportedEIPs.includes(eip)) {
throw new Error(`EIP-${eip} is not supported by the VM`)
}
}
this._common = opts.common
} else {
const DEFAULT_CHAIN = Chain.Mainnet
this._common = new Common({ chain: DEFAULT_CHAIN })
}

const supportedHardforks = [
Hardfork.Chainstart,
Hardfork.Homestead,
Hardfork.Dao,
Hardfork.TangerineWhistle,
Hardfork.SpuriousDragon,
Hardfork.Byzantium,
Hardfork.Constantinople,
Hardfork.Petersburg,
Hardfork.Istanbul,
Hardfork.MuirGlacier,
Hardfork.Berlin,
Hardfork.London,
Hardfork.ArrowGlacier,
Hardfork.MergeForkIdTransition,
Hardfork.Merge,
]
if (!supportedHardforks.includes(this._common.hardfork() as Hardfork)) {
throw new Error(
`Hardfork ${this._common.hardfork()} not set as supported in supportedHardforks`
)
}

if (opts.stateManager) {
this.stateManager = opts.stateManager
} else {
Expand Down

0 comments on commit 932f4f9

Please sign in to comment.