From 93438eca0bdde2b023aafa803c86ccf50a2f0c2c Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 2 Feb 2021 22:07:56 +0100 Subject: [PATCH] Merge 3.4 master into solc-0.8 (#2499) * 3.4.0-rc.0 * Allow manual dispatch of Test CI job * Update lockfile (#2481) Co-authored-by: Renovate Bot * Add "available since" comments in documentation * Add "available since" comments in documentation (cherry picked from commit 63a0343dda0b553319a799c63e4fa23f2f3737da) * Remove SafeMathMock compilation warnings (#2497) * Remove SafeMathMock compilation warnings (#2497) (cherry picked from commit f4e57fd52931e5f434bc382506af959351b5598d) * 3.4.0 * fix safemath test to use renamed function from the mock Co-authored-by: Francisco Giordano Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Renovate Bot --- CHANGELOG.md | 2 +- contracts/drafts/EIP712.sol | 2 ++ contracts/drafts/ERC20Permit.sol | 2 ++ contracts/introspection/ERC165Checker.sol | 2 ++ contracts/math/SafeMath.sol | 10 ++++++ contracts/mocks/SafeMathMock.sol | 12 ++++--- contracts/package.json | 2 +- contracts/presets/ERC20PresetFixedSupply.sol | 2 ++ contracts/presets/ERC777PresetFixedSupply.sol | 2 ++ contracts/proxy/BeaconProxy.sol | 2 ++ contracts/proxy/Clones.sol | 2 ++ contracts/utils/Address.sol | 4 +-- contracts/utils/EnumerableMap.sol | 2 ++ package-lock.json | 2 +- package.json | 2 +- test/math/SafeMath.test.js | 32 +++++++++---------- 16 files changed, 55 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d32313a20..da3772d19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 3.4.0 (2021-02-02) * `Context`: making `_msgData` return `bytes calldata` instead of `bytes memory` ([#2492](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2492)) diff --git a/contracts/drafts/EIP712.sol b/contracts/drafts/EIP712.sol index 62d93a7c9..68ee9de4a 100644 --- a/contracts/drafts/EIP712.sol +++ b/contracts/drafts/EIP712.sol @@ -18,6 +18,8 @@ pragma solidity ^0.8.0; * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. + * + * _Available since v3.4._ */ abstract contract EIP712 { /* solhint-disable var-name-mixedcase */ diff --git a/contracts/drafts/ERC20Permit.sol b/contracts/drafts/ERC20Permit.sol index a36b581db..7a8b97163 100644 --- a/contracts/drafts/ERC20Permit.sol +++ b/contracts/drafts/ERC20Permit.sol @@ -15,6 +15,8 @@ import "./EIP712.sol"; * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. + * + * _Available since v3.4._ */ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { using Counters for Counters.Counter; diff --git a/contracts/introspection/ERC165Checker.sol b/contracts/introspection/ERC165Checker.sol index 4147f8cf9..8a31efa61 100644 --- a/contracts/introspection/ERC165Checker.sol +++ b/contracts/introspection/ERC165Checker.sol @@ -44,6 +44,8 @@ library ERC165Checker { * is that some interfaces may not be supported. * * See {IERC165-supportsInterface}. + * + * _Available since v3.4._ */ function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) { // an array of booleans corresponding to interfaceIds and whether they're supported or not diff --git a/contracts/math/SafeMath.sol b/contracts/math/SafeMath.sol index ed4a4984f..a9a3bdc8c 100644 --- a/contracts/math/SafeMath.sol +++ b/contracts/math/SafeMath.sol @@ -8,6 +8,8 @@ pragma solidity ^0.8.0; library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. + * + * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { @@ -19,6 +21,8 @@ library SafeMath { /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. + * + * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { @@ -29,6 +33,8 @@ library SafeMath { /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. + * + * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { @@ -44,6 +50,8 @@ library SafeMath { /** * @dev Returns the division of two unsigned integers, with a division by zero flag. + * + * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { @@ -54,6 +62,8 @@ library SafeMath { /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. + * + * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { unchecked { diff --git a/contracts/mocks/SafeMathMock.sol b/contracts/mocks/SafeMathMock.sol index b491c472a..2aacf11fb 100644 --- a/contracts/mocks/SafeMathMock.sol +++ b/contracts/mocks/SafeMathMock.sol @@ -25,23 +25,25 @@ contract SafeMathMock { return SafeMath.tryMod(a, b); } - function add(uint256 a, uint256 b) public pure returns (uint256) { + // using the do* naming convention to avoid warnings due to clashing opcode names + + function doAdd(uint256 a, uint256 b) public pure returns (uint256) { return SafeMath.add(a, b); } - function sub(uint256 a, uint256 b) public pure returns (uint256) { + function doSub(uint256 a, uint256 b) public pure returns (uint256) { return SafeMath.sub(a, b); } - function mul(uint256 a, uint256 b) public pure returns (uint256) { + function doMul(uint256 a, uint256 b) public pure returns (uint256) { return SafeMath.mul(a, b); } - function div(uint256 a, uint256 b) public pure returns (uint256) { + function doDiv(uint256 a, uint256 b) public pure returns (uint256) { return SafeMath.div(a, b); } - function mod(uint256 a, uint256 b) public pure returns (uint256) { + function doMod(uint256 a, uint256 b) public pure returns (uint256) { return SafeMath.mod(a, b); } diff --git a/contracts/package.json b/contracts/package.json index d95b21b36..bfa325ead 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,7 +1,7 @@ { "name": "@openzeppelin/contracts", "description": "Secure Smart Contract library for Solidity", - "version": "3.3.0-solc-0.8", + "version": "3.4.0", "files": [ "**/*.sol", "/build/contracts/*.json", diff --git a/contracts/presets/ERC20PresetFixedSupply.sol b/contracts/presets/ERC20PresetFixedSupply.sol index 075e0868d..b56329d4b 100644 --- a/contracts/presets/ERC20PresetFixedSupply.sol +++ b/contracts/presets/ERC20PresetFixedSupply.sol @@ -12,6 +12,8 @@ import "../token/ERC20/ERC20Burnable.sol"; * * This contract uses {ERC20Burnable} to include burn capabilities - head to * its documentation for details. + * + * _Available since v3.4._ */ contract ERC20PresetFixedSupply is ERC20Burnable { /** diff --git a/contracts/presets/ERC777PresetFixedSupply.sol b/contracts/presets/ERC777PresetFixedSupply.sol index 127b588a6..0556daccd 100644 --- a/contracts/presets/ERC777PresetFixedSupply.sol +++ b/contracts/presets/ERC777PresetFixedSupply.sol @@ -8,6 +8,8 @@ import "../token/ERC777/ERC777.sol"; * * - Preminted initial supply * - No access control mechanism (for minting/pausing) and hence no governance + * + * _Available since v3.4._ */ contract ERC777PresetFixedSupply is ERC777 { /** diff --git a/contracts/proxy/BeaconProxy.sol b/contracts/proxy/BeaconProxy.sol index 31fd4d5fd..fa9c1af31 100644 --- a/contracts/proxy/BeaconProxy.sol +++ b/contracts/proxy/BeaconProxy.sol @@ -11,6 +11,8 @@ import "./IBeacon.sol"; * * The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't * conflict with the storage layout of the implementation behind the proxy. + * + * _Available since v3.4._ */ contract BeaconProxy is Proxy { /** diff --git a/contracts/proxy/Clones.sol b/contracts/proxy/Clones.sol index 010eae958..6fb7061c4 100644 --- a/contracts/proxy/Clones.sol +++ b/contracts/proxy/Clones.sol @@ -12,6 +12,8 @@ pragma solidity ^0.8.0; * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2` * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the * deterministic method. + * + * _Available since v3.4._ */ library Clones { /** diff --git a/contracts/utils/Address.sol b/contracts/utils/Address.sol index b75217ad0..bd9a5e072 100644 --- a/contracts/utils/Address.sol +++ b/contracts/utils/Address.sol @@ -148,7 +148,7 @@ library Address { * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * - * _Available since v3.3._ + * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); @@ -158,7 +158,7 @@ library Address { * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * - * _Available since v3.3._ + * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); diff --git a/contracts/utils/EnumerableMap.sol b/contracts/utils/EnumerableMap.sol index e6423cfec..77fd12562 100644 --- a/contracts/utils/EnumerableMap.sol +++ b/contracts/utils/EnumerableMap.sol @@ -235,6 +235,8 @@ library EnumerableMap { /** * @dev Tries to returns the value associated with `key`. O(1). * Does not revert if `key` is not in the map. + * + * _Available since v3.4._ */ function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) { (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key)); diff --git a/package-lock.json b/package-lock.json index 714722122..4ddd37991 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "openzeppelin-solidity", - "version": "3.3.0-solc-0.8", + "version": "3.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 78e2f0106..ce94c7bda 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "openzeppelin-solidity", "description": "Secure Smart Contract library for Solidity", - "version": "3.3.0-solc-0.8", + "version": "3.4.0", "files": [ "/contracts/**/*.sol", "/build/contracts/*.json", diff --git a/test/math/SafeMath.test.js b/test/math/SafeMath.test.js index 31b702a68..7c9b937a8 100644 --- a/test/math/SafeMath.test.js +++ b/test/math/SafeMath.test.js @@ -172,14 +172,14 @@ contract('SafeMath', function (accounts) { const a = new BN('5678'); const b = new BN('1234'); - await testCommutative(this.safeMath.add, a, b, a.add(b)); + await testCommutative(this.safeMath.doAdd, a, b, a.add(b)); }); it('reverts on addition overflow', async function () { const a = MAX_UINT256; const b = new BN('1'); - await testFailsCommutative(this.safeMath.add, a, b, undefined); + await testFailsCommutative(this.safeMath.doAdd, a, b, undefined); }); }); @@ -188,14 +188,14 @@ contract('SafeMath', function (accounts) { const a = new BN('5678'); const b = new BN('1234'); - expect(await this.safeMath.sub(a, b)).to.be.bignumber.equal(a.sub(b)); + expect(await this.safeMath.doSub(a, b)).to.be.bignumber.equal(a.sub(b)); }); it('reverts if subtraction result would be negative', async function () { const a = new BN('1234'); const b = new BN('5678'); - await expectRevert.unspecified(this.safeMath.sub(a, b)); + await expectRevert.unspecified(this.safeMath.doSub(a, b)); }); }); @@ -204,21 +204,21 @@ contract('SafeMath', function (accounts) { const a = new BN('1234'); const b = new BN('5678'); - await testCommutative(this.safeMath.mul, a, b, a.mul(b)); + await testCommutative(this.safeMath.doMul, a, b, a.mul(b)); }); it('multiplies by zero correctly', async function () { const a = new BN('0'); const b = new BN('5678'); - await testCommutative(this.safeMath.mul, a, b, '0'); + await testCommutative(this.safeMath.doMul, a, b, '0'); }); it('reverts on multiplication overflow', async function () { const a = MAX_UINT256; const b = new BN('2'); - await testFailsCommutative(this.safeMath.mul, a, b, undefined); + await testFailsCommutative(this.safeMath.doMul, a, b, undefined); }); }); @@ -227,28 +227,28 @@ contract('SafeMath', function (accounts) { const a = new BN('5678'); const b = new BN('5678'); - expect(await this.safeMath.div(a, b)).to.be.bignumber.equal(a.div(b)); + expect(await this.safeMath.doDiv(a, b)).to.be.bignumber.equal(a.div(b)); }); it('divides zero correctly', async function () { const a = new BN('0'); const b = new BN('5678'); - expect(await this.safeMath.div(a, b)).to.be.bignumber.equal('0'); + expect(await this.safeMath.doDiv(a, b)).to.be.bignumber.equal('0'); }); it('returns complete number result on non-even division', async function () { const a = new BN('7000'); const b = new BN('5678'); - expect(await this.safeMath.div(a, b)).to.be.bignumber.equal('1'); + expect(await this.safeMath.doDiv(a, b)).to.be.bignumber.equal('1'); }); it('reverts on division by zero', async function () { const a = new BN('5678'); const b = new BN('0'); - await expectRevert.unspecified(this.safeMath.div(a, b)); + await expectRevert.unspecified(this.safeMath.doDiv(a, b)); }); }); @@ -258,28 +258,28 @@ contract('SafeMath', function (accounts) { const a = new BN('284'); const b = new BN('5678'); - expect(await this.safeMath.mod(a, b)).to.be.bignumber.equal(a.mod(b)); + expect(await this.safeMath.doMod(a, b)).to.be.bignumber.equal(a.mod(b)); }); it('when the dividend is equal to the divisor', async function () { const a = new BN('5678'); const b = new BN('5678'); - expect(await this.safeMath.mod(a, b)).to.be.bignumber.equal(a.mod(b)); + expect(await this.safeMath.doMod(a, b)).to.be.bignumber.equal(a.mod(b)); }); it('when the dividend is larger than the divisor', async function () { const a = new BN('7000'); const b = new BN('5678'); - expect(await this.safeMath.mod(a, b)).to.be.bignumber.equal(a.mod(b)); + expect(await this.safeMath.doMod(a, b)).to.be.bignumber.equal(a.mod(b)); }); it('when the dividend is a multiple of the divisor', async function () { const a = new BN('17034'); // 17034 == 5678 * 3 const b = new BN('5678'); - expect(await this.safeMath.mod(a, b)).to.be.bignumber.equal(a.mod(b)); + expect(await this.safeMath.doMod(a, b)).to.be.bignumber.equal(a.mod(b)); }); }); @@ -287,7 +287,7 @@ contract('SafeMath', function (accounts) { const a = new BN('5678'); const b = new BN('0'); - await expectRevert.unspecified(this.safeMath.mod(a, b)); + await expectRevert.unspecified(this.safeMath.doMod(a, b)); }); }); });