GitXplorerGitXplorer
r

metamorphic

public
46 stars
4 forks
1 issues

Commits

List of commits on branch main.
Unverified
127dde07e12be1a20b0dcd00191702f0f54191ec

more fixes - compiles

rrefcell committed 2 years ago
Unverified
bf50d2025890c6cbb4aa68dd3397e6595c74f06f

fixes

rrefcell committed 2 years ago
Unverified
5b8f8099dd40001bd5c1454ecc2fa0c0333a4388

finish hash storage to bytes

rrefcell committed 2 years ago
Unverified
335cefc784b7fd56f5f79eecfeb0c524d7fcb201

finish copying data from memory to storage

rrefcell committed 2 years ago
Unverified
e91102a5d876af655eb230bf3175118308550d82

deploy with constructor complete

rrefcell committed 2 years ago
Unverified
9cbd3ac7472ebc911b83a0a30dbfcbcd186fffa6

store init code in storage

rrefcell committed 2 years ago

README

The README file for this repository.

metamorphic tests license solidity huff

Huff Smart Contracts for creating Metamorphic (or "redeployable") EVM Contracts.

Note This is a rewrite of 0age's metamorphic contracts in Huff.

A Trip Down Ethereum History

Prior to EIP-1014 (included in the Constantinople hard fork), contracts on ethereum were completely immutable. Code deployed to a given address could only be created and subsequently destroyed using the CREATE and SELFDESTRUCT opcodes. Migrating contracts involved replaying state onto a new contract, which is expensive and not scalable.

Fortunately, EIP-1014 introduced the CREATE2 opcode, a form of "wild magic" allowing a contract to be redeployed to the same address with different bytecode.

CREATE2 uses the caller’s address, a supplied salt parameter, and the initialization code of the contract that is created. Altering any one of these parameters will result in your bytecode being deployed to a completely different contract address.

Cool, so we have completely deterministic, redeployable contracts on Ethereum using CREATE2, right?

Well, this fails if the initialization code of the contract is non-deterministic. 0age presents a simple example: consider a contract that calls into some external contract and uses the variable return data to construct the final bytecode. Then the initialization code is in fact non-deterministic, and CREATE2 will generate an entirely new address for each time the contract is redeployed if the return data from the external contract changes.

// TODO:

Usage

Deploying Metamorphic Contracts

// TODO:

Clone factory contracts should use the HuffCloneLib library. CLONE is the main macro for creating clones.

Contracts intended to be cloned should include HuffClone to get access to the helper macros for reading immutable args.

To see an example usage of the library, check out ExampleClone and ExampleCloneFactory.

Installing as a Foundry Library

To install with Foundry:

forge install abigger87/metamorphic

Warning

These contracts are unaudited and are not recommended for use in production.

Although contracts have been rigorously reviewed, this is experimental software and is provided on an "as is" and "as available" basis. We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.

Contracts

.
├─ src
|  ├─ interfaces
|  |  ├─ IImmutableCreate2Factory.sol — 
|  |  ├─ IMetamorphicFactory.sol — 
|  |  └─ IMetapod.sol — 
|  ├─ ImmutableCreate2Factory.huff — 
|  ├─ MetamorphicFactory.huff — 
|  ├─ Metapod.huff — 
|  └─ TransientContract.huff — 
└─ tests
   └─ 🧪🧪🧪

Acknowledgements