GithubHelp home page GithubHelp logo

andyzzm / solidity-patterns Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fravoll/solidity-patterns

0.0 0.0 0.0 167 KB

A compilation of patterns and best practices for the smart contract programming language Solidity

Home Page: https://fravoll.github.io/solidity-patterns/

License: MIT License

Solidity 100.00%

solidity-patterns's Introduction

Solidity Patterns

This repository contains a collection of design and programming patterns for the smart contract programming language Solidity in version 0.4.20. Note that newer versions might have changed some of the functionalities. Each pattern consists of a code sample and a detailed explanation, including background, implications and additional information about the patterns.

Have a look at the documentation site: https://fravoll.github.io/solidity-patterns/

Contents

  • Behavioral Patterns
    • Guard Check: Ensure that the behavior of a smart contract and its input parameters are as expected.
    • State Machine: Enable a contract to go through different stages with different corresponding functionality exposed.
    • Oracle: Gain access to data stored outside of the blockchain.
    • Randomness: Generate a random number of a predefined interval in the deterministic environment of a blockchain.
  • Security Patterns
    • Access Restriction: Restrict the access to contract functionality according to suitable criteria.
    • Checks Effects Interactions: Reduce the attack surface for malicious contracts trying to hijack control flow after an external call.
    • Secure Ether Transfer: Secure transfer of ether from a contract to another address.
    • Pull over Push: Shift the risk associated with transferring ether to the user.
    • Emergency Stop: Add an option to disable critical contract functionality in case of an emergency.
  • Upgradeability Patterns
    • Proxy Delegate: Introduce the possibility to upgrade smart contracts without breaking any dependencies.
    • Eternal Storage: Keep contract storage after a smart contract upgrade.
  • Economic Patterns
    • String Equality Comparison: Check for the equality of two provided strings in a way that minimizes average gas consumption for a large number of different inputs.
    • Tight Variable Packing: Optimize gas consumption when storing or loading statically-sized variables.
    • Memory Array Building: Aggregate and retrieve data from contract storage in a gas efficient way.

Disclaimer

This repository is not under active development anymore and some (if not most) sections might be outdated. There is no liability for any damages caused by the use of one of these patterns.

solidity-patterns's People

Contributors

fravoll avatar 0x3bfc avatar dawsbot avatar colddevil 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.