Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix homestead [WIP] #125

Merged
merged 6 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exports.ERROR = {
OUT_OF_GAS: 'out of gas',
STACK_UNDERFLOW: 'stack underflow',
STACK_OVERFLOW: 'stack overflow',
INVALID_JUMP: 'invalid JUMP',
INVALID_OPCODE: 'invalid opcode'
}
28 changes: 19 additions & 9 deletions lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,14 @@ module.exports = {

return result
},
SIGNEXTEND: function (k, runState) {
SIGNEXTEND: function (k, val, runState) {
k = new BN(k)
val = new Buffer(val) // use clone, don't modify object reference
var extendOnes = false

if (k.cmpn(31) <= 0) {
k = k.toNumber()

var val = new Buffer(utils.setLengthLeft(runState.stack.pop(), 32))

if (val[31 - k] & 0x80) {
extendOnes = true
}
Expand All @@ -148,9 +147,9 @@ module.exports = {
for (var i = 30 - k; i >= 0; i--) {
val[i] = extendOnes ? 0xff : 0
}

return val
}

return val
},
// 0x10 range - bit ops
LT: function (a, b, runState) {
Expand Down Expand Up @@ -547,17 +546,28 @@ module.exports = {
options.gasLimit.iadd(new BN(fees.callStipend.v))
}

checkCallMemCost(runState, options, localOpts)

stateManager.exists(toAddress, function (err, exists) {
if (err) {
done(err)
return
}

if (!exists) {
// can't wrap because we are in a callback
runState.gasLeft.isub(new BN(fees.callNewAccountGas.v))
try {
subGas(runState, new BN(fees.callNewAccountGas.v))
} catch (e) {
done(e.error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be within a if (homestead) check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the rule that a 0-value call creates a new account (and pays the new account gas fee) was there in frontier.

Copy link
Member

@axic axic Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, the commit log was a bit misleading. It fixes a bug when there wasn't sufficient gas left.

return
}
}

try {
checkCallMemCost(runState, options, localOpts)
} catch (e) {
done(e.error)
return
}

makeCall(runState, options, localOpts, done)
})
},
Expand Down
2 changes: 1 addition & 1 deletion lib/opcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const codes = {
0x08: ['ADDMOD', 8, 3, 1, false],
0x09: ['MULMOD', 8, 3, 1, false],
0x0a: ['EXP', 10, 2, 1, false],
0x0b: ['SIGNEXTEND', 5, 1, 1, false],
0x0b: ['SIGNEXTEND', 5, 2, 1, false],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you review the rest of the opcodes? Others might have bugs :)


// 0x10 range - bit ops
0x10: ['LT', 3, 2, 1, false],
Expand Down
7 changes: 4 additions & 3 deletions lib/runCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ module.exports = function (opts, cb) {
}

function iterateVm (done) {
if (runState.stack.length > 1024) {
return done(ERROR.INVALID_OPCODE)
}

var opCode = runState.code[runState.programCounter]
var opInfo = lookupOpInfo(opCode)
Expand All @@ -131,6 +128,10 @@ module.exports = function (opts, cb) {
return done(ERROR.STACK_UNDERFLOW)
}

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

async.series([
runStepHook,
runOp
Expand Down