From d761e5934b65efa698603c065b436a6c1c776e27 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 8 Mar 2021 09:15:20 +0100 Subject: [PATCH 1/6] ethereum-tests: updated submodule to 8.0.0 release (2021-03-07, 3f25e87) --- packages/ethereum-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ethereum-tests b/packages/ethereum-tests index 0966f56536..3f25e873a4 160000 --- a/packages/ethereum-tests +++ b/packages/ethereum-tests @@ -1 +1 @@ -Subproject commit 0966f56536511200326e5ca939385da462730240 +Subproject commit 3f25e873a442700d0024168c54a45f6a9d2dec6e From 03d00fdc41086aa7fd9dc4869453704f3ab69dc1 Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 8 Mar 2021 09:30:11 +0100 Subject: [PATCH 2/6] common: removed EIP-2315 from the Berlin HF --- packages/common/src/hardforks/berlin.json | 2 +- packages/common/tests/eips.spec.ts | 3 ++- packages/common/tests/params.spec.ts | 2 -- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/common/src/hardforks/berlin.json b/packages/common/src/hardforks/berlin.json index 14c80c0c62..baa9d71e36 100644 --- a/packages/common/src/hardforks/berlin.json +++ b/packages/common/src/hardforks/berlin.json @@ -3,5 +3,5 @@ "comment": "HF targeted for July 2020 following the Muir Glacier HF", "url": "https://eips.ethereum.org/EIPS/eip-2070", "status": "Draft", - "eips": [ 2315, 2565, 2929, 2718, 2930 ] + "eips": [ 2565, 2929, 2718, 2930 ] } diff --git a/packages/common/tests/eips.spec.ts b/packages/common/tests/eips.spec.ts index 9aa3aa244b..c11efd62c4 100644 --- a/packages/common/tests/eips.spec.ts +++ b/packages/common/tests/eips.spec.ts @@ -52,7 +52,8 @@ tape('[Common]: Initialization / Chain params', function (t: tape.Test) { c = new Common({ chain: 'rinkeby', hardfork: 'istanbul', eips: [2315] }) st.equal(c.isActivatedEIP(2315), true, 'istanbul, eips: [2315] -> true (EIP-2315)') c = new Common({ chain: 'rinkeby', hardfork: 'berlin' }) - st.equal(c.isActivatedEIP(2315), true, 'berlin, eips: [] -> true (EIP-2315)') + st.equal(c.isActivatedEIP(2929), true, 'berlin, eips: [] -> true (EIP-2929)') + st.equal(c.isActivatedEIP(2315), false, 'berlin, eips: [] -> true (EIP-2315)') st.equal(c.isActivatedEIP(2537), false, 'berlin, eips: [] -> false (EIP-2537)') st.end() diff --git a/packages/common/tests/params.spec.ts b/packages/common/tests/params.spec.ts index 74f1172ff8..b448fb86ff 100644 --- a/packages/common/tests/params.spec.ts +++ b/packages/common/tests/params.spec.ts @@ -14,8 +14,6 @@ tape('[Common]: Parameter access for param(), paramByHardfork()', function (t: t 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) From 28caab591dea8877951c99382191084dce3651ae Mon Sep 17 00:00:00 2001 From: holgerd77 Date: Mon, 8 Mar 2021 16:48:12 +0100 Subject: [PATCH 3/6] vm: added dedicated EIP opcode activation list, added EIP-2315 to the list of supported opcodes --- packages/vm/lib/evm/opcodes/codes.ts | 16 ++++++++++++---- packages/vm/lib/index.ts | 5 +++-- packages/vm/tests/api/opcodes.spec.ts | 21 +++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/vm/lib/evm/opcodes/codes.ts b/packages/vm/lib/evm/opcodes/codes.ts index ad8692dee3..e0d98bec37 100644 --- a/packages/vm/lib/evm/opcodes/codes.ts +++ b/packages/vm/lib/evm/opcodes/codes.ts @@ -240,12 +240,15 @@ const hardforkOpcodes = [ 0x47: { name: 'SELFBALANCE', isAsync: false }, // EIP 1884 }, }, +] + +const eipOpcodes = [ { - hardforkName: 'berlin', + eip: 2315, opcodes: { - 0x5c: { name: 'BEGINSUB', isAsync: false }, // EIP 2315 - 0x5d: { name: 'RETURNSUB', isAsync: false }, // EIP 2315 - 0x5e: { name: 'JUMPSUB', isAsync: false }, // EIP 2315 + 0x5c: { name: 'BEGINSUB', isAsync: false }, + 0x5d: { name: 'RETURNSUB', isAsync: false }, + 0x5e: { name: 'JUMPSUB', isAsync: false }, }, }, ] @@ -288,6 +291,11 @@ export function getOpcodesForHF(common: Common): OpcodeList { opcodeBuilder = { ...opcodeBuilder, ...hardforkOpcodes[fork].opcodes } } } + for (const eipOps of eipOpcodes) { + if (common.isActivatedEIP(eipOps.eip)) { + opcodeBuilder = { ...opcodeBuilder, ...eipOps.opcodes } + } + } /* eslint-disable-next-line no-restricted-syntax */ for (const key in opcodeBuilder) { diff --git a/packages/vm/lib/index.ts b/packages/vm/lib/index.ts index 181c1e4262..8d9dc30680 100644 --- a/packages/vm/lib/index.ts +++ b/packages/vm/lib/index.ts @@ -40,8 +40,9 @@ export interface VMOpts { * * ### Supported EIPs * + * - [EIP-2315](https://eips.ethereum.org/EIPS/eip-2315) - VM simple subroutines * - [EIP-2537](https://eips.ethereum.org/EIPS/eip-2537) (`experimental`) - BLS12-381 precompiles - * - [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929) (`experimental`) - Gas cost increases for state access opcodes + * - [EIP-2929](https://eips.ethereum.org/EIPS/eip-2929) - Gas cost increases for state access opcodes * * *Annotations:* * @@ -163,7 +164,7 @@ export default class VM extends AsyncEventEmitter { if (opts.common) { //EIPs - const supportedEIPs = [2537, 2565, 2718, 2929, 2930] + const supportedEIPs = [2315, 2537, 2565, 2718, 2929, 2930] for (const eip of opts.common.eips()) { if (!supportedEIPs.includes(eip)) { throw new Error(`${eip} is not supported by the VM`) diff --git a/packages/vm/tests/api/opcodes.spec.ts b/packages/vm/tests/api/opcodes.spec.ts index c63588d3a3..d48be50c77 100644 --- a/packages/vm/tests/api/opcodes.spec.ts +++ b/packages/vm/tests/api/opcodes.spec.ts @@ -4,6 +4,7 @@ import VM from '../../lib' tape('VM -> getActiveOpcodes()', (t) => { const CHAINID = 0x46 //istanbul opcode + const BEGINSUB = 0x5c // EIP-2315 opcode t.test('should not expose opcodes from a follow-up HF (istanbul -> petersburg)', (st) => { const common = new Common({ chain: 'mainnet', hardfork: 'petersburg' }) @@ -36,6 +37,26 @@ tape('VM -> getActiveOpcodes()', (t) => { st.end() }) + t.test('should expose opcodes when EIP is active', (st) => { + let common = new Common({ chain: 'mainnet', hardfork: 'istanbul', eips: [2315] }) + let vm = new VM({ common }) + st.equal( + vm.getActiveOpcodes().get(BEGINSUB)!.name, + 'BEGINSUB', + 'EIP-2315 opcode BEGINSUB exposed (EIP-2315 activated)' + ) + + common = new Common({ chain: 'mainnet', hardfork: 'istanbul' }) + vm = new VM({ common }) + st.equal( + vm.getActiveOpcodes().get(BEGINSUB), + undefined, + 'EIP-2315 opcode BEGINSUB not exposed (EIP-2315 not activated)' + ) + + st.end() + }) + t.test('should update opcodes on a hardfork change', async (st) => { const common = new Common({ chain: 'mainnet', hardfork: 'istanbul' }) const vm = new VM({ common }) From 813b18deae497ff36ed5a40df6176c5e9f15adec Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Mon, 8 Mar 2021 21:33:12 +0100 Subject: [PATCH 4/6] vm: fix eip2315 tests --- packages/vm/tests/api/{berlin => EIPs}/eip-2315.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename packages/vm/tests/api/{berlin => EIPs}/eip-2315.spec.ts (99%) diff --git a/packages/vm/tests/api/berlin/eip-2315.spec.ts b/packages/vm/tests/api/EIPs/eip-2315.spec.ts similarity index 99% rename from packages/vm/tests/api/berlin/eip-2315.spec.ts rename to packages/vm/tests/api/EIPs/eip-2315.spec.ts index b6e6aeaa88..8837d32ee5 100644 --- a/packages/vm/tests/api/berlin/eip-2315.spec.ts +++ b/packages/vm/tests/api/EIPs/eip-2315.spec.ts @@ -4,7 +4,7 @@ import VM from '../../../lib' import Common from '@ethereumjs/common' tape('Berlin: EIP 2315 tests', (t) => { - const common = new Common({ chain: 'mainnet', hardfork: 'berlin' }) + const common = new Common({ chain: 'mainnet', hardfork: 'berlin', eips: [2315] }) const runTest = async function (test: any, st: tape.Test) { let i = 0 From e2a03c8c99a684990ef03a21c07575a946333300 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Mon, 8 Mar 2021 22:03:24 +0100 Subject: [PATCH 5/6] common: add berlin blocks and hashes to chains --- packages/common/src/chains/goerli.json | 4 ++-- packages/common/src/chains/mainnet.json | 4 ++-- packages/common/src/chains/rinkeby.json | 4 ++-- packages/common/src/chains/ropsten.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/common/src/chains/goerli.json b/packages/common/src/chains/goerli.json index 052b76e259..b4eeecb9fc 100644 --- a/packages/common/src/chains/goerli.json +++ b/packages/common/src/chains/goerli.json @@ -70,8 +70,8 @@ }, { "name": "berlin", - "block": null, - "forkHash": null + "block": 4460644, + "forkHash": "0x757a1c47" } ], "bootstrapNodes": [ diff --git a/packages/common/src/chains/mainnet.json b/packages/common/src/chains/mainnet.json index 514e73a3c2..f6a5e8cde6 100644 --- a/packages/common/src/chains/mainnet.json +++ b/packages/common/src/chains/mainnet.json @@ -72,8 +72,8 @@ }, { "name": "berlin", - "block": null, - "forkHash": null + "block": 12244000, + "forkHash": "0xeb440f6" } ], "bootstrapNodes": [ diff --git a/packages/common/src/chains/rinkeby.json b/packages/common/src/chains/rinkeby.json index a52f3ceb98..508897c29d 100644 --- a/packages/common/src/chains/rinkeby.json +++ b/packages/common/src/chains/rinkeby.json @@ -70,8 +70,8 @@ }, { "name": "berlin", - "block": null, - "forkHash": null + "block": 8290928, + "forkHash": "0x6910c8bd" } ], "bootstrapNodes": [ diff --git a/packages/common/src/chains/ropsten.json b/packages/common/src/chains/ropsten.json index b54242514c..e217ec3c25 100644 --- a/packages/common/src/chains/ropsten.json +++ b/packages/common/src/chains/ropsten.json @@ -72,8 +72,8 @@ }, { "name": "berlin", - "block": null, - "forkHash": null + "block": 9812189, + "forkHash": "0xa157d377" } ], "bootstrapNodes": [ From ffaf9cb784e1d36c03706bd69589addc30392323 Mon Sep 17 00:00:00 2001 From: Jochem Brouwer Date: Mon, 8 Mar 2021 22:03:36 +0100 Subject: [PATCH 6/6] common: update tests to reflect berlin changes --- packages/common/tests/hardforks.spec.ts | 35 +++++++++++++------------ 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/packages/common/tests/hardforks.spec.ts b/packages/common/tests/hardforks.spec.ts index e801ea04e5..895ceb03ad 100644 --- a/packages/common/tests/hardforks.spec.ts +++ b/packages/common/tests/hardforks.spec.ts @@ -34,7 +34,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { st.equal(c.getHardforkByBlockNumber(1150000), 'homestead', msg) st.equal(c.getHardforkByBlockNumber(1400000), 'homestead', msg) st.equal(c.getHardforkByBlockNumber(9200000), 'muirGlacier', msg) - st.equal(c.getHardforkByBlockNumber(999999999999), 'muirGlacier', msg) + st.equal(c.getHardforkByBlockNumber(12244000), 'berlin', msg) + st.equal(c.getHardforkByBlockNumber(999999999999), 'berlin', msg) msg = 'should set HF correctly' @@ -42,8 +43,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { st.equal(c.setHardforkByBlockNumber(1149999), 'chainstart', msg) st.equal(c.setHardforkByBlockNumber(1150000), 'homestead', msg) st.equal(c.setHardforkByBlockNumber(1400000), 'homestead', msg) - st.equal(c.setHardforkByBlockNumber(9200000), 'muirGlacier', msg) - st.equal(c.setHardforkByBlockNumber(999999999999), 'muirGlacier', msg) + st.equal(c.setHardforkByBlockNumber(12244000), 'berlin', msg) + st.equal(c.setHardforkByBlockNumber(999999999999), 'berlin', msg) c = new Common({ chain: 'ropsten' }) st.equal(c.setHardforkByBlockNumber(0), 'tangerineWhistle', msg) @@ -107,8 +108,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { msg = 'should return correct next HF (rinkeby: byzantium -> constantinople)' st.equal(c.nextHardforkBlock('byzantium'), 3660663, msg) - msg = 'should return null if next HF is not available (rinkeby: istanbul -> berlin)' - st.equal(c.nextHardforkBlock('istanbul'), null, msg) + msg = 'should return null if next HF is not available (rinkeby: berlin -> london)' + st.equal(c.nextHardforkBlock('berlin'), null, msg) msg = 'should work correctly along the need to skip several forks (ropsten: chainstart -> (homestead) -> (dao) -> (tangerineWhistle) -> spuriousDragon)' @@ -142,8 +143,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { t.test('activeHardforks()', function (st: tape.Test) { let c = new Common({ chain: 'ropsten' }) - let msg = 'should return 9 active hardforks for Ropsten' - st.equal(c.activeHardforks().length, 9, msg) + let msg = 'should return 10 active hardforks for Ropsten' + st.equal(c.activeHardforks().length, 10, msg) msg = 'should return the correct HF data for Ropsten' st.equal(c.activeHardforks()[3]['name'], 'spuriousDragon', msg) @@ -169,24 +170,24 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { st.equal(c.activeHardforks(null, { onlySupported: true }).length, 2, msg) c = new Common({ chain: 'mainnet' }) - msg = 'should return 10 active HFs for mainnet' - st.equal(c.activeHardforks().length, 10, msg) + msg = 'should return 11 active HFs for mainnet' + st.equal(c.activeHardforks().length, 11, msg) c = new Common({ chain: 'rinkeby' }) - msg = 'should return 8 active HFs for rinkeby' - st.equal(c.activeHardforks().length, 8, msg) + msg = 'should return 9 active HFs for rinkeby' + st.equal(c.activeHardforks().length, 9, msg) c = new Common({ chain: 'goerli' }) - msg = 'should return 8 active HFs for goerli' - st.equal(c.activeHardforks().length, 8, msg) + msg = 'should return 9 active HFs for goerli' + st.equal(c.activeHardforks().length, 9, msg) st.end() }) t.test('activeHardfork()', function (st: tape.Test) { let c = new Common({ chain: 'ropsten' }) - let msg = 'should return muirGlacier as latest active HF for Ropsten' - st.equal(c.activeHardfork(), 'muirGlacier', msg) + let msg = 'should return berlin as latest active HF for Ropsten' + st.equal(c.activeHardfork(), 'berlin', msg) msg = 'should return spuriousDragon as latest active HF for Ropsten for block 10' st.equal(c.activeHardfork(10), 'spuriousDragon', msg) @@ -199,8 +200,8 @@ tape('[Common]: Hardfork logic', function (t: tape.Test) { st.equal(c.activeHardfork(null, { onlySupported: true }), 'spuriousDragon', msg) c = new Common({ chain: 'rinkeby' }) - msg = 'should return Istanbul as latest active HF for Rinkeby' - st.equal(c.activeHardfork(), 'istanbul', msg) + msg = 'should return berlin as latest active HF for Rinkeby' + st.equal(c.activeHardfork(), 'berlin', msg) st.end() })