Skip to content

Commit

Permalink
Merge pull request #279 from gnidan/patch-1
Browse files Browse the repository at this point in the history
Move initial iterateVm checks to after step hook
  • Loading branch information
axic authored Feb 25, 2018
2 parents 688aec6 + c37298e commit e863b93
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/runCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,6 @@ module.exports = function (opts, cb) {
runState.opName = opName
runState.opCode = opCode

// check for invalid opcode
if (opName === 'INVALID') {
return done(new VmError(ERROR.INVALID_OPCODE))
}

// check for stack underflows
if (runState.stack.length < opInfo.in) {
return done(new VmError(ERROR.STACK_UNDERFLOW))
}

if ((runState.stack.length - opInfo.in + opInfo.out) > 1024) {
return done(new VmError(ERROR.STACK_OVERFLOW))
}

async.series([
runStepHook,
runOp
Expand All @@ -153,6 +139,20 @@ module.exports = function (opts, cb) {
}

function runOp (cb) {
// check for invalid opcode
if (opName === 'INVALID') {
return cb(new VmError(ERROR.INVALID_OPCODE))
}

// check for stack underflows
if (runState.stack.length < opInfo.in) {
return cb(new VmError(ERROR.STACK_UNDERFLOW))
}

if ((runState.stack.length - opInfo.in + opInfo.out) > 1024) {
return cb(new VmError(ERROR.STACK_OVERFLOW))
}

// calculate gas
var fee = new BN(opInfo.fee)
// TODO: move to a shared funtion; subGas in opFuns
Expand Down

0 comments on commit e863b93

Please sign in to comment.