ethereumjs-vm
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -8,2 +8,10 @@ # Changelog | ||
## [2.3.2] - 2017-10-29 | ||
- Better handling of ``rustbn.js`` exceptions | ||
- Fake (default if non-provided) blockchain fixes | ||
- Testing improvements (separate skip lists) | ||
- Minor optimizations and bug fixes | ||
[2.3.2]: https://github.com/ethereumjs/ethereumjs-vm/compare/v2.3.1...v2.3.2 | ||
## [2.3.1] - 2017-10-11 | ||
@@ -10,0 +18,0 @@ - ``Byzantium`` compatible |
@@ -5,6 +5,13 @@ const Buffer = require('safe-buffer').Buffer | ||
module.exports = { | ||
getBlock: function (n, cb) { | ||
// FIXME: this will fail on block numbers >53 bits | ||
var hash = utils.sha3(Buffer.from(utils.bufferToInt(n).toString(), 'utf8')) | ||
getBlock: function (blockTag, cb) { | ||
var hash | ||
if (Buffer.isBuffer(blockTag)) { | ||
hash = utils.sha3(blockTag) | ||
} else if (Number.isInteger(blockTag)) { | ||
hash = utils.sha3('0x' + utils.toBuffer(blockTag).toString('hex')) | ||
} else { | ||
cb(new Error('Unknown blockTag type')) | ||
} | ||
var block = { | ||
@@ -17,3 +24,7 @@ hash: function () { | ||
cb(null, block) | ||
}, | ||
delBlock: function (hash, cb) { | ||
cb(null) | ||
} | ||
} |
@@ -870,3 +870,3 @@ const Buffer = require('safe-buffer').Buffer | ||
function subMemUsage (runState, offset, length) { | ||
// abort if no usage | ||
// YP (225): access with zero length will not extend the memory | ||
if (!length) return | ||
@@ -885,3 +885,2 @@ | ||
if (newMemoryWordCount <= runState.memoryWordCount) return | ||
runState.memoryWordCount = newMemoryWordCount | ||
@@ -898,2 +897,4 @@ const words = new BN(newMemoryWordCount) | ||
} | ||
runState.memoryWordCount = newMemoryWordCount | ||
} | ||
@@ -913,2 +914,8 @@ | ||
subMemUsage(runState, offset, length) | ||
// shortcut | ||
if (length === 0) { | ||
return new Buffer('') | ||
} | ||
var loaded = runState.memory.slice(offset, offset + length) | ||
@@ -935,2 +942,7 @@ // fill the remaining lenth with zeros | ||
// shortcut | ||
if (length === 0) { | ||
return | ||
} | ||
var valLength = Math.min(val.length, length) | ||
@@ -937,0 +949,0 @@ |
@@ -5,4 +5,7 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
var results = {} | ||
@@ -9,0 +12,0 @@ |
@@ -5,4 +5,7 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
var results = {} | ||
@@ -9,0 +12,0 @@ var data = opts.data |
@@ -5,4 +5,7 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
var results = {} | ||
@@ -9,0 +12,0 @@ var data = opts.data |
@@ -5,4 +5,7 @@ const utils = require('ethereumjs-util') | ||
const error = require('../constants.js').ERROR | ||
const assert = require('assert') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
var results = {} | ||
@@ -9,0 +12,0 @@ var data = opts.data |
@@ -5,2 +5,3 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
@@ -75,2 +76,4 @@ const Gquaddivisor = fees.modexpGquaddivisor.v | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
var results = {} | ||
@@ -77,0 +80,0 @@ var data = opts.data |
@@ -5,2 +5,3 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
@@ -11,2 +12,4 @@ const bn128Module = require('rustbn.js') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
let results = {} | ||
@@ -25,9 +28,6 @@ let data = opts.data | ||
try { | ||
let returnData = ecAddPrecompile(inputHexStr) | ||
results.return = Buffer.from(returnData, 'hex') | ||
results.exception = 1 | ||
} catch (e) { | ||
console.log('exception in ecAdd precompile is expected. ignore previous panic...') | ||
// console.log(e) | ||
let returnData = ecAddPrecompile(inputHexStr) | ||
// check ecadd success or failure by comparing the output length | ||
if (returnData.length !== 128) { | ||
results.return = Buffer.alloc(0) | ||
@@ -37,2 +37,5 @@ results.exception = 0 | ||
results.exceptionError = error.OUT_OF_GAS | ||
} else { | ||
results.return = Buffer.from(returnData, 'hex') | ||
results.exception = 1 | ||
} | ||
@@ -39,0 +42,0 @@ |
@@ -5,2 +5,3 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
@@ -11,2 +12,4 @@ const bn128Module = require('rustbn.js') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
let results = {} | ||
@@ -26,11 +29,11 @@ let data = opts.data | ||
try { | ||
let returnData = ecMulPrecompile(inputHexStr) | ||
let returnData = ecMulPrecompile(inputHexStr) | ||
// check ecmul success or failure by comparing the output length | ||
if (returnData.length !== 128) { | ||
results.return = Buffer.alloc(0) | ||
results.exception = 0 | ||
} else { | ||
results.return = Buffer.from(returnData, 'hex') | ||
results.exception = 1 | ||
} catch (e) { | ||
console.log('exception in ecMul precompile is expected. ignore previous panic...') | ||
// console.log(e) | ||
results.return = Buffer.alloc(0) | ||
results.exception = 0 | ||
} | ||
@@ -37,0 +40,0 @@ |
@@ -5,2 +5,3 @@ const utils = require('ethereumjs-util') | ||
const fees = require('ethereum-common') | ||
const assert = require('assert') | ||
@@ -11,2 +12,4 @@ const bn128Module = require('rustbn.js') | ||
module.exports = function (opts) { | ||
assert(opts.data) | ||
let results = {} | ||
@@ -29,9 +32,6 @@ let data = opts.data | ||
try { | ||
let returnData = ecPairingPrecompile(inputHexStr) | ||
results.return = Buffer.from(returnData, 'hex') | ||
results.exception = 1 | ||
} catch (e) { | ||
console.log('exception in ecPairing precompile is expected, ignore previous panic...') | ||
// console.log(e) | ||
let returnData = ecPairingPrecompile(inputHexStr) | ||
// check ecpairing success or failure by comparing the output length | ||
if (returnData.length !== 64) { | ||
results.return = Buffer.alloc(0) | ||
@@ -41,2 +41,5 @@ results.gasUsed = opts.gasLimit | ||
results.exception = 0 | ||
} else { | ||
results.return = Buffer.from(returnData, 'hex') | ||
results.exception = 1 | ||
} | ||
@@ -43,0 +46,0 @@ |
@@ -12,2 +12,4 @@ const async = require('async') | ||
self.blockchain = self.stateManager.blockchain | ||
// parse arguments | ||
@@ -21,3 +23,3 @@ if (typeof blockchain === 'function') { | ||
// setup blockchain iterator | ||
this.stateManager.blockchain.iterator('vm', processBlock, cb) | ||
self.blockchain.iterator('vm', processBlock, cb) | ||
function processBlock (block, reorg, cb) { | ||
@@ -33,3 +35,3 @@ async.series([ | ||
if (!headBlock || reorg) { | ||
self.stateManager.blockchain.getBlock(block.header.parentHash, function (err, parentBlock) { | ||
self.blockchain.getBlock(block.header.parentHash, function (err, parentBlock) { | ||
parentState = parentBlock.header.stateRoot | ||
@@ -59,3 +61,3 @@ // generate genesis state if we are at the genesis block | ||
console.log('Invalid block error:', err) | ||
self.stateManager.blockchain.delBlock(block.header.hash(), cb) | ||
self.blockchain.delBlock(block.header.hash(), cb) | ||
} else { | ||
@@ -62,0 +64,0 @@ // set as new head block |
{ | ||
"name": "ethereumjs-vm", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "an ethereum VM implementation", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"merkle-patricia-tree": "^2.1.2", | ||
"rustbn.js": "~0.1.0", | ||
"rustbn.js": "~0.1.1", | ||
"safe-buffer": "^5.1.1" | ||
@@ -19,0 +19,0 @@ }, |
@@ -213,2 +213,7 @@ # SYNOPSIS | ||
For a wider picture about how to use tests to implement EIPs you can have a look at this [reddit post](https://www.reddit.com/r/ethereum/comments/6kc5g3/ethereumjs_team_is_seeking_contributors/) | ||
or the associated YouTube video introduction to [core development with Ethereumjs-vm](https://www.youtube.com/watch?v=L0BVDl6HZzk&feature=youtu.be). | ||
#### Running different Test Types | ||
Running all the tests: | ||
@@ -228,2 +233,4 @@ | ||
#### Running Specific Tests | ||
Running all the blockchain tests in a file: | ||
@@ -247,16 +254,21 @@ | ||
Compare TAP output from blockchain/state tests and produces concise diff of the differences between them (example): | ||
``` | ||
curl https://gist.githubusercontent.com/jwasinger/6cef66711b5e0787667ceb3db6bea0dc/raw/0740f03b4ce90d0955d5aba1e0c30ce698c7145a/gistfile1.txt > output-wip-byzantium.txt | ||
curl https://gist.githubusercontent.com/jwasinger/e7004e82426ff0a7137a88d273f11819/raw/66fbd58722747ebe4f7006cee59bbe22461df8eb/gistfile1.txt > output-master.txt | ||
python utils/diffTestOutput.py output-wip-byzantium.txt output-master.txt | ||
``` | ||
Run a state test from a specified source file not under the ``tests`` directory: | ||
`node ./tests/tester -s --customStateTest='{path_to_file}'` | ||
For a wider picture about how to use tests to implement EIPs you can have a look at this [reddit post](https://www.reddit.com/r/ethereum/comments/6kc5g3/ethereumjs_team_is_seeking_contributors/) | ||
or the associated YouTube video introduction to [core development with Ethereumjs-vm](https://www.youtube.com/watch?v=L0BVDl6HZzk&feature=youtu.be). | ||
#### Skipping Tests | ||
There are three types of skip lists (``BROKEN``, ``PERMANENT`` and ``SLOW``) which | ||
can be found in ``tests/tester.js``. By default tests from all skip lists are omitted. | ||
You can change this behaviour with: | ||
`node tests/tester -s --skip=BROKEN,PERMANENT`˘ | ||
to skip only the ``BROKEN`` and ``PERMANENT`` tests and include the ``SLOW`` tests. | ||
There are also the keywords ``NONE`` or ``ALL`` for convenience. | ||
It is also possible to only run the tests from the skip lists: | ||
`node tests/tester -s runSkipped=SLOW` | ||
### Debugging | ||
@@ -272,4 +284,12 @@ | ||
Compare TAP output from blockchain/state tests and produces concise diff of the differences between them (example): | ||
``` | ||
curl https://gist.githubusercontent.com/jwasinger/6cef66711b5e0787667ceb3db6bea0dc/raw/0740f03b4ce90d0955d5aba1e0c30ce698c7145a/gistfile1.txt > output-wip-byzantium.txt | ||
curl https://gist.githubusercontent.com/jwasinger/e7004e82426ff0a7137a88d273f11819/raw/66fbd58722747ebe4f7006cee59bbe22461df8eb/gistfile1.txt > output-master.txt | ||
python utils/diffTestOutput.py output-wip-byzantium.txt output-master.txt | ||
``` | ||
# LICENSE | ||
[MPL-2.0](https://www.mozilla.org/MPL/2.0/) |
@@ -6,5 +6,5 @@ const argv = require('minimist')(process.argv.slice(2)) | ||
const FORK_CONFIG = argv.fork || 'Byzantium' | ||
const skip = [ | ||
// tests which should be fixed | ||
const skipBroken = [ | ||
'CreateHashCollision', // impossible hash collision on generating address | ||
'SuicidesMixingCoinbase', // sucides to the coinbase, since we run a blockLevel we create coinbase account. | ||
'TransactionMakeAccountBalanceOverflow', | ||
@@ -17,21 +17,2 @@ 'RecursiveCreateContracts', | ||
'QuadraticComplexitySolidity_CallDataCopy', // tests hash collisoin, sending from a contract | ||
'Call50000', // slow | ||
'Call50000_ecrec', // slow | ||
'Call50000_identity', // slow | ||
'Call50000_identity2', // slow | ||
'Call50000_sha256', // slow | ||
'Call50000_rip160', // slow | ||
'Call50000bytesContract50_1', // slow | ||
'Call50000bytesContract50_2', | ||
'Call1MB1024Calldepth', // slow | ||
'static_Call1MB1024Calldepth', // slow | ||
'static_Call50000', // slow | ||
'static_Call50000_ecrec', | ||
'static_Call50000_identity', | ||
'static_Call50000_identity2', | ||
'static_Call50000_rip160', | ||
'static_Return50000_2', | ||
'Callcode50000', // slow | ||
'Return50000', // slow | ||
'Return50000_2', // slow | ||
'uncleBlockAtBlock3AfterBlock3', | ||
@@ -53,3 +34,2 @@ 'ForkUncle', // correct behaviour unspecified (?) | ||
'static_CreateHashCollision', // impossible hash collision on generating address | ||
'static_SuicidesMixingCoinbase', // sucides to the coinbase, since we run a blockLevel we create coinbase account. | ||
'static_TransactionMakeAccountBalanceOverflow', | ||
@@ -62,14 +42,2 @@ 'static_RecursiveCreateContracts', | ||
'static_QuadraticComplexitySolidity_CallDataCopy', // tests hash collisoin, sending from a contract | ||
'static_Call50000', // slow | ||
'static_Call50000_ecrec', // slow | ||
'static_Call50000_identity', // slow | ||
'static_Call50000_identity2', // slow | ||
'static_Call50000_sha256', // slow | ||
'static_Call50000_rip160', // slow | ||
'static_Call50000bytesContract50_1', // slow | ||
'static_Call50000bytesContract50_2', | ||
'static_Call1MB1024Calldepth', // slow | ||
'static_Callcode50000', // slow | ||
'static_Return50000', // slow | ||
'static_Return50000_2', // slow | ||
'static_uncleBlockAtBlock3AfterBlock3', | ||
@@ -87,2 +55,41 @@ 'static_ForkUncle', // correct behaviour unspecified (?) | ||
] | ||
// tests skipped due to system specifics / design considerations | ||
const skipPermanent = [ | ||
'SuicidesMixingCoinbase', // sucides to the coinbase, since we run a blockLevel we create coinbase account. | ||
'static_SuicidesMixingCoinbase' // sucides to the coinbase, since we run a blockLevel we create coinbase account. | ||
] | ||
// tests running slow (run from time to time) | ||
const skipSlow = [ | ||
'Call50000', // slow | ||
'Call50000_ecrec', // slow | ||
'Call50000_identity', // slow | ||
'Call50000_identity2', // slow | ||
'Call50000_sha256', // slow | ||
'Call50000_rip160', // slow | ||
'Call50000bytesContract50_1', // slow | ||
'Call50000bytesContract50_2', | ||
'Call1MB1024Calldepth', // slow | ||
'static_Call1MB1024Calldepth', // slow | ||
'static_Call50000', // slow | ||
'static_Call50000_ecrec', | ||
'static_Call50000_identity', | ||
'static_Call50000_identity2', | ||
'static_Call50000_rip160', | ||
'static_Return50000_2', | ||
'Callcode50000', // slow | ||
'Return50000', // slow | ||
'Return50000_2', // slow | ||
'static_Call50000', // slow | ||
'static_Call50000_ecrec', // slow | ||
'static_Call50000_identity', // slow | ||
'static_Call50000_identity2', // slow | ||
'static_Call50000_sha256', // slow | ||
'static_Call50000_rip160', // slow | ||
'static_Call50000bytesContract50_1', // slow | ||
'static_Call50000bytesContract50_2', | ||
'static_Call1MB1024Calldepth', // slow | ||
'static_Callcode50000', // slow | ||
'static_Return50000', // slow | ||
'static_Return50000_2' // slow | ||
] | ||
@@ -182,5 +189,29 @@ /* | ||
function getSkipTests (choices, defaultChoice) { | ||
let skipTests = [] | ||
if (!choices) { | ||
choices = defaultChoice | ||
} | ||
choices = choices.toLowerCase() | ||
if (choices !== 'none') { | ||
let choicesList = choices.split(',') | ||
let all = choicesList.includes('all') | ||
if (all || choicesList.includes('broken')) { | ||
skipTests = skipTests.concat(skipBroken) | ||
} | ||
if (all || choicesList.includes('permanent')) { | ||
skipTests = skipTests.concat(skipPermanent) | ||
} | ||
if (all || choicesList.includes('slow')) { | ||
skipTests = skipTests.concat(skipSlow) | ||
} | ||
} | ||
return skipTests | ||
} | ||
function runTests (name, runnerArgs, cb) { | ||
let testGetterArgs = {} | ||
testGetterArgs.skipTests = skip | ||
testGetterArgs.skipTests = getSkipTests(argv.skip, argv.runSkipped ? 'NONE' : 'ALL') | ||
testGetterArgs.runSkipped = getSkipTests(argv.runSkipped, 'NONE') | ||
testGetterArgs.skipVM = skipVM | ||
@@ -234,4 +265,10 @@ testGetterArgs.forkConfig = FORK_CONFIG | ||
} else { | ||
t.comment(`file: ${fileName} test: ${testName}`) | ||
runner(runnerArgs, test, t, resolve) | ||
let runSkipped = testGetterArgs.runSkipped | ||
let inRunSkipped = runSkipped.includes(fileName) | ||
if (runSkipped.length === 0 || inRunSkipped) { | ||
t.comment(`file: ${fileName} test: ${testName}`) | ||
runner(runnerArgs, test, t, resolve) | ||
} else { | ||
resolve() | ||
} | ||
} | ||
@@ -238,0 +275,0 @@ }).catch(err => console.log(err)) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2065645
50522
292
Updatedrustbn.js@~0.1.1