Skip to content

Commit

Permalink
add EXTCODEHASH opcode implementation
Browse files Browse the repository at this point in the history
add EXTCODEHASH rules for nonexistent accounts and precompiles

.

Replace removed state manager method

Fix lint
  • Loading branch information
jwasinger authored and rmeissner committed Nov 16, 2018
1 parent fca78fc commit 45f1ef8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,30 @@ module.exports = {
cb(null)
})
},
EXTCODEHASH: function (address, runState, cb) {
if (!runState._common.gteHardfork('constantinople')) {
trap(ERROR.INVALID_OPCODE)
}
var stateManager = runState.stateManager
address = addressToBuffer(address)

stateManager.getAccount(address, function (err, account) {
if (err) return cb(err)

if (account.isEmpty()) {
return cb(null, new BN(0))
}

stateManager.getContractCode(address, function (err, code) {
if (err) return cb(err)
if (code.length === 0) {
return cb(null, new BN(utils.KECCAK256_NULL))
}

return cb(null, new BN(utils.keccak256(code)))
})
})
},
RETURNDATASIZE: function (runState) {
return new BN(runState.lastReturned.length)
},
Expand Down
1 change: 1 addition & 0 deletions lib/opcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const codes = {
0x3c: ['EXTCODECOPY', 700, 4, 0, true, true],
0x3d: ['RETURNDATASIZE', 2, 0, 1, true],
0x3e: ['RETURNDATACOPY', 3, 3, 0, true],
0x3f: ['EXTCODEHASH', 400, 1, 1, true, true],

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

0 comments on commit 45f1ef8

Please sign in to comment.