Giter VIP home page Giter VIP logo

singlekeccakcreate3's Introduction

Single Keccak Create3

This is a different implementation of CREATE3 that only requires a single keccak256 hash to calculate deployed address.

How it works

To achieve this, before deploying a proxy, we SSTORE2.write the final deployed bytecode from the deployer and store a pointer to the storage contract in the deployer. The proxies deployed from the deployer will do a SSTORE2.read on CALLER.pointer to get the final deployed bytecode and return that in its constructor.

We use a different SSTORE2 implementation here, using CREATE2 instead of CREATE under the hood. This bumps up costs slightly for the first deployment, but on the 2nd+ deployment of the same contract we get significant savings.

Because of how this works, contract constructors are never run. It's highly recommended for constructor logic to be in an initializer function instead. See the section on safety below.

Gas

Gas estimates with Solady's CREATE3 are in GasComparison.t.sol. Disclaimer: Gas values are measured using foundry and will be inaccurate so this should only be used as a ballpark estimate.

Cost of deploying an ERC20:
Single Keccak Create3, cached contract + no storage: 636k
Solady CREATE3: 732k
Single Keccak Create3, cached contract + storage: 810k
Single Keccak Create3, new contract + no storage: 1.26m
Single Keccak Create3, new contract + storage: 1.44m

Safety

Deployments using this proxy bypass all constructor logic and is significantly less safe than regular deployments. The danger here can largely be mitigated via adding tests to foundry deploy scripts - see example in SafeDeployPatternDemo.

Acknowledgements

A significant amount of assembly logic was lifted from Solady.

Future Extensions

  1. Utilizing SSTORE or TSTORE instead of another SSTORE2 for storageArgs
  2. We currently cache deployed bytecode, this means deploying a second contract a different immutable variable wouldn't count as 2nd+ deployment. Can consider doing it like how solidity constructors set up immutable vars and have the proxy take in arrays of memory arguments and memory locations of immutable args

singlekeccakcreate3's People

Contributors

howydev avatar

Stargazers

David Eiber avatar

Watchers

 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.