diff --git a/packages/common/src/eips/2315.json b/packages/common/src/eips/2315.json new file mode 100644 index 0000000000..4e6df97cf4 --- /dev/null +++ b/packages/common/src/eips/2315.json @@ -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": {} +} \ No newline at end of file diff --git a/packages/common/src/eips/EIP2537.json b/packages/common/src/eips/2537.json similarity index 98% rename from packages/common/src/eips/EIP2537.json rename to packages/common/src/eips/2537.json index 8cfdcc97d3..08684b6810 100644 --- a/packages/common/src/eips/EIP2537.json +++ b/packages/common/src/eips/2537.json @@ -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", diff --git a/packages/common/src/eips/index.ts b/packages/common/src/eips/index.ts index ae050ea233..29a6a99455 100644 --- a/packages/common/src/eips/index.ts +++ b/packages/common/src/eips/index.ts @@ -1,5 +1,6 @@ import { eipsType } from './../types' export const EIPs: eipsType = { - 2537: require('./EIP2537.json'), + 2315: require('./2315.json'), + 2537: require('./2537.json'), } diff --git a/packages/common/src/hardforks/berlin.json b/packages/common/src/hardforks/berlin.json index c2474ade77..79770ae9f5 100644 --- a/packages/common/src/hardforks/berlin.json +++ b/packages/common/src/hardforks/berlin.json @@ -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 ] } diff --git a/packages/common/src/hardforks/byzantium.json b/packages/common/src/hardforks/byzantium.json index 78e60a9d0b..69899586d4 100644 --- a/packages/common/src/hardforks/byzantium.json +++ b/packages/common/src/hardforks/byzantium.json @@ -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": { diff --git a/packages/common/src/hardforks/chainstart.json b/packages/common/src/hardforks/chainstart.json index a1b70e3b2d..00ccca0941 100644 --- a/packages/common/src/hardforks/chainstart.json +++ b/packages/common/src/hardforks/chainstart.json @@ -1,10 +1,7 @@ { "name": "chainstart", "comment": "Start of the Ethereum main chain", - "eip": { - "url": "", - "status": "" - }, + "url": "", "status": "", "gasConfig": { "minGasLimit": { diff --git a/packages/common/src/hardforks/constantinople.json b/packages/common/src/hardforks/constantinople.json index 237ac722a8..92b90f0f59 100644 --- a/packages/common/src/hardforks/constantinople.json +++ b/packages/common/src/hardforks/constantinople.json @@ -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": { diff --git a/packages/common/src/hardforks/dao.json b/packages/common/src/hardforks/dao.json index 5fa453555f..1113511900 100644 --- a/packages/common/src/hardforks/dao.json +++ b/packages/common/src/hardforks/dao.json @@ -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": {}, diff --git a/packages/common/src/hardforks/homestead.json b/packages/common/src/hardforks/homestead.json index 09a26145a2..95a2134a84 100644 --- a/packages/common/src/hardforks/homestead.json +++ b/packages/common/src/hardforks/homestead.json @@ -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": { diff --git a/packages/common/src/hardforks/istanbul.json b/packages/common/src/hardforks/istanbul.json index 2ffc86f928..ae0e290792 100644 --- a/packages/common/src/hardforks/istanbul.json +++ b/packages/common/src/hardforks/istanbul.json @@ -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": { diff --git a/packages/common/src/hardforks/muirGlacier.json b/packages/common/src/hardforks/muirGlacier.json index 6ce61ddd4c..dfeeff2c54 100644 --- a/packages/common/src/hardforks/muirGlacier.json +++ b/packages/common/src/hardforks/muirGlacier.json @@ -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": [] } diff --git a/packages/common/src/hardforks/petersburg.json b/packages/common/src/hardforks/petersburg.json index f530f38c67..696fa164d4 100644 --- a/packages/common/src/hardforks/petersburg.json +++ b/packages/common/src/hardforks/petersburg.json @@ -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": { diff --git a/packages/common/src/hardforks/spuriousDragon.json b/packages/common/src/hardforks/spuriousDragon.json index acfc129b8c..3327482ab0 100644 --- a/packages/common/src/hardforks/spuriousDragon.json +++ b/packages/common/src/hardforks/spuriousDragon.json @@ -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": { diff --git a/packages/common/src/hardforks/tangerineWhistle.json b/packages/common/src/hardforks/tangerineWhistle.json index be6a3093fd..c2420f4f89 100644 --- a/packages/common/src/hardforks/tangerineWhistle.json +++ b/packages/common/src/hardforks/tangerineWhistle.json @@ -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": { diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index dde77ff5b9..fc32f2198c 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -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' @@ -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 @@ -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 } diff --git a/packages/common/tests/params.ts b/packages/common/tests/params.ts index 277d7aee39..a78db13736 100644 --- a/packages/common/tests/params.ts +++ b/packages/common/tests/params.ts @@ -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)