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

core/vm, params: implement EXTCODEHASH opcode #17202

Merged
merged 4 commits into from
Jul 24, 2018

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Jul 19, 2018

Implements EIP1052.

@holiman
Copy link
Contributor

holiman commented Jul 19, 2018

From eip:

In case the account does not have code the keccak256 hash of empty data (i.e. c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) is pushed to the stack. In case the account does not exist 0 is pushed to the stack.

I don't see the check for existence, as implemented it will set zero for both non-existent and no-code ( I may be wrong...?)

slot.SetUint64(0)
} else {
slot.SetBytes(hash.Bytes())
}
Copy link
Member

Choose a reason for hiding this comment

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

Martin is right here, if the code does have a hash, you can return it. If there is no code however, 3 scenarios can happen:

  • The account is a plain account: the returned code hash should be Keccak256("") (ie. c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470)
  • The account is a precompile, this is an interesting case, but I think Keccak256("") would be the correct one.
  • The account does not exist: 00...0

Please see https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1052.md#test-cases for details

Copy link
Member

Choose a reason for hiding this comment

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

I think you could simplify this code via:

slot := stack.peek()
slot.SetBytes(evm.StateDB.GetCodeHash(common.BigToAddress(slot)))

I.e. Your optimization of slot.SetUint64(0) is not worth it, because it entails the hash == (common.Hash{}) comparison, which in theory should be equivalent runtime wise to slot.SetBytes(hash.Bytes()).

@rjl493456442
Copy link
Member Author

rjl493456442 commented Jul 19, 2018

@holiman @karalabe This PR relays everything to state.GetCodeHash function.
For example:

  • if an account is not exist, this function will return common.Hash{}, zero result will be set.
  • if an account is exist but no code, this function will return emptyCodeHash, emptyCodeHash will be set.
  • if an account is marked as deleted, this function will return common.Hash{}, zero result will be set.
  • if an account is marked as suicide(has not been deleted yet), this function will return the code hash.

All things will keep continuous with statedb.

@@ -63,7 +64,7 @@ var (
CreateBySuicide: 25000,
}
// GasTableEIP158 contain the gas re-prices for
// the EIP15* phase.
// the EIP158 phase.
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick, this was correct, because this is EIP155 and EIP158 combo :)

Copy link
Member

Choose a reason for hiding this comment

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

But maybe we can correct it to EIP155/EIP158

@karalabe
Copy link
Member

@rjl493456442 You are right with regard to the behavior. I stand corrected, code LGTM, just please fix the two issues I've raised just now.

@rjl493456442
Copy link
Member Author

@karalabe Updated

@karalabe
Copy link
Member

Ah, sorry for a followup nitpick. Could you add your comment (#17202 (comment)) into that method's description just so any reviewer will know why it works correctly?

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman
Copy link
Contributor

holiman commented Jul 24, 2018

Lgtm

@karalabe karalabe merged commit 2433349 into ethereum:master Jul 24, 2018
firmianavan pushed a commit to firmianavan/go-ethereum that referenced this pull request Aug 28, 2018
* core/vm, params: implement EXTCODEHASH opcode

* core, params: tiny fixes and polish

* core: add function description
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants