Skip to content

Commit 45f1ef8

Browse files
jwasingerrmeissner
authored andcommitted
add EXTCODEHASH opcode implementation
add EXTCODEHASH rules for nonexistent accounts and precompiles . Replace removed state manager method Fix lint
1 parent fca78fc commit 45f1ef8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/opFns.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,30 @@ module.exports = {
288288
cb(null)
289289
})
290290
},
291+
EXTCODEHASH: function (address, runState, cb) {
292+
if (!runState._common.gteHardfork('constantinople')) {
293+
trap(ERROR.INVALID_OPCODE)
294+
}
295+
var stateManager = runState.stateManager
296+
address = addressToBuffer(address)
297+
298+
stateManager.getAccount(address, function (err, account) {
299+
if (err) return cb(err)
300+
301+
if (account.isEmpty()) {
302+
return cb(null, new BN(0))
303+
}
304+
305+
stateManager.getContractCode(address, function (err, code) {
306+
if (err) return cb(err)
307+
if (code.length === 0) {
308+
return cb(null, new BN(utils.KECCAK256_NULL))
309+
}
310+
311+
return cb(null, new BN(utils.keccak256(code)))
312+
})
313+
})
314+
},
291315
RETURNDATASIZE: function (runState) {
292316
return new BN(runState.lastReturned.length)
293317
},

lib/opcodes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const codes = {
4949
0x3c: ['EXTCODECOPY', 700, 4, 0, true, true],
5050
0x3d: ['RETURNDATASIZE', 2, 0, 1, true],
5151
0x3e: ['RETURNDATACOPY', 3, 3, 0, true],
52+
0x3f: ['EXTCODEHASH', 400, 1, 1, true, true],
5253

5354
// '0x40' range - block operations
5455
0x40: ['BLOCKHASH', 20, 1, 1, true, true],

0 commit comments

Comments
 (0)