Unverified Commit faec973e by Hadrien Croubois Committed by GitHub

Make non-view functions virtual (#2468)

parent 65b7e515
...@@ -36,7 +36,7 @@ contract Escrow is Ownable { ...@@ -36,7 +36,7 @@ contract Escrow is Ownable {
* @dev Stores the sent amount as credit to be withdrawn. * @dev Stores the sent amount as credit to be withdrawn.
* @param payee The destination address of the funds. * @param payee The destination address of the funds.
*/ */
function deposit(address payee) public virtual payable onlyOwner { function deposit(address payee) public payable virtual onlyOwner {
uint256 amount = msg.value; uint256 amount = msg.value;
_deposits[payee] = _deposits[payee].add(amount); _deposits[payee] = _deposits[payee].add(amount);
......
...@@ -63,7 +63,7 @@ contract BeaconProxy is Proxy { ...@@ -63,7 +63,7 @@ contract BeaconProxy is Proxy {
* - `beacon` must be a contract. * - `beacon` must be a contract.
* - The implementation returned by `beacon` must be a contract. * - The implementation returned by `beacon` must be a contract.
*/ */
function _setBeacon(address beacon, bytes memory data) internal { function _setBeacon(address beacon, bytes memory data) internal virtual {
require( require(
Address.isContract(beacon), Address.isContract(beacon),
"BeaconProxy: beacon is not a contract" "BeaconProxy: beacon is not a contract"
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// solhint-disable-next-line compiler-version // solhint-disable-next-line compiler-version
pragma solidity >=0.4.24 <0.8.0; pragma solidity >=0.4.24 <0.8.0;
import "../utils/Address.sol";
/** /**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
...@@ -49,15 +50,6 @@ abstract contract Initializable { ...@@ -49,15 +50,6 @@ abstract contract Initializable {
/// @dev Returns true if and only if the function is running in the constructor /// @dev Returns true if and only if the function is running in the constructor
function _isConstructor() private view returns (bool) { function _isConstructor() private view returns (bool) {
// extcodesize checks the size of the code stored in an address, and return !Address.isContract(address(this));
// address returns the current address. Since the code is still not
// deployed when running a constructor, any checks on its code size will
// yield zero, making it an effective way to detect if a contract is
// under construction or not.
address self = address(this);
uint256 cs;
// solhint-disable-next-line no-inline-assembly
assembly { cs := extcodesize(self) }
return cs == 0;
} }
} }
...@@ -18,7 +18,7 @@ abstract contract Proxy { ...@@ -18,7 +18,7 @@ abstract contract Proxy {
* *
* This function does not return to its internall call site, it will return directly to the external caller. * This function does not return to its internall call site, it will return directly to the external caller.
*/ */
function _delegate(address implementation) internal { function _delegate(address implementation) internal virtual {
// solhint-disable-next-line no-inline-assembly // solhint-disable-next-line no-inline-assembly
assembly { assembly {
// Copy msg.data. We take full control of memory in this inline assembly // Copy msg.data. We take full control of memory in this inline assembly
...@@ -51,7 +51,7 @@ abstract contract Proxy { ...@@ -51,7 +51,7 @@ abstract contract Proxy {
* *
* This function does not return to its internall call site, it will return directly to the external caller. * This function does not return to its internall call site, it will return directly to the external caller.
*/ */
function _fallback() internal { function _fallback() internal virtual {
_beforeFallback(); _beforeFallback();
_delegate(_implementation()); _delegate(_implementation());
} }
...@@ -60,7 +60,7 @@ abstract contract Proxy { ...@@ -60,7 +60,7 @@ abstract contract Proxy {
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data. * function in the contract matches the call data.
*/ */
fallback () external payable { fallback () external payable virtual {
_fallback(); _fallback();
} }
...@@ -68,7 +68,7 @@ abstract contract Proxy { ...@@ -68,7 +68,7 @@ abstract contract Proxy {
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty. * is empty.
*/ */
receive () external payable { receive () external payable virtual {
_fallback(); _fallback();
} }
......
...@@ -48,7 +48,7 @@ contract ProxyAdmin is Ownable { ...@@ -48,7 +48,7 @@ contract ProxyAdmin is Ownable {
* *
* - This contract must be the current admin of `proxy`. * - This contract must be the current admin of `proxy`.
*/ */
function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public onlyOwner { function changeProxyAdmin(TransparentUpgradeableProxy proxy, address newAdmin) public virtual onlyOwner {
proxy.changeAdmin(newAdmin); proxy.changeAdmin(newAdmin);
} }
...@@ -59,7 +59,7 @@ contract ProxyAdmin is Ownable { ...@@ -59,7 +59,7 @@ contract ProxyAdmin is Ownable {
* *
* - This contract must be the admin of `proxy`. * - This contract must be the admin of `proxy`.
*/ */
function upgrade(TransparentUpgradeableProxy proxy, address implementation) public onlyOwner { function upgrade(TransparentUpgradeableProxy proxy, address implementation) public virtual onlyOwner {
proxy.upgradeTo(implementation); proxy.upgradeTo(implementation);
} }
...@@ -71,7 +71,7 @@ contract ProxyAdmin is Ownable { ...@@ -71,7 +71,7 @@ contract ProxyAdmin is Ownable {
* *
* - This contract must be the admin of `proxy`. * - This contract must be the admin of `proxy`.
*/ */
function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable onlyOwner { function upgradeAndCall(TransparentUpgradeableProxy proxy, address implementation, bytes memory data) public payable virtual onlyOwner {
proxy.upgradeToAndCall{value: msg.value}(implementation, data); proxy.upgradeToAndCall{value: msg.value}(implementation, data);
} }
} }
...@@ -91,7 +91,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy { ...@@ -91,7 +91,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
* *
* NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}. * NOTE: Only the admin can call this function. See {ProxyAdmin-changeProxyAdmin}.
*/ */
function changeAdmin(address newAdmin) external ifAdmin { function changeAdmin(address newAdmin) external virtual ifAdmin {
require(newAdmin != address(0), "TransparentUpgradeableProxy: new admin is the zero address"); require(newAdmin != address(0), "TransparentUpgradeableProxy: new admin is the zero address");
emit AdminChanged(_admin(), newAdmin); emit AdminChanged(_admin(), newAdmin);
_setAdmin(newAdmin); _setAdmin(newAdmin);
...@@ -102,7 +102,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy { ...@@ -102,7 +102,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
* *
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}. * NOTE: Only the admin can call this function. See {ProxyAdmin-upgrade}.
*/ */
function upgradeTo(address newImplementation) external ifAdmin { function upgradeTo(address newImplementation) external virtual ifAdmin {
_upgradeTo(newImplementation); _upgradeTo(newImplementation);
} }
...@@ -113,7 +113,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy { ...@@ -113,7 +113,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
* *
* NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}. * NOTE: Only the admin can call this function. See {ProxyAdmin-upgradeAndCall}.
*/ */
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { function upgradeToAndCall(address newImplementation, bytes calldata data) external payable virtual ifAdmin {
_upgradeTo(newImplementation); _upgradeTo(newImplementation);
Address.functionDelegateCall(newImplementation, data); Address.functionDelegateCall(newImplementation, data);
} }
...@@ -144,7 +144,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy { ...@@ -144,7 +144,7 @@ contract TransparentUpgradeableProxy is UpgradeableProxy {
/** /**
* @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}. * @dev Makes sure the admin cannot access the fallback function. See {Proxy-_beforeFallback}.
*/ */
function _beforeFallback() internal override virtual { function _beforeFallback() internal virtual override {
require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target"); require(msg.sender != _admin(), "TransparentUpgradeableProxy: admin cannot fallback to proxy target");
super._beforeFallback(); super._beforeFallback();
} }
......
...@@ -45,7 +45,7 @@ contract UpgradeableBeacon is IBeacon, Ownable { ...@@ -45,7 +45,7 @@ contract UpgradeableBeacon is IBeacon, Ownable {
* - msg.sender must be the owner of the contract. * - msg.sender must be the owner of the contract.
* - `newImplementation` must be a contract. * - `newImplementation` must be a contract.
*/ */
function upgradeTo(address newImplementation) public onlyOwner { function upgradeTo(address newImplementation) public virtual onlyOwner {
_setImplementation(newImplementation); _setImplementation(newImplementation);
emit Upgraded(newImplementation); emit Upgraded(newImplementation);
} }
......
...@@ -44,7 +44,7 @@ contract UpgradeableProxy is Proxy { ...@@ -44,7 +44,7 @@ contract UpgradeableProxy is Proxy {
/** /**
* @dev Returns the current implementation address. * @dev Returns the current implementation address.
*/ */
function _implementation() internal override view returns (address impl) { function _implementation() internal view override returns (address impl) {
bytes32 slot = _IMPLEMENTATION_SLOT; bytes32 slot = _IMPLEMENTATION_SLOT;
// solhint-disable-next-line no-inline-assembly // solhint-disable-next-line no-inline-assembly
assembly { assembly {
...@@ -57,7 +57,7 @@ contract UpgradeableProxy is Proxy { ...@@ -57,7 +57,7 @@ contract UpgradeableProxy is Proxy {
* *
* Emits an {Upgraded} event. * Emits an {Upgraded} event.
*/ */
function _upgradeTo(address newImplementation) internal { function _upgradeTo(address newImplementation) internal virtual {
_setImplementation(newImplementation); _setImplementation(newImplementation);
emit Upgraded(newImplementation); emit Upgraded(newImplementation);
} }
......
...@@ -355,7 +355,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -355,7 +355,8 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) )
internal virtual internal
virtual
{ } { }
function _doSafeTransferAcceptanceCheck( function _doSafeTransferAcceptanceCheck(
......
...@@ -30,7 +30,9 @@ abstract contract ERC1155Pausable is ERC1155, Pausable { ...@@ -30,7 +30,9 @@ abstract contract ERC1155Pausable is ERC1155, Pausable {
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) )
internal virtual override internal
virtual
override
{ {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
......
...@@ -284,7 +284,7 @@ contract ERC20 is Context, IERC20 { ...@@ -284,7 +284,7 @@ contract ERC20 is Context, IERC20 {
* applications that interact with token contracts will not expect * applications that interact with token contracts will not expect
* {decimals} to ever change, and may work incorrectly if it does. * {decimals} to ever change, and may work incorrectly if it does.
*/ */
function _setupDecimals(uint8 decimals_) internal { function _setupDecimals(uint8 decimals_) internal virtual {
_decimals = decimals_; _decimals = decimals_;
} }
......
...@@ -70,7 +70,9 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -70,7 +70,9 @@ contract ERC777 is Context, IERC777, IERC20 {
string memory name_, string memory name_,
string memory symbol_, string memory symbol_,
address[] memory defaultOperators_ address[] memory defaultOperators_
) public { )
public
{
_name = name_; _name = name_;
_symbol = symbol_; _symbol = symbol_;
...@@ -136,7 +138,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -136,7 +138,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Also emits a {IERC20-Transfer} event for ERC20 compatibility. * Also emits a {IERC20-Transfer} event for ERC20 compatibility.
*/ */
function send(address recipient, uint256 amount, bytes memory data) public override { function send(address recipient, uint256 amount, bytes memory data) public virtual override {
_send(_msgSender(), recipient, amount, data, "", true); _send(_msgSender(), recipient, amount, data, "", true);
} }
...@@ -148,7 +150,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -148,7 +150,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Also emits a {Sent} event. * Also emits a {Sent} event.
*/ */
function transfer(address recipient, uint256 amount) public override returns (bool) { function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address"); require(recipient != address(0), "ERC777: transfer to the zero address");
address from = _msgSender(); address from = _msgSender();
...@@ -167,17 +169,14 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -167,17 +169,14 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Also emits a {IERC20-Transfer} event for ERC20 compatibility. * Also emits a {IERC20-Transfer} event for ERC20 compatibility.
*/ */
function burn(uint256 amount, bytes memory data) public override { function burn(uint256 amount, bytes memory data) public virtual override {
_burn(_msgSender(), amount, data, ""); _burn(_msgSender(), amount, data, "");
} }
/** /**
* @dev See {IERC777-isOperatorFor}. * @dev See {IERC777-isOperatorFor}.
*/ */
function isOperatorFor( function isOperatorFor(address operator, address tokenHolder) public view override returns (bool) {
address operator,
address tokenHolder
) public view override returns (bool) {
return operator == tokenHolder || return operator == tokenHolder ||
(_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) || (_defaultOperators[operator] && !_revokedDefaultOperators[tokenHolder][operator]) ||
_operators[tokenHolder][operator]; _operators[tokenHolder][operator];
...@@ -186,7 +185,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -186,7 +185,7 @@ contract ERC777 is Context, IERC777, IERC20 {
/** /**
* @dev See {IERC777-authorizeOperator}. * @dev See {IERC777-authorizeOperator}.
*/ */
function authorizeOperator(address operator) public override { function authorizeOperator(address operator) public virtual override {
require(_msgSender() != operator, "ERC777: authorizing self as operator"); require(_msgSender() != operator, "ERC777: authorizing self as operator");
if (_defaultOperators[operator]) { if (_defaultOperators[operator]) {
...@@ -201,7 +200,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -201,7 +200,7 @@ contract ERC777 is Context, IERC777, IERC20 {
/** /**
* @dev See {IERC777-revokeOperator}. * @dev See {IERC777-revokeOperator}.
*/ */
function revokeOperator(address operator) public override { function revokeOperator(address operator) public virtual override {
require(operator != _msgSender(), "ERC777: revoking self as operator"); require(operator != _msgSender(), "ERC777: revoking self as operator");
if (_defaultOperators[operator]) { if (_defaultOperators[operator]) {
...@@ -232,7 +231,9 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -232,7 +231,9 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory data, bytes memory data,
bytes memory operatorData bytes memory operatorData
) )
public override public
virtual
override
{ {
require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder"); require(isOperatorFor(_msgSender(), sender), "ERC777: caller is not an operator for holder");
_send(sender, recipient, amount, data, operatorData, true); _send(sender, recipient, amount, data, operatorData, true);
...@@ -243,7 +244,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -243,7 +244,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Emits {Burned} and {IERC20-Transfer} events. * Emits {Burned} and {IERC20-Transfer} events.
*/ */
function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public override { function operatorBurn(address account, uint256 amount, bytes memory data, bytes memory operatorData) public virtual override {
require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder"); require(isOperatorFor(_msgSender(), account), "ERC777: caller is not an operator for holder");
_burn(account, amount, data, operatorData); _burn(account, amount, data, operatorData);
} }
...@@ -264,7 +265,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -264,7 +265,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Note that accounts cannot have allowance issued by their operators. * Note that accounts cannot have allowance issued by their operators.
*/ */
function approve(address spender, uint256 value) public override returns (bool) { function approve(address spender, uint256 value) public virtual override returns (bool) {
address holder = _msgSender(); address holder = _msgSender();
_approve(holder, spender, value); _approve(holder, spender, value);
return true; return true;
...@@ -279,7 +280,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -279,7 +280,7 @@ contract ERC777 is Context, IERC777, IERC20 {
* *
* Emits {Sent}, {IERC20-Transfer} and {IERC20-Approval} events. * Emits {Sent}, {IERC20-Transfer} and {IERC20-Approval} events.
*/ */
function transferFrom(address holder, address recipient, uint256 amount) public override returns (bool) { function transferFrom(address holder, address recipient, uint256 amount) public virtual override returns (bool) {
require(recipient != address(0), "ERC777: transfer to the zero address"); require(recipient != address(0), "ERC777: transfer to the zero address");
require(holder != address(0), "ERC777: transfer from the zero address"); require(holder != address(0), "ERC777: transfer from the zero address");
...@@ -318,7 +319,8 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -318,7 +319,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory userData, bytes memory userData,
bytes memory operatorData bytes memory operatorData
) )
internal virtual internal
virtual
{ {
require(account != address(0), "ERC777: mint to the zero address"); require(account != address(0), "ERC777: mint to the zero address");
...@@ -354,6 +356,7 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -354,6 +356,7 @@ contract ERC777 is Context, IERC777, IERC20 {
bool requireReceptionAck bool requireReceptionAck
) )
internal internal
virtual
{ {
require(from != address(0), "ERC777: send from the zero address"); require(from != address(0), "ERC777: send from the zero address");
require(to != address(0), "ERC777: send to the zero address"); require(to != address(0), "ERC777: send to the zero address");
...@@ -380,7 +383,8 @@ contract ERC777 is Context, IERC777, IERC20 { ...@@ -380,7 +383,8 @@ contract ERC777 is Context, IERC777, IERC20 {
bytes memory data, bytes memory data,
bytes memory operatorData bytes memory operatorData
) )
internal virtual internal
virtual
{ {
require(from != address(0), "ERC777: burn from the zero address"); require(from != address(0), "ERC777: burn from the zero address");
......
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