Create and Create2 are used to create contract addresses.
Create opcode https://www.evm.codes/#f0
CREATE opcode use nonce to create a new contract address so, you cannot predict the new contract address.
The Arguments of CREATE
1: creator address: The address of msg.sender 2: nonce: nonce of msg.sender
keccak256(senderAddress, nonce)
address = keccak256(rlp([sender_address,sender_nonce]))[12:]
Create2 opcode https://www.evm.codes/#f5
The arguments of CREATE2
1: 0xff : CREATEで生成されたcontractとaddressが被らないようにするためのoffset値 2: creator address: msg.sender of executing this opcode 3: salt: uint256の任意の値 4: init_code: このCREATE2で生成されるcontractの初期化code
keccak256(0xFF, senderAddress, salt, bytecode)
The benefit of using CREATE2
is that the contract address doesn't depend on the transaction nonce
■ CREATE2 opecode example
// uniswap code
bytes memory bytecode = type(UniswapV2Pair).creationCode;
bytes32 salt = keccak256(abi.encodePacked(token0, token1));
assembly {
pair := create2(0, add(bytecode, 32), mload(bytecode), salt)
}
//keccak256( 0xff ++ senderAddress ++ salt ++ keccak256(init_code))