Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MintableToken using Roles #1236

Merged
merged 38 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4fb9bb7
Minor test style improvements (#1219)
nventuro Aug 22, 2018
2adb491
Add ERC165Query library (#1086)
ldub Aug 22, 2018
d58fac8
Added mint and burn tests for zero amounts. (#1230)
nventuro Aug 23, 2018
48fe7b8
Changed .eq to .equal. (#1231)
nventuro Aug 23, 2018
9e6307f
ERC721 pausable token (#1154)
urvalla Aug 24, 2018
a466e76
Add some detail to releasing steps (#1190)
frangio Aug 24, 2018
a9f910d
Increase test coverage (#1237)
nventuro Aug 24, 2018
524a276
ci: trigger docs update on tag (#1186)
Aug 28, 2018
4b3b6b6
Roles can now be transfered.
nventuro Aug 23, 2018
6ea040f
MintableToken now uses Roles.
nventuro Aug 22, 2018
9bc946c
Fixed FinalizableCrowdsale test.
nventuro Aug 23, 2018
32b84b9
Fixed tests related to MintableToken.
nventuro Aug 23, 2018
be6b78e
Removed Roles.check.
nventuro Aug 23, 2018
7a3dace
Renamed transferMintPermission.
nventuro Aug 23, 2018
5c71cf5
Moved MinterRole
nventuro Aug 23, 2018
cf57fbd
Fixed RBAC.
nventuro Aug 23, 2018
72aa867
Adressed review comments.
nventuro Aug 24, 2018
d080b3a
Addressed review comments
nventuro Aug 28, 2018
10b10a4
Fixed linter errors.
nventuro Aug 28, 2018
132994d
Added Events tests of Pausable contract (#1207)
viquezclaudio Aug 28, 2018
4e7d150
Fixed roles tests.
nventuro Aug 28, 2018
1c05324
Rename events to past-tense (#1181)
Aug 29, 2018
1c57637
fix: refactor sign.js and related tests (#1243)
shrugs Aug 29, 2018
b694326
Added "_" sufix to internal variables (#1171)
viquezclaudio Aug 29, 2018
c54681a
Added PublicRole test.
nventuro Aug 30, 2018
894fbed
Fixed crowdsale tests.
nventuro Aug 31, 2018
2e0713b
Rename ERC interfaces to I prefix (#1252)
frangio Aug 31, 2018
4385fd5
added explicit visibility (#1261)
vyomshm Sep 1, 2018
964bc40
Remove underscores from event parameters. (#1258)
Sep 3, 2018
2441fd7
Move contracts to subdirectories (#1253)
Sep 3, 2018
bd994a8
Remove HasNoEther, HasNoTokens, HasNoContracts, and NoOwner (#1254)
frangio Sep 3, 2018
fbfd1fe
Functions in interfaces changed to "external" (#1263)
Miraj98 Sep 3, 2018
b0f20d4
Add a leading underscore to internal and private functions. (#1257)
Sep 3, 2018
f4eb51a
Improve encapsulation on SignatureBouncer, Whitelist and RBAC example…
Sep 3, 2018
69f7f49
Merge branch 'master' into rbac-to-roles
nventuro Sep 4, 2018
41d0c08
Addressed review comments.
nventuro Sep 4, 2018
2136be9
Merge branch 'rbac-migration' into rbac-to-roles
nventuro Sep 4, 2018
b2c48b6
Fixed build error.
nventuro Sep 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ jobs:
- stage: tests
name: "static tests"
script: npm run lint
- stage: update docs
if: tag =~ ^v[0-9]+\.[0-9]+\.[0-9]+$
addons:
apt:
packages:
- curl
script:
- ./scripts/ci/trigger_docs_update "${TRAVIS_TAG}"

notifications:
slack:
Expand Down
59 changes: 55 additions & 4 deletions CODE_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,59 @@ Any exception or additions specific to our project are documented below.

* Parameters must be prefixed with an underscore.

```
function test(uint256 _testParameter1, uint256 _testParameter2) {
```
function test(uint256 _testParameter1, uint256 _testParameter2) {
...
}
```
}
```

The exception are the parameters of events. There is no chance of ambiguity
with these, so they should not have underscores. Not even if they are
specified on an ERC with underscores; removing them doesn't change the ABI,
so we should be consistent with the rest of the events in this repository
and remove them.

* Internal and private state variables should have an underscore suffix.

```
contract TestContract {
uint256 internal internalVar_;
uint256 private privateVar_;
}
```

Variables declared in a function should not follow this rule.

```
function test() {
uint256 functionVar;
...
}
```

* Internal and private functions should have an underscore prefix.

```
function _testInternal() internal {
...
}
```

```
function _testPrivate() private {
...
}
```

* Events should be emitted immediately after the state change that they
represent, and consequently they should be named in past tense.

```
function _burn(address _who, uint256 _value) internal {
super._burn(_who, _value);
emit TokensBurned(_who, _value);
}
```

Some standards (e.g. ERC20) use present tense, and in those cases the
standard specification prevails.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The following provides visibility into how OpenZeppelin's contracts are organize
- **ERC20** - A standard interface for fungible tokens:
- *Interfaces* - Includes the ERC-20 token standard basic interface. I.e., what the contract’s ABI can represent.
- *Implementations* - Includes ERC-20 token implementations that include all required and some optional ERC-20 functionality.
- **ERC721** - A standard interface for non-fungible tokens
- **ERC721** - A standard interface for non-fungible tokens
- *Interfaces* - Includes the ERC-721 token standard basic interface. I.e., what the contract’s ABI can represent.
- *Implementations* - Includes ERC-721 token implementations that include all required and some optional ERC-721 functionality.

Expand Down Expand Up @@ -125,6 +125,7 @@ Interested in contributing to OpenZeppelin?
- Framework proposal and roadmap: https://medium.com/zeppelin-blog/zeppelin-framework-proposal-and-development-roadmap-fdfa9a3a32ab#.iain47pak
- Issue tracker: https://github.com/OpenZeppelin/openzeppelin-solidity/issues
- Contribution guidelines: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md
- Code-style guide: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CODE_STYLE.md
- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki

## License
Expand Down
14 changes: 12 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We release a new version of OpenZeppelin monthly. Release cycles are tracked in
Each release has at least one release candidate published first, intended for community review and any critical fixes that may come out of it. At the moment we leave 1 week between the first release candidate and the final release.

Before starting make sure to verify the following items.
* Your local `master` branch is in sync with your upstream remote.
* Your local `master` branch is in sync with your `upstream` remote (it may have another name depending on your setup).
* Your repo is clean, particularly with no untracked files in the contracts and tests directories. Verify with `git clean -n`.


Expand Down Expand Up @@ -44,8 +44,11 @@ Publish the release notes on GitHub and ask our community manager to announce th

## Creating the final release

Make sure to have the latest changes from `upstream` in your local release branch.

```
git checkout release-vX.Y.Z
git pull upstream
```

Change the version string in `package.json`, `package-lock.json` and `ethpm.json` removing the "-rc.R" suffix. Commit these changes and tag the commit as `vX.Y.Z`.
Expand Down Expand Up @@ -75,7 +78,14 @@ npm dist-tag rm --otp $2FA_CODE openzeppelin-solidity next

## Merging the release branch

After the final release, the release branch should be merged back into `master`. This merge must not be squashed, because it would lose the tagged release commit, so it should be merged locally and pushed.
After the final release, the release branch should be merged back into `master`. This merge must not be squashed because it would lose the tagged release commit. Since the GitHub repo is set up to only allow squashed merges, the merge should be done locally and pushed.

Make sure to have the latest changes from `upstream` in your local release branch.

```
git checkout release-vX.Y.Z
git pull upstream
```

```
git checkout master
Expand Down
31 changes: 0 additions & 31 deletions contracts/LimitBalance.sol

This file was deleted.

51 changes: 31 additions & 20 deletions contracts/access/SignatureBouncer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pragma solidity ^0.4.24;

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


/**
Expand All @@ -17,7 +17,7 @@ import "../ECRecovery.sol";
* valid addresses on-chain, simply sign a grant of the form
* keccak256(abi.encodePacked(`:contractAddress` + `:granteeAddress`)) using a valid bouncer address.
* Then restrict access to your crowdsale/whitelist/airdrop using the
* `onlyValidSignature` modifier (or implement your own using isValidSignature).
* `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.
Expand All @@ -30,19 +30,22 @@ import "../ECRecovery.sol";
* much more complex. See https://ethereum.stackexchange.com/a/50616 for more details.
*/
contract SignatureBouncer is Ownable, RBAC {
using ECRecovery for bytes32;
using ECDSA for bytes32;

string public constant ROLE_BOUNCER = "bouncer";
uint constant METHOD_ID_SIZE = 4;
// signature size is 65 bytes (tightly packed v + r + s), but gets padded to 96 bytes
uint constant SIGNATURE_SIZE = 96;
// 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
*/
modifier onlyValidSignature(bytes _signature)
{
require(isValidSignature(msg.sender, _signature));
require(_isValidSignature(msg.sender, _signature));
_;
}

Expand All @@ -51,7 +54,7 @@ contract SignatureBouncer is Ownable, RBAC {
*/
modifier onlyValidSignatureAndMethod(bytes _signature)
{
require(isValidSignatureAndMethod(msg.sender, _signature));
require(_isValidSignatureAndMethod(msg.sender, _signature));
_;
}

Expand All @@ -60,10 +63,18 @@ contract SignatureBouncer is Ownable, RBAC {
*/
modifier onlyValidSignatureAndData(bytes _signature)
{
require(isValidSignatureAndData(msg.sender, _signature));
require(_isValidSignatureAndData(msg.sender, _signature));
_;
}

/**
* @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
*/
Expand All @@ -72,7 +83,7 @@ contract SignatureBouncer is Ownable, RBAC {
onlyOwner
{
require(_bouncer != address(0));
addRole(_bouncer, ROLE_BOUNCER);
_addRole(_bouncer, ROLE_BOUNCER);
}

/**
Expand All @@ -82,19 +93,19 @@ contract SignatureBouncer is Ownable, RBAC {
public
onlyOwner
{
removeRole(_bouncer, ROLE_BOUNCER);
_removeRole(_bouncer, ROLE_BOUNCER);
}

/**
* @dev is the signature of `this + sender` from a bouncer?
* @return bool
*/
function isValidSignature(address _address, bytes _signature)
function _isValidSignature(address _address, bytes _signature)
internal
view
returns (bool)
{
return isValidDataHash(
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address)),
_signature
);
Expand All @@ -104,7 +115,7 @@ contract SignatureBouncer is Ownable, RBAC {
* @dev is the signature of `this + sender + methodId` from a bouncer?
* @return bool
*/
function isValidSignatureAndMethod(address _address, bytes _signature)
function _isValidSignatureAndMethod(address _address, bytes _signature)
internal
view
returns (bool)
Expand All @@ -113,7 +124,7 @@ contract SignatureBouncer is Ownable, RBAC {
for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i];
}
return isValidDataHash(
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address, data)),
_signature
);
Expand All @@ -124,7 +135,7 @@ contract SignatureBouncer is Ownable, RBAC {
* @notice the _signature parameter of the method being validated must be the "last" parameter
* @return bool
*/
function isValidSignatureAndData(address _address, bytes _signature)
function _isValidSignatureAndData(address _address, bytes _signature)
internal
view
returns (bool)
Expand All @@ -134,7 +145,7 @@ contract SignatureBouncer is Ownable, RBAC {
for (uint i = 0; i < data.length; i++) {
data[i] = msg.data[i];
}
return isValidDataHash(
return _isValidDataHash(
keccak256(abi.encodePacked(address(this), _address, data)),
_signature
);
Expand All @@ -145,14 +156,14 @@ contract SignatureBouncer is Ownable, RBAC {
* and then recover the signature and check it against the bouncer role
* @return bool
*/
function isValidDataHash(bytes32 _hash, bytes _signature)
function _isValidDataHash(bytes32 _hash, bytes _signature)
internal
view
returns (bool)
{
address signer = _hash
.toEthSignedMessageHash()
.recover(_signature);
return hasRole(signer, ROLE_BOUNCER);
return isBouncer(signer);
}
}
13 changes: 8 additions & 5 deletions contracts/access/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import "../access/rbac/RBAC.sol";
* This simplifies the implementation of "user permissions".
*/
contract Whitelist is Ownable, RBAC {
string public constant ROLE_WHITELISTED = "whitelist";

// Name of the whitelisted role.
string private constant ROLE_WHITELISTED = "whitelist";

/**
* @dev Throws if operator is not whitelisted.
Expand All @@ -31,13 +33,14 @@ contract Whitelist is Ownable, RBAC {
public
onlyOwner
{
addRole(_operator, ROLE_WHITELISTED);
_addRole(_operator, ROLE_WHITELISTED);
}

/**
* @dev getter to determine if address is in whitelist
* @dev Determine if an account is whitelisted.
* @return true if the account is whitelisted, false otherwise.
*/
function whitelist(address _operator)
function isWhitelisted(address _operator)
public
view
returns (bool)
Expand Down Expand Up @@ -70,7 +73,7 @@ contract Whitelist is Ownable, RBAC {
public
onlyOwner
{
removeRole(_operator, ROLE_WHITELISTED);
_removeRole(_operator, ROLE_WHITELISTED);
}

/**
Expand Down
Loading