Skip to content

Commit 1f3fe8f

Browse files
committed
fix: address all feedback on determ deploy
1 parent adc1460 commit 1f3fe8f

File tree

1 file changed

+34
-89
lines changed

1 file changed

+34
-89
lines changed

smart-contracts/advanced/deterministic-deployment.md

Lines changed: 34 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,24 @@ Contract address can be precomputed, before the contract is deployed, using a cr
1313

1414
### **`CREATE`**
1515

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-
2116
If deploying using a `CREATE` factory contract, contract addresses are calculated using the:
2217

2318
- Address of the factory contract (that calls `CREATE` opcode) itself;
2419
- 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).
2520

2621
### **`CREATE2`**
2722

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:
2924

3025
- Address of the factory contract (that calls `CREATE2` opcode) itself;
3126
- Bytecode of the contract;
3227
- Salt (a chosen value).
3328

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.
7130

72-
### **`CREATE3`**
31+
## **Deploying a factory contract to Filecoin**
7332

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.
8534

8635
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.
8736

@@ -99,43 +48,39 @@ If there isn't one yet then you'll need to deploy the factory contract via a **r
9948
- Wait for the transaction to be mined and confirmed.
10049

10150
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.
10352
- Ensure the contract code matches the expected bytecode.
10453

10554
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**
58+
- **Address:** `0x4e59b44847b379578588920ca78fbf26c0b4956c`
59+
- **How-to:**
60+
- 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.
62+
- [Repository Link](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master)
63+
64+
### **2. Safe Singleton Factory**
65+
- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7`
66+
- **How-to:**
11367
- Safe Multisig Wallet
68+
- Deployed by Masa Finance, Starlings lab, and align.network on many blockchains.
11469
- [Masa Finance](https://www.masa.ai/)
115-
- Starlings lab forked and deployed it on many blockchains
116-
- [align.network](http://align.network) - Long-term storage solution for Ethereum
117-
3. [**pcaversaccio/createx**](https://createx.rocks/)
118-
119-
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)
124-
125-
4. [**pcaversaccio/xdeployer**](https://github.com/pcaversaccio/xdeployer) - hardhat
126-
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`
131-
132-
5. OpenZepplin Defender
70+
- [align.network](http://align.network)
71+
72+
### **3. CreateX / xdeployer by pcaversaccio**
73+
- **Address:** `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed`
74+
- **How-to:**
75+
- 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+).
79+
- [CreateX Repository](https://github.com/pcaversaccio/createx), [xdeployer Repository](https://github.com/pcaversaccio/xdeployer)
80+
- [Deployment Result from Dune](https://dune.com/patronumlabs/createx)
81+
82+
### **4. OpenZeppelin Defender**
83+
- **Address:** N/A
84+
- **How-to:**
85+
- Follow the tutorial to use OpenZeppelin Defender for deterministic deployments.
13386
- [How to tutorial](https://blog.openzeppelin.com/evm-deterministic-deployments-made-easy-with-openzeppelin-defender)
134-
135-
Some of the most popular projects are using their own proxy for deterministic deployment across multiple chains. For example,
136-
137-
- Uniswap V2/V3 Factory Contracts
138-
- Compound and Aave Proxy Contracts
139-
- Synthetix Proxy and Synth Contracts
140-
- ENS (Ethereum Name Service) Registrar Contracts
141-
- Argent Wallet’s `Identity Proxy Factory`

0 commit comments

Comments
 (0)