Skip to content

Commit

Permalink
common: added EIP-based HF file format as preparation for Yolo v2 int…
Browse files Browse the repository at this point in the history
…egration (and other ephemeral testnets) (#876)

Co-authored-by: Ryan Ghods <[email protected]>
  • Loading branch information
holgerd77 and ryanio authored Sep 21, 2020
1 parent b1429b9 commit 38dc920
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 76 deletions.
25 changes: 25 additions & 0 deletions packages/common/src/eips/2315.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "EIP-2315",
"number": 2315,
"comment": "Simple subroutines for the EVM",
"url": "https://eips.ethereum.org/EIPS/eip-2315",
"status": "Draft",
"minimumHardfork": "berlin",
"gasConfig": {},
"gasPrices": {
"beginsub": {
"v": 2,
"d": "Base fee of the BEGINSUB opcode"
},
"returnsub": {
"v": 5,
"d": "Base fee of the RETURNSUB opcode"
},
"jumpsub": {
"v": 10,
"d": "Base fee of the JUMPSUB opcode"
}
},
"vm": {},
"pow": {}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "EIP2537",
"name": "EIP-2537",
"number": 2537,
"comment": "BLS12-381 precompiles",
"url": "https://eips.ethereum.org/EIPS/eip-2537",
"status": "Draft",
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/eips/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { eipsType } from './../types'

export const EIPs: eipsType = {
2537: require('./EIP2537.json'),
2315: require('./2315.json'),
2537: require('./2537.json'),
}
24 changes: 3 additions & 21 deletions packages/common/src/hardforks/berlin.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
{
"name": "berlin",
"comment": "HF targeted for July 2020 following the Muir Glacier HF",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-2070",
"status": "Draft"
},
"gasConfig": {},
"gasPrices": {
"beginsub": {
"v": 2,
"d": "Base fee of the BEGINSUB opcode"
},
"returnsub": {
"v": 5,
"d": "Base fee of the RETURNSUB opcode"
},
"jumpsub": {
"v": 10,
"d": "Base fee of the JUMPSUB opcode"
}
},
"vm": {},
"pow": {}
"url": "https://eips.ethereum.org/EIPS/eip-2070",
"status": "Draft",
"eips": [ 2315 ]
}
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/byzantium.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "byzantium",
"comment": "Hardfork with new precompiles, instructions and other protocol changes",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-609",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-609",
"status": "Final",
"gasConfig": {},
"gasPrices": {
"modexpGquaddivisor": {
Expand Down
5 changes: 1 addition & 4 deletions packages/common/src/hardforks/chainstart.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"name": "chainstart",
"comment": "Start of the Ethereum main chain",
"eip": {
"url": "",
"status": ""
},
"url": "",
"status": "",
"gasConfig": {
"minGasLimit": {
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/constantinople.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "constantinople",
"comment": "Postponed hardfork including EIP-1283 (SSTORE gas metering changes)",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-1013",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-1013",
"status": "Final",
"gasConfig": {},
"gasPrices": {
"netSstoreNoopGas": {
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/dao.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "dao",
"comment": "DAO rescue hardfork",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-779",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-779",
"status": "Final",
"gasConfig": {},
"gasPrices": {},
"vm": {},
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/homestead.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "homestead",
"comment": "Homestead hardfork with protocol and network changes",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-606",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-606",
"status": "Final",
"gasConfig": {},
"gasPrices": {
"delegatecall": {
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/istanbul.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "istanbul",
"comment": "HF targeted for December 2019 following the Constantinople/Petersburg HF",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-1679",
"status": "Draft"
},
"url": "https://eips.ethereum.org/EIPS/eip-1679",
"status": "Draft",
"gasConfig": {},
"gasPrices": {
"blake2Round": {
Expand Down
11 changes: 3 additions & 8 deletions packages/common/src/hardforks/muirGlacier.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"name": "muirGlacier",
"comment": "HF to delay the difficulty bomb",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-2384",
"status": "Last Call"
},
"gasConfig": {},
"gasPrices": {},
"vm": {},
"pow": {}
"url": "https://eips.ethereum.org/EIPS/eip-2384",
"status": "Final",
"eips": []
}
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/petersburg.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "petersburg",
"comment": "Aka constantinopleFix, removes EIP-1283, activate together with or after constantinople",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-1716",
"status": "Draft"
},
"url": "https://eips.ethereum.org/EIPS/eip-1716",
"status": "Draft",
"gasConfig": {},
"gasPrices": {
"netSstoreNoopGas": {
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/spuriousDragon.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "spuriousDragon",
"comment": "HF with EIPs for simple replay attack protection, EXP cost increase, state trie clearing, contract code size limit",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-607",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-607",
"status": "Final",
"gasConfig": {},
"gasPrices": {
"expByte": {
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hardforks/tangerineWhistle.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"name": "tangerineWhistle",
"comment": "Hardfork with gas cost changes for IO-heavy operations",
"eip": {
"url": "https://eips.ethereum.org/EIPS/eip-608",
"status": "Final"
},
"url": "https://eips.ethereum.org/EIPS/eip-608",
"status": "Final",
"gasConfig": {},
"gasPrices": {
"sload": {
Expand Down
26 changes: 18 additions & 8 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { buf as crc32Buffer } from 'crc-32'
import { chains as chainParams } from './chains'
import { hardforks as hardforkChanges } from './hardforks'
import { hardforks as HARDFORK_CHANGES } from './hardforks'
import { EIPs } from './eips'
import { Chain } from './types'

Expand Down Expand Up @@ -144,7 +144,7 @@ export default class Common {
throw new Error(`Hardfork ${hardfork} not set as supported in supportedHardforks`)
}
let changed = false
for (const hfChanges of hardforkChanges) {
for (const hfChanges of HARDFORK_CHANGES) {
if (hfChanges[0] === hardfork) {
this._hardfork = hardfork
changed = true
Expand Down Expand Up @@ -275,12 +275,22 @@ export default class Common {
hardfork = this._chooseHardfork(hardfork)

let value = null
for (const hfChanges of hardforkChanges) {
if (!hfChanges[1][topic]) {
throw new Error(`Topic ${topic} not defined`)
}
if (hfChanges[1][topic][name] !== undefined) {
value = hfChanges[1][topic][name].v
for (const hfChanges of HARDFORK_CHANGES) {
// EIP-referencing HF file (e.g. berlin.json)
if (hfChanges[1].hasOwnProperty('eips')) {
const hfEIPs = hfChanges[1]['eips']
for (const eip of hfEIPs) {
const valueEIP = this.paramByEIP(topic, name, eip)
value = valueEIP !== null ? valueEIP : value
}
// Paramater-inlining HF file (e.g. istanbul.json)
} else {
if (!hfChanges[1][topic]) {
throw new Error(`Topic ${topic} not defined`)
}
if (hfChanges[1][topic][name] !== undefined) {
value = hfChanges[1][topic][name].v
}
}
if (hfChanges[0] === hardfork) break
}
Expand Down
8 changes: 7 additions & 1 deletion packages/common/tests/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ tape('[Common]: Parameter access for param(), paramByHardfork()', function (t: t
let msg = 'Should return correct value when HF directly provided'
st.equal(c.paramByHardfork('gasPrices', 'ecAdd', 'byzantium'), 500, msg)

c.setHardfork('byzantium')
msg = 'Should return correct value for HF set in class'
c.setHardfork('byzantium')
st.equal(c.param('gasPrices', 'ecAdd'), 500, msg)
c.setHardfork('istanbul')
st.equal(c.param('gasPrices', 'ecAdd'), 150, msg)
c.setHardfork('muirGlacier')
st.equal(c.param('gasPrices', 'ecAdd'), 150, msg)
c.setHardfork('berlin')
st.equal(c.param('gasPrices', 'beginsub'), 2, msg)

msg = 'Should return null for non-existing value'
st.equal(c.param('gasPrices', 'notexistingvalue'), null, msg)
Expand Down

1 comment on commit 38dc920

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 38dc920 Previous: b1429b9 Ratio
Block 9422905 1956 ops/sec (±6.85%) 1764 ops/sec (±2.80%) 0.90
Block 9422906 1960 ops/sec (±9.33%) 1765 ops/sec (±2.91%) 0.90
Block 9422907 2063 ops/sec (±2.23%) 1666 ops/sec (±8.20%) 0.81
Block 9422908 2010 ops/sec (±1.57%) 1748 ops/sec (±1.26%) 0.87
Block 9422909 1672 ops/sec (±12.10%) 1730 ops/sec (±1.04%) 1.03
Block 9422910 1975 ops/sec (±2.35%) 1697 ops/sec (±1.50%) 0.86
Block 9422911 2013 ops/sec (±2.31%) 1655 ops/sec (±1.24%) 0.82
Block 9422912 1944 ops/sec (±1.89%) 1254 ops/sec (±13.98%) 0.65
Block 9422913 1798 ops/sec (±2.55%) 1633 ops/sec (±1.39%) 0.91
Block 9422914 1939 ops/sec (±1.96%) 1614 ops/sec (±1.58%) 0.83

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.