-
Notifications
You must be signed in to change notification settings - Fork 765
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
Some smaller cleanups (mostly regarding calls) #186
Changes from all commits
f7f7c0e
2477e66
948e459
339ecfe
67f23a0
5b3593e
f4122b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,7 +258,7 @@ module.exports = { | |
|
||
memStore(runState, memOffset, runState.callData, dataOffset, dataLength) | ||
// sub the COPY fee | ||
subGas(runState, new BN(Number(fees.copyGas.v) * Math.ceil(dataLength / 32))) | ||
subGas(runState, new BN(fees.copyGas.v).imuln(Math.ceil(dataLength / 32))) | ||
}, | ||
CODESIZE: function (runState) { | ||
return utils.intToBuffer(runState.code.length) | ||
|
@@ -270,14 +270,14 @@ module.exports = { | |
|
||
memStore(runState, memOffset, runState.code, codeOffset, length) | ||
// sub the COPY fee | ||
subGas(runState, new BN(fees.copyGas.v * Math.ceil(length / 32))) | ||
subGas(runState, new BN(fees.copyGas.v).imuln(Math.ceil(length / 32))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
}, | ||
EXTCODESIZE: function (address, runState, cb) { | ||
var stateManager = runState.stateManager | ||
address = utils.setLengthLeft(address, 20) | ||
stateManager.getContractCode(address, function (err, code) { | ||
if (err) return cb(err) | ||
cb(err, utils.intToBuffer(code.length)) | ||
cb(null, utils.intToBuffer(code.length)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
}) | ||
}, | ||
EXTCODECOPY: function (address, memOffset, codeOffset, length, runState, cb) { | ||
|
@@ -286,15 +286,16 @@ module.exports = { | |
memOffset = utils.bufferToInt(memOffset) | ||
codeOffset = utils.bufferToInt(codeOffset) | ||
length = utils.bufferToInt(length) | ||
subMemUsage(runState, memOffset, length) | ||
|
||
// FIXME: for some reason this must come before subGas | ||
subMemUsage(runState, memOffset, length) | ||
// copy fee | ||
subGas(runState, new BN(fees.copyGas.v).imuln(Math.ceil(length / 32))) | ||
|
||
stateManager.getContractCode(address, function (err, code) { | ||
if (err) return cb(err) | ||
memStore(runState, memOffset, code, codeOffset, length, false) | ||
cb(err) | ||
cb(null) | ||
}) | ||
}, | ||
GASPRICE: function (runState) { | ||
|
@@ -386,7 +387,7 @@ module.exports = { | |
stateManager.putContractStorage(address, key, value, function (err) { | ||
if (err) return cb(err) | ||
runState.contract = stateManager.cache.get(address) | ||
cb() | ||
cb(null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both ok. |
||
}) | ||
}) | ||
}, | ||
|
@@ -473,7 +474,7 @@ module.exports = { | |
memLength = utils.bufferToInt(memLength) | ||
const numOfTopics = runState.opCode - 0xa0 | ||
const mem = memLoad(runState, memOffset, memLength) | ||
subGas(runState, new BN(numOfTopics * fees.logTopicGas.v + memLength * fees.logDataGas.v)) | ||
subGas(runState, new BN(fees.logTopicGas.v).imuln(numOfTopics).iadd(new BN(fees.logDataGas.v).imuln(memLength))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can optionally put some brackets around first multiplication like |
||
|
||
// add address | ||
var log = [runState.address] | ||
|
@@ -616,18 +617,22 @@ module.exports = { | |
options.gasLimit.iadd(new BN(fees.callStipend.v)) | ||
} | ||
|
||
if (utils.isPrecompiled(toAddress)) { | ||
options.compiled = true | ||
options.code = runState._precompiled[toAddress.toString('hex')] | ||
makeCall(runState, options, localOpts, done) | ||
} else { | ||
stateManager.getContractCode(toAddress, function (err, code, compiled) { | ||
if (err) return done(err) | ||
options.code = code | ||
options.compiled = compiled | ||
// load the code | ||
stateManager.getAccount(toAddress, function (err, account) { | ||
if (err) return done(err) | ||
if (utils.isPrecompiled(toAddress)) { | ||
options.compiled = true | ||
options.code = runState._precompiled[toAddress.toString('hex')] | ||
makeCall(runState, options, localOpts, done) | ||
}) | ||
} | ||
} else { | ||
stateManager.getContractCode(toAddress, function (err, code, compiled) { | ||
if (err) return done(err) | ||
options.compiled = compiled || false | ||
options.code = code | ||
makeCall(runState, options, localOpts, done) | ||
}) | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, code looks correct, not completely understand the changing semantics here, so probably for someone else to review again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The account must exists even for precompiles. |
||
}, | ||
DELEGATECALL: function (gas, toAddress, inOffset, inLength, outOffset, outLength, runState, done) { | ||
var stateManager = runState.stateManager | ||
|
@@ -670,8 +675,8 @@ module.exports = { | |
} else { | ||
stateManager.getContractCode(toAddress, function (err, code, compiled) { | ||
if (err) return done(err) | ||
options.compiled = compiled || false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
options.code = code | ||
options.compiled = compiled | ||
makeCall(runState, options, localOpts, done) | ||
}) | ||
} | ||
|
@@ -874,7 +879,7 @@ function makeCall (runState, callOptions, localOpts, cb) { | |
// Note: in the case of delegatecall, the value is persisted and doesn't need to be deducted again | ||
if (runState.depth >= fees.stackLimit.v || (callOptions.delegatecall !== true && new BN(runState.contract.balance).lt(callOptions.value))) { | ||
runState.stack.push(Buffer.from([0])) | ||
cb() | ||
cb(null) | ||
} else { | ||
// if creating a new contract then increament the nonce | ||
if (!callOptions.to) { | ||
|
@@ -886,6 +891,8 @@ function makeCall (runState, callOptions, localOpts, cb) { | |
} | ||
|
||
function parseCallResults (err, results) { | ||
if (err) return cb(err) | ||
|
||
// concat the runState.logs | ||
if (results.vm.logs) { | ||
runState.logs = runState.logs.concat(results.vm.logs) | ||
|
@@ -907,12 +914,14 @@ function makeCall (runState, callOptions, localOpts, cb) { | |
|
||
// update stateRoot on current contract | ||
runState.stateManager.getAccount(runState.address, function (err, account) { | ||
if (err) return cb(err) | ||
|
||
runState.contract = account | ||
// push the created address to the stack | ||
if (results.createdAddress) { | ||
cb(err, results.createdAddress) | ||
cb(null, results.createdAddress) | ||
} else { | ||
cb(err, Buffer.from([results.vm.exception])) | ||
cb(null, Buffer.from([results.vm.exception])) | ||
} | ||
}) | ||
} else { | ||
|
@@ -921,7 +930,7 @@ function makeCall (runState, callOptions, localOpts, cb) { | |
runState.contract.nonce = new BN(runState.contract.nonce).subn(1) | ||
} | ||
|
||
cb(err, Buffer.from([results.vm.exception])) | ||
cb(null, Buffer.from([results.vm.exception])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All above ok. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,14 +173,17 @@ module.exports = function (opts, cb) { | |
// create a callback for async opFunc | ||
if (opInfo.async) { | ||
args.push(function (err, result) { | ||
if (err) return cb(err) | ||
|
||
// save result to the stack | ||
if (result) { | ||
// NOTE: Ensure that every stack item is padded to 256 bits. | ||
// This should be done at every opcode in the future. | ||
result = utils.setLengthLeft(result, 32) | ||
runState.stack.push(result) | ||
} | ||
cb(err) | ||
|
||
cb() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, though that file has all the callbacks without null, need to tackle it at some point. Also some other methods ( |
||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.