Skip to content
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

EIP 1052 EXTCODEHASH #326

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mattdean-digicatapult, short note: what occurred to mean when having a short look on how to update here regarding StateManager: we should make it clear in the docs especially for the the get* methods (so getAccount, getContractStorage,...) what the behavior is when called on a non-existing account (will it throw or not, what is returned).

Think it would also not be overblown to have additional test cases for that. If you don't want to do yourself you can also alternatively open an issue on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, I've started working a bit on the documentation so I'll make that clear. If I find too many inconsistencies for the missing values I might make some changes as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. 😀


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