Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sovaslava/create3
Deploy another contract to the same address
https://github.com/sovaslava/create3
create3 ethereum solidity
Last synced: 2 months ago
JSON representation
Deploy another contract to the same address
- Host: GitHub
- URL: https://github.com/sovaslava/create3
- Owner: SovaSlava
- Created: 2022-08-14T21:55:45.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-08-15T19:58:14.000Z (over 2 years ago)
- Last Synced: 2024-11-14T01:38:37.943Z (3 months ago)
- Topics: create3, ethereum, solidity
- Language: Solidity
- Homepage:
- Size: 190 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Create3 with assembly
Solidity has the ability to deploy another bytecode to the same address. This works because we can use Create and Create2 opcodes. But we can't verify code(v2), because etherscan show that its dangerous contract.
## How it works:
There are 3 contracts: a deployer (which creates a proxy, a proxy contract (which deploys the implementation) and the implementation contracts(v1 and v2) itself.
1. You need to take the bytecode of the first implementation version and pass it as a parameter to the deploy function of the deployer contract.
2. The contract saves the passed bytecode and deploys the proxy contract using create2 with a constant salt. The proxy contract is written as a bytecode.
3. The proxy contract begins the creation stage. It accesses the deployer contract to read from the variable the implementation bytecode that it needs to deploy. The constructor cannot be used as it will affect the proxy address. And it should always be the same. After the proxy contract has read the implementation code, it deploys it through create and selfdestruct. Nonce at the proxy address is reset to 0.
4. At the moment there is only a deployer and an implementation contract. We call the selfdestruct function of the implementation.
5. We repeat everything from step 1, but we should pass the implementation bytecode of the second version.## Example:
- https://goerli.etherscan.io/address/0xBc92f18Fe932EE7dF88F1Ab85ED1866B28Ec3243#code
### Links:
- https://medium.com/coinmonks/dark-side-of-create2-opcode-6b6838a42d71