From 141f245eba3b3e27c1f454605a262b377579b5b2 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Thu, 9 Sep 2021 09:38:31 +0200 Subject: [PATCH 1/3] Fix EIP712 for delegatecalls --- contracts/utils/cryptography/draft-EIP712.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contracts/utils/cryptography/draft-EIP712.sol b/contracts/utils/cryptography/draft-EIP712.sol index 2d45fa4eeb2..a372b8de888 100644 --- a/contracts/utils/cryptography/draft-EIP712.sol +++ b/contracts/utils/cryptography/draft-EIP712.sol @@ -29,6 +29,7 @@ abstract contract EIP712 { // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _CACHED_DOMAIN_SEPARATOR; uint256 private immutable _CACHED_CHAIN_ID; + address private immutable _CACHED_THIS; bytes32 private immutable _HASHED_NAME; bytes32 private immutable _HASHED_VERSION; @@ -58,6 +59,7 @@ abstract contract EIP712 { _HASHED_VERSION = hashedVersion; _CACHED_CHAIN_ID = block.chainid; _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion); + _CACHED_THIS = address(this); _TYPE_HASH = typeHash; } @@ -65,7 +67,7 @@ abstract contract EIP712 { * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { - if (block.chainid == _CACHED_CHAIN_ID) { + if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) { return _CACHED_DOMAIN_SEPARATOR; } else { return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION); From 4bf09eb1b0c9ce8822f1517253c17697be5e7f86 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 6 Oct 2021 09:17:44 +0200 Subject: [PATCH 2/3] add Changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 607d864b75e..c082074bf32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * `Ownable`: add an internal `_transferOwnership(address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) * `AccessControl`: add internal `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) * `AccessControl`: mark `_setupRole(bytes32,address)` as deprecated in favor of `_grantRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) + * `EIP712`: cache `address(this)` to immutable storage to avoid potential issues if a vanila contract is used in an upgradeable context. ([#2852](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2852)) ## 4.3.2 (2021-09-14) From a7f4be3013d3e07805e995ce0f98ffd3c08dea36 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 6 Oct 2021 10:24:04 -0300 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c082074bf32..e7527eff477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ * `Ownable`: add an internal `_transferOwnership(address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) * `AccessControl`: add internal `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) * `AccessControl`: mark `_setupRole(bytes32,address)` as deprecated in favor of `_grantRole(bytes32,address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) - * `EIP712`: cache `address(this)` to immutable storage to avoid potential issues if a vanila contract is used in an upgradeable context. ([#2852](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2852)) + * `EIP712`: cache `address(this)` to immutable storage to avoid potential issues if a vanilla contract is used in a delegatecall context. ([#2852](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2852)) ## 4.3.2 (2021-09-14)