From 9664d775ef524602516bf87c32a1c485dca1ce68 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Mon, 30 Jul 2018 15:22:27 -0700 Subject: [PATCH] add EXTCODEHASH rules for nonexistent accounts and precompiles --- lib/opFns.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/opFns.js b/lib/opFns.js index 20e1cd82814..6e6c21dd70d 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(Buffer.from(utils.KECCAK256_NULL_S, 'hex'))) + return + } + + cb(null, new BN(utils.keccak256(code))) + }) }) }, RETURNDATASIZE: function (runState) {