From fddfd4fb1c4af2406e1236b8ff027a62dbf5591c Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 20 Jul 2018 16:46:51 +0800 Subject: [PATCH] core, crypto: use option2 to generate new address --- core/vm/evm.go | 2 +- crypto/crypto.go | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 5625246688..0189351e7f 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -408,7 +408,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I // The different between Create2 with Create is Create2 uses sha3(msg.sender ++ salt ++ init_code)[12:] // instead of the usual sender-and-nonce-hash as the address where the contract is initialized at. func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment *big.Int, salt *big.Int) (ret []byte, contractAddr common.Address, leftOverGas uint64, err error) { - contractAddr = crypto.CreateAddress2(caller.Address(), salt.Bytes(), code) + contractAddr = crypto.CreateAddress2(caller.Address(), common.BigToHash(salt), code) return evm.create(caller, code, gas, endowment, contractAddr) } diff --git a/crypto/crypto.go b/crypto/crypto.go index 58538d1765..dec6e3c19e 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -78,10 +78,8 @@ func CreateAddress(b common.Address, nonce uint64) common.Address { // CreateAddress2 creates an ethereum address given the address bytes, initial // contract code and a salt. -// 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:]) +func CreateAddress2(b common.Address, salt common.Hash, code []byte) common.Address { + return common.BytesToAddress(Keccak256([]byte{0xff}, b.Bytes(), salt.Bytes(), code)[12:]) } // ToECDSA creates a private key with the given D value.