Commit 16ee514b by github-actions

Merge upstream openzeppelin-contracts into upstream-patched

parents 357d1205 2e6ef745
...@@ -99,6 +99,8 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 { ...@@ -99,6 +99,8 @@ abstract contract AccessControl is Context, IAccessControl, ERC165 {
* The format of the revert reason is given by the following regular expression: * The format of the revert reason is given by the following regular expression:
* *
* /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/
*
* _Available since v4.1._
*/ */
modifier onlyRole(bytes32 role) { modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender()); _checkRole(role, _msgSender());
......
...@@ -5,6 +5,8 @@ pragma solidity ^0.8.0; ...@@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
/** /**
* @dev Interface of the ERC1271 standard signature validation method for * @dev Interface of the ERC1271 standard signature validation method for
* contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271]. * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
*
* _Available since v4.1._
*/ */
interface IERC1271 { interface IERC1271 {
/** /**
......
...@@ -5,6 +5,8 @@ pragma solidity ^0.8.0; ...@@ -5,6 +5,8 @@ pragma solidity ^0.8.0;
/** /**
* @dev Interface of the ERC3156 FlashBorrower, as defined in * @dev Interface of the ERC3156 FlashBorrower, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156]. * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/ */
interface IERC3156FlashBorrower { interface IERC3156FlashBorrower {
/** /**
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "../CountersImpl.sol"; import "../CountersImpl.sol";
import "../../proxy/UUPS/UUPSUpgradeable.sol"; import "../../proxy/utils/UUPSUpgradeable.sol";
contract UUPSUpgradeableMock is CountersImpl, UUPSUpgradeable { contract UUPSUpgradeableMock is CountersImpl, UUPSUpgradeable {
// Not having any checks in this function is dangerous! Do not do this outside tests! // Not having any checks in this function is dangerous! Do not do this outside tests!
......
...@@ -9,6 +9,8 @@ import "../../utils/StorageSlot.sol"; ...@@ -9,6 +9,8 @@ import "../../utils/StorageSlot.sol";
/** /**
* @dev This abstract contract provides setters and getters for the different * @dev This abstract contract provides setters and getters for the different
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] storage slots. * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] storage slots.
*
* _Available since v4.1._
*/ */
abstract contract ERC1967Storage { abstract contract ERC1967Storage {
/** /**
......
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.3; pragma solidity ^0.8.2;
import "./ERC1967Storage.sol"; import "./ERC1967Storage.sol";
...@@ -8,6 +8,8 @@ import "./ERC1967Storage.sol"; ...@@ -8,6 +8,8 @@ import "./ERC1967Storage.sol";
* @dev This abstract contract provides event emitting update functions for * @dev This abstract contract provides event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots. * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
* *
* _Available since v4.1._
*
* @custom:oz-upgrades-unsafe-allow delegatecall * @custom:oz-upgrades-unsafe-allow delegatecall
*/ */
abstract contract ERC1967Upgrade is ERC1967Storage { abstract contract ERC1967Upgrade is ERC1967Storage {
...@@ -59,16 +61,17 @@ abstract contract ERC1967Upgrade is ERC1967Storage { ...@@ -59,16 +61,17 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
*/ */
function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal { function _upgradeToAndCallSecure(address newImplementation, bytes memory data, bool forceCall) internal {
address oldImplementation = _getImplementation(); address oldImplementation = _getImplementation();
// do inital upgrade
// Initial upgrade and setup call
_setImplementation(newImplementation); _setImplementation(newImplementation);
// do setup call
if (data.length > 0 || forceCall) { if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data); Address.functionDelegateCall(newImplementation, data);
} }
// check if nested in an upgrade check
// Perform rollback test if not already in progress
StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT); StorageSlot.BooleanSlot storage rollbackTesting = StorageSlot.getBooleanSlot(_ROLLBACK_SLOT);
if (!rollbackTesting.value) { if (!rollbackTesting.value) {
// trigger upgrade check with flag set to true // Trigger rollback using upgradeTo from the new implementation
rollbackTesting.value = true; rollbackTesting.value = true;
Address.functionDelegateCall( Address.functionDelegateCall(
newImplementation, newImplementation,
...@@ -78,11 +81,10 @@ abstract contract ERC1967Upgrade is ERC1967Storage { ...@@ -78,11 +81,10 @@ abstract contract ERC1967Upgrade is ERC1967Storage {
) )
); );
rollbackTesting.value = false; rollbackTesting.value = false;
// check upgrade was effective // Check rollback was effective
require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades"); require(oldImplementation == _getImplementation(), "ERC1967Upgrade: upgrade breaks further upgrades");
// reset upgrade // Finally reset to the new implementation and log the upgrade
_setImplementation(newImplementation); _setImplementation(newImplementation);
// emit event
emit Upgraded(newImplementation); emit Upgraded(newImplementation);
} }
} }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
// solhint-disable-next-line compiler-version // solhint-disable-next-line compiler-version
pragma solidity ^0.8.0; pragma solidity ^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
* behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an
......
...@@ -10,6 +10,8 @@ import "../ERC1967/ERC1967Upgrade.sol"; ...@@ -10,6 +10,8 @@ import "../ERC1967/ERC1967Upgrade.sol";
* continuation of the upgradability. * continuation of the upgradability.
* *
* The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism. * The {_authorizeUpgrade} function MUST be overridden to include access restriction to the upgrade mechanism.
*
* _Available since v4.1._
*/ */
abstract contract UUPSUpgradeable is ERC1967Upgrade { abstract contract UUPSUpgradeable is ERC1967Upgrade {
function upgradeTo(address newImplementation) external virtual { function upgradeTo(address newImplementation) external virtual {
......
...@@ -130,11 +130,57 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -130,11 +130,57 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
virtual virtual
override override
{ {
require(to != address(0), "ERC1155: transfer to the zero address");
require( require(
from == _msgSender() || isApprovedForAll(from, _msgSender()), from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: caller is not owner nor approved" "ERC1155: caller is not owner nor approved"
); );
_safeTransferFrom(from, to, id, amount, data);
}
/**
* @dev See {IERC1155-safeBatchTransferFrom}.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
)
public
virtual
override
{
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
_safeBatchTransferFrom(from, to, ids, amounts, data);
}
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function _safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes memory data
)
internal
virtual
{
require(to != address(0), "ERC1155: transfer to the zero address");
address operator = _msgSender(); address operator = _msgSender();
...@@ -151,25 +197,27 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI { ...@@ -151,25 +197,27 @@ contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI {
} }
/** /**
* @dev See {IERC1155-safeBatchTransferFrom}. * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/ */
function safeBatchTransferFrom( function _safeBatchTransferFrom(
address from, address from,
address to, address to,
uint256[] memory ids, uint256[] memory ids,
uint256[] memory amounts, uint256[] memory amounts,
bytes memory data bytes memory data
) )
public internal
virtual virtual
override
{ {
require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");
require(to != address(0), "ERC1155: transfer to the zero address"); require(to != address(0), "ERC1155: transfer to the zero address");
require(
from == _msgSender() || isApprovedForAll(from, _msgSender()),
"ERC1155: transfer caller is not owner nor approved"
);
address operator = _msgSender(); address operator = _msgSender();
......
...@@ -6,6 +6,8 @@ import "../IERC20.sol"; ...@@ -6,6 +6,8 @@ import "../IERC20.sol";
/** /**
* @dev Interface for the optional metadata functions from the ERC20 standard. * @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/ */
interface IERC20Metadata is IERC20 { interface IERC20Metadata is IERC20 {
/** /**
......
...@@ -11,6 +11,8 @@ import "../ERC20.sol"; ...@@ -11,6 +11,8 @@ import "../ERC20.sol";
* *
* Adds the {flashLoan} method, which provides flash loan support at the token * Adds the {flashLoan} method, which provides flash loan support at the token
* level. By default there is no fee, but this can be changed by overriding {flashFee}. * level. By default there is no fee, but this can be changed by overriding {flashFee}.
*
* _Available since v4.1._
*/ */
abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender { abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
bytes32 constant private RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan"); bytes32 constant private RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");
......
...@@ -77,6 +77,8 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { ...@@ -77,6 +77,8 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 {
/** /**
* @dev "Consume a nonce": return the current value and increment. * @dev "Consume a nonce": return the current value and increment.
*
* _Available since v4.1._
*/ */
function _useNonce(address owner) internal virtual returns (uint256 current) { function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _nonces[owner]; Counters.Counter storage nonce = _nonces[owner];
......
...@@ -6,6 +6,8 @@ import "./Address.sol"; ...@@ -6,6 +6,8 @@ import "./Address.sol";
/** /**
* @dev Provides a function to batch together multiple calls in a single external call. * @dev Provides a function to batch together multiple calls in a single external call.
*
* _Available since v4.1._
*/ */
abstract contract Multicall { abstract contract Multicall {
/** /**
......
...@@ -26,7 +26,7 @@ pragma solidity ^0.8.0; ...@@ -26,7 +26,7 @@ pragma solidity ^0.8.0;
* } * }
* ``` * ```
* *
* Available since v4.1.0 for `address`, `bool`, `bytes32`, and `uint256`. * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._
*/ */
library StorageSlot { library StorageSlot {
struct AddressSlot { struct AddressSlot {
......
...@@ -31,7 +31,7 @@ library ECDSA { ...@@ -31,7 +31,7 @@ library ECDSA {
// Check the signature length // Check the signature length
// - case 65: r,s,v signature (standard) // - case 65: r,s,v signature (standard)
// - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
if (signature.length == 65) { if (signature.length == 65) {
// ecrecover takes the signature parameters, and the only way to get them // ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly. // currently is to use assembly.
......
...@@ -13,6 +13,8 @@ import "../../interfaces/IERC1271.sol"; ...@@ -13,6 +13,8 @@ import "../../interfaces/IERC1271.sol";
* *
* Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change * Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change
* through time. It could return true at block N and false at block N+1 (or the opposite). * through time. It could return true at block N and false at block N+1 (or the opposite).
*
* _Available since v4.1._
*/ */
library SignatureChecker { library SignatureChecker {
function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) { function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
......
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