GithubHelp home page GithubHelp logo

ssdef / contracts-upgradeable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from daonomic/contracts-upgradeable

0.0 1.0 0.0 20 KB

Upgradeable smart contracts

License: Apache License 2.0

JavaScript 98.21% Shell 1.79%

contracts-upgradeable's Introduction

Upgradeable contracts

Small library providing upgradeable smart contracts. You can have upgradeable contracts for reasonable price (about 1100 gas per call. it depends on data size). Dispatcher uses new returndatasize and returndatacopy opcodes. So it won't work in pre-byzantium network.

Disclaimer

Library has not been heavily tested. Use it on your own risk. Do it only if you understand how data is stored.

Basic Usage

  1. Deploy target contract (You can use Upgradeable as base contract, it has some useful functions)
  2. Deploy Dispatcher contract with address of the target as constructor argument.
  3. You can use dispatcher's address as static address even if you want to switch to other implementation in future.

Writing compatible contracts

  • The first storage slot in the contract will be used to store the address of the target contract
  • Additionally, when you upgrade a contract that has already stored data on the blockchain, you will need to be sure not to change the organization of your contract's storage. You can safely add new storage variables, but do not delete or re-order existing ones. It may also be risky to change the version of the Solidity compiler used, as there is no guarantee the storage layout will remain the same
  • Take a look at upgradeable.js to see some examples

Upgradeable overview

  • Upgradeable has some checks to ensure next version is compatible with previous.
  • See Upgradeable.verifyTargetState. It uses delegatecall to check if next contract version stores "target" storage variable in the same slot
  • Also, you'd better implement your own version of "verifyState" function. It can check if other storage variables are in the same slots. See Target for example. NotVerifyingTarget doesn't have this check. This leads to data corruption. See upgradeable.js "but it'll let upgrade if no check present" test
  • Implement checkAdmin function. Usually you can check if msg.sender is some address responsible for upgrading contracts

contracts-upgradeable's People

Contributors

0v1se avatar

Watchers

James Cloos 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.