Skip to content

Commit

Permalink
Move initial iterateVm checks to after step hook
Browse files Browse the repository at this point in the history
To ensure those conditions still generate a valid step for `runStepHook` handler.
  • Loading branch information
gnidan authored Feb 21, 2018
1 parent 688aec6 commit e03fb51
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 e03fb51

Please sign in to comment.