Re-enable immutable forwarder in ERC2771Context (#2917)

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
Hadrien Croubois
2021-12-28 01:21:56 +01:00
committed by GitHub
parent 915ca181ba
commit fe38eae6cd
4 changed files with 11 additions and 6 deletions

View File

@ -10,6 +10,7 @@
* `ERC721`: improved revert reason when transferring from wrong owner. ([#2975](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2975)) * `ERC721`: improved revert reason when transferring from wrong owner. ([#2975](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2975))
* `Votes`: Added a base contract for vote tracking with delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944)) * `Votes`: Added a base contract for vote tracking with delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944))
* `ERC721Votes`: Added an extension of ERC721 enabled with vote tracking and delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944)) * `ERC721Votes`: Added an extension of ERC721 enabled with vote tracking and delegation. ([#2944](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2944))
* `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))
## 4.4.1 (2021-12-14) ## 4.4.1 (2021-12-14)

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (metatx/ERC2771Context.sol) // OpenZeppelin Contracts v4.4.1 (metatx/ERC2771Context.sol)
pragma solidity ^0.8.0; pragma solidity ^0.8.9;
import "../utils/Context.sol"; import "../utils/Context.sol";
@ -9,8 +9,10 @@ import "../utils/Context.sol";
* @dev Context variant with ERC2771 support. * @dev Context variant with ERC2771 support.
*/ */
abstract contract ERC2771Context is Context { abstract contract ERC2771Context is Context {
address private _trustedForwarder; /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable _trustedForwarder;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(address trustedForwarder) { constructor(address trustedForwarder) {
_trustedForwarder = trustedForwarder; _trustedForwarder = trustedForwarder;
} }

View File

@ -1,13 +1,15 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.9;
import "./ContextMock.sol"; import "./ContextMock.sol";
import "../metatx/ERC2771Context.sol"; import "../metatx/ERC2771Context.sol";
// By inheriting from ERC2771Context, Context's internal functions are overridden automatically // By inheriting from ERC2771Context, Context's internal functions are overridden automatically
contract ERC2771ContextMock is ContextMock, ERC2771Context { 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) { function _msgSender() internal view virtual override(Context, ERC2771Context) returns (address) {
return ERC2771Context._msgSender(); return ERC2771Context._msgSender();

View File

@ -3,7 +3,7 @@
// - COVERAGE: enable coverage report // - COVERAGE: enable coverage report
// - ENABLE_GAS_REPORT: enable gas report // - ENABLE_GAS_REPORT: enable gas report
// - COMPILE_MODE: production modes enables optimizations (default: development) // - 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 // - COINMARKETCAP: coinmarkercat api key for USD value in gas report
const fs = require('fs'); const fs = require('fs');
@ -33,7 +33,7 @@ const argv = require('yargs/yargs')()
compiler: { compiler: {
alias: 'compileVersion', alias: 'compileVersion',
type: 'string', type: 'string',
default: '0.8.3', default: '0.8.9',
}, },
coinmarketcap: { coinmarketcap: {
alias: 'coinmarketcapApiKey', alias: 'coinmarketcapApiKey',