Skip to content

Commit

Permalink
Replace immutable with constant for _PERMIT_TYPEHASH (#3196)
Browse files Browse the repository at this point in the history
* replace `immutable` with `constant` for _PERMIT_TYPEHASH

This commit is related to the following issue discussion: OpenZeppelin/contracts-wizard#89 (comment)

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.

* Update CHANGELOG

* fix: ensure transpiler compatibility

* fix: fixing var-name-mixedcase

* prettier & lint check

Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>

Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
  • Loading branch information
pcaversaccio and Amxx authored Mar 9, 2022
1 parent c72281e commit cc1c180
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* `ERC20FlashMint`: support infinite allowance when paying back a flash loan. ([#3226](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3226))
* `Governor`: Add a way to parameterize votes. This can be used to implement voting systems such as fractionalized voting, ERC721 based voting, or any number of other systems. The `params` argument added to `_countVote` method, and included in the newly added `_getVotes` method, can be used by counting and voting modules respectively for such purposes.
* `TimelockController`: Add a separate canceller role for the ability to cancel. ([#3165](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3165))
* `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))

### Breaking changes

Expand Down
10 changes: 9 additions & 1 deletion contracts/token/ERC20/extensions/draft-ERC20Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ 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)");
/**
* @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
*/
// solhint-disable-next-line var-name-mixedcase
bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT;

/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
Expand Down

0 comments on commit cc1c180

Please sign in to comment.