Giter Club home page Giter Club logo

metamorphic's Introduction

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

metamorphic's People

Contributors

refcell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.