diff --git a/lib/opFns.js b/lib/opFns.js index 20e1cd8281..12faef3100 100644 --- a/lib/opFns.js +++ b/lib/opFns.js @@ -291,13 +291,28 @@ module.exports = { EXTCODEHASH: function (address, runState, cb) { var stateManager = runState.stateManager address = addressToBuffer(address) - stateManager.getContractCode(address, function (err, code) { + + if (runState._precompiled[address.toString('hex')]) { + cb(null, new BN(0)) + return + } + + stateManager.exists(address, function (err, exists) { if (err) return cb(err) - if (code.length == 0) { - cb(null, new BN(Buffer.from(utils.KECCAK256_NULL_S, 'hex'))) + if (!exists) { + cb(null, new BN(0)) + return } - cb(null, new BN(utils.keccak256(code))) + stateManager.getContractCode(address, function (err, code) { + if (err) return cb(err) + if (code.length === 0) { + cb(null, new BN(utils.KECCAK256_NULL)) + return + } + + cb(null, new BN(utils.keccak256(code))) + }) }) }, RETURNDATASIZE: function (runState) {