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

Replaced static vm logTable with dynamic inline version in EXP opcode #450

Merged
merged 2 commits into from
Feb 25, 2019
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/exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const ERROR = {
STACK_OVERFLOW: 'stack overflow',
INVALID_JUMP: 'invalid JUMP',
INVALID_OPCODE: 'invalid opcode',
OUT_OF_RANGE: 'value out of range',
REVERT: 'revert',
STATIC_STATE_CHANGE: 'static state change',
INTERNAL_ERROR: 'internal error'
Expand Down
104 changes: 0 additions & 104 deletions lib/vm/logTable.js

This file was deleted.

20 changes: 13 additions & 7 deletions lib/vm/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const async = require('async')
const utils = require('ethereumjs-util')
const BN = utils.BN
const exceptions = require('../exceptions.js')
const logTable = require('./logTable.js')
const ERROR = exceptions.ERROR
const VmError = exceptions.VmError
const MASK_160 = new BN(1).shln(160).subn(1)
Expand Down Expand Up @@ -90,14 +89,21 @@ module.exports = {
EXP: function (base, exponent, runState) {
if (exponent.isZero()) {
holgerd77 marked this conversation as resolved.
Show resolved Hide resolved
return new BN(1)
} else {
var bytes = 1 + logTable(exponent)
subGas(runState, new BN(bytes).muln(runState._common.param('gasPrices', 'expByte')))
}
const byteLength = exponent.byteLength()
if (byteLength < 1 || byteLength > 32) {
trap(ERROR.OUT_OF_RANGE)
}
const gasPrice = runState._common.param('gasPrices', 'expByte')
const amount = new BN(byteLength).muln(gasPrice)
subGas(runState, amount)

var m = BN.red(utils.TWO_POW256)
base = base.toRed(m)
return base.redPow(exponent)
if (base.isZero()) {
return new BN(0)
}
const m = BN.red(utils.TWO_POW256)
base = base.toRed(m)
return base.redPow(exponent)
},
SIGNEXTEND: function (k, val, runState) {
val = val.toArrayLike(Buffer, 'be', 32)
Expand Down