From fa5db25d7d06a606bb1817bdd94c9dea47b7de4e Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Thu, 17 Feb 2022 10:36:29 +0100 Subject: [PATCH 1/5] replace `immutable` with `constant` for _PERMIT_TYPEHASH This commit is related to the following issue discussion: https://github.com/OpenZeppelin/contracts-wizard/issues/89#issuecomment-1042391318 Since Solidity version `0.6.12` the `keccak256` of string literals is treated specially and the hash is evaluated at compile time. Since the OpenZeppelin Wizard also uses `constant` for OpenZeppelin's AccessControl's roles declarations, it's good practice to make this consistent. --- contracts/token/ERC20/extensions/draft-ERC20Permit.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol index cf72fc086ee..10ce9068f72 100644 --- a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +++ b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol @@ -25,7 +25,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { mapping(address => Counters.Counter) private _nonces; // solhint-disable-next-line var-name-mixedcase - bytes32 private immutable _PERMIT_TYPEHASH = + bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** From c869d9943c17c65743a76675fb5ab497993662a7 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Thu, 17 Feb 2022 10:43:52 +0100 Subject: [PATCH 2/5] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be8df954a9f..3bfb0fa81ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * `EnumerableMap`: add new `AddressToUintMap` map type. ([#3150](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3150)) * `ERC1155`: Add a `_afterTokenTransfer` hook for improved extensibility. ([#3166](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3166)) * `DoubleEndedQueue`: a new data structure that supports efficient push and pop to both front and back, useful for FIFO and LIFO queues. ([#3153](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3153)) + * `draft-ERC20Permit`: replace `immutable` with `constant` for `_PERMIT_TYPEHASH` since the `keccak256` of string literals is treated specially and the hash is evaluated at compile time. ([#3196](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3196)) ## 4.5.0 (2022-02-09) From 201d3bff07c9fa67b3898fcc5a7eb89d0ea85592 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Wed, 9 Mar 2022 14:41:47 +0100 Subject: [PATCH 3/5] fix: ensure transpiler compatibility --- contracts/token/ERC20/extensions/draft-ERC20Permit.sol | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol index 10ce9068f72..aec701238dc 100644 --- a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +++ b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol @@ -27,6 +27,13 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { // solhint-disable-next-line var-name-mixedcase bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); + /** + * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. + * However, to ensure consistency with the upgradeable transpiler, we will continue + * to reserve a slot. + * @custom:oz-renamed-from _PERMIT_TYPEHASH + */ + bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; /** * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. From 20d6c009f8abaf72b183eef898ffd56d0b2af373 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Wed, 9 Mar 2022 14:47:01 +0100 Subject: [PATCH 4/5] fix: fixing var-name-mixedcase --- contracts/token/ERC20/extensions/draft-ERC20Permit.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol index aec701238dc..95d143c9b49 100644 --- a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +++ b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol @@ -33,6 +33,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { * to reserve a slot. * @custom:oz-renamed-from _PERMIT_TYPEHASH */ + // solhint-disable-next-line var-name-mixedcase bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; /** From d7fddb9baa1dc6061918ac66a61023980826ca37 Mon Sep 17 00:00:00 2001 From: Pascal Marco Caversaccio Date: Wed, 9 Mar 2022 15:14:51 +0100 Subject: [PATCH 5/5] prettier & lint check Signed-off-by: Pascal Marco Caversaccio --- contracts/token/ERC20/extensions/draft-ERC20Permit.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol index 95d143c9b49..55172f6e36c 100644 --- a/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +++ b/contracts/token/ERC20/extensions/draft-ERC20Permit.sol @@ -28,7 +28,7 @@ abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { bytes32 private constant _PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); /** - * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. + * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. * However, to ensure consistency with the upgradeable transpiler, we will continue * to reserve a slot. * @custom:oz-renamed-from _PERMIT_TYPEHASH