Blog

Explanation of the create2 opcode



At its core, Create2 allows for deterministic deployment of smart contracts. This means that the address of a to-be-deployed contract can be known in advance, even before the contract is actually deployed.

The formula is as follows:

new_address = hash(0xFF, sender, salt, bytecode).

Here, 0xFF is a constant, sender refers to the address deploying the contract, salt is a nonce that allows for the deployment of multiple contracts with the same deploying address, and bytecode is the compiled code of the contract.

The benefit of using it?

Enhanced Security and Predictability: Knowing the address of a smart contract before it is deployed adds a layer of predictability that can be leveraged in various ways. For example, it enables more secure interactions between contracts even before they are deployed. Parties can agree on the future address of a contract, which can then be coded into other contracts or applications, reducing the risk of misaddressing or scams.