Skip to content

Commit fe38eae

Browse files
Amxxfrangio
andauthored
Re-enable immutable forwarder in ERC2771Context (OpenZeppelin#2917)
Co-authored-by: Francisco Giordano <[email protected]>
1 parent 915ca18 commit fe38eae

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* `ERC721`: improved revert reason when transferring from wrong owner. ([#2975](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2975))
1111
* `Votes`: Added a base contract for vote tracking with delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944))
1212
* `ERC721Votes`: Added an extension of ERC721 enabled with vote tracking and delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944))
13+
* `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))
1314

1415
## 4.4.1 (2021-12-14)
1516

contracts/metatx/ERC2771Context.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
// SPDX-License-Identifier: MIT
22
// OpenZeppelin Contracts v4.4.1 (metatx/ERC2771Context.sol)
33

4-
pragma solidity ^0.8.0;
4+
pragma solidity ^0.8.9;
55

66
import "../utils/Context.sol";
77

88
/**
99
* @dev Context variant with ERC2771 support.
1010
*/
1111
abstract contract ERC2771Context is Context {
12-
address private _trustedForwarder;
12+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
13+
address private immutable _trustedForwarder;
1314

15+
/// @custom:oz-upgrades-unsafe-allow constructor
1416
constructor(address trustedForwarder) {
1517
_trustedForwarder = trustedForwarder;
1618
}

contracts/mocks/ERC2771ContextMock.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
// SPDX-License-Identifier: MIT
22

3-
pragma solidity ^0.8.0;
3+
pragma solidity ^0.8.9;
44

55
import "./ContextMock.sol";
66
import "../metatx/ERC2771Context.sol";
77

88
// By inheriting from ERC2771Context, Context's internal functions are overridden automatically
99
contract ERC2771ContextMock is ContextMock, ERC2771Context {
10-
constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {}
10+
constructor(address trustedForwarder) ERC2771Context(trustedForwarder) {
11+
emit Sender(_msgSender()); // _msgSender() should be accessible during construction
12+
}
1113

1214
function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) {
1315
return ERC2771Context._msgSender();

hardhat.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// - COVERAGE: enable coverage report
44
// - ENABLE_GAS_REPORT: enable gas report
55
// - COMPILE_MODE: production modes enables optimizations (default: development)
6-
// - COMPILE_VERSION: compiler version (default: 0.8.3)
6+
// - COMPILE_VERSION: compiler version (default: 0.8.9)
77
// - COINMARKETCAP: coinmarkercat api key for USD value in gas report
88

99
const fs = require('fs');
@@ -33,7 +33,7 @@ const argv = require('yargs/yargs')()
3333
compiler: {
3434
alias: 'compileVersion',
3535
type: 'string',
36-
default: '0.8.3',
36+
default: '0.8.9',
3737
},
3838
coinmarketcap: {
3939
alias: 'coinmarketcapApiKey',

0 commit comments

Comments
 (0)