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

Update contracts to support Solidity 0.8.x #2442

Merged
merged 18 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ OpenZeppelin Contracts features a [stable API](https://docs.openzeppelin.com/con
Once installed, you can use the contracts in the library by importing them:

```solidity
pragma solidity ^0.6.0;
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

Expand Down
2 changes: 1 addition & 1 deletion buidler.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ module.exports = {
},
},
solc: {
version: '0.6.12',
version: '0.8.0',
},
};
4 changes: 2 additions & 2 deletions contracts/GSN/Context.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/*
* @dev Provides information about the current execution context, including the
Expand All @@ -14,7 +14,7 @@ pragma solidity >=0.6.0 <0.8.0;
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
return payable(msg.sender);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Solidity changed the type of msg.sender we should change the return type of our _msgSender function accordingly, instead of casting it here.

}

function _msgData() internal view virtual returns (bytes memory) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/GSN/GSNRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "./IRelayRecipient.sol";
import "./IRelayHub.sol";
Expand Down Expand Up @@ -89,7 +89,7 @@ abstract contract GSNRecipient is IRelayRecipient, Context {
*/
function _msgSender() internal view virtual override returns (address payable) {
if (msg.sender != _relayHub) {
return msg.sender;
return payable(msg.sender);
} else {
return _getRelayedCallSender();
}
Expand Down
14 changes: 6 additions & 8 deletions contracts/GSN/GSNRecipientERC20Fee.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "./GSNRecipient.sol";
import "../math/SafeMath.sol";
import "../access/Ownable.sol";
import "../token/ERC20/SafeERC20.sol";
import "../token/ERC20/ERC20.sol";
Expand All @@ -19,7 +18,6 @@ import "../token/ERC20/ERC20.sol";
*/
contract GSNRecipientERC20Fee is GSNRecipient {
using SafeERC20 for __unstable__ERC20Owned;
using SafeMath for uint256;

enum GSNRecipientERC20FeeErrorCodes {
INSUFFICIENT_BALANCE
Expand All @@ -30,7 +28,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
/**
* @dev The arguments to the constructor are the details that the gas payment token will have: `name` and `symbol`. `decimals` is hard-coded to 18.
*/
constructor(string memory name, string memory symbol) public {
constructor(string memory name, string memory symbol) {
_token = new __unstable__ERC20Owned(name, symbol);
}

Expand Down Expand Up @@ -100,11 +98,11 @@ contract GSNRecipientERC20Fee is GSNRecipient {
// actualCharge is an _estimated_ charge, which assumes postRelayedCall will use all available gas.
// This implementation's gas cost can be roughly estimated as 10k gas, for the two SSTORE operations in an
// ERC20 transfer.
uint256 overestimation = _computeCharge(_POST_RELAYED_CALL_MAX_GAS.sub(10000), gasPrice, transactionFee);
actualCharge = actualCharge.sub(overestimation);
uint256 overestimation = _computeCharge(_POST_RELAYED_CALL_MAX_GAS - 10000, gasPrice, transactionFee);
actualCharge = actualCharge - overestimation;

// After the relayed call has been executed and the actual charge estimated, the excess pre-charge is returned
_token.safeTransfer(from, maxPossibleCharge.sub(actualCharge));
_token.safeTransfer(from, maxPossibleCharge - actualCharge);
}
}

Expand All @@ -118,7 +116,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
contract __unstable__ERC20Owned is ERC20, Ownable {
uint256 private constant _UINT256_MAX = 2**256 - 1;

constructor(string memory name, string memory symbol) public ERC20(name, symbol) { }
constructor(string memory name, string memory symbol) ERC20(name, symbol) { }

// The owner (GSNRecipientERC20Fee) can mint tokens
function mint(address account, uint256 amount) public onlyOwner {
Expand Down
4 changes: 2 additions & 2 deletions contracts/GSN/GSNRecipientSignature.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "./GSNRecipient.sol";
import "../cryptography/ECDSA.sol";
Expand All @@ -23,7 +23,7 @@ contract GSNRecipientSignature is GSNRecipient {
/**
* @dev Sets the trusted signer that is going to be producing signatures to approve relayed calls.
*/
constructor(address trustedSigner) public {
constructor(address trustedSigner) {
require(trustedSigner != address(0), "GSNRecipientSignature: trusted signer is the zero address");
_trustedSigner = trustedSigner;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/GSN/IRelayHub.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Interface for `RelayHub`, the core contract of the GSN. Users should not need to interact with this contract
Expand Down
2 changes: 1 addition & 1 deletion contracts/GSN/IRelayRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Base interface for a contract that will be called via the GSN from {IRelayHub}.
Expand Down
2 changes: 1 addition & 1 deletion contracts/access/AccessControl.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "../utils/EnumerableSet.sol";
import "../utils/Address.sol";
Expand Down
4 changes: 2 additions & 2 deletions contracts/access/Ownable.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "../GSN/Context.sol";
/**
Expand All @@ -23,7 +23,7 @@ abstract contract Ownable is Context {
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor () internal {
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
Expand Down
8 changes: 3 additions & 5 deletions contracts/access/TimelockController.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.9 <0.8.0;
pragma experimental ABIEncoderV2;
pragma solidity ^0.8.0;

import "./../math/SafeMath.sol";
import "./AccessControl.sol";

/**
Expand Down Expand Up @@ -52,7 +50,7 @@ contract TimelockController is AccessControl {
/**
* @dev Initializes the contract with a given `minDelay`.
*/
constructor(uint256 minDelay, address[] memory proposers, address[] memory executors) public {
constructor(uint256 minDelay, address[] memory proposers, address[] memory executors) {
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
Expand Down Expand Up @@ -188,7 +186,7 @@ contract TimelockController is AccessControl {
require(_timestamps[id] == 0, "TimelockController: operation already scheduled");
require(delay >= _minDelay, "TimelockController: insufficient delay");
// solhint-disable-next-line not-rely-on-time
_timestamps[id] = SafeMath.add(block.timestamp, delay);
_timestamps[id] = block.timestamp + delay;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/cryptography/ECDSA.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
Expand Down
2 changes: 1 addition & 1 deletion contracts/cryptography/MerkleProof.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev These functions deal with verification of Merkle trees (hash trees),
Expand Down
11 changes: 4 additions & 7 deletions contracts/drafts/EIP712.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
Expand Down Expand Up @@ -43,7 +43,7 @@ abstract contract EIP712 {
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) internal {
constructor(string memory name, string memory version) {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
Expand Down Expand Up @@ -96,10 +96,7 @@ abstract contract EIP712 {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
}

function _getChainId() private pure returns (uint256 chainId) {
// solhint-disable-next-line no-inline-assembly
assembly {
chainId := chainid()
}
function _getChainId() private view returns (uint256 chainId) {
chainId = block.chainid;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this function now and just use the built in.

}
4 changes: 2 additions & 2 deletions contracts/drafts/ERC20Permit.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.5 <0.8.0;
pragma solidity ^0.8.0;

import "../token/ERC20/ERC20.sol";
import "./IERC20Permit.sol";
Expand Down Expand Up @@ -29,7 +29,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) internal EIP712(name, "1") {
constructor(string memory name) EIP712(name, "1") {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/drafts/IERC20Permit.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
Expand Down
4 changes: 2 additions & 2 deletions contracts/introspection/ERC165.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "./IERC165.sol";

Expand All @@ -21,7 +21,7 @@ abstract contract ERC165 is IERC165 {
*/
mapping(bytes4 => bool) private _supportedInterfaces;

constructor () internal {
constructor () {
// Derived contracts need only register support for their own interfaces,
// we register support for ERC165 itself here
_registerInterface(_INTERFACE_ID_ERC165);
Expand Down
2 changes: 1 addition & 1 deletion contracts/introspection/ERC165Checker.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Library used to query support of an interface declared via {IERC165}.
Expand Down
2 changes: 1 addition & 1 deletion contracts/introspection/ERC1820Implementer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "./IERC1820Implementer.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/introspection/IERC165.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Interface of the ERC165 standard, as defined in the
Expand Down
2 changes: 1 addition & 1 deletion contracts/introspection/IERC1820Implementer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Interface for an ERC1820 implementer, as defined in the
Expand Down
2 changes: 1 addition & 1 deletion contracts/introspection/IERC1820Registry.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Interface of the global ERC1820 Registry, as defined in the
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/Math.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Standard math utilities missing in the Solidity language.
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/SafeMath.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
Expand Down
2 changes: 1 addition & 1 deletion contracts/math/SignedSafeMath.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

/**
* @title SignedSafeMath
Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/AccessControlMock.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "../access/AccessControl.sol";

contract AccessControlMock is AccessControl {
constructor() public {
constructor() {
_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/AddressImpl.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "../utils/Address.sol";

Expand Down
4 changes: 2 additions & 2 deletions contracts/mocks/ArraysImpl.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

import "../utils/Arrays.sol";

Expand All @@ -9,7 +9,7 @@ contract ArraysImpl {

uint256[] private _array;

constructor (uint256[] memory array) public {
constructor (uint256[] memory array) {
_array = array;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/BadBeacon.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

contract BadBeaconNoImpl {
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/CallReceiverMock.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;
pragma solidity ^0.8.0;

contract CallReceiverMock {
string public sharedAnswer;
Expand Down
Loading