Skip to content

Commit 230c083

Browse files
authored
Merge branch 'master' into patch-3
2 parents 6192663 + 9eb779f commit 230c083

File tree

12 files changed

+716
-372
lines changed

12 files changed

+716
-372
lines changed

.circleci/config.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2
33
defaults: &defaults
44
working_directory: ~/project/ethereumjs-vm
55
docker:
6-
- image: circleci/node:8
6+
- image: circleci/node:8-browsers
77
restore_node_modules: &restore_node_modules
88
restore_cache:
99
name: Restore node_modules cache
@@ -46,6 +46,15 @@ jobs:
4646
- run:
4747
name: testAPI
4848
command: npm run testAPI
49+
test_api_browser:
50+
<<: *defaults
51+
steps:
52+
- attach_workspace:
53+
at: ~/project
54+
- *restore_node_modules
55+
- run:
56+
name: testAPI:browser
57+
command: npm run testAPI:browser
4958
test_state_byzantium:
5059
<<: *defaults
5160
steps:
@@ -102,6 +111,9 @@ workflows:
102111
- test_api:
103112
requires:
104113
- install
114+
- test_api_browser:
115+
requires:
116+
- install
105117
- test_state_byzantium:
106118
requires:
107119
- install

karma.conf.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Karma configuration
2+
// Generated on Fri Mar 01 2019 22:02:29 GMT+0100 (CET)
3+
4+
module.exports = function (config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: ['browserify', 'detectBrowsers', 'tap'],
13+
14+
// list of files / patterns to load in the browser
15+
files: [
16+
'./tests/api/**/*.js'
17+
],
18+
19+
// list of files / patterns to exclude
20+
// currently failing tests, open separate PRs to fix
21+
exclude: [
22+
'./tests/api/state/stateManager.js', // 4, "# should clear the cache when the state root is set"
23+
'./tests/api/state/storageReader.js', // 1, "# should get value from stateManager"
24+
'./tests/api/index.js', // 11, "# should run blockchain with mocked runBlock" not working"
25+
'./tests/api/runBlock.js', // 3, "# should fail when runTx fails"
26+
'./tests/api/runBlockchain.js' // 2, "# should run with valid and invalid blocks"
27+
],
28+
29+
// preprocess matching files before serving them to the browser
30+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
31+
preprocessors: {
32+
'./tests/api/**/*.js': [ 'browserify' ]
33+
},
34+
35+
// test results reporter to use
36+
// possible values: 'dots', 'progress'
37+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
38+
reporters: ['progress'],
39+
40+
// web server port
41+
port: 9876,
42+
43+
// enable / disable colors in the output (reporters and logs)
44+
colors: true,
45+
46+
// level of logging
47+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
48+
logLevel: config.LOG_INFO,
49+
50+
// enable / disable watching file and executing tests whenever any file changes
51+
autoWatch: false,
52+
53+
// start these browsers
54+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
55+
browsers: ['Firefox'],
56+
57+
// Continuous Integration mode
58+
// if true, Karma captures browsers, runs the tests and exits
59+
singleRun: true,
60+
61+
// karma-detect-browsers plugin config
62+
detectBrowsers: {
63+
enabled: true,
64+
usePhantomJS: false,
65+
postDetection: function (availableBrowsers) {
66+
return [ 'Firefox' ]
67+
}
68+
},
69+
70+
// Concurrency level
71+
// how many browser should be started simultaneous
72+
concurrency: Infinity
73+
})
74+
}

lib/runCode.js

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Block = require('ethereumjs-block')
1818
const lookupOpInfo = require('./vm/opcodes.js')
1919
const opFns = require('./vm/opFns.js')
2020
const Memory = require('./vm/memory')
21+
const Stack = require('./vm/stack')
2122
const exceptions = require('./exceptions.js')
2223
const { StorageReader } = require('./state')
2324
const setImmediate = require('timers').setImmediate
@@ -79,7 +80,7 @@ module.exports = function (opts, cb) {
7980
gasPrice: opts.gasPrice,
8081
memory: new Memory(),
8182
memoryWordCount: new BN(0),
82-
stack: [],
83+
stack: new Stack(),
8384
lastReturned: [],
8485
logs: [],
8586
validJumps: [],
@@ -158,7 +159,7 @@ module.exports = function (opts, cb) {
158159
pc: runState.programCounter,
159160
gasLeft: runState.gasLeft,
160161
opcode: lookupOpInfo(opCode, true, self.emitFreeLogs),
161-
stack: runState.stack,
162+
stack: runState.stack._store,
162163
depth: runState.depth,
163164
address: runState.address,
164165
account: runState.contract,
@@ -191,15 +192,6 @@ module.exports = function (opts, cb) {
191192
return cb(new VmError(ERROR.INVALID_OPCODE))
192193
}
193194

194-
// check for stack underflows
195-
if (runState.stack.length < opInfo.in) {
196-
return cb(new VmError(ERROR.STACK_UNDERFLOW))
197-
}
198-
199-
if ((runState.stack.length - opInfo.in + opInfo.out) > 1024) {
200-
return cb(new VmError(ERROR.STACK_OVERFLOW))
201-
}
202-
203195
// calculate gas
204196
var fee = new BN(opInfo.fee)
205197
// TODO: move to a shared funtion; subGas in opFuns
@@ -212,35 +204,10 @@ module.exports = function (opts, cb) {
212204

213205
// advance program counter
214206
runState.programCounter++
215-
var argsNum = opInfo.in
216-
var retNum = opInfo.out
217-
// pop the stack
218-
var args = argsNum ? runState.stack.splice(-argsNum) : []
219-
220-
args.reverse()
221-
args.push(runState)
207+
let args = [runState]
222208
// create a callback for async opFunc
223209
if (opInfo.async) {
224-
args.push(function (err, result) {
225-
if (err) return cb(err)
226-
227-
// save result to the stack
228-
if (result !== undefined) {
229-
if (retNum !== 1) {
230-
// opcode post-stack mismatch
231-
return cb(new VmError(ERROR.INTERNAL_ERROR))
232-
}
233-
234-
runState.stack.push(result)
235-
} else {
236-
if (retNum !== 0) {
237-
// opcode post-stack mismatch
238-
return cb(new VmError(ERROR.INTERNAL_ERROR))
239-
}
240-
}
241-
242-
cb()
243-
})
210+
args.push(cb)
244211
}
245212

246213
// if opcode is log and emitFreeLogs is enabled, remove static context
@@ -251,7 +218,7 @@ module.exports = function (opts, cb) {
251218

252219
try {
253220
// run the opcode
254-
var result = opFn.apply(null, args)
221+
opFn.apply(null, args)
255222
} catch (e) {
256223
if (e.errorType && e.errorType === 'VmError') {
257224
cb(e)
@@ -264,21 +231,6 @@ module.exports = function (opts, cb) {
264231
// restore previous static context
265232
runState.static = prevStatic
266233

267-
// save result to the stack
268-
if (result !== undefined) {
269-
if (retNum !== 1) {
270-
// opcode post-stack mismatch
271-
return cb(new VmError(ERROR.INTERNAL_ERROR))
272-
}
273-
274-
runState.stack.push(result)
275-
} else {
276-
if (!opInfo.async && retNum !== 0) {
277-
// opcode post-stack mismatch
278-
return cb(new VmError(ERROR.INTERNAL_ERROR))
279-
}
280-
}
281-
282234
// call the callback if opFn was sync
283235
if (!opInfo.async) {
284236
cb()

0 commit comments

Comments
 (0)