From ca4ceae2a7cd99a0dd74abb23bdd5de1e4b6cb96 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 18 Oct 2021 14:02:45 +0200 Subject: [PATCH 1/8] Re-enable immutable forwarder in ERC2771Context --- contracts/metatx/ERC2771Context.sol | 4 ++-- contracts/mocks/ERC2771ContextMock.sol | 6 ++++-- hardhat.config.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contracts/metatx/ERC2771Context.sol b/contracts/metatx/ERC2771Context.sol index e5c0674a765..e3c9031e3c9 100644 --- a/contracts/metatx/ERC2771Context.sol +++ b/contracts/metatx/ERC2771Context.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.3.2 (metatx/ERC2771Context.sol) -pragma solidity ^0.8.0; +pragma solidity ^0.8.8; import "../utils/Context.sol"; @@ -9,7 +9,7 @@ import "../utils/Context.sol"; * @dev Context variant with ERC2771 support. */ abstract contract ERC2771Context is Context { - address private _trustedForwarder; + address private immutable _trustedForwarder; constructor(address trustedForwarder) { _trustedForwarder = trustedForwarder; diff --git a/contracts/mocks/ERC2771ContextMock.sol b/contracts/mocks/ERC2771ContextMock.sol index 7bc1c4538dc..e466c07db21 100644 --- a/contracts/mocks/ERC2771ContextMock.sol +++ b/contracts/mocks/ERC2771ContextMock.sol @@ -1,13 +1,15 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; +pragma solidity ^0.8.8; import "./ContextMock.sol"; import "../metatx/ERC2771Context.sol"; // By inheriting from ERC2771Context, Context's internal functions are overridden automatically contract ERC2771ContextMock is ContextMock, ERC2771Context { - constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {} + constructor(address trustedForwarder) ERC2771Context(trustedForwarder) { + emit Sender(_msgSender()); // _msgSender() should be accessible during construction + } function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) { return ERC2771Context._msgSender(); diff --git a/hardhat.config.js b/hardhat.config.js index aaa1ca03606..d12a1914c56 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -33,7 +33,7 @@ const argv = require('yargs/yargs')() compiler: { alias: 'compileVersion', type: 'string', - default: '0.8.3', + default: '0.8.9', }, coinmarketcap: { alias: 'coinmarketcapApiKey', From 1e53bbaa24f834026d92b24041c93dee52bef324 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 8 Nov 2021 23:14:41 +0100 Subject: [PATCH 2/8] =?UTF-8?q?0.8.8=20=E2=86=92=200.8.9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/metatx/ERC2771Context.sol | 2 +- hardhat.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/metatx/ERC2771Context.sol b/contracts/metatx/ERC2771Context.sol index e3c9031e3c9..322b55d8968 100644 --- a/contracts/metatx/ERC2771Context.sol +++ b/contracts/metatx/ERC2771Context.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.3.2 (metatx/ERC2771Context.sol) -pragma solidity ^0.8.8; +pragma solidity ^0.8.9; import "../utils/Context.sol"; diff --git a/hardhat.config.js b/hardhat.config.js index d12a1914c56..1fbf856b247 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -3,7 +3,7 @@ // - COVERAGE: enable coverage report // - ENABLE_GAS_REPORT: enable gas report // - COMPILE_MODE: production modes enables optimizations (default: development) -// - COMPILE_VERSION: compiler version (default: 0.8.3) +// - COMPILE_VERSION: compiler version (default: 0.8.9) // - COINMARKETCAP: coinmarkercat api key for USD value in gas report const fs = require('fs'); From c27c67f4bb9f05a3729edab852da113fe3b51aa4 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Tue, 16 Nov 2021 15:08:37 +0100 Subject: [PATCH 3/8] Update contracts/metatx/ERC2771Context.sol Co-authored-by: Francisco Giordano --- contracts/metatx/ERC2771Context.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/metatx/ERC2771Context.sol b/contracts/metatx/ERC2771Context.sol index 322b55d8968..87a39826cc5 100644 --- a/contracts/metatx/ERC2771Context.sol +++ b/contracts/metatx/ERC2771Context.sol @@ -9,6 +9,7 @@ import "../utils/Context.sol"; * @dev Context variant with ERC2771 support. */ abstract contract ERC2771Context is Context { + /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable _trustedForwarder; constructor(address trustedForwarder) { From 3ce2ad9e535808a2d890213df807880d53405925 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 17 Nov 2021 09:31:47 +0100 Subject: [PATCH 4/8] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37ac4793776..9d7eb6dfba8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + + * `ERC2771Context`: revert to immutable storage to store the forwarder address. This is possible with solidity 0.8.8 added support for reading immutable variables in constructor. ([#2917](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2917)) + ## Unreleased * `Ownable`: add an internal `_transferOwnership(address)`. ([#2568](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/#2568)) From 3af81dac7d3428be2831cc0060320c569c7f801b Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 17 Nov 2021 22:48:49 +0100 Subject: [PATCH 5/8] fix merge --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a571e0d4b..df153991483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,11 @@ ## Unreleased - * `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)) + * `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)) * `AccessControlEnumerable`: hook into `_grantRole(bytes32,address)` and `_revokeRole(bytes32,address)`. ([#2946](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2946)) - * `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)) + * `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)) * Add internal `_setApprovalForAll` to `ERC721` and `ERC1155`. ([#2834](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2834)) * `Governor`: shift vote start and end by one block to better match Compound's GovernorBravo and prevent voting at the Governor level if the voting snapshot is not ready. ([#2892](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2892)) * `GovernorCompatibilityBravo`: consider quorum an inclusive rather than exclusive minimum to match Compound's GovernorBravo. ([#2974](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2974)) From 9b09f7cb003057d21c3e6a3a56d92138d2aac2a8 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Thu, 18 Nov 2021 11:00:08 -0300 Subject: [PATCH 6/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df153991483..771f16eaf32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased - * `ERC2771Context`: revert to immutable storage to store the forwarder address. This is possible with solidity 0.8.8 added support for reading immutable variables in constructor. ([#2917](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2917)) + * `ERC2771Context`: use immutable storage to store the forwarder address, no longer an issue since Solidity >=0.8.8 allows reading immutable variables in the constructor. ([#2917](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2917)) ## Unreleased From ad98a2479e94555e7f5ec7ce2b3ce04f664bd68f Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Wed, 22 Dec 2021 19:42:53 -0300 Subject: [PATCH 7/8] use 0.8.9 --- contracts/mocks/ERC2771ContextMock.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/mocks/ERC2771ContextMock.sol b/contracts/mocks/ERC2771ContextMock.sol index e466c07db21..de8b52170fe 100644 --- a/contracts/mocks/ERC2771ContextMock.sol +++ b/contracts/mocks/ERC2771ContextMock.sol @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.8; +pragma solidity ^0.8.9; import "./ContextMock.sol"; import "../metatx/ERC2771Context.sol"; From cf8972ab0d84102fbb790e4bd38604d4378de035 Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Mon, 27 Dec 2021 21:06:43 -0300 Subject: [PATCH 8/8] add unsafe-allow constructor --- contracts/metatx/ERC2771Context.sol | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/metatx/ERC2771Context.sol b/contracts/metatx/ERC2771Context.sol index 2d64dffef9e..1abed9a9374 100644 --- a/contracts/metatx/ERC2771Context.sol +++ b/contracts/metatx/ERC2771Context.sol @@ -12,6 +12,7 @@ abstract contract ERC2771Context is Context { /// @custom:oz-upgrades-unsafe-allow state-variable-immutable address private immutable _trustedForwarder; + /// @custom:oz-upgrades-unsafe-allow constructor constructor(address trustedForwarder) { _trustedForwarder = trustedForwarder; }