GithubHelp home page GithubHelp logo

bitaccesscontrol's Introduction

Bit access control

Most of the smart-contacts don't use many roles inside access control. This version is gas-optimized access control for DEFAULT_ADMIN and 7 other roles. This smart contract is actually a copy of default OZ AccessControl.sol, but the roles have a type of uint8 bitmask instead of bytes32.

Example:

uint8 public constant MINTER = uint8(1) << 1;

As you can see, each of the role is a bit shifted with some value. Run test command to see gas difference.

·-------------------------------|----------------------------|-------------|-----------------------------·
|     Solc version: 0.8.20      ·  Optimizer enabled: false  ·  Runs: 200  ·  Block limit: 30000000 gas  │
································|····························|·············|······························
|  Methods                                                                                               │
···············|················|··············|·············|·············|···············|··············
|  Contract    ·  Method        ·  Min         ·  Max        ·  Avg        ·  # calls      ·  usd (avg)  │
···············|················|··············|·············|·············|···············|··············
|  ACBit       ·  grantRole     ·       32244  ·      49344  ·      37944  ·           12  ·          -  │
···············|················|··············|·············|·············|···············|··············
|  ACBit       ·  renounceRole  ·           -  ·          -  ·      24401  ·            1  ·          -  │
···············|················|··············|·············|·············|···············|··············
|  ACBit       ·  revokeRole    ·       27428  ·      32228  ·      29028  ·            3  ·          -  │
···············|················|··············|·············|·············|···············|··············
|  ACOriginal  ·  grantRole     ·       51696  ·      52080  ·      51888  ·            4  ·          -  │
···············|················|··············|·············|·············|···············|··············
|  ACOriginal  ·  renounceRole  ·           -  ·          -  ·      25097  ·            1  ·          -  │
···············|················|··············|·············|·············|···············|··············
|  ACOriginal  ·  revokeRole    ·       29798  ·      30182  ·      30054  ·            3  ·          -  │

Try running some of the following tasks:

npx hardhat help
npx hardhat test
REPORT_GAS=true npx hardhat test

Disclaimer

These contracts are not audited and haven't been tested in production. Use at your own risk.

bitaccesscontrol's People

Watchers

Ivan Marchuk 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.