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

Initial migration to Solidity 0.6.x - v3.0 first steps #2063

Merged
merged 14 commits into from
Jan 28, 2020
3 changes: 2 additions & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"separate-by-one-line-in-contract": "off",
"two-lines-top-level-separator": "off",
"mark-callable-contracts": "off",
"compiler-version": ["error", "^0.5.0"]
"no-empty-blocks": "off",
"compiler-version": ["error", "^0.6.0"]
}
}
7 changes: 3 additions & 4 deletions contracts/GSN/Context.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

/*
* @dev Provides information about the current execution context, including the
Expand All @@ -14,13 +14,12 @@ contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor () internal { }
// solhint-disable-previous-line no-empty-blocks

function _msgSender() internal view returns (address payable) {
function _msgSender() internal view virtual returns (address payable) {
return msg.sender;
}

function _msgData() internal view returns (bytes memory) {
function _msgData() internal view virtual returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
Expand Down
22 changes: 11 additions & 11 deletions contracts/GSN/GSNRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "./IRelayRecipient.sol";
import "./IRelayHub.sol";
Expand All @@ -15,7 +15,7 @@ import "./Context.sol";
* information on how to use the pre-built {GSNRecipientSignature} and
* {GSNRecipientERC20Fee}, or how to write your own.
*/
contract GSNRecipient is IRelayRecipient, Context {
abstract contract GSNRecipient is IRelayRecipient, Context {
// Default RelayHub address, deployed on mainnet and all testnets at the same address
address private _relayHub = 0xD216153c06E857cD7f72665E0aF1d7D82172F494;

Expand All @@ -33,7 +33,7 @@ contract GSNRecipient is IRelayRecipient, Context {
/**
* @dev Returns the address of the {IRelayHub} contract for this recipient.
*/
function getHubAddr() public view returns (address) {
function getHubAddr() public view override returns (address) {
return _relayHub;
}

Expand All @@ -44,7 +44,7 @@ contract GSNRecipient is IRelayRecipient, Context {
* IMPORTANT: After upgrading, the {GSNRecipient} will no longer be able to receive relayed calls from the old
* {IRelayHub} instance. Additionally, all funds should be previously withdrawn via {_withdrawDeposits}.
*/
function _upgradeRelayHub(address newRelayHub) internal {
function _upgradeRelayHub(address newRelayHub) internal virtual {
address currentRelayHub = _relayHub;
require(newRelayHub != address(0), "GSNRecipient: new RelayHub is the zero address");
require(newRelayHub != currentRelayHub, "GSNRecipient: new RelayHub is the current one");
Expand All @@ -70,7 +70,7 @@ contract GSNRecipient is IRelayRecipient, Context {
*
* Derived contracts should expose this in an external interface with proper access control.
*/
function _withdrawDeposits(uint256 amount, address payable payee) internal {
function _withdrawDeposits(uint256 amount, address payable payee) internal virtual {
IRelayHub(_relayHub).withdraw(amount, payee);
}

Expand All @@ -85,7 +85,7 @@ contract GSNRecipient is IRelayRecipient, Context {
*
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.sender`, and use {_msgSender} instead.
*/
function _msgSender() internal view returns (address payable) {
function _msgSender() internal view virtual override returns (address payable) {
if (msg.sender != _relayHub) {
return msg.sender;
} else {
Expand All @@ -99,7 +99,7 @@ contract GSNRecipient is IRelayRecipient, Context {
*
* IMPORTANT: Contracts derived from {GSNRecipient} should never use `msg.data`, and use {_msgData} instead.
*/
function _msgData() internal view returns (bytes memory) {
function _msgData() internal view virtual override returns (bytes memory) {
if (msg.sender != _relayHub) {
return msg.data;
} else {
Expand All @@ -119,7 +119,7 @@ contract GSNRecipient is IRelayRecipient, Context {
*
* - the caller must be the `RelayHub` contract.
*/
function preRelayedCall(bytes calldata context) external returns (bytes32) {
function preRelayedCall(bytes calldata context) external virtual override returns (bytes32) {
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
return _preRelayedCall(context);
}
Expand All @@ -131,7 +131,7 @@ contract GSNRecipient is IRelayRecipient, Context {
* must implement this function with any relayed-call preprocessing they may wish to do.
*
*/
function _preRelayedCall(bytes memory context) internal returns (bytes32);
function _preRelayedCall(bytes memory context) internal virtual returns (bytes32);

/**
* @dev See `IRelayRecipient.postRelayedCall`.
Expand All @@ -142,7 +142,7 @@ contract GSNRecipient is IRelayRecipient, Context {
*
* - the caller must be the `RelayHub` contract.
*/
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external {
function postRelayedCall(bytes calldata context, bool success, uint256 actualCharge, bytes32 preRetVal) external virtual override {
require(msg.sender == getHubAddr(), "GSNRecipient: caller is not RelayHub");
_postRelayedCall(context, success, actualCharge, preRetVal);
}
Expand All @@ -154,7 +154,7 @@ contract GSNRecipient is IRelayRecipient, Context {
* must implement this function with any relayed-call postprocessing they may wish to do.
*
*/
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal;
function _postRelayedCall(bytes memory context, bool success, uint256 actualCharge, bytes32 preRetVal) internal virtual;

/**
* @dev Return this in acceptRelayedCall to proceed with the execution of a relayed call. Note that this contract
Expand Down
20 changes: 10 additions & 10 deletions contracts/GSN/GSNRecipientERC20Fee.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "./GSNRecipient.sol";
import "../math/SafeMath.sol";
Expand Down Expand Up @@ -43,7 +43,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
/**
* @dev Internal function that mints the gas payment token. Derived contracts should expose this function in their public API, with proper access control mechanisms.
*/
function _mint(address account, uint256 amount) internal {
function _mint(address account, uint256 amount) internal virtual {
_token.mint(account, amount);
}

Expand All @@ -63,6 +63,8 @@ contract GSNRecipientERC20Fee is GSNRecipient {
)
external
view
virtual
override
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope the linter decides to put these 4 words on a single line

returns (uint256, bytes memory)
{
if (_token.balanceOf(from) < maxPossibleCharge) {
Expand All @@ -78,7 +80,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
* actual charge, necessary because we cannot predict how much gas the execution will actually need. The remainder
* is returned to the user in {_postRelayedCall}.
*/
function _preRelayedCall(bytes memory context) internal returns (bytes32) {
function _preRelayedCall(bytes memory context) internal virtual override returns (bytes32) {
(address from, uint256 maxPossibleCharge) = abi.decode(context, (address, uint256));

// The maximum token charge is pre-charged from the user
Expand All @@ -88,7 +90,7 @@ contract GSNRecipientERC20Fee is GSNRecipient {
/**
* @dev Returns to the user the extra amount that was previously charged, once the actual execution cost is known.
*/
function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal virtual override {
(address from, uint256 maxPossibleCharge, uint256 transactionFee, uint256 gasPrice) =
abi.decode(context, (address, uint256, uint256, uint256));

Expand All @@ -113,17 +115,15 @@ contract GSNRecipientERC20Fee is GSNRecipient {
contract __unstable__ERC20PrimaryAdmin is ERC20, ERC20Detailed, Secondary {
uint256 private constant UINT256_MAX = 2**256 - 1;

constructor(string memory name, string memory symbol, uint8 decimals) public ERC20Detailed(name, symbol, decimals) {
// solhint-disable-previous-line no-empty-blocks
}
constructor(string memory name, string memory symbol, uint8 decimals) public ERC20Detailed(name, symbol, decimals) { }

// The primary account (GSNRecipientERC20Fee) can mint tokens
function mint(address account, uint256 amount) public onlyPrimary {
_mint(account, amount);
}

// The primary account has 'infinite' allowance for all token holders
function allowance(address owner, address spender) public view returns (uint256) {
function allowance(address owner, address spender) public view override(ERC20, IERC20) returns (uint256) {
if (spender == primary()) {
return UINT256_MAX;
} else {
Expand All @@ -132,15 +132,15 @@ contract __unstable__ERC20PrimaryAdmin is ERC20, ERC20Detailed, Secondary {
}

// Allowance for the primary account cannot be changed (it is always 'infinite')
function _approve(address owner, address spender, uint256 value) internal {
function _approve(address owner, address spender, uint256 value) internal override {
if (spender == primary()) {
return;
} else {
super._approve(owner, spender, value);
}
}

function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
function transferFrom(address sender, address recipient, uint256 amount) public override(ERC20, IERC20) returns (bool) {
if (recipient == primary()) {
_transfer(sender, recipient, amount);
return true;
Expand Down
12 changes: 5 additions & 7 deletions contracts/GSN/GSNRecipientSignature.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "./GSNRecipient.sol";
import "../cryptography/ECDSA.sol";
Expand Down Expand Up @@ -42,6 +42,8 @@ contract GSNRecipientSignature is GSNRecipient {
)
external
view
virtual
override
returns (uint256, bytes memory)
{
bytes memory blob = abi.encodePacked(
Expand All @@ -62,11 +64,7 @@ contract GSNRecipientSignature is GSNRecipient {
}
}

function _preRelayedCall(bytes memory) internal returns (bytes32) {
// solhint-disable-previous-line no-empty-blocks
}
function _preRelayedCall(bytes memory) internal virtual override returns (bytes32) { }

function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal {
// solhint-disable-previous-line no-empty-blocks
}
function _postRelayedCall(bytes memory, bool, uint256, bytes32) internal virtual override { }
}
6 changes: 3 additions & 3 deletions contracts/GSN/IRelayHub.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

/**
* @dev Interface for `RelayHub`, the core contract of the GSN. Users should not need to interact with this contract
Expand Down Expand Up @@ -207,7 +207,7 @@ interface IRelayHub {
event CanRelayFailed(address indexed relay, address indexed from, address indexed to, bytes4 selector, uint256 reason);

/**
* @dev Emitted when a transaction is relayed.
* @dev Emitted when a transaction is relayed.
* Useful when monitoring a relay's operation and relayed calls to a contract
*
* Note that the actual encoded function might be reverted: this is indicated in the `status` parameter.
Expand Down Expand Up @@ -236,7 +236,7 @@ interface IRelayHub {
*/
function maxPossibleCharge(uint256 relayedCallStipend, uint256 gasPrice, uint256 transactionFee) external view returns (uint256);

// Relay penalization.
// Relay penalization.
// Any account can penalize relays, removing them from the system immediately, and rewarding the
// reporter with half of the relay's stake. The other half is burned so that, even if the relay penalizes itself, it
// still loses half of its stake.
Expand Down
2 changes: 1 addition & 1 deletion contracts/GSN/IRelayRecipient.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.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/Roles.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

/**
* @title Roles
Expand Down
10 changes: 5 additions & 5 deletions contracts/access/roles/CapperRole.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "../../GSN/Context.sol";
import "../Roles.sol";
Expand All @@ -24,20 +24,20 @@ contract CapperRole is Context {
return _cappers.has(account);
}

function addCapper(address account) public onlyCapper {
function addCapper(address account) public virtual onlyCapper {
_addCapper(account);
}

function renounceCapper() public {
function renounceCapper() public virtual {
_removeCapper(_msgSender());
}

function _addCapper(address account) internal {
function _addCapper(address account) internal virtual {
_cappers.add(account);
emit CapperAdded(account);
}

function _removeCapper(address account) internal {
function _removeCapper(address account) internal virtual {
_cappers.remove(account);
emit CapperRemoved(account);
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/access/roles/MinterRole.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "../../GSN/Context.sol";
import "../Roles.sol";
Expand All @@ -24,20 +24,20 @@ contract MinterRole is Context {
return _minters.has(account);
}

function addMinter(address account) public onlyMinter {
function addMinter(address account) public virtual onlyMinter {
_addMinter(account);
}

function renounceMinter() public {
function renounceMinter() public virtual {
_removeMinter(_msgSender());
}

function _addMinter(address account) internal {
function _addMinter(address account) internal virtual {
_minters.add(account);
emit MinterAdded(account);
}

function _removeMinter(address account) internal {
function _removeMinter(address account) internal virtual {
_minters.remove(account);
emit MinterRemoved(account);
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/access/roles/PauserRole.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "../../GSN/Context.sol";
import "../Roles.sol";
Expand All @@ -24,20 +24,20 @@ contract PauserRole is Context {
return _pausers.has(account);
}

function addPauser(address account) public onlyPauser {
function addPauser(address account) public virtual onlyPauser {
_addPauser(account);
}

function renouncePauser() public {
function renouncePauser() public virtual {
_removePauser(_msgSender());
}

function _addPauser(address account) internal {
function _addPauser(address account) internal virtual {
_pausers.add(account);
emit PauserAdded(account);
}

function _removePauser(address account) internal {
function _removePauser(address account) internal virtual {
_pausers.remove(account);
emit PauserRemoved(account);
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/access/roles/SignerRole.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6.0;

import "../../GSN/Context.sol";
import "../Roles.sol";
Expand All @@ -24,20 +24,20 @@ contract SignerRole is Context {
return _signers.has(account);
}

function addSigner(address account) public onlySigner {
function addSigner(address account) public virtual onlySigner {
_addSigner(account);
}

function renounceSigner() public {
function renounceSigner() public virtual {
_removeSigner(_msgSender());
}

function _addSigner(address account) internal {
function _addSigner(address account) internal virtual {
_signers.add(account);
emit SignerAdded(account);
}

function _removeSigner(address account) internal {
function _removeSigner(address account) internal virtual {
_signers.remove(account);
emit SignerRemoved(account);
}
Expand Down
Loading