Skip to content
Verified contractPartial

DSRoles

Address0xe75220cb014dfb2d354bb59be26d7458bb8d0706
Balance

0 ETH

 

Transactions

42

 

Compiler

solc 0.6.12

 

Same code

Only this contract

 

Details

Compiler
solc 0.6.12+commit.27d51765
Language
solidity
Optimization
Yes, 200 runs
EVM version
istanbul
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
21,836,809
Creation transaction
0x05aca6650c…ba5e01a19b
Libraries
:SignatureChecker0x70fb…c7c9bb

pht/lib/Roles.sol

// roles.sol - roled based authentication

// Copyright (C) 2017  DappHub, LLC

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity ^0.6.12;

import "ds-auth/auth.sol";

// clone of https://github.com/dapphub/ds-roles
// changes:
//      added `override` modifier to the `canCall` function
//      in order to compile on 0.6.12

contract DSRoles is DSAuth, DSAuthority {
    mapping(address => bool) _root_users;
    mapping(address => bytes32) _user_roles;
    mapping(address => mapping(bytes4 => bytes32)) _capability_roles;
    mapping(address => mapping(bytes4 => bool)) _public_capabilities;

    function getUserRoles(address who) public view returns (bytes32) {
        return _user_roles[who];
    }

    function getCapabilityRoles(address code, bytes4 sig) public view returns (bytes32) {
        return _capability_roles[code][sig];
    }

    function isUserRoot(address who) public view returns (bool) {
        return _root_users[who];
    }

    function isCapabilityPublic(address code, bytes4 sig) public view returns (bool) {
        return _public_capabilities[code][sig];
    }

    function hasUserRole(address who, uint8 role) public view returns (bool) {
        bytes32 roles = getUserRoles(who);
        bytes32 shifted = bytes32(uint256(uint256(2) ** uint256(role)));
        return bytes32(0) != roles & shifted;
    }

    function canCall(address caller, address code, bytes4 sig) public view override returns (bool) {
        if (isUserRoot(caller) || isCapabilityPublic(code, sig)) {
            return true;
        } else {
            bytes32 has_roles = getUserRoles(caller);
            bytes32 needs_one_of = getCapabilityRoles(code, sig);
            return bytes32(0) != has_roles & needs_one_of;
        }
    }

    function BITNOT(bytes32 input) internal pure returns (bytes32 output) {
        return (input ^ bytes32(uint256(-1)));
    }

    function setRootUser(address who, bool enabled) public auth {
        _root_users[who] = enabled;
    }

    function setUserRole(address who, uint8 role, bool enabled) public auth {
        bytes32 last_roles = _user_roles[who];
        bytes32 shifted = bytes32(uint256(uint256(2) ** uint256(role)));
        if (enabled) {
            _user_roles[who] = last_roles | shifted;
        } else {
            _user_roles[who] = last_roles & BITNOT(shifted);
        }
    }

    function setPublicCapability(address code, bytes4 sig, bool enabled) public auth {
        _public_capabilities[code][sig] = enabled;
    }

    function setRoleCapability(uint8 role, address code, bytes4 sig, bool enabled) public auth {
        bytes32 last_roles = _capability_roles[code][sig];
        bytes32 shifted = bytes32(uint256(uint256(2) ** uint256(role)));
        if (enabled) {
            _capability_roles[code][sig] = last_roles | shifted;
        } else {
            _capability_roles[code][sig] = last_roles & BITNOT(shifted);
        }
    }
}

lib/ds-token/lib/ds-auth/src/auth.sol

// SPDX-License-Identifier: GNU-3
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

pragma solidity >=0.4.23;

interface DSAuthority {
    function canCall(
        address src, address dst, bytes4 sig
    ) external view returns (bool);
}

contract DSAuthEvents {
    event LogSetAuthority (address indexed authority);
    event LogSetOwner     (address indexed owner);
}

contract DSAuth is DSAuthEvents {
    DSAuthority  public  authority;
    address      public  owner;

    constructor() public {
        owner = msg.sender;
        emit LogSetOwner(msg.sender);
    }

    function setOwner(address owner_)
        public
        auth
    {
        owner = owner_;
        emit LogSetOwner(owner);
    }

    function setAuthority(DSAuthority authority_)
        public
        auth
    {
        authority = authority_;
        emit LogSetAuthority(address(authority));
    }

    modifier auth {
        require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized");
        _;
    }

    function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
        if (src == address(this)) {
            return true;
        } else if (src == owner) {
            return true;
        } else if (authority == DSAuthority(address(0))) {
            return false;
        } else {
            return authority.canCall(src, address(this), sig);
        }
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {
    "": {
      "SignatureChecker": "0x70fb096d6bcd14db76a4119d83b4fc8facc7c9bb"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "istanbul",
  "remappings": [
    ":@chainlink/=lib/chainlink-brownie-contracts/",
    ":@openzeppelin/=lib/openzeppelin-contracts/",
    ":chainlink-brownie-contracts/=lib/chainlink-brownie-contracts/",
    ":chainlink/=lib/chainlink-brownie-contracts/contracts/",
    ":ds-auth/=lib/ds-token/lib/ds-auth/src/",
    ":ds-math/=lib/ds-token/lib/ds-math/src/",
    ":ds-note/=lib/ds-value/lib/ds-thing/lib/ds-note/src/",
    ":ds-pause/=lib/dss-deploy/lib/ds-pause/src/",
    ":ds-proxy/=lib/dss-proxy-actions/lib/proxy-registry/lib/ds-proxy/src/",
    ":ds-roles/=lib/ds-roles/src/",
    ":ds-test/=lib/ds-test/src/",
    ":ds-thing/=lib/ds-value/lib/ds-thing/src/",
    ":ds-token/=lib/ds-token/src/",
    ":ds-value/=lib/ds-value/src/",
    ":ds-weth/=lib/dss-proxy-actions/lib/ds-weth/",
    ":dsr-manager/=lib/dsr-manager/src/",
    ":dss-auto-line/=lib/dss-auto-line/src/",
    ":dss-cdp-manager/=lib/dss-cdp-manager/src/",
    ":dss-cron/=lib/dss-cron/src/",
    ":dss-deploy/=lib/dss-deploy/src/",
    ":dss-gem-joins/=lib/dss-gem-joins/src/",
    ":dss-ilk-registry/=lib/ilk-registry/src/",
    ":dss-interfaces/=lib/dss-psm/lib/dss-interfaces/src/",
    ":dss-lite-psm/=lib/dss-lite-psm/",
    ":dss-proxy-actions/=lib/dss-proxy-actions/src/",
    ":dss-proxy/=lib/dss-proxy/src/",
    ":dss-psm/=lib/dss-psm/src/",
    ":dss-test/=lib/dss-cron/lib/dss-test/src/",
    ":dss/=src/",
    ":erc20/=lib/dss-proxy-actions/lib/ds-weth/lib/erc20/src/",
    ":esm/=lib/dss-deploy/lib/esm/src/",
    ":forge-std/=lib/forge-std/src/",
    ":ilk-registry/=lib/ilk-registry/src/",
    ":mkr-authority/=lib/mkr-authority/src/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    ":proxy-registry/=lib/dss-proxy-actions/lib/proxy-registry/src/",
    ":stablecoin-evm/=lib/stablecoin-evm/contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.