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, crypto, params: implement CREATE2 evm instrction #17196

Merged
merged 4 commits into from
Jul 24, 2018

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Jul 18, 2018

Implements EIP1014

@@ -209,6 +209,7 @@ const (
CALLCODE
RETURN
DELEGATECALL
CREATE2
Copy link
Member

Choose a reason for hiding this comment

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

Please skim through this file, there are 1 or 2 more instances where you need to add the opcode (the string to opcode and opcode to string mappings).

core/vm/evm.go Outdated
func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {

// create creates a new contract using code as deployment code.
func (evm *EVM) create(caller ContractRef, code []byte, gas uint64, value *big.Int, address common.Address) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

Please remote the contractAddr from the returns. Since you're passing it in as as argument, it just makes things confusing.

@karalabe
Copy link
Member

Small issues, otherwise LGTM

@holiman
Copy link
Contributor

holiman commented Jul 18, 2018

Within op Create2, no need to check for eip150 or homestead. There is no create2 prior to Constantinople.

@karalabe
Copy link
Member

karalabe commented Jul 18, 2018 via email

@holiman
Copy link
Contributor

holiman commented Jul 18, 2018

Can you use a fixed size buffer for salt instead of slice? It's defined by the eip, right?

@rjl493456442
Copy link
Member Author

@holiman Sorry i didn't find the salt definition in the EIP

crypto/crypto.go Outdated
// TODO(rjl493456442) considering address collision, should we add the 0xff as the input prefix?
func CreateAddress2(b common.Address, salt []byte, code []byte) common.Address {
data, _ := rlp.EncodeToBytes([]interface{}{b, salt, code})
return common.BytesToAddress(Keccak256(data)[12:])
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure whether this method is correct or not. The spec seems to state sha3(msg.sender ++ salt ++ init_code)[12:]. Given that sender, salt and code are all bytes, I'd interpret the formula as simple append, not RLP encoding. Might be worth a clarification on the EIP.

Copy link
Member Author

Choose a reason for hiding this comment

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

For the rlp encoding, no matter address is common.Address or byte slice, the result should be same.
And RLP or simple Append, yes we should give some feedbacks to EIP and make a clarification

Copy link
Member

Choose a reason for hiding this comment

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

input = memory.Get(offset.Int64(), size.Int64())
gas = contract.Gas
)
if evm.ChainConfig().IsEIP150(evm.BlockNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is 'speculative' -- how would Create2 work before EIP150? That's not defined, so I'd vote to remove this.

// homestead we must check for CodeStoreOutOfGasError (homestead only
// rule) and treat as an error, if the ruleset is frontier we must
// ignore this error and pretend the operation was successful.
if evm.ChainConfig().IsHomestead(evm.BlockNumber) && suberr == ErrCodeStoreOutOfGas {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Yes, it's (post) homestead

@rjl493456442
Copy link
Member Author

@holiman @karalabe Updated, PTAL again.

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

@karalabe karalabe added this to the 1.8.13 milestone Jul 24, 2018
@karalabe
Copy link
Member

We'll need to extend the call tracer to be able to handle this new create. But lets do that in a followup pr.

@rjl493456442
Copy link
Member Author

@karalabe Will do!

@holiman
Copy link
Contributor

holiman commented Jul 24, 2018

Lgtm!

@karalabe karalabe merged commit cab1cff into ethereum:master Jul 24, 2018
firmianavan pushed a commit to firmianavan/go-ethereum that referenced this pull request Aug 28, 2018
* core, crypto, params: implement CREATE2 evm instrction

* core/vm: add opcode to string mapping

* core: remove past fork checking

* core, crypto: use option2 to generate new address
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