Skip to content

Commit 90502d0

Browse files
authored
Merge branch 'master' into account-names
2 parents f7b431b + ca9e317 commit 90502d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2518
-2457
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = 2
10+
indent_style = space
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"comma-dangle": ["warn", "always-multiline"],
2929
"comma-spacing": ["error", {"before": false, "after": true}],
3030
"dot-notation": ["error", {"allowKeywords": true, "allowPattern": ""}],
31-
"eol-last": "warn",
31+
"eol-last": ["error", "always"],
3232
"eqeqeq": ["error", "smart"],
3333
"generator-star-spacing": ["error", "before"],
3434
"indent": ["error", 2],
@@ -38,7 +38,7 @@
3838
"no-dupe-keys": "error",
3939
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
4040
"no-redeclare": ["error", {"builtinGlobals": true}],
41-
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
41+
"no-trailing-spaces": ["error", { "skipBlankLines": false }],
4242
"no-undef": "error",
4343
"no-use-before-define": "off",
4444
"no-var": "error",

.soliumrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"rules": {
55
"quotes": ["error", "double"],
66
"no-empty-blocks": "off",
7+
"uppercase": "off",
78
"indentation": ["error", 2],
89
"max-len": ["warning", 79],
910
"no-constant": ["error"],

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ With OpenZeppelin, you can build distributed applications, protocols and organiz
1515

1616
OpenZeppelin integrates with [Truffle](https://github.com/ConsenSys/truffle) and [Embark](https://github.com/embark-framework/embark/).
1717

18-
## Truffle
18+
## truffle
1919

2020
To use with Truffle, first install it and initialize your project with `truffle init`.
2121

@@ -66,9 +66,50 @@ contract MyContract is Ownable {
6666
}
6767
```
6868

69+
## Architecture
70+
The following provides visibility into how OpenZeppelin's contracts are organized:
71+
72+
- **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.
73+
- **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.
74+
- **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.
75+
- **distribution** - Includes extensions of the base crowdsale contract which can be used to customize the completion of a crowdsale.
76+
- **emission** - Includes extensions of the base crowdsale contract which can be used to mint and manage how tokens are issued to purchasers.
77+
- **price** - Includes extensions of the crowdsale contract that can be used to manage changes in token prices.
78+
- **validation** - Includes extensions of the crowdsale contract that can be used to enforce restraints and limit access to token purchases.
79+
- **examples** - A collection of simple smart contracts that demonstrate how to add new features to base contracts through multiple inheritance.
80+
- **introspection** - An interface that can be used to make a contract comply with the ERC-165 standard as well as a contract that implements ERC-165 using a lookup table.
81+
- **lifecycle** - A collection of base contracts used to manage the existence and behavior of your contracts and their funds.
82+
- **math** - Libraries with safety checks on operations that throw on errors.
83+
- **mocks** - A collection of abstract contracts that are primarily used for unit testing. They also serve as good usage examples and demonstrate how to combine contracts with inheritence when developing your own custom applciations.
84+
- **ownership** - A collection of smart contracts that can be used to manage contract and token ownership
85+
- **payment** - A collection of smart contracts that can be used to manage payments through escrow arrangements, withdrawals, and claims. Includes support for both single payees and multiple payees.
86+
- **proposals** - A collection of smart contracts that reflect community Ethereum Improvement Proposals (EIPs). These contracts are under development and standardization. They are not recommended for production, but they are useful for experimentation with pending EIP standards. Go [here](https://github.com/OpenZeppelin/openzeppelin-solidity/wiki/ERC-Process) for more information.
87+
88+
- **token** - A collection of approved ERC standard tokens -- their interfaces and implementations.
89+
- **ERC20** - A standard interface for fungible tokens:
90+
- *Interfaces* - Includes the ERC-20 token standard basic interface. I.e., what the contract’s ABI can represent.
91+
- *Implementations* - Includes ERC-20 token implementations that include all required and some optional ERC-20 functionality.
92+
- **ERC721** - A standard interface for non-fungible tokens
93+
- *Interfaces* - Includes the ERC-721 token standard basic interface. I.e., what the contract’s ABI can represent.
94+
- *Implementations* - Includes ERC-721 token implementations that include all required and some optional ERC-721 functionality.
95+
96+
## Tests
97+
Unit test are critical to the OpenZeppelin framework. They help ensure code quality and mitigate against security vulnerabilities. The directory structure within the `/tests` directory corresponds to the `/contracts` directory. OpenZeppelin uses Mocha’s JavaScript testing framework and Chai’s assertion library. To learn more about how to tests are structured, please reference OpenZeppelin’s Testing Guide.
98+
99+
## How To Use And Modify OpenZeppelin Contracts
100+
When using OpenZeppelin to build your own distributed applications, for security reasons we encourage you NOT to modify the framework’s base contracts, libraries, and interfaces. In order to leverage and extend their functionality, we encourage you to inherit from them or compose them together with your own contracts.
101+
102+
The Solidity programming language supports multiple inheritance. This is very powerful yet it can also be confusing: the more complexity you introduce to your distributed applications through multiple inheritance, the greater your application’s attack surface is.
103+
104+
You’ll notice in the `/mocks` directory there are a collection of abstract contracts used primarily for unit testing purposes that can also be used as the foundation for your own custom implementations. These mock contracts demonstrate how OpenZeppelin’s secure base contracts can be used with multiple inheritance.
105+
106+
To learn more about combining OpenZeppelin contracts with your own custom contracts using multiple inheritance we encourage you to read the following: [On crowdsales and multiple inheritance](https://blog.zeppelin.solutions/on-crowdsales-and-multiple-inheritance-af90c694e35f)
107+
69108
## Security
70109
OpenZeppelin is meant to provide secure, tested and community-audited code, but please use common sense when doing anything that deals with real money! We take no responsibility for your implementation decisions and any security problem you might experience.
71110

111+
The core development principles and strategies that OpenZeppelin is based on include: security in depth, simple and modular code, clarity-driven naming conventions, comprehensive unit testing, pre-and-post-condition sanity checks, code consistency, and regular audits.
112+
72113
If you find a security issue, please email [[email protected]](mailto:[email protected]).
73114

74115
## Developer Resources
@@ -87,4 +128,4 @@ Interested in contributing to OpenZeppelin?
87128
- Wiki: https://github.com/OpenZeppelin/openzeppelin-solidity/wiki
88129

89130
## License
90-
Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE).
131+
Code released under the [MIT License](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/LICENSE).

contracts/AddressUtils.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ library AddressUtils {
1010
* Returns whether the target address is a contract
1111
* @dev This function will return false if invoked during the constructor of a contract,
1212
* as the code is not actually created until after the constructor finishes.
13-
* @param addr address to check
13+
* @param _addr address to check
1414
* @return whether the target address is a contract
1515
*/
16-
function isContract(address addr) internal view returns (bool) {
16+
function isContract(address _addr) internal view returns (bool) {
1717
uint256 size;
1818
// XXX Currently there is no better way to check if there is a contract in an address
1919
// than to check the size of the code at that address.
@@ -22,7 +22,7 @@ library AddressUtils {
2222
// TODO Check this again before the Serenity release, because all addresses will be
2323
// contracts then.
2424
// solium-disable-next-line security/no-inline-assembly
25-
assembly { size := extcodesize(addr) }
25+
assembly { size := extcodesize(_addr) }
2626
return size > 0;
2727
}
2828

contracts/Bounty.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ contract Bounty is PullPayment, Destructible {
3636

3737
/**
3838
* @dev Transfers the contract funds to the researcher that proved the contract is broken.
39-
* @param target contract
39+
* @param _target contract
4040
*/
41-
function claim(Target target) public {
42-
address researcher = researchers[target];
41+
function claim(Target _target) public {
42+
address researcher = researchers[_target];
4343
require(researcher != address(0));
4444
// Check Target contract invariants
45-
require(!target.checkInvariant());
45+
require(!_target.checkInvariant());
4646
asyncTransfer(researcher, address(this).balance);
4747
claimed = true;
4848
}

contracts/ECRecovery.sol

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ library ECRecovery {
1212

1313
/**
1414
* @dev Recover signer address from a message by using their signature
15-
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
16-
* @param sig bytes signature, the signature is generated using web3.eth.sign()
15+
* @param _hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
16+
* @param _sig bytes signature, the signature is generated using web3.eth.sign()
1717
*/
18-
function recover(bytes32 hash, bytes sig)
18+
function recover(bytes32 _hash, bytes _sig)
1919
internal
2020
pure
2121
returns (address)
@@ -25,7 +25,7 @@ library ECRecovery {
2525
uint8 v;
2626

2727
// Check the signature length
28-
if (sig.length != 65) {
28+
if (_sig.length != 65) {
2929
return (address(0));
3030
}
3131

@@ -34,9 +34,9 @@ library ECRecovery {
3434
// currently is to use assembly.
3535
// solium-disable-next-line security/no-inline-assembly
3636
assembly {
37-
r := mload(add(sig, 32))
38-
s := mload(add(sig, 64))
39-
v := byte(0, mload(add(sig, 96)))
37+
r := mload(add(_sig, 32))
38+
s := mload(add(_sig, 64))
39+
v := byte(0, mload(add(_sig, 96)))
4040
}
4141

4242
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions
@@ -49,7 +49,7 @@ library ECRecovery {
4949
return (address(0));
5050
} else {
5151
// solium-disable-next-line arg-overflow
52-
return ecrecover(hash, v, r, s);
52+
return ecrecover(_hash, v, r, s);
5353
}
5454
}
5555

@@ -58,15 +58,15 @@ library ECRecovery {
5858
* @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
5959
* and hash the result
6060
*/
61-
function toEthSignedMessageHash(bytes32 hash)
61+
function toEthSignedMessageHash(bytes32 _hash)
6262
internal
6363
pure
6464
returns (bytes32)
6565
{
6666
// 32 is the length in bytes of hash,
6767
// enforced by the type signature above
6868
return keccak256(
69-
abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
69+
abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)
7070
);
7171
}
7272
}

contracts/ReentrancyGuard.sol

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ pragma solidity ^0.4.24;
33

44
/**
55
* @title Helps contracts guard against reentrancy attacks.
6-
* @author Remco Bloemen <remco@2π.com>
6+
* @author Remco Bloemen <remco@2π.com>, Eenae <[email protected]>
77
* @dev If you mark a function `nonReentrant`, you should also
88
* mark it `external`.
99
*/
1010
contract ReentrancyGuard {
1111

12+
/// @dev Constant for unlocked guard state - non-zero to prevent extra gas costs.
13+
/// See: https://github.com/OpenZeppelin/openzeppelin-solidity/issues/1056
14+
uint private constant REENTRANCY_GUARD_FREE = 1;
15+
16+
/// @dev Constant for locked guard state
17+
uint private constant REENTRANCY_GUARD_LOCKED = 2;
18+
1219
/**
1320
* @dev We use a single lock for the whole contract.
1421
*/
15-
bool private reentrancyLock = false;
22+
uint private reentrancyLock = REENTRANCY_GUARD_FREE;
1623

1724
/**
1825
* @dev Prevents a contract from calling itself, directly or indirectly.
@@ -23,10 +30,10 @@ contract ReentrancyGuard {
2330
* wrapper marked as `nonReentrant`.
2431
*/
2532
modifier nonReentrant() {
26-
require(!reentrancyLock);
27-
reentrancyLock = true;
33+
require(reentrancyLock == REENTRANCY_GUARD_FREE);
34+
reentrancyLock = REENTRANCY_GUARD_LOCKED;
2835
_;
29-
reentrancyLock = false;
36+
reentrancyLock = REENTRANCY_GUARD_FREE;
3037
}
3138

3239
}

contracts/access/SignatureBouncer.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ contract SignatureBouncer is Ownable, RBAC {
6868
* @dev allows the owner to add additional bouncer addresses
6969
*/
7070
function addBouncer(address _bouncer)
71-
onlyOwner
7271
public
72+
onlyOwner
7373
{
7474
require(_bouncer != address(0));
7575
addRole(_bouncer, ROLE_BOUNCER);
@@ -79,8 +79,8 @@ contract SignatureBouncer is Ownable, RBAC {
7979
* @dev allows the owner to remove bouncer addresses
8080
*/
8181
function removeBouncer(address _bouncer)
82-
onlyOwner
8382
public
83+
onlyOwner
8484
{
8585
require(_bouncer != address(0));
8686
removeRole(_bouncer, ROLE_BOUNCER);
@@ -146,12 +146,12 @@ contract SignatureBouncer is Ownable, RBAC {
146146
* and then recover the signature and check it against the bouncer role
147147
* @return bool
148148
*/
149-
function isValidDataHash(bytes32 hash, bytes _sig)
149+
function isValidDataHash(bytes32 _hash, bytes _sig)
150150
internal
151151
view
152152
returns (bool)
153153
{
154-
address signer = hash
154+
address signer = _hash
155155
.toEthSignedMessageHash()
156156
.recover(_sig);
157157
return hasRole(signer, ROLE_BOUNCER);

contracts/access/Whitelist.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ contract Whitelist is Ownable, RBAC {
2828
* @return true if the address was added to the whitelist, false if the address was already in the whitelist
2929
*/
3030
function addAddressToWhitelist(address _operator)
31-
onlyOwner
3231
public
32+
onlyOwner
3333
{
3434
addRole(_operator, ROLE_WHITELISTED);
3535
}
@@ -52,8 +52,8 @@ contract Whitelist is Ownable, RBAC {
5252
* false if all addresses were already in the whitelist
5353
*/
5454
function addAddressesToWhitelist(address[] _operators)
55-
onlyOwner
5655
public
56+
onlyOwner
5757
{
5858
for (uint256 i = 0; i < _operators.length; i++) {
5959
addAddressToWhitelist(_operators[i]);
@@ -67,8 +67,8 @@ contract Whitelist is Ownable, RBAC {
6767
* false if the address wasn't in the whitelist in the first place
6868
*/
6969
function removeAddressFromWhitelist(address _operator)
70-
onlyOwner
7170
public
71+
onlyOwner
7272
{
7373
removeRole(_operator, ROLE_WHITELISTED);
7474
}
@@ -80,8 +80,8 @@ contract Whitelist is Ownable, RBAC {
8080
* false if all addresses weren't in the whitelist in the first place
8181
*/
8282
function removeAddressesFromWhitelist(address[] _operators)
83-
onlyOwner
8483
public
84+
onlyOwner
8585
{
8686
for (uint256 i = 0; i < _operators.length; i++) {
8787
removeAddressFromWhitelist(_operators[i]);

0 commit comments

Comments
 (0)