From d99ceeba624b9a2999877397f0c3d8c10d790c5c Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Wed, 17 May 2023 10:26:02 -0300 Subject: [PATCH 01/11] Added internal getters --- contracts/utils/cryptography/EIP712.sol | 20 ++++++++++++++++++++ test/utils/cryptography/EIP712.test.js | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index 6a4e1cad276..8f421d12288 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -139,4 +139,24 @@ abstract contract EIP712 is IERC5267 { new uint256[](0) ); } + + /** + * @dev The name parameter for the EIP712 domain. + * + * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs + * are a concern. + */ + function _EIP712Name() internal virtual view returns (string memory) { + return ShortStrings.toStringWithFallback(_name, _nameFallback); + } + + /** + * @dev The version parameter for the EIP712 domain. + * + * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs + * are a concern. + */ + function _EIP712Version() internal virtual view returns (string memory) { + return ShortStrings.toStringWithFallback(_version, _versionFallback); + } } diff --git a/test/utils/cryptography/EIP712.test.js b/test/utils/cryptography/EIP712.test.js index 54a4e772372..7ea535b7f7d 100644 --- a/test/utils/cryptography/EIP712.test.js +++ b/test/utils/cryptography/EIP712.test.js @@ -98,6 +98,14 @@ contract('EIP712', function (accounts) { await this.eip712.verify(signature, wallet.getAddressString(), message.to, message.contents); }); + + it('name', async function () { + expect(await this.eip712.$_EIP712Name()).to.be.equal(name); + }); + + it('version', async function () { + expect(await this.eip712.$_EIP712Version()).to.be.equal(version); + }); }); } }); From 9b0a9d47caf494b589f5285bf0cbfbabba13cca8 Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Fri, 2 Jun 2023 10:56:42 -0300 Subject: [PATCH 02/11] fix linter, add changeset --- .changeset/little-falcons-build.md | 5 +++++ contracts/utils/cryptography/EIP712.sol | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/little-falcons-build.md diff --git a/.changeset/little-falcons-build.md b/.changeset/little-falcons-build.md new file mode 100644 index 00000000000..2dfd449c071 --- /dev/null +++ b/.changeset/little-falcons-build.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-solidity': minor +--- + +Add internal name and version getters for EIP712 diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index 3a128cbb4f5..bae5719d883 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -146,7 +146,7 @@ abstract contract EIP712 is IERC5267 { * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ - function _EIP712Name() internal virtual view returns (string memory) { + function _EIP712Name() internal view virtual returns (string memory) { return ShortStrings.toStringWithFallback(_name, _nameFallback); } @@ -156,7 +156,7 @@ abstract contract EIP712 is IERC5267 { * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ - function _EIP712Version() internal virtual view returns (string memory) { + function _EIP712Version() internal view virtual returns (string memory) { return ShortStrings.toStringWithFallback(_version, _versionFallback); } } From 9f40410a0c69e537ba3787184f3f10a301f181db Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Fri, 2 Jun 2023 11:21:19 -0300 Subject: [PATCH 03/11] diable solhint unc-name-mixedcase for getter names --- contracts/utils/cryptography/EIP712.sol | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index bae5719d883..8e83d35d97a 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -146,6 +146,7 @@ abstract contract EIP712 is IERC5267 { * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ + // solhint-disable-next-line func-name-mixedcase function _EIP712Name() internal view virtual returns (string memory) { return ShortStrings.toStringWithFallback(_name, _nameFallback); } @@ -156,6 +157,7 @@ abstract contract EIP712 is IERC5267 { * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs * are a concern. */ + // solhint-disable-next-line func-name-mixedcase function _EIP712Version() internal view virtual returns (string memory) { return ShortStrings.toStringWithFallback(_version, _versionFallback); } From ecd94da954df7549f1227593c99daa9714704b0f Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Fri, 2 Jun 2023 14:20:53 -0300 Subject: [PATCH 04/11] Use getters in EIP712Domain --- contracts/utils/cryptography/EIP712.sol | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index 8e83d35d97a..ff5ac4be991 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -131,8 +131,8 @@ abstract contract EIP712 is IERC5267 { { return ( hex"0f", // 01111 - _name.toStringWithFallback(_nameFallback), - _version.toStringWithFallback(_versionFallback), + _EIP712Name(), + _EIP712Version(), block.chainid, address(this), bytes32(0), @@ -148,7 +148,7 @@ abstract contract EIP712 is IERC5267 { */ // solhint-disable-next-line func-name-mixedcase function _EIP712Name() internal view virtual returns (string memory) { - return ShortStrings.toStringWithFallback(_name, _nameFallback); + return _name.toStringWithFallback(_nameFallback); } /** @@ -159,6 +159,6 @@ abstract contract EIP712 is IERC5267 { */ // solhint-disable-next-line func-name-mixedcase function _EIP712Version() internal view virtual returns (string memory) { - return ShortStrings.toStringWithFallback(_version, _versionFallback); + return _version.toStringWithFallback(_versionFallback); } } From c3f6246de4e65736b69bcd35c2fabce82474dfe5 Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Fri, 2 Jun 2023 14:23:21 -0300 Subject: [PATCH 05/11] Remove virtual modifier from getters --- contracts/utils/cryptography/EIP712.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index ff5ac4be991..d00c303e7d8 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -147,7 +147,7 @@ abstract contract EIP712 is IERC5267 { * are a concern. */ // solhint-disable-next-line func-name-mixedcase - function _EIP712Name() internal view virtual returns (string memory) { + function _EIP712Name() internal view returns (string memory) { return _name.toStringWithFallback(_nameFallback); } @@ -158,7 +158,7 @@ abstract contract EIP712 is IERC5267 { * are a concern. */ // solhint-disable-next-line func-name-mixedcase - function _EIP712Version() internal view virtual returns (string memory) { + function _EIP712Version() internal view returns (string memory) { return _version.toStringWithFallback(_versionFallback); } } From f15c1cf5aa50607d0749e003b7b1d18106a0b119 Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Mon, 5 Jun 2023 10:39:04 -0300 Subject: [PATCH 06/11] Update comments --- contracts/utils/cryptography/EIP712.sol | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index d00c303e7d8..e8e259eb946 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -143,8 +143,8 @@ abstract contract EIP712 is IERC5267 { /** * @dev The name parameter for the EIP712 domain. * - * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs - * are a concern. + * NOTE: By default this function reads _name which is an immutable value. + * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase function _EIP712Name() internal view returns (string memory) { @@ -152,10 +152,10 @@ abstract contract EIP712 is IERC5267 { } /** - * @dev The version parameter for the EIP712 domain. + * @dev The name parameter for the EIP712 domain. * - * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs - * are a concern. + * NOTE: By default this function reads _version which is an immutable value. + * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase function _EIP712Version() internal view returns (string memory) { From dede30585efdd7734dddc1523f18bc6099375724 Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Mon, 5 Jun 2023 15:41:46 -0300 Subject: [PATCH 07/11] Fix linter --- contracts/utils/cryptography/EIP712.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index e8e259eb946..595b43d5a42 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -143,7 +143,7 @@ abstract contract EIP712 is IERC5267 { /** * @dev The name parameter for the EIP712 domain. * - * NOTE: By default this function reads _name which is an immutable value. + * NOTE: By default this function reads _name which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase @@ -154,7 +154,7 @@ abstract contract EIP712 is IERC5267 { /** * @dev The name parameter for the EIP712 domain. * - * NOTE: By default this function reads _version which is an immutable value. + * NOTE: By default this function reads _version which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). */ // solhint-disable-next-line func-name-mixedcase From b66cd0b543532ee80c949b87009cff767797c752 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 6 Jun 2023 10:48:54 +0200 Subject: [PATCH 08/11] Update contracts/utils/cryptography/EIP712.sol --- contracts/utils/cryptography/EIP712.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index 595b43d5a42..57b31f88d95 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -152,7 +152,7 @@ abstract contract EIP712 is IERC5267 { } /** - * @dev The name parameter for the EIP712 domain. + * @dev The version parameter for the EIP712 domain. * * NOTE: By default this function reads _version which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). From cfb770ba940b20ff7f4b66e29424b37f1a76c02f Mon Sep 17 00:00:00 2001 From: RenanSouza2 Date: Fri, 9 Jun 2023 09:17:54 -0300 Subject: [PATCH 09/11] Update changeset message --- .changeset/little-falcons-build.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/little-falcons-build.md b/.changeset/little-falcons-build.md index 2dfd449c071..b310a8ae697 100644 --- a/.changeset/little-falcons-build.md +++ b/.changeset/little-falcons-build.md @@ -2,4 +2,4 @@ 'openzeppelin-solidity': minor --- -Add internal name and version getters for EIP712 +`EIP712`: Add internal getters for the name and version strings From d9e307278395439f4cc6b9287874f8a74554c5f2 Mon Sep 17 00:00:00 2001 From: ernestognw Date: Fri, 9 Jun 2023 15:50:56 -0600 Subject: [PATCH 10/11] Add Available tags --- contracts/utils/cryptography/EIP712.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol index 57b31f88d95..a1c65c8393c 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -145,6 +145,8 @@ abstract contract EIP712 is IERC5267 { * * NOTE: By default this function reads _name which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). + * + * _Available since v5.0._ */ // solhint-disable-next-line func-name-mixedcase function _EIP712Name() internal view returns (string memory) { @@ -156,6 +158,8 @@ abstract contract EIP712 is IERC5267 { * * NOTE: By default this function reads _version which is an immutable value. * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). + * + * _Available since v5.0._ */ // solhint-disable-next-line func-name-mixedcase function _EIP712Version() internal view returns (string memory) { From 37102d55c681dbbe13851f97eef0e13521717b5d Mon Sep 17 00:00:00 2001 From: ernestognw Date: Fri, 9 Jun 2023 18:49:24 -0600 Subject: [PATCH 11/11] Update upgradeable patch --- scripts/upgradeable/upgradeable.patch | 90 ++++++++++++++------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/scripts/upgradeable/upgradeable.patch b/scripts/upgradeable/upgradeable.patch index b29e7d12bed..554775ffe8e 100644 --- a/scripts/upgradeable/upgradeable.patch +++ b/scripts/upgradeable/upgradeable.patch @@ -59,10 +59,10 @@ index ff596b0c..00000000 - - diff --git a/README.md b/README.md -index 9fc95518..53130e3c 100644 +index aba99171..6656267b 100644 --- a/README.md +++ b/README.md -@@ -16,17 +16,20 @@ +@@ -19,17 +19,20 @@ :building_construction: **Want to scale your decentralized application?** Check out [OpenZeppelin Defender](https://openzeppelin.com/defender) — a secure platform for automating and monitoring your operations. @@ -85,7 +85,7 @@ index 9fc95518..53130e3c 100644 ### Usage -@@ -35,10 +38,11 @@ Once installed, you can use the contracts in the library by importing them: +@@ -38,10 +41,11 @@ Once installed, you can use the contracts in the library by importing them: ```solidity pragma solidity ^0.8.19; @@ -101,7 +101,7 @@ index 9fc95518..53130e3c 100644 } ``` diff --git a/contracts/finance/VestingWallet.sol b/contracts/finance/VestingWallet.sol -index bb70d19f..38513771 100644 +index 5b7e1b15..1ca745d6 100644 --- a/contracts/finance/VestingWallet.sol +++ b/contracts/finance/VestingWallet.sol @@ -18,6 +18,8 @@ import "../utils/Context.sol"; @@ -114,7 +114,7 @@ index bb70d19f..38513771 100644 contract VestingWallet is Context { event EtherReleased(uint256 amount); diff --git a/contracts/governance/extensions/GovernorVotes.sol b/contracts/governance/extensions/GovernorVotes.sol -index 64431711..885f0e42 100644 +index 5d8318f4..ef3cde55 100644 --- a/contracts/governance/extensions/GovernorVotes.sol +++ b/contracts/governance/extensions/GovernorVotes.sol @@ -10,6 +10,8 @@ import "../../interfaces/IERC5805.sol"; @@ -127,7 +127,7 @@ index 64431711..885f0e42 100644 abstract contract GovernorVotes is Governor { IERC5805 public immutable token; diff --git a/contracts/package.json b/contracts/package.json -index 55e70b17..ceefb984 100644 +index 4d0f576b..822fd471 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -1,5 +1,5 @@ @@ -135,7 +135,7 @@ index 55e70b17..ceefb984 100644 - "name": "@openzeppelin/contracts", + "name": "@openzeppelin/contracts-upgradeable", "description": "Secure Smart Contract library for Solidity", - "version": "4.8.2", + "version": "4.9.0", "files": [ @@ -13,7 +13,7 @@ }, @@ -147,7 +147,7 @@ index 55e70b17..ceefb984 100644 "keywords": [ "solidity", diff --git a/contracts/token/ERC20/extensions/ERC20Capped.sol b/contracts/token/ERC20/extensions/ERC20Capped.sol -index 16f830d1..9ef98148 100644 +index cda07265..d314148c 100644 --- a/contracts/token/ERC20/extensions/ERC20Capped.sol +++ b/contracts/token/ERC20/extensions/ERC20Capped.sol @@ -7,6 +7,8 @@ import "../ERC20.sol"; @@ -160,20 +160,20 @@ index 16f830d1..9ef98148 100644 abstract contract ERC20Capped is ERC20 { uint256 private immutable _cap; diff --git a/contracts/token/ERC20/extensions/ERC20Permit.sol b/contracts/token/ERC20/extensions/ERC20Permit.sol -index a357199b..9dc8e894 100644 +index 9379e445..e02f0644 100644 --- a/contracts/token/ERC20/extensions/ERC20Permit.sol +++ b/contracts/token/ERC20/extensions/ERC20Permit.sol -@@ -18,6 +18,8 @@ import "../../../utils/Counters.sol"; +@@ -18,6 +18,8 @@ import "../../../utils/Nonces.sol"; * need to send a transaction, and thus is not required to hold Ether at all. * * _Available since v3.4._ + * + * @custom:storage-size 51 */ - abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { - using Counters for Counters.Counter; + abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces { + // solhint-disable-next-line var-name-mixedcase diff --git a/contracts/token/ERC20/extensions/ERC20Wrapper.sol b/contracts/token/ERC20/extensions/ERC20Wrapper.sol -index bfe782e4..7264fe32 100644 +index bf2b225c..0e5b3628 100644 --- a/contracts/token/ERC20/extensions/ERC20Wrapper.sol +++ b/contracts/token/ERC20/extensions/ERC20Wrapper.sol @@ -14,6 +14,8 @@ import "../utils/SafeERC20.sol"; @@ -186,7 +186,7 @@ index bfe782e4..7264fe32 100644 abstract contract ERC20Wrapper is ERC20 { IERC20 private immutable _underlying; diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol -index 6a4e1cad..55d8eced 100644 +index 2628014f..7d5193c8 100644 --- a/contracts/utils/cryptography/EIP712.sol +++ b/contracts/utils/cryptography/EIP712.sol @@ -4,7 +4,6 @@ @@ -268,7 +268,7 @@ index 6a4e1cad..55d8eced 100644 } /** -@@ -129,14 +114,80 @@ abstract contract EIP712 is IERC5267 { +@@ -128,6 +113,10 @@ abstract contract EIP712 is IERC5267 { uint256[] memory extensions ) { @@ -278,34 +278,34 @@ index 6a4e1cad..55d8eced 100644 + return ( hex"0f", // 01111 -- _name.toStringWithFallback(_nameFallback), -- _version.toStringWithFallback(_versionFallback), -+ _EIP712Name(), -+ _EIP712Version(), - block.chainid, - address(this), - bytes32(0), - new uint256[](0) - ); - } -+ -+ /** -+ * @dev The name parameter for the EIP712 domain. -+ * + _EIP712Name(), +@@ -142,26 +131,62 @@ abstract contract EIP712 is IERC5267 { + /** + * @dev The name parameter for the EIP712 domain. + * +- * NOTE: By default this function reads _name which is an immutable value. +- * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). +- * +- * _Available since v5.0._ + * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs + * are a concern. -+ */ -+ function _EIP712Name() internal virtual view returns (string memory) { + */ +- // solhint-disable-next-line func-name-mixedcase +- function _EIP712Name() internal view returns (string memory) { +- return _name.toStringWithFallback(_nameFallback); ++ function _EIP712Name() internal view virtual returns (string memory) { + return _name; -+ } -+ -+ /** -+ * @dev The version parameter for the EIP712 domain. -+ * + } + + /** + * @dev The version parameter for the EIP712 domain. + * +- * NOTE: By default this function reads _version which is an immutable value. +- * It only reads from storage if necessary (in case the value is too large to fit in a ShortString). + * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs + * are a concern. + */ -+ function _EIP712Version() internal virtual view returns (string memory) { ++ function _EIP712Version() internal view virtual returns (string memory) { + return _version; + } + @@ -332,9 +332,13 @@ index 6a4e1cad..55d8eced 100644 + + /** + * @dev The hash of the version parameter for the EIP712 domain. -+ * + * +- * _Available since v5.0._ + * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead. -+ */ + */ +- // solhint-disable-next-line func-name-mixedcase +- function _EIP712Version() internal view returns (string memory) { +- return _version.toStringWithFallback(_versionFallback); + function _EIP712VersionHash() internal view returns (bytes32) { + string memory version = _EIP712Version(); + if (bytes(version).length > 0) { @@ -349,13 +353,13 @@ index 6a4e1cad..55d8eced 100644 + return keccak256(""); + } + } -+ } + } } diff --git a/package.json b/package.json -index 8458dd61..b4672240 100644 +index c070915f..9a513cac 100644 --- a/package.json +++ b/package.json -@@ -36,7 +36,7 @@ +@@ -33,7 +33,7 @@ }, "repository": { "type": "git", @@ -365,7 +369,7 @@ index 8458dd61..b4672240 100644 "keywords": [ "solidity", diff --git a/test/utils/cryptography/EIP712.test.js b/test/utils/cryptography/EIP712.test.js -index 54a4e772..ba4602ed 100644 +index 7ea535b7..32e3a370 100644 --- a/test/utils/cryptography/EIP712.test.js +++ b/test/utils/cryptography/EIP712.test.js @@ -47,26 +47,6 @@ contract('EIP712', function (accounts) {