Skip to content

Commit

Permalink
Documentation & Comments (#55)
Browse files Browse the repository at this point in the history
* Added @truls's description of minting restriction

* Update contracts overview image

* Issue a warning for missing doc comments

* Added comments for ENS contract

* Bumbed OpenZeppelin linting version to their git, as they havn't tagged a release (#57)

* Update docs group1 (#60)

* Added some comments

* Group 1 comments

* Fix minor inconsistencies

* Typo

* update docs group 2 (#61)

* Added comments for Accesslist, minterrole, blacklistadminrolemock and burnerrolemock

* Added additional comments

* fixed comment errors

* Slight fixes for accuracy

* Added comments for group 3 (#62)

* Minor fixes

* Typo

* Fix actual and documented param name mismatch

* Apply suggestions from code review

* Added several formatting fixes (#63)

* Added several formatting fixes

* fix @ dev -> @dev

* Fixed IUpgradableTokenX, which should be an interface not a contract

* Removed trailing whitespaces
  • Loading branch information
peteremiljensen authored and truls committed Jan 13, 2019
1 parent d31e501 commit 12475d6
Show file tree
Hide file tree
Showing 33 changed files with 704 additions and 107 deletions.
6 changes: 2 additions & 4 deletions .soliumrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
"quotes": ["error", "double"],
"uppercase": "off",
"visibility-first": "error",
"missing-natspec-comments": "off",

"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["warning"],
"security/no-inline-assembly": ["warning"],

"zeppelin/missing-natspec-comments": ["off"]
"zeppelin/missing-natspec-comments": ["warning"],
"security/no-inline-assembly": ["warning"]
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Access to token transfer functions is guarded by the AccessList. Accounts can be

2. The AccessList contains a large number of addresses and it is impractical to require that this data is transferred if we need to upgrade the token contracts.

### Restricted Minting
In order to limit the damage which can be caused by a compromised minter account, we have implemented the concept of a restricted minting. In restricted minting, a minter is only allowed to mint to a predetermined account which is specified by the owner. This prevents an attacker from minting new supply directly to their account, since new supply can only be minted to the dedicated minting account and is subsequently transferred to its final destination as an independent action.

## Class Diagram

![classdiagram](docs/images/class_diagram.svg)
Expand Down
2 changes: 1 addition & 1 deletion contracts/ENS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import "@ensdomains/ens/contracts/ENSRegistry.sol";
import "@ensdomains/ens/contracts/PublicResolver.sol";
import "@ensdomains/ens/contracts/ReverseRegistrar.sol";

// Avoild recompiling every time
/** @title Contract declaration to avoid recompiling ENS every time */
contract ENSdummy { }
10 changes: 6 additions & 4 deletions contracts/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ contract TokenManager is Ownable {
}

/**
* @dev Returns a token of specified name
* @param _name Name of token to be returned
* @dev Finds a token of the specified name
* @param _name Name of the token to be returned
* @return The token of the given name
*/
function getToken (bytes32 _name)
public
Expand All @@ -121,21 +122,22 @@ contract TokenManager is Ownable {
}

/**
* @dev Returns list of tokens
* @dev Gets all token names
* @return A list of names
*/
function getTokens ()
public
view
returns (bytes32[])
{
// TODO: Maybe filter out 0 entries (deleted names) from the list?
return names;
}

/**
* @dev Checks whether a token of specified name exists exists
* in list of tokens
* @param _name Name of token
* @return true if a token of the given name exists
*/
function _tokenExists (bytes32 _name)
private
Expand Down
60 changes: 31 additions & 29 deletions contracts/access/Accesslist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import "./roles/WhitelistAdminRole.sol";
import "./roles/BlacklistAdminRole.sol";

/**
* @title The Accesslist contract
* @dev Contract that contains a whitelist and a blacklist and manages them
* @title The Accesslist contract
* @dev Contract that contains a whitelist and a blacklist and manages them
*/

contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
using Roles for Roles.Role;

Expand All @@ -21,9 +20,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
Roles.Role private blacklist;

/**
* @dev Calls internal function _addWhitelisted
* to add given address to whitelist
* @param account Address to be added
* @dev Calls internal function _addWhitelisted
* to add given address to whitelist
* @param account Address to be added
*/
function addWhitelisted(address account)
public
Expand All @@ -33,9 +32,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Calls internal function _removeWhitelisted
* to remove given address from the whitelist
* @param account Address to be removed
* @dev Calls internal function _removeWhitelisted
* to remove given address from the whitelist
* @param account Address to be removed
*/
function removeWhitelisted(address account)
public
Expand All @@ -45,9 +44,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Calls internal function _addBlacklisted
* to add given address to blacklist
* @param account Address to be added
* @dev Calls internal function _addBlacklisted
* to add given address to blacklist
* @param account Address to be added
*/
function addBlacklisted(address account)
public
Expand All @@ -57,9 +56,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Calls internal function _removeBlacklisted
* to remove given address from blacklist
* @param account Address to be removed
* @dev Calls internal function _removeBlacklisted
* to remove given address from blacklist
* @param account Address to be removed
*/
function removeBlacklisted(address account)
public
Expand All @@ -69,8 +68,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Checks to see if given address is whitelisted
* @param account Address to be checked
* @dev Checks to see if the given address is whitelisted
* @param account Address to be checked
* @return true if address is whitelisted
*/
function isWhitelisted(address account)
public
Expand All @@ -81,8 +81,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Checks to see if given address is blacklisted
* @param account Address to be checked
* @dev Checks to see if given address is blacklisted
* @param account Address to be checked
* @return true if address is blacklisted
*/
function isBlacklisted(address account)
public
Expand All @@ -93,8 +94,9 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {
}

/**
* @dev Checks to see if given address is whitelisted and not blacklisted
* @param account Address to be checked
* @dev Checks to see if given address is whitelisted and not blacklisted
* @param account Address to be checked
* @return true if address has access
*/
function hasAccess(address account)
public
Expand All @@ -106,35 +108,35 @@ contract Accesslist is WhitelistAdminRole, BlacklistAdminRole {


/**
* @dev Adds given address to the whitelist
* @param account Address to be added
* @dev Adds given address to the whitelist
* @param account Address to be added
*/
function _addWhitelisted(address account) internal {
whitelist.add(account);
emit WhitelistAdded(account);
}

/**
* @dev Removes given address to the whitelist
* @param account Address to be removed
* @dev Removes given address to the whitelist
* @param account Address to be removed
*/
function _removeWhitelisted(address account) internal {
whitelist.remove(account);
emit WhitelistRemoved(account);
}

/**
* @dev Adds given address to the blacklist
* @param account Address to be added
* @dev Adds given address to the blacklist
* @param account Address to be added
*/
function _addBlacklisted(address account) internal {
blacklist.add(account);
emit BlacklistAdded(account);
}

/**
* @dev Removes given address to the blacklist
* @param account Address to be removed
* @dev Removes given address to the blacklist
* @param account Address to be removed
*/
function _removeBlacklisted(address account) internal {
blacklist.remove(account);
Expand Down
61 changes: 35 additions & 26 deletions contracts/access/AccesslistGuarded.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ pragma solidity ^0.4.24;
import "./Accesslist.sol";

/**
* @title The AccesslistGuarded contract
* @dev Contract containing an accesslist and
* modifiers to ensure proper access
* @title The AccesslistGuarded contract
* @dev Contract containing an accesslist and
* modifiers to ensure proper access
*/
contract AccesslistGuarded {

Accesslist private accesslist;
bool public whitelistEnabled;

/**
* @dev Constructor. Checks if the accesslist is a zero address
* @param _accesslist The access list
* @param _whitelistEnabled If the whitelist is enabled
*/
constructor(
Accesslist _accesslist,
bool _whitelistEnabled
Expand All @@ -27,67 +32,69 @@ contract AccesslistGuarded {
}

/**
* @dev Modifier that requires given address
* to be whitelisted and not blacklisted
* @param account address to be checked
* @dev Modifier that requires given address
* to be whitelisted and not blacklisted
* @param account address to be checked
*/
modifier requireHasAccess(address account) {
require(hasAccess(account), "no access");
_;
}

/**
* @dev Modifier that requires the message sender
* to be whitelisted and not blacklisted
* @dev Modifier that requires the message sender
* to be whitelisted and not blacklisted
*/
modifier onlyHasAccess() {
require(hasAccess(msg.sender), "no access");
_;
}

/**
* @dev Modifier that requires given address
* to be whitelisted
* @param account address to be checked
* @dev Modifier that requires given address
* to be whitelisted
* @param account address to be checked
*/
modifier requireWhitelisted(address account) {
require(isWhitelisted(account), "no access");
_;
}

/**
* @dev Modifier that requires message sender
* to be whitelisted
* @dev Modifier that requires message sender
* to be whitelisted
*/
modifier onlyWhitelisted() {
require(isWhitelisted(msg.sender), "no access");
_;
}

/**
* @dev Modifier that requires given address
* to not be blacklisted
* @param account address to be checked
* @dev Modifier that requires given address
* to not be blacklisted
* @param account address to be checked
*/
modifier requireNotBlacklisted(address account) {
require(isNotBlacklisted(account), "no access");
_;
}

/**
* @dev Modifier that requires message sender
* to not be blacklisted
* @dev Modifier that requires message sender
* to not be blacklisted
*/
modifier onlyNotBlacklisted() {
require(isNotBlacklisted(msg.sender), "no access");
_;
}

/**
* @dev Returns whether account has access.
* If whitelist is enabled a whitelist check is also made,
* otherwise it only checks for blacklisting.
* @param account address to be checked
* @dev Returns whether account has access.
* If whitelist is enabled a whitelist check is also made,
* otherwise it only checks for blacklisting.
* @param account Address to be checked
* @return true if address has access or is not blacklisted when whitelist
* is disabled
*/
function hasAccess(address account) public view returns (bool) {
if (whitelistEnabled) {
Expand All @@ -98,16 +105,18 @@ contract AccesslistGuarded {
}

/**
* @dev Returns whether account is whitelisted
* @param account address to be checked
* @dev Returns whether account is whitelisted
* @param account Address to be checked
* @return true if address is whitelisted
*/
function isWhitelisted(address account) public view returns (bool) {
return accesslist.isWhitelisted(account);
}

/**
* @dev Returns whether account is not blacklisted
* @param account address to be checked
* @dev Returns whether account is not blacklisted
* @param account Address to be checked
* @return true if address is not blacklisted
*/
function isNotBlacklisted(address account) public view returns (bool) {
return !accesslist.isBlacklisted(account);
Expand Down
Loading

0 comments on commit 12475d6

Please sign in to comment.