From e6be3e14e7f80f90dba2a056783449f7340c98c0 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Thu, 31 Jan 2019 13:58:47 -0330 Subject: [PATCH 1/7] Updates package.json and code to use latest ethereumjs-common version --- lib/index.js | 2 +- lib/stateManager.js | 6 +++--- package.json | 2 +- tests/api/runBlock.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/index.js b/lib/index.js index 724dd61e1e..9cecb9cc76 100644 --- a/lib/index.js +++ b/lib/index.js @@ -2,7 +2,7 @@ const Buffer = require('safe-buffer').Buffer const util = require('util') const ethUtil = require('ethereumjs-util') const StateManager = require('./stateManager.js') -const Common = require('ethereumjs-common') +const Common = require('ethereumjs-common').default const Account = require('ethereumjs-account') const AsyncEventEmitter = require('async-eventemitter') const Trie = require('merkle-patricia-tree/secure.js') diff --git a/lib/stateManager.js b/lib/stateManager.js index d9dfba26ec..2f7141842f 100644 --- a/lib/stateManager.js +++ b/lib/stateManager.js @@ -1,7 +1,7 @@ const Buffer = require('safe-buffer').Buffer const Trie = require('merkle-patricia-tree/secure.js') -const Common = require('ethereumjs-common') -const genesisStates = require('ethereumjs-common/genesisStates') +const Common = require('ethereumjs-common').default +const { genesisStateByName } = require('ethereumjs-common/dist/genesisStates') const async = require('async') const Account = require('ethereumjs-account') const Cache = require('./cache.js') @@ -481,7 +481,7 @@ proto.generateCanonicalGenesis = function (cb) { this.hasGenesisState(function (err, genesis) { if (!genesis && !err) { - self.generateGenesis(genesisStates[self._common.chainName()], cb) + self.generateGenesis(genesisStateByName(self._common.chainName()), cb) } else { cb(err) } diff --git a/package.json b/package.json index f059faa940..906673b1ce 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "async-eventemitter": "^0.2.2", "ethereumjs-account": "^2.0.3", "ethereumjs-block": "~2.1.0", - "ethereumjs-common": "^0.6.0", + "ethereumjs-common": "^1.1.0", "ethereumjs-util": "^6.0.0", "fake-merkle-patricia-tree": "^1.0.1", "functional-red-black-tree": "^1.0.1", diff --git a/tests/api/runBlock.js b/tests/api/runBlock.js index ffdd30802d..ec3da28aff 100644 --- a/tests/api/runBlock.js +++ b/tests/api/runBlock.js @@ -2,7 +2,7 @@ const { promisify } = require('util') const tape = require('tape') const Block = require('ethereumjs-block') const Transaction = require('ethereumjs-tx') -const Common = require('ethereumjs-common') +const Common = require('ethereumjs-common').default const util = require('ethereumjs-util') const runBlock = require('../../lib/runBlock') const StateManager = require('../../lib/stateManager') From e7dff19823be2a95d197b6ae2f894fc7e54629a3 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 1 Feb 2019 12:23:37 -0330 Subject: [PATCH 2/7] Update lib/ code to support petersburg hardfork --- lib/index.js | 3 ++- lib/vm/opFns.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index 9cecb9cc76..88637f8762 100644 --- a/lib/index.js +++ b/lib/index.js @@ -48,7 +48,8 @@ function VM (opts = {}) { let hardfork = opts.hardfork ? opts.hardfork : 'byzantium' let supportedHardforks = [ 'byzantium', - 'constantinople' + 'constantinople', + 'petersburg' ] this._common = new Common(chain, hardfork, supportedHardforks) diff --git a/lib/vm/opFns.js b/lib/vm/opFns.js index bb309c7a98..18756a7173 100644 --- a/lib/vm/opFns.js +++ b/lib/vm/opFns.js @@ -1082,7 +1082,7 @@ function isCreateOpCode (opName) { } function getContractStorage (runState, address, key, cb) { - if (runState._common.gteHardfork('constantinople')) { + if (runState._common.activeHardfork() === 'constantinople') { runState.storageReader.getContractStorage(address, key, cb) } else { runState.stateManager.getContractStorage(address, key, cb) @@ -1090,7 +1090,7 @@ function getContractStorage (runState, address, key, cb) { } function updateSstoreGas (runState, found, value) { - if (runState._common.gteHardfork('constantinople')) { + if (runState._common.activeHardfork() === 'constantinople') { var original = found.original var current = found.current if (current.equals(value)) { From e1652a631ce4ce805ee5925dd092f2df059d652b Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 1 Feb 2019 12:54:34 -0330 Subject: [PATCH 3/7] Update tests to cover petersburg hardfork --- package.json | 1 + tests/GeneralStateTestsRunner.js | 6 +++++- tests/tester.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 906673b1ce..6b76593d2e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "testVM": "node ./tests/tester -v", "testStateByzantium": "npm run build:dist && node ./tests/tester -s --fork='Byzantium' --dist", "testStateConstantinople": "npm run build:dist && node ./tests/tester -s --fork='Constantinople' --dist", + "testStatePetersburg": "npm run build:dist && node ./tests/tester -s --fork='Petersburg' --dist", "testBuildIntegrity": "npm run build:dist && node ./tests/tester -s --dist --test='stackOverflow'", "testBlockchain": "npm run build:dist && node --stack-size=1500 ./tests/tester -b --fork='Constantinople' --dist --excludeDir='GeneralStateTests'", "testBlockchainGeneralStateTests": "npm run build:dist && node --stack-size=1500 ./tests/tester -b --dist --dir='GeneralStateTests'", diff --git a/tests/GeneralStateTestsRunner.js b/tests/GeneralStateTestsRunner.js index 24d80d522a..500387063c 100644 --- a/tests/GeneralStateTestsRunner.js +++ b/tests/GeneralStateTestsRunner.js @@ -126,7 +126,11 @@ function runTestCase (options, testData, t, cb) { module.exports = function runStateTest (options, testData, t, cb) { try { - const testCases = parseTestCases(options.forkConfig, testData, options.data, options.gasLimit, options.value) + let aliasForkConfig + if (options.forkConfig === 'Petersburg') { + aliasForkConfig = 'ConstantinopleFix' + } + const testCases = parseTestCases(aliasForkConfig || options.forkConfig, testData, options.data, options.gasLimit, options.value) if (testCases.length > 0) { async.eachSeries(testCases, (testCase, done) => runTestCase(options, testCase, t, done), diff --git a/tests/tester.js b/tests/tester.js index 35cecee686..b85b6aac0e 100755 --- a/tests/tester.js +++ b/tests/tester.js @@ -178,7 +178,7 @@ function runTests (name, runnerArgs, cb) { testGetterArgs.skipTests = getSkipTests(argv.skip, argv.runSkipped ? 'NONE' : 'ALL') testGetterArgs.runSkipped = getSkipTests(argv.runSkipped, 'NONE') testGetterArgs.skipVM = skipVM - testGetterArgs.forkConfig = FORK_CONFIG + testGetterArgs.forkConfig = FORK_CONFIG === 'Petersburg' ? 'ConstantinopleFix' : FORK_CONFIG testGetterArgs.file = argv.file testGetterArgs.test = argv.test testGetterArgs.dir = argv.dir From d208ea746a259cc3dae899e6793739e822e28bc8 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Fri, 1 Feb 2019 12:55:13 -0330 Subject: [PATCH 4/7] Add test_state_petersburg job to circleci config --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d118278987..f55b92815d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,6 +64,15 @@ jobs: - run: name: testStateConstantinople command: npm run testStateConstantinople + test_state_petersburg: + <<: *defaults + steps: + - attach_workspace: + at: ~/project + - *restore_node_modules + - run: + name: testStatePetersburg + command: npm run testStatePetersburg test_blockchain: <<: *defaults steps: @@ -99,6 +108,9 @@ workflows: - test_state_constantinople: requires: - install + - test_state_petersburg: + requires: + - install - test_blockchain: requires: - install From 1b31eadcd4ffc4caebd1f209d2370d860e5da685 Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Tue, 5 Feb 2019 09:26:56 -0330 Subject: [PATCH 5/7] Make handling of petersburg fork names case agnostic and abstract fork alias handling logic in tests. --- tests/GeneralStateTestsRunner.js | 12 +++++------- tests/tester.js | 5 ++++- tests/util.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/GeneralStateTestsRunner.js b/tests/GeneralStateTestsRunner.js index 500387063c..408a5688c3 100644 --- a/tests/GeneralStateTestsRunner.js +++ b/tests/GeneralStateTestsRunner.js @@ -3,6 +3,7 @@ const testUtil = require('./util') const Trie = require('merkle-patricia-tree/secure') const ethUtil = require('ethereumjs-util') const BN = ethUtil.BN +const { getRequiredForkConfigAlias } = require('./util') function parseTestCases (forkConfig, testData, data, gasLimit, value) { let testCases = [] @@ -125,22 +126,19 @@ function runTestCase (options, testData, t, cb) { } module.exports = function runStateTest (options, testData, t, cb) { + const forkConfig = getRequiredForkConfigAlias(options.forkConfig) try { - let aliasForkConfig - if (options.forkConfig === 'Petersburg') { - aliasForkConfig = 'ConstantinopleFix' - } - const testCases = parseTestCases(aliasForkConfig || options.forkConfig, testData, options.data, options.gasLimit, options.value) + const testCases = parseTestCases(forkConfig, testData, options.data, options.gasLimit, options.value) if (testCases.length > 0) { async.eachSeries(testCases, (testCase, done) => runTestCase(options, testCase, t, done), cb) } else { - t.comment(`No ${options.forkConfig} post state defined, skip test`) + t.comment(`No ${forkConfig} post state defined, skip test`) cb() } } catch (e) { - t.fail('error running test case for fork: ' + options.forkConfig) + t.fail('error running test case for fork: ' + forkConfig) console.log('error:', e) cb() } diff --git a/tests/tester.js b/tests/tester.js index b85b6aac0e..474be46cfd 100755 --- a/tests/tester.js +++ b/tests/tester.js @@ -5,6 +5,9 @@ const async = require('async') const tape = require('tape') const testing = require('ethereumjs-testing') const FORK_CONFIG = argv.fork || 'Byzantium' +const { + getRequiredForkConfigAlias +} = require('./util') // tests which should be fixed const skipBroken = [ 'ExtCodeCopyTargetRangeLongerThanCodeTests', // temporary till fixed (2018-11-14) @@ -178,7 +181,7 @@ function runTests (name, runnerArgs, cb) { testGetterArgs.skipTests = getSkipTests(argv.skip, argv.runSkipped ? 'NONE' : 'ALL') testGetterArgs.runSkipped = getSkipTests(argv.runSkipped, 'NONE') testGetterArgs.skipVM = skipVM - testGetterArgs.forkConfig = FORK_CONFIG === 'Petersburg' ? 'ConstantinopleFix' : FORK_CONFIG + testGetterArgs.forkConfig = getRequiredForkConfigAlias(FORK_CONFIG) testGetterArgs.file = argv.file testGetterArgs.test = argv.test testGetterArgs.dir = argv.dir diff --git a/tests/util.js b/tests/util.js index 65a2e1a8d8..0968635fcb 100644 --- a/tests/util.js +++ b/tests/util.js @@ -393,3 +393,15 @@ exports.setupPreConditions = function (state, testData, done) { ], callback) }, done) } + +/** + * Returns an alias for specified hardforks to meet test dependencies requirements/assumptions. + * @param {String} forkConfig - the name of the hardfork for which an alias should be returned + * @returns {String} Either an alias of the forkConfig param, or the forkConfig param itself + */ +exports.getRequiredForkConfigAlias = function (forkConfig) { + if (String(forkConfig).match(/^petersburg$/i)) { + return 'ConstantinopleFix' + } + return forkConfig +} From ceb17876507b8c4565d4d08c7c05b194bbf6092a Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Wed, 6 Feb 2019 05:19:22 -0330 Subject: [PATCH 6/7] Update logic for checking for constantinople in opFns.js to handle multiple supported forks --- lib/vm/opFns.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vm/opFns.js b/lib/vm/opFns.js index 18756a7173..265e67c35b 100644 --- a/lib/vm/opFns.js +++ b/lib/vm/opFns.js @@ -1082,7 +1082,7 @@ function isCreateOpCode (opName) { } function getContractStorage (runState, address, key, cb) { - if (runState._common.activeHardfork() === 'constantinople') { + if (runState._common.hardfork() === 'constantinople') { runState.storageReader.getContractStorage(address, key, cb) } else { runState.stateManager.getContractStorage(address, key, cb) @@ -1090,7 +1090,7 @@ function getContractStorage (runState, address, key, cb) { } function updateSstoreGas (runState, found, value) { - if (runState._common.activeHardfork() === 'constantinople') { + if (runState._common.hardfork() === 'constantinople') { var original = found.original var current = found.current if (current.equals(value)) { From 3d8f14f3e7ca4c28c83d852afffa12e7b9c22abe Mon Sep 17 00:00:00 2001 From: Dan Miller Date: Wed, 6 Feb 2019 10:40:44 -0330 Subject: [PATCH 7/7] Update ethereumjs-block to 2.2.0 and ethereumjs-blockchain to 3.4.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6b76593d2e..b42258732b 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "async": "^2.1.2", "async-eventemitter": "^0.2.2", "ethereumjs-account": "^2.0.3", - "ethereumjs-block": "~2.1.0", + "ethereumjs-block": "~2.2.0", "ethereumjs-common": "^1.1.0", "ethereumjs-util": "^6.0.0", "fake-merkle-patricia-tree": "^1.0.1", @@ -51,7 +51,7 @@ "babel-preset-env": "^1.6.1", "coveralls": "^3.0.0", "documentation": "^8.1.2", - "ethereumjs-blockchain": "^3.3.3", + "ethereumjs-blockchain": "^3.4.0", "ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.2.7", "ethereumjs-tx": "1.3.7", "level": "^4.0.0",