crypto: change formula for create2 (#17393)
This commit is contained in:
		
				
					committed by
					
						
						Péter Szilágyi
					
				
			
			
				
	
			
			
			
						parent
						
							97887d98da
						
					
				
				
					commit
					e0e0e53401
				
			@@ -427,7 +427,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Create2 creates a new contract using code as deployment code.
 | 
					// Create2 creates a new contract using code as deployment code.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
// The different between Create2 with Create is Create2 uses sha3(msg.sender ++ salt ++ init_code)[12:]
 | 
					// The different between Create2 with Create is Create2 uses sha3(0xff ++ msg.sender ++ salt ++ sha3(init_code))[12:]
 | 
				
			||||||
// instead of the usual sender-and-nonce-hash as the address where the contract is initialized at.
 | 
					// 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) {
 | 
					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(), common.BigToHash(salt), code)
 | 
						contractAddr = crypto.CreateAddress2(caller.Address(), common.BigToHash(salt), code)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,8 +78,8 @@ func CreateAddress(b common.Address, nonce uint64) common.Address {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// CreateAddress2 creates an ethereum address given the address bytes, initial
 | 
					// CreateAddress2 creates an ethereum address given the address bytes, initial
 | 
				
			||||||
// contract code and a salt.
 | 
					// contract code and a salt.
 | 
				
			||||||
func CreateAddress2(b common.Address, salt common.Hash, code []byte) common.Address {
 | 
					func CreateAddress2(b common.Address, salt [32]byte, code []byte) common.Address {
 | 
				
			||||||
	return common.BytesToAddress(Keccak256([]byte{0xff}, b.Bytes(), salt.Bytes(), code)[12:])
 | 
						return common.BytesToAddress(Keccak256([]byte{0xff}, b.Bytes(), salt[:], Keccak256(code))[12:])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ToECDSA creates a private key with the given D value.
 | 
					// ToECDSA creates a private key with the given D value.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user