Metamorphic - A factory contract for creating metamorphic (i.e. redeployable) contracts.
This factory contract creates metamorphic contracts, or contracts that can be redeployed with new code to the same address. It does so by deploying the metamorphic contract with fixed, non-deterministic initialization code via the CREATE2 opcode. This initalization code clones a given implementation contract and optionally initializes it in one operation. Once a contract undergoes metamorphosis, all existing storage will be deleted and any existing contract code will be replaced with the deployed contract code of the new implementation contract. There is also an immutable create2 factory that will not perform contract redeployments, thereby preventing metamorphism in contracts it deploys.
DISCLAIMER: this implements a highly experimental feature / bug - be sure to implement appropriate controls on your metamorphic contracts and educate the users of your contract if it will be interacted with! CREATE2 will not be available on mainnet until (at least) block 7,280,000. This contract has not yet been fully tested or audited - proceed with caution and please share any exploits or optimizations you discover.
To install locally, you'll need Node.js 10+ and Yarn (or npm). To get everything set up:
$ git clone https://github.com/0age/metamorphic.git
$ cd metamorphic
$ yarn install
$ yarn build
In a new terminal window, start the testRPC, run tests, and tear down the testRPC (you can do all of this at once via yarn all
if you prefer):
$ yarn start
$ yarn test
$ yarn linter
$ yarn stop
Refer to contract source and natspec for documentation and usage information.
PRs accepted gladly - make sure the tests and linters pass.
MIT © 2019 0age