Git Product home page Git Product logo

ds-auth's Introduction

DSAuth

Fully updatable unobtrusive auth

Provides a flexible and updatable auth pattern which is completely separate from application logic. By default, the auth modifier will restrict function-call access to the including contract owner and the including contract itself.

In addition, fine-grained function access can be controlled by specifying an authority - a contract which implements the DSAuthority interface to define custom access permissions.

Dappsys provides a couple of ready-made authority contracts, ds-guard and ds-roles, which can be used as authorities where updatable fine-grained permissioned auth is required.

Usage

The auth modifier provided by DSAuth triggers the internal isAuthorized function to require that the msg.sender is authorized ie. the sender is either:

  1. the contract owner;
  2. the contract itself;
  3. or has been granted permission via a specified authority.
function myProtectedFunction() auth {}

API

setOwner(address owner_)

Set a new owner (requires auth)

setAuthority(DSAuthority authority_)

Set a new authority (requires auth)

ds-auth's People

Contributors

apmilen avatar d-xo avatar dbrock avatar desaperados avatar livnev avatar mbrock avatar mrchico avatar nanexcool avatar nmushegian avatar rainbreak avatar xwvvvvwx 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

ds-auth's Issues

Use Local Memory Type Variable Instead of Global Storage Type Variable in Event to Save Gas

Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.

The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.

For your repository, we find that the following event use can be improved:

  • auth.sol
    function name:setOwner
    event name:  LogSetOwner
    variable:    owner->owner_
    function setOwner(address owner_)
        public
        auth
    {
        owner = owner_;
        emit LogSetOwner(owner);
    }

Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!

`canCall` constant?

constant or not is part of the function signature for override purposes. constant has no real effect except for metadata yet, but that may change

Modifier `authorized` is not implemented

Hey, I just noticed some discrepencies between the documentation of DSAuth and the implementation of DSAuth:

  1. The documentation states that there would be a modifier authorized, but that doesn't seem to exist in the implementation.
  2. The documentation suggests that modifer authorized would would accept a single argument of type bytes4, but the examples show an argument of type string.

My suggestion is to overload authorized to accept types of both string and bytes4:

// This can be used with static strings.
modifier authorized (string _action) 
{
    assert(isAuthorized(msg.sender, bytes4(sha3(_action))));
    _;
}

// This should be used with dynamic strings.
// The caller will have to manually generate a signature, e.g., `bytes4(sha3(stringVar))`                                                            
modifier authorized (bytes4 _sig) 
{
    assert(isAuthorized(msg.sender, _sig));
    _;
}

updated "auth mode" mechanism

the auth mode is an enum because I anticipated more auth modes, but that didn't happen. canCall is a nice general ACL scheme.

An authority can fully simulate owner mode by returning true for canCall(authority, target, bytes4(sha3("updateAuthority(bytes4,uint8)"))

brainstorming DSAuthorized changes:

  • when in "auth" mode, falls back to msg.sender check
  • enableAuthLookup/disableAuthLookup, internally auth_lookup_enabled instead of enum
  • releaseToAuthority - direct to auth mode
  • releaseToOwner - direct to owner mode

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.