You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: smart-contracts/advanced/deterministic-deployment.md
+34-89Lines changed: 34 additions & 89 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,75 +13,24 @@ Contract address can be precomputed, before the contract is deployed, using a cr
13
13
14
14
### **`CREATE`**
15
15
16
-
If deploying from an externally-owned account (EOA), e.g. by calling `ethers.deployContract` from a hardhat script, the `CREATE` opcode will run in the EVM and contract addresses will be calculated using the:
17
-
18
-
- Address of the EOA;
19
-
- Nonce of the EOA.
20
-
21
16
If deploying using a `CREATE` factory contract, contract addresses are calculated using the:
22
17
23
18
- Address of the factory contract (that calls `CREATE` opcode) itself;
24
19
- Nonce of the factory contract ([EIP-161](https://eips.ethereum.org/EIPS/eip-161) specifies that contract nonce starts at 1, not 0 like EOAs).
25
20
26
21
### **`CREATE2`**
27
22
28
-
The `CREATE2`opcode must be run from a deployed contract, so usually it's done from a `CREATE2`factory contract. Contract addresses are precomputed using the:
23
+
Similar to `CREATE`, `CREATE2`is used to deploy contracts to the same address across different blockchain networks in factory contract implementations. Contract addresses are precomputed using the:
29
24
30
25
- Address of the factory contract (that calls `CREATE2` opcode) itself;
31
26
- Bytecode of the contract;
32
27
- Salt (a chosen value).
33
28
34
-
See the following code snippet for an example of how to call `CREATE2` from a factory contract:
35
-
36
-
```solidity
37
-
// SPDX-License-Identifier: MIT
38
-
pragma solidity ^0.8.0;
39
-
40
-
...
41
-
42
-
function deploy(bytes memory bytecode, uint256 _salt) public payable {
43
-
address addr;
44
-
45
-
/*
46
-
NOTE: How to call create2
47
-
48
-
create2(v, p, n, s)
49
-
create new contract with code at memory p to p + n
50
-
and send v wei
51
-
and return the new address
52
-
where new address = first 20 bytes of keccak256(0xff + address(this) + s + keccak256(mem[p…(p+n)))
53
-
s = big-endian 256-bit value
54
-
*/
55
-
assembly {
56
-
addr :=
57
-
create2(
58
-
callvalue(), // wei sent with current call
59
-
// Actual code starts after skipping the first 32 bytes
60
-
add(bytecode, 0x20),
61
-
mload(bytecode), // Load the size of code contained in the first 32 bytes
62
-
_salt // Salt from function arguments
63
-
)
64
-
65
-
if iszero(extcodesize(addr)) { revert(0, 0) }
66
-
}
67
-
68
-
emit Deployed(addr, _salt);
69
-
}
70
-
```
29
+
See this [code snippet](https://solidity-by-example.org/app/create2/) for an example of how to call `CREATE2` from a factory contract.
71
30
72
-
###**`CREATE3`**
31
+
## **Deploying a factory contract to Filecoin**
73
32
74
-
With `CREATE2`, the contract bytecode affects the deployment address. So even blank spaces and comment text can affect the address.
75
-
76
-
CREATE3 is similar to CREATE2 but without including the contract initCode on the address derivation formula. It can be used to generate deterministic contract addresses that aren’t tied to a specific contract code.
77
-
78
-
CREATE3 is a way to use CREATE and CREATE2 in combination such that bytecode no longer affects the deployment address. — CREATE3 is more expensive than CREATE or CREATE2 (Fixed extra cost of ~55k gas).
79
-
80
-
Check out a reference implementation [here](https://github.com/0xsequence/create3).
81
-
82
-
### **Usage**
83
-
84
-
Other people may have already deployed the factory contract onto some of your desired blockchains to the expected address (if they didn't change the deployment transaction data), in which case you won't need to deploy it on those blockchains - you can then just use those already-deployed factory contracts to deploy whatever other contracts you want to deploy. So first check the expected address on a blockchain explorer to see if a factory contract already exists there.
33
+
Other people may have already deployed the factory contract onto Filecoin, in which case you won't need to redeploy it. You can just use the factory to deploy your contracts. So first check the expected address on a blockchain explorer to see if a factory contract already exists there.
85
34
86
35
If there isn't one yet then you'll need to deploy the factory contract via a **reusable signed raw deployment transaction**. The factory contract will then have the same address as on other blockchains (as long as the transaction bytecode stays the same). See the steps below to deploy the factory.
87
36
@@ -99,43 +48,39 @@ If there isn't one yet then you'll need to deploy the factory contract via a **r
99
48
- Wait for the transaction to be mined and confirmed.
100
49
101
50
4.**Verify the deployment:**
102
-
- Check the blockchain explorer to verify that the factory contract has been deployed to the expected address.
51
+
- Check the [blockchain explorer](https://docs.filecoin.io/networks/mainnet/explorers) to verify that the factory contract has been deployed to the expected address.
103
52
- Ensure the contract code matches the expected bytecode.
104
53
105
54
By following these steps, you can deploy the factory contract to multiple blockchains, ensuring it has the same address on each one. This allows for consistent and deterministic deployment of other contracts using the factory contract.
106
-
107
-
## **Popular Tools**
108
-
109
-
1.[**Deterministic Deployment Proxy by Arachnid**](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master)
110
-
- Signing the Proxy deployment tx is hidden, only recover the public key from signed tx.
111
-
- Somehow, the signing key and address is associated with the deployment tx. So if we change anything related to that deployment tx, the signing key and address will be different → proxy address is different.
112
-
2.**Safe singleton Factory**
55
+
## **Using Popular Tools on Filecoin**
56
+
57
+
### **1. Deterministic Deployment Proxy by Arachnid**
- Signing the Proxy deployment transaction is hidden, only recover the public key from the signed transaction.
61
+
- The signing key and address are associated with the deployment transaction. If anything related to the deployment transaction changes, the signing key and address will be different, resulting in a different proxy address.
They offer two options for deploying [`CreateX`](https://github.com/pcaversaccio/createx/blob/main/src/CreateX.sol) to your desired chain:
120
-
121
-
1. Deploy it yourself by using one of the pre-signed transactions. Details can be found in the subsequent paragraph.
122
-
2. Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+). You can significantly reduce the time to deployment by sending funds to cover the deployment cost (a reliable amount with a small tip 😏 would be ~0.3 ETH) to the deployer account: `0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5`.
123
-
3. See the [deployment result from Dune](https://dune.com/patronumlabs/createx)
hardhat **plugin** to deploy your smart contracts across multiple EVM chains with the same deterministic address.
127
-
`npx hardhat xdeploy`
128
-
129
-
- It also deployed on Filecoin mainnet and testnet.
130
-
- contract creation transaction is the helper smart contract [`CreateX`](https://github.com/pcaversaccio/createx) with address `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed`
- Deploy it yourself using one of the pre-signed transactions. Details can be found in the repository.
76
+
- xdeployer is a hardhat plugin that allows you to deploy your smart contracts across multiple EVM chains with the same deterministic address.
77
+
- It is deployed on Filecoin mainnet and testnet.
78
+
- Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+).
0 commit comments