Skip to content

Commit

Permalink
Remove RBAC, SignatureBouncer refactor (#1289)
Browse files Browse the repository at this point in the history
* Added CapperRole.

* RefundEscrow is now Secondary.

* FinalizableCrowdsale is no longer Ownable.

* Removed Whitelist and WhitelistedCrowdsale, redesign needed.

* Fixed linter errors, disabled lbrace due to it being buggy.

* Moved SignatureBouncer tests.

* Deleted RBAC and Superuser.

* Deleted rbac directory.

* Updated readme.

* SignatureBouncer now uses SignerRole, renamed bouncer to signer.
  • Loading branch information
nventuro authored Sep 6, 2018
1 parent 199e156 commit d4dea3c
Show file tree
Hide file tree
Showing 37 changed files with 327 additions and 772 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ contract MyContract is Ownable {
## Architecture
The following provides visibility into how OpenZeppelin's contracts are organized:

- **access** - Smart contracts that enable functionality that can be used for selective restrictions and basic authorization control functions. Includes address whitelisting and signature-based permissions management.
- **rbac** - A library used to manage addresses assigned to different user roles and an example Role-Based Access Control (RBAC) interface that demonstrates how to handle setters and getters for roles and addresses.
- **access** - Smart contracts that enable functionality that can be used for selective restrictions and basic authorization control functions.
- **crowdsale** - A collection of smart contracts used to manage token crowdsales that allow investors to purchase tokens with ETH. Includes a base contract which implements fundamental crowdsale functionality in its simplest form. The base contract can be extended in order to satisfy your crowdsale’s specific requirements.
- **distribution** - Includes extensions of the base crowdsale contract which can be used to customize the completion of a crowdsale.
- **emission** - Includes extensions of the base crowdsale contract which can be used to mint and manage how tokens are issued to purchasers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ pragma solidity ^0.4.24;

/**
* @title Roles
* @author Francisco Giordano (@frangio)
* @dev Library for managing addresses assigned to a Role.
* See RBAC.sol for example usage.
*/
library Roles {
struct Role {
Expand Down
106 changes: 0 additions & 106 deletions contracts/access/rbac/RBAC.sol

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;

import "./Roles.sol";
import "../Roles.sol";


contract CapperRole {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;

import "./Roles.sol";
import "../Roles.sol";


contract MinterRole {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;

import "./Roles.sol";
import "../Roles.sol";


contract PauserRole {
Expand Down
35 changes: 35 additions & 0 deletions contracts/access/roles/SignerRole.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.4.24;

import "../Roles.sol";


contract SignerRole {
using Roles for Roles.Role;

Roles.Role private signers;

constructor() public {
signers.add(msg.sender);
}

modifier onlySigner() {
require(isSigner(msg.sender));
_;
}

function isSigner(address _account) public view returns (bool) {
return signers.has(_account);
}

function addSigner(address _account) public onlySigner {
signers.add(_account);
}

function renounceSigner() public {
signers.remove(msg.sender);
}

function _removeSigner(address _account) internal {
signers.remove(_account);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.24;

import "../../math/SafeMath.sol";
import "../Crowdsale.sol";
import "../../access/rbac/CapperRole.sol";
import "../../access/roles/CapperRole.sol";


/**
Expand Down
64 changes: 16 additions & 48 deletions contracts/drafts/SignatureBouncer.sol
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
pragma solidity ^0.4.24;

import "../ownership/Ownable.sol";
import "../access/rbac/RBAC.sol";
import "../access/roles/SignerRole.sol";
import "../cryptography/ECDSA.sol";


/**
* @title SignatureBouncer
* @author PhABC, Shrugs and aflesher
* @dev Bouncer allows users to submit a signature as a permission to do an action.
* If the signature is from one of the authorized bouncer addresses, the signature
* is valid. The owner of the contract adds/removes bouncers.
* Bouncer addresses can be individual servers signing grants or different
* @dev SignatureBouncer allows users to submit a signature as a permission to do an action.
* If the signature is from one of the authorized signer addresses, the signature
* is valid.
* Signer addresses can be individual servers signing grants or different
* users within a decentralized club that have permission to invite other members.
* This technique is useful for whitelists and airdrops; instead of putting all
* valid addresses on-chain, simply sign a grant of the form
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid signer address.
* Then restrict access to your crowdsale/whitelist/airdrop using the
* `onlyValidSignature` modifier (or implement your own using _isValidSignature).
* In addition to `onlyValidSignature`, `onlyValidSignatureAndMethod` and
* `onlyValidSignatureAndData` can be used to restrict access to only a given method
* or a given method with given parameters respectively.
* See the tests Bouncer.test.js for specific usage examples.
* See the tests in SignatureBouncer.test.js for specific usage examples.
* @notice A method that uses the `onlyValidSignatureAndData` modifier must make the _signature
* parameter the "last" parameter. You cannot sign a message that has its own
* signature in it so the last 128 bytes of msg.data (which represents the
* length of the _signature data and the _signaature data itself) is ignored when validating.
* Also non fixed sized parameters make constructing the data in the signature
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
*/
contract SignatureBouncer is Ownable, RBAC {
contract SignatureBouncer is SignerRole {
using ECDSA for bytes32;

// Name of the bouncer role.
string private constant ROLE_BOUNCER = "bouncer";
// Function selectors are 4 bytes long, as documented in
// https://solidity.readthedocs.io/en/v0.4.24/abi-spec.html#function-selector
uint256 private constant METHOD_ID_SIZE = 4;
// Signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint256 private constant SIGNATURE_SIZE = 96;

/**
* @dev requires that a valid signature of a bouncer was provided
* @dev requires that a valid signature of a signer was provided
*/
modifier onlyValidSignature(bytes _signature)
{
Expand All @@ -50,7 +47,7 @@ contract SignatureBouncer is Ownable, RBAC {
}

/**
* @dev requires that a valid signature with a specifed method of a bouncer was provided
* @dev requires that a valid signature with a specifed method of a signer was provided
*/
modifier onlyValidSignatureAndMethod(bytes _signature)
{
Expand All @@ -59,7 +56,7 @@ contract SignatureBouncer is Ownable, RBAC {
}

/**
* @dev requires that a valid signature with a specifed method and params of a bouncer was provided
* @dev requires that a valid signature with a specifed method and params of a signer was provided
*/
modifier onlyValidSignatureAndData(bytes _signature)
{
Expand All @@ -68,36 +65,7 @@ contract SignatureBouncer is Ownable, RBAC {
}

/**
* @dev Determine if an account has the bouncer role.
* @return true if the account is a bouncer, false otherwise.
*/
function isBouncer(address _account) public view returns(bool) {
return hasRole(_account, ROLE_BOUNCER);
}

/**
* @dev allows the owner to add additional bouncer addresses
*/
function addBouncer(address _bouncer)
public
onlyOwner
{
require(_bouncer != address(0));
_addRole(_bouncer, ROLE_BOUNCER);
}

/**
* @dev allows the owner to remove bouncer addresses
*/
function removeBouncer(address _bouncer)
public
onlyOwner
{
_removeRole(_bouncer, ROLE_BOUNCER);
}

/**
* @dev is the signature of `this + sender` from a bouncer?
* @dev is the signature of `this + sender` from a signer?
* @return bool
*/
function _isValidSignature(address _address, bytes _signature)
Expand All @@ -112,7 +80,7 @@ contract SignatureBouncer is Ownable, RBAC {
}

/**
* @dev is the signature of `this + sender + methodId` from a bouncer?
* @dev is the signature of `this + sender + methodId` from a signer?
* @return bool
*/
function _isValidSignatureAndMethod(address _address, bytes _signature)
Expand All @@ -131,7 +99,7 @@ contract SignatureBouncer is Ownable, RBAC {
}

/**
* @dev is the signature of `this + sender + methodId + params(s)` from a bouncer?
* @dev is the signature of `this + sender + methodId + params(s)` from a signer?
* @notice the _signature parameter of the method being validated must be the "last" parameter
* @return bool
*/
Expand All @@ -153,7 +121,7 @@ contract SignatureBouncer is Ownable, RBAC {

/**
* @dev internal function to convert a hash to an eth signed message
* and then recover the signature and check it against the bouncer role
* and then recover the signature and check it against the signer role
* @return bool
*/
function _isValidDataHash(bytes32 _hash, bytes _signature)
Expand All @@ -164,6 +132,6 @@ contract SignatureBouncer is Ownable, RBAC {
address signer = _hash
.toEthSignedMessageHash()
.recover(_signature);
return isBouncer(signer);
return isSigner(signer);
}
}
Loading

0 comments on commit d4dea3c

Please sign in to comment.