Commit 2b9dc9ae by Francisco Giordano

Merge tag 'v2.2.0' of github.com:OpenZeppelin/openzeppelin-solidity

v2.2.0
parents f18fd173 9ed1b448
......@@ -16,6 +16,7 @@ Fixes #
(https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/CONTRIBUTING.md),
- added tests where applicable to test new functionality,
- made sure that your contracts are well-documented,
- run the JS/Solidity linters and fixed any issues (`npm run lint:fix`), and
- run the Solidity linter (`npm run lint:sol`) and fixed any issues,
- run the JS linter and fixed any issues (`npm run lint:fix`), and
- updated the changelog, if applicable.
-->
......@@ -32,10 +32,13 @@ npm-debug.log
# truffle build directory
build/
# lol macs
.DS_Store/
# macOS
.DS_Store
# truffle
.node-xmlhttprequest-*
.zos.session
# IntelliJ IDE
.idea
......@@ -25,11 +25,10 @@ jobs:
name: "Unit tests"
script: npm run test
# solidity-coverage fails at parsing 0.5.x code
# - stage: tests
# name: "Unit tests with coverage report"
# script: npm run test
# env: SOLIDITY_COVERAGE=true
- stage: tests
name: "Unit tests with coverage report"
script: npm run test
env: SOLIDITY_COVERAGE=true
- stage: tests
name: "Unit tests using solc nightly"
......
# Changelog
## 2.2.0 (unreleased)
## 2.2.0 (2019-03-14)
## 2.1.2 (2019-17-01)
### New features:
* `ERC20Snapshot`: create snapshots on demand of the token balances and total supply, to later retrieve and e.g. calculate dividends at a past time. ([#1617](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1617))
* `SafeERC20`: `ERC20` contracts with no return value (i.e. that revert on failure) are now supported. ([#1655](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/))
* `ERC20`: added internal `_approve(address owner, address spender, uint256 value)`, allowing derived contracts to set the allowance of arbitrary accounts. ([#1609](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1609))
* `ERC20Metadata`: added internal `_setTokenURI(string memory tokenURI)`. ([#1618](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1618))
* `TimedCrowdsale`: added internal `_extendTime(uint256 newClosingTime)` as well as `TimedCrowdsaleExtended(uint256 prevClosingTime, uint256 newClosingTime)` event allowing to extend the crowdsale, as long as it hasn't already closed.
### Improvements:
* Upgraded the minimum compiler version to v0.5.2: this removes many Solidity warnings that were false positives. ([#1606](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1606))
* `ECDSA`: `recover` no longer accepts malleable signatures (those using upper-range values for `s`, or 0/1 for `v`). ([#1622](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1622))
* `ERC721`'s transfers are now more gas efficient due to removal of unnecessary `SafeMath` calls. ([#1610](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1610))
* `Counter`'s API has been improved, and is now used by `ERC721` (though it is still in `drafts`). ([#1610](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1610))
* Fixed variable shadowing issues. ([#1606](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1606))
### Bugfixes:
* (minor) `SafeERC20`: `safeApprove` wasn't properly checking for a zero allowance when attempting to set a non-zero allowance. ([#1647](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1647))
### Breaking changes:
* `TokenMetadata` (in drafts) has been renamed to `ERC20Metadata`. ([#1618](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1618))
## 2.1.3 (2019-02-26)
* Backported `SafeERC20.safeApprove` bugfix. ([#1647](https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1647))
## 2.1.2 (2019-01-17)
* Removed most of the test suite from the npm package, except `PublicRole.behavior.js`, which may be useful to users testing their own `Roles`.
## 2.1.1 (2019-04-01)
## 2.1.1 (2019-01-04)
* Version bump to avoid conflict in the npm registry.
## 2.1.0 (2019-04-01)
## 2.1.0 (2019-01-04)
### New features:
* Now targeting the 0.5.x line of Solidity compilers. For 0.4.24 support, use version 2.0 of OpenZeppelin.
......
......@@ -94,6 +94,24 @@ contract MyNFT is Initializable, ERC721Full, ERC721Mintable {
}
```
> You need an ethereum development framework for the above import statements to work! Check out these guides for [Truffle] or [Embark].
On our site you will find a few [guides] to learn about the different parts of OpenZeppelin, as well as [documentation for the API][API docs]. Keep in mind that the API docs are work in progress, and don’t hesitate to ask questions in [our Slack][Slack].
## Security
OpenZeppelin the project is maintained by [Zeppelin] the company, and developed following our high standards for code quality and security. OpenZeppelin is meant to provide 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 problems you might experience.
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.
The latest audit was done on October 2018 on version 2.0.0.
Please report any security issues you find to security@openzeppelin.org.
## Contribute
OpenZeppelin exists thanks to its contributors. There are many ways you can participate and help build high quality software. Check out the [contribution guide]!
## License
OpenZeppelin is released under the [MIT License](LICENSE).
......@@ -51,12 +51,15 @@ git checkout release-vX.Y.Z
git pull upstream
```
Before starting the release process, make one final commit to CHANGELOG.md, including the date of the release.
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`.
```
git add package.json package-lock.json ethpm.json
git commit -m "Release vX.Y.Z"
git tag -a vX.Y.Z
git push upstream release-vX.Y.Z
git push upstream vX.Y.Z
```
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title Roles
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Roles.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/IERC20.sol";
......@@ -12,8 +12,8 @@ import "../utils/ReentrancyGuard.sol";
* allowing investors to purchase tokens with ether. This contract implements
* such functionality in its most fundamental form and can be extended to provide additional
* functionality and/or custom behavior.
* The external interface represents the basic interface for purchasing tokens, and conform
* the base architecture for crowdsales. They are *not* intended to be modified / overridden.
* The external interface represents the basic interface for purchasing tokens, and conforms
* the base architecture for crowdsales. It is *not* intended to be modified / overridden.
* The internal interface conforms the extensible and modifiable surface of crowdsales. Override
* the methods to add functionality. Consider using 'super' where appropriate to concatenate
* behavior.
......@@ -66,7 +66,7 @@ contract Crowdsale is Initializable, ReentrancyGuard {
/**
* @dev fallback function ***DO NOT OVERRIDE***
* Note that other contracts will transfer fund with a base gas stipend
* Note that other contracts will transfer funds with a base gas stipend
* of 2300, which is not enough to call buyTokens. Consider calling
* buyTokens directly when purchasing tokens from a contract.
*/
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol";
......@@ -6,7 +6,7 @@ import "../validation/TimedCrowdsale.sol";
/**
* @title FinalizableCrowdsale
* @dev Extension of Crowdsale with a one-off finalization action, where one
* @dev Extension of TimedCrowdsale with a one-off finalization action, where one
* can do extra work after finishing.
*/
contract FinalizableCrowdsale is Initializable, TimedCrowdsale {
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../validation/TimedCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol";
......@@ -7,8 +7,8 @@ import "../../payment/escrow/RefundEscrow.sol";
/**
* @title RefundableCrowdsale
* @dev Extension of Crowdsale contract that adds a funding goal, and the possibility of users getting a refund if goal
* is not met.
* @dev Extension of FinalizableCrowdsale contract that adds a funding goal, and the possibility of users
* getting a refund if goal is not met.
*
* Deprecated, use RefundablePostDeliveryCrowdsale instead. Note that if you allow tokens to be traded before the goal
* is met, then an attack is possible in which the attacker purchases tokens from the crowdsale and when they sees that
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Crowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../Crowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../validation/TimedCrowdsale.sol";
......@@ -31,7 +31,7 @@ contract IncreasingPriceCrowdsale is Initializable, TimedCrowdsale {
}
/**
* The base rate function is overridden to revert, since this crowdsale doens't use it, and
* The base rate function is overridden to revert, since this crowdsale doesn't use it, and
* all calls to it are a mistake.
*/
function rate() public view returns (uint256) {
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../math/SafeMath.sol";
......@@ -15,6 +15,13 @@ contract TimedCrowdsale is Initializable, Crowdsale {
uint256 private _closingTime;
/**
* Event for crowdsale extending
* @param newClosingTime new closing time
* @param prevClosingTime old closing time
*/
event TimedCrowdsaleExtended(uint256 prevClosingTime, uint256 newClosingTime);
/**
* @dev Reverts if not in crowdsale time range.
*/
modifier onlyWhileOpen {
......@@ -82,5 +89,17 @@ contract TimedCrowdsale is Initializable, Crowdsale {
super._preValidatePurchase(beneficiary, weiAmount);
}
/**
* @dev Extend crowdsale
* @param newClosingTime Crowdsale closing time
*/
function _extendTime(uint256 newClosingTime) internal {
require(!hasClosed());
require(newClosingTime > _closingTime);
emit TimedCrowdsaleExtended(_closingTime, newClosingTime);
_closingTime = newClosingTime;
}
uint256[50] private ______gap;
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../Crowdsale.sol";
import "../../access/roles/WhitelistedRole.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title Elliptic curve signature operations
......@@ -14,16 +14,16 @@ library ECDSA {
* @param signature bytes signature, the signature is generated using web3.eth.sign()
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
bytes32 r;
bytes32 s;
uint8 v;
// Check the signature length
if (signature.length != 65) {
return (address(0));
}
// Divide the signature in r, s and v variables
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
// solhint-disable-next-line no-inline-assembly
......@@ -33,17 +33,25 @@ library ECDSA {
v := byte(0, mload(add(signature, 0x60)))
}
// Version of signature should be 27 or 28, but 0 and 1 are also possible versions
if (v < 27) {
v += 27;
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return address(0);
}
// If the version is correct return the signer address
if (v != 27 && v != 28) {
return (address(0));
} else {
return ecrecover(hash, v, r, s);
return address(0);
}
// If the signature is valid (and not malleable), return the signer address
return ecrecover(hash, v, r, s);
}
/**
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title MerkleProof
......
pragma solidity ^0.5.0;
/**
* @title Counter
* @author Matt Condon (@shrugs)
* @dev Provides an incrementing uint256 id acquired by the `Counter#next` getter.
* Use this for issuing ERC721 ids or keeping track of request ids, anything you want, really.
*
* Include with `using Counter for Counter.Counter;`
* @notice Does not allow an Id of 0, which is popularly used to signify a null state in solidity.
* Does not protect from overflows, but if you have 2^256 ids, you have other problems.
* (But actually, it's generally impossible to increment a counter this many times, energy wise
* so it's not something you have to worry about.)
*/
library Counter {
struct Counter {
uint256 current; // default: 0
}
function next(Counter storage index) internal returns (uint256) {
index.current += 1;
return index.current;
}
}
pragma solidity ^0.5.2;
import "../math/SafeMath.sol";
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented or decremented by one. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids
*
* Include with `using Counters for Counters.Counter;`
* Since it is not possible to overflow a 256 bit integer with increments of one, `increment` can skip the SafeMath
* overflow check, thereby saving gas. This does assume however correct usage, in that the underlying `_value` is never
* directly accessed.
*/
library Counters {
using SafeMath for uint256;
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
counter._value += 1;
}
function decrement(Counter storage counter) internal {
counter._value = counter._value.sub(1);
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../../token/ERC20/IERC20.sol";
......@@ -8,22 +8,20 @@ import "../../token/ERC20/IERC20.sol";
* @dev See https://eips.ethereum.org/EIPS/eip-1046
* @dev tokenURI must respond with a URI that implements https://eips.ethereum.org/EIPS/eip-1047
*/
contract ERC20TokenMetadata is Initializable, IERC20 {
function tokenURI() external view returns (string memory);
uint256[50] private ______gap;
}
contract ERC20WithMetadata is Initializable, ERC20TokenMetadata {
contract ERC20Metadata is Initializable {
string private _tokenURI;
function initialize(string memory tokenURI) public {
_tokenURI = tokenURI;
function initialize(string memory tokenURI_) public {
_setTokenURI(tokenURI_);
}
function tokenURI() external view returns (string memory) {
return _tokenURI;
}
function _setTokenURI(string memory tokenURI_) internal {
_tokenURI = tokenURI_;
}
uint256[50] private ______gap;
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/IERC20.sol";
......@@ -18,7 +18,7 @@ import "../math/Math.sol";
* OpenZeppelin's ERC20Mintable, but the only functions that are needed are
* `isMinter(address)` and `mint(address, amount)`. The migrator will check
* that it is a minter for the token.
* The balance from the legacy token will be transfered to the migrator, as it
* The balance from the legacy token will be transferred to the migrator, as it
* is migrated, and remain there forever.
* Although this contract can be used in many different scenarios, the main
* motivation was to provide a way to migrate ERC20 tokens into an upgradeable
......@@ -66,14 +66,14 @@ contract ERC20Migrator is Initializable {
/**
* @dev Begins the migration by setting which is the new token that will be
* minted. This contract must be a minter for the new token.
* @param newToken the token that will be minted
* @param newToken_ the token that will be minted
*/
function beginMigration(ERC20Mintable newToken) public {
function beginMigration(ERC20Mintable newToken_) public {
require(address(_newToken) == address(0));
require(address(newToken) != address(0));
require(newToken.isMinter(address(this)));
require(address(newToken_) != address(0));
require(newToken_.isMinter(address(this)));
_newToken = newToken;
_newToken = newToken_;
}
/**
......@@ -83,6 +83,7 @@ contract ERC20Migrator is Initializable {
* @param amount amount of tokens to be migrated
*/
function migrate(address account, uint256 amount) public {
require(address(_newToken) != address(0));
_legacyToken.safeTransferFrom(account, address(this), amount);
_newToken.mint(account, amount);
}
......
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../math/SafeMath.sol";
import "../utils/Arrays.sol";
import "../drafts/Counters.sol";
import "../token/ERC20/ERC20.sol";
/**
* @title ERC20 token with snapshots.
* @dev Inspired by Jordi Baylina's MiniMeToken to record historical balances:
* https://github.com/Giveth/minime/blob/ea04d950eea153a04c51fa510b068b9dded390cb/contracts/MiniMeToken.sol
* When a snapshot is made, the balances and totalSupply at the time of the snapshot are recorded for later
* access.
*
* To make a snapshot, call the `snapshot` function, which will emit the `Snapshot` event and return a snapshot id.
* To get the total supply from a snapshot, call the function `totalSupplyAt` with the snapshot id.
* To get the balance of an account from a snapshot, call the `balanceOfAt` function with the snapshot id and the
* account address.
* @author Validity Labs AG <info@validitylabs.org>
*/
contract ERC20Snapshot is Initializable, ERC20 {
using SafeMath for uint256;
using Arrays for uint256[];
using Counters for Counters.Counter;
// Snapshotted values have arrays of ids and the value corresponding to that id. These could be an array of a
// Snapshot struct, but that would impede usage of functions that work on an array.
struct Snapshots {
uint256[] ids;
uint256[] values;
}
mapping (address => Snapshots) private _accountBalanceSnapshots;
Snapshots private _totalSupplySnaphots;
// Snapshot ids increase monotonically, with the first value being 1. An id of 0 is invalid.
Counters.Counter private _currentSnapshotId;
event Snapshot(uint256 id);
// Creates a new snapshot id. Balances are only stored in snapshots on demand: unless a snapshot was taken, a
// balance change will not be recorded. This means the extra added cost of storing snapshotted balances is only paid
// when required, but is also flexible enough that it allows for e.g. daily snapshots.
function snapshot() public returns (uint256) {
_currentSnapshotId.increment();
uint256 currentId = _currentSnapshotId.current();
emit Snapshot(currentId);
return currentId;
}
function balanceOfAt(address account, uint256 snapshotId) public view returns (uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _accountBalanceSnapshots[account]);
return snapshotted ? value : balanceOf(account);
}
function totalSupplyAt(uint256 snapshotId) public view returns(uint256) {
(bool snapshotted, uint256 value) = _valueAt(snapshotId, _totalSupplySnaphots);
return snapshotted ? value : totalSupply();
}
// _transfer, _mint and _burn are the only functions where the balances are modified, so it is there that the
// snapshots are updated. Note that the update happens _before_ the balance change, with the pre-modified value.
// The same is true for the total supply and _mint and _burn.
function _transfer(address from, address to, uint256 value) internal {
_updateAccountSnapshot(from);
_updateAccountSnapshot(to);
super._transfer(from, to, value);
}
function _mint(address account, uint256 value) internal {
_updateAccountSnapshot(account);
_updateTotalSupplySnapshot();
super._mint(account, value);
}
function _burn(address account, uint256 value) internal {
_updateAccountSnapshot(account);
_updateTotalSupplySnapshot();
super._burn(account, value);
}
// When a valid snapshot is queried, there are three possibilities:
// a) The queried value was not modified after the snapshot was taken. Therefore, a snapshot entry was never
// created for this id, and all stored snapshot ids are smaller than the requested one. The value that corresponds
// to this id is the current one.
// b) The queried value was modified after the snapshot was taken. Therefore, there will be an entry with the
// requested id, and its value is the one to return.
// c) More snapshots were created after the requested one, and the queried value was later modified. There will be
// no entry for the requested id: the value that corresponds to it is that of the smallest snapshot id that is
// larger than the requested one.
//
// In summary, we need to find an element in an array, returning the index of the smallest value that is larger if
// it is not found, unless said value doesn't exist (e.g. when all values are smaller). Arrays.findUpperBound does
// exactly this.
function _valueAt(uint256 snapshotId, Snapshots storage snapshots)
private view returns (bool, uint256)
{
require(snapshotId > 0);
require(snapshotId <= _currentSnapshotId.current());
uint256 index = snapshots.ids.findUpperBound(snapshotId);
if (index == snapshots.ids.length) {
return (false, 0);
} else {
return (true, snapshots.values[index]);
}
}
function _updateAccountSnapshot(address account) private {
_updateSnapshot(_accountBalanceSnapshots[account], balanceOf(account));
}
function _updateTotalSupplySnapshot() private {
_updateSnapshot(_totalSupplySnaphots, totalSupply());
}
function _updateSnapshot(Snapshots storage snapshots, uint256 currentValue) private {
uint256 currentId = _currentSnapshotId.current();
if (_lastSnapshotId(snapshots.ids) < currentId) {
snapshots.ids.push(currentId);
snapshots.values.push(currentValue);
}
}
function _lastSnapshotId(uint256[] storage ids) private view returns (uint256) {
if (ids.length == 0) {
return 0;
} else {
return ids[ids.length - 1];
}
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../access/roles/SignerRole.sol";
......@@ -30,7 +30,7 @@ import "../cryptography/ECDSA.sol";
* @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)
* represents the length of the _signature data and the _signature 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.
......@@ -57,7 +57,7 @@ contract SignatureBouncer is Initializable, SignerRole {
}
/**
* @dev requires that a valid signature with a specifed method of a signer was provided
* @dev requires that a valid signature with a specified method of a signer was provided
*/
modifier onlyValidSignatureAndMethod(bytes memory signature) {
require(_isValidSignatureAndMethod(msg.sender, signature));
......@@ -65,7 +65,7 @@ contract SignatureBouncer is Initializable, SignerRole {
}
/**
* @dev requires that a valid signature with a specifed method and params of a signer was provided
* @dev requires that a valid signature with a specified method and params of a signer was provided
*/
modifier onlyValidSignatureAndData(bytes memory signature) {
require(_isValidSignatureAndData(msg.sender, signature));
......@@ -73,7 +73,7 @@ contract SignatureBouncer is Initializable, SignerRole {
}
/**
* @dev is the signature of `this + sender` from a signer?
* @dev is the signature of `this + account` from a signer?
* @return bool
*/
function _isValidSignature(address account, bytes memory signature) internal view returns (bool) {
......@@ -81,7 +81,7 @@ contract SignatureBouncer is Initializable, SignerRole {
}
/**
* @dev is the signature of `this + sender + methodId` from a signer?
* @dev is the signature of `this + account + methodId` from a signer?
* @return bool
*/
function _isValidSignatureAndMethod(address account, bytes memory signature) internal view returns (bool) {
......@@ -93,7 +93,7 @@ contract SignatureBouncer is Initializable, SignerRole {
}
/**
* @dev is the signature of `this + sender + methodId + params(s)` from a signer?
* @dev is the signature of `this + account + methodId + params(s)` from a signer?
* @notice the signature parameter of the method being validated must be the "last" parameter
* @return bool
*/
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title SignedSafeMath
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/SafeERC20.sol";
......@@ -14,8 +14,8 @@ import "../math/SafeMath.sol";
contract TokenVesting is Initializable, Ownable {
// The vesting schedule is time-based (i.e. using block timestamps as opposed to e.g. block numbers), and is
// therefore sensitive to timestamp manipulation (which is something miners can do, to a certain degree). Therefore,
// it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a cliff
// period of a year and a duration of four years, are safe to use.
// it is recommended to avoid using short time durations (less than a minute). Typical vesting schemes, with a
// cliff period of a year and a duration of four years, are safe to use.
// solhint-disable not-rely-on-time
using SafeMath for uint256;
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../crowdsale/validation/CappedCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../token/ERC20/ERC20.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "./IERC165.sol";
......@@ -10,7 +10,7 @@ import "./IERC165.sol";
*/
contract ERC165 is Initializable, IERC165 {
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
/*
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title ERC165Checker
* @dev Use `using ERC165Checker for address`; to include this library
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
* https://eips.ethereum.org/EIPS/eip-165
*/
library ERC165Checker {
// As per the EIP-165 spec, no interface should ever match 0xffffffff
bytes4 private constant _INTERFACE_ID_INVALID = 0xffffffff;
bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
/*
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title IERC165
* @dev https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md
* @dev https://eips.ethereum.org/EIPS/eip-165
*/
interface IERC165 {
/**
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "zos-lib/contracts/Initializable.sol";
import "../access/roles/PauserRole.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title Math
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
/**
* @title SafeMath
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
contract Acknowledger {
event AcknowledgeFoo(uint256 a);
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../utils/Address.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/emission/AllowanceCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../utils/Arrays.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/CappedCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../access/roles/CapperRole.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../payment/escrow/ConditionalEscrow.sol";
......
pragma solidity ^0.5.0;
import "../drafts/Counter.sol";
contract CounterImpl {
using Counter for Counter.Counter;
uint256 public theId;
// use whatever key you want to track your counters
mapping(string => Counter.Counter) private _counters;
function doThing(string memory key) public returns (uint256) {
theId = _counters[key].next();
return theId;
}
}
pragma solidity ^0.5.2;
import "../drafts/Counters.sol";
contract CountersImpl {
using Counters for Counters.Counter;
Counters.Counter private _counter;
function current() public view returns (uint256) {
return _counter.current();
}
function increment() public {
_counter.increment();
}
function decrement() public {
_counter.decrement();
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../crowdsale/Crowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../cryptography/ECDSA.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../../introspection/IERC165.sol";
/**
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-214.md#specification
* https://eips.ethereum.org/EIPS/eip-214#specification
* From the specification:
* > Any attempts to make state-changing operations inside an execution instance with STATIC set to true will instead
* throw an exception.
* > These operations include [...], LOG0, LOG1, LOG2, [...]
......@@ -13,7 +14,7 @@ import "../../introspection/IERC165.sol";
*/
contract SupportsInterfaceWithLookupMock is IERC165 {
bytes4 public constant INTERFACE_ID_ERC165 = 0x01ffc9a7;
/**
/*
* 0x01ffc9a7 ===
* bytes4(keccak256('supportsInterface(bytes4)'))
*/
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
contract ERC165NotSupported {
// solhint-disable-previous-line no-empty-blocks
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../introspection/ERC165Checker.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../introspection/ERC165.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Burnable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol";
import "../token/ERC20/ERC20Detailed.sol";
......
pragma solidity ^0.5.0;
import "../token/ERC20/ERC20.sol";
import "../drafts/ERC1046/TokenMetadata.sol";
import "../drafts/ERC1046/ERC20Metadata.sol";
contract ERC20WithMetadataMock is ERC20, ERC20WithMetadata {
contract ERC20MetadataMock is ERC20, ERC20Metadata {
constructor (string memory tokenURI) public {
ERC20WithMetadata.initialize(tokenURI);
ERC20Metadata.initialize(tokenURI);
}
function setTokenURI(string memory tokenURI) public {
_setTokenURI(tokenURI);
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Mintable.sol";
import "./MinterRoleMock.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol";
......@@ -19,4 +19,8 @@ contract ERC20Mock is ERC20 {
function burnFrom(address account, uint256 amount) public {
_burnFrom(account, amount);
}
function approveInternal(address owner, address spender, uint256 value) public {
_approve(owner, spender, value);
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Pausable.sol";
import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.2;
import "../drafts/ERC20Snapshot.sol";
contract ERC20SnapshotMock is ERC20Snapshot {
constructor(address initialAccount, uint256 initialBalance) public {
_mint(initialAccount, initialBalance);
}
function mint(address account, uint256 amount) public {
_mint(account, amount);
}
function burn(address account, uint256 amount) public {
_burn(account, amount);
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Full.sol";
import "../token/ERC721/ERC721Mintable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Full.sol";
import "../token/ERC721/ERC721Mintable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC721/ERC721.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC721/ERC721Pausable.sol";
import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC721/IERC721Receiver.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
contract EventEmitter {
event Argumentless();
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
contract Failer {
uint256[] private array;
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/FinalizableCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../crowdsale/price/IncreasingPriceCrowdsale.sol";
import "../math/SafeMath.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/validation/IndividuallyCappedCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../math/Math.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import { MerkleProof } from "../cryptography/MerkleProof.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20Mintable.sol";
import "../crowdsale/emission/MintedCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../access/roles/MinterRole.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../ownership/Ownable.sol";
/**
* @title Ownable interface id calculator.
* @dev See the EIP165 specification for more information:
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-165.md#specification
* https://eips.ethereum.org/EIPS/eip-165#specification
*/
contract OwnableInterfaceId {
function getInterfaceId() public pure returns (bytes4) {
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../ownership/Ownable.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/ERC20.sol";
import "../crowdsale/validation/PausableCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../lifecycle/Pausable.sol";
import "./PauserRoleMock.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../access/roles/PauserRole.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/PostDeliveryCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../payment/PullPayment.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
contract ReentrancyAttack {
function callSender(bytes4 data) public {
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../utils/ReentrancyGuard.sol";
import "./ReentrancyAttack.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/RefundableCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../crowdsale/distribution/RefundablePostDeliveryCrowdsale.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../access/Roles.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/SafeERC20.sol";
contract ERC20FailingMock {
contract ERC20ReturnFalseMock {
uint256 private _allowance;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable.
uint256 private _dummy;
function transfer(address, uint256) public returns (bool) {
_dummy = 0;
return false;
}
function transferFrom(address, address, uint256) public returns (bool) {
_dummy = 0;
return false;
}
function approve(address, uint256) public returns (bool) {
_dummy = 0;
return false;
}
function allowance(address, address) public view returns (uint256) {
require(_dummy == 0);
return 0;
}
}
contract ERC20SucceedingMock {
uint256 private _allowance;
contract ERC20ReturnTrueMock {
mapping (address => uint256) private _allowances;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable.
uint256 private _dummy;
function transfer(address, uint256) public returns (bool) {
_dummy = 0;
return true;
}
function transferFrom(address, address, uint256) public returns (bool) {
_dummy = 0;
return true;
}
function approve(address, uint256) public returns (bool) {
_dummy = 0;
return true;
}
function setAllowance(uint256 allowance_) public {
_allowance = allowance_;
_allowances[msg.sender] = allowance_;
}
function allowance(address, address) public view returns (uint256) {
return _allowance;
function allowance(address owner, address) public view returns (uint256) {
return _allowances[owner];
}
}
contract SafeERC20Helper {
using SafeERC20 for IERC20;
contract ERC20NoReturnMock {
mapping (address => uint256) private _allowances;
IERC20 private _failing;
IERC20 private _succeeding;
// IERC20's functions are not pure, but these mock implementations are: to prevent Solidity from issuing warnings,
// we write to a dummy state variable.
uint256 private _dummy;
constructor () public {
_failing = IERC20(address(new ERC20FailingMock()));
_succeeding = IERC20(address(new ERC20SucceedingMock()));
function transfer(address, uint256) public {
_dummy = 0;
}
function doFailingTransfer() public {
_failing.safeTransfer(address(0), 0);
function transferFrom(address, address, uint256) public {
_dummy = 0;
}
function doFailingTransferFrom() public {
_failing.safeTransferFrom(address(0), address(0), 0);
function approve(address, uint256) public {
_dummy = 0;
}
function doFailingApprove() public {
_failing.safeApprove(address(0), 0);
function setAllowance(uint256 allowance_) public {
_allowances[msg.sender] = allowance_;
}
function doFailingIncreaseAllowance() public {
_failing.safeIncreaseAllowance(address(0), 0);
function allowance(address owner, address) public view returns (uint256) {
return _allowances[owner];
}
}
contract SafeERC20Wrapper {
using SafeERC20 for IERC20;
IERC20 private _token;
function doFailingDecreaseAllowance() public {
_failing.safeDecreaseAllowance(address(0), 0);
constructor (IERC20 token) public {
_token = token;
}
function doSucceedingTransfer() public {
_succeeding.safeTransfer(address(0), 0);
function transfer() public {
_token.safeTransfer(address(0), 0);
}
function doSucceedingTransferFrom() public {
_succeeding.safeTransferFrom(address(0), address(0), 0);
function transferFrom() public {
_token.safeTransferFrom(address(0), address(0), 0);
}
function doSucceedingApprove(uint256 amount) public {
_succeeding.safeApprove(address(0), amount);
function approve(uint256 amount) public {
_token.safeApprove(address(0), amount);
}
function doSucceedingIncreaseAllowance(uint256 amount) public {
_succeeding.safeIncreaseAllowance(address(0), amount);
function increaseAllowance(uint256 amount) public {
_token.safeIncreaseAllowance(address(0), amount);
}
function doSucceedingDecreaseAllowance(uint256 amount) public {
_succeeding.safeDecreaseAllowance(address(0), amount);
function decreaseAllowance(uint256 amount) public {
_token.safeDecreaseAllowance(address(0), amount);
}
function setAllowance(uint256 allowance_) public {
ERC20SucceedingMock(address(_succeeding)).setAllowance(allowance_);
ERC20ReturnTrueMock(address(_token)).setAllowance(allowance_);
}
function allowance() public view returns (uint256) {
return _succeeding.allowance(address(0), address(0));
return _token.allowance(address(0), address(0));
}
}
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../math/SafeMath.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../ownership/Secondary.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../drafts/SignatureBouncer.sol";
import "./SignerRoleMock.sol";
......
pragma solidity ^0.5.0;
pragma solidity ^0.5.2;
import "../drafts/SignedSafeMath.sol";
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment