@@ -59,7 +59,7 @@ index ff596b0c3..000000000
5959- <!-- Make sure that you have reviewed the OpenZeppelin Contracts Contributor Guidelines. -->
6060- <!-- https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/CONTRIBUTING.md -->
6161diff --git a/README.md b/README.md
62- index 6a01f5616..168b74aa7 100644
62+ index 6a01f5616..b01c6e88f 100644
6363--- a/README.md
6464+++ b/README.md
6565@@ -18,6 +18,9 @@
@@ -173,7 +173,7 @@ index c156fa1cc..895e39342 100644
173173 * @dev Prevents a contract from calling itself, directly or indirectly.
174174 * Calling a `nonReentrant` function from another `nonReentrant`
175175diff --git a/contracts/utils/cryptography/EIP712.sol b/contracts/utils/cryptography/EIP712.sol
176- index 2bc45a4b2..09e84815e 100644
176+ index 2bc45a4b2..a5aa41d21 100644
177177--- a/contracts/utils/cryptography/EIP712.sol
178178+++ b/contracts/utils/cryptography/EIP712.sol
179179@@ -4,7 +4,6 @@
@@ -184,7 +184,7 @@ index 2bc45a4b2..09e84815e 100644
184184 import {IERC5267} from "../../interfaces/IERC5267.sol";
185185
186186 /**
187- @@ -25,33 +24,20 @@ import {IERC5267} from "../../interfaces/IERC5267.sol";
187+ @@ -25,33 +24,18 @@ import {IERC5267} from "../../interfaces/IERC5267.sol";
188188 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
189189 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
190190 *
@@ -194,7 +194,7 @@ index 2bc45a4b2..09e84815e 100644
194194- *
195195- * @custom:oz-upgrades-unsafe-allow state-variable-immutable
196196+ * NOTE: The upgradeable version of this contract does not use an immutable cache and recomputes the domain separator
197- + * each time {_domainSeparatorV4} is called. That is cheaper than accessing a cached version in cold storage.
197+ + * each time {_domainSeparatorV4} is called. This is cheaper than accessing a cached version in cold storage.
198198 */
199199 abstract contract EIP712 is IERC5267 {
200200- using ShortStrings for *;
@@ -208,9 +208,7 @@ index 2bc45a4b2..09e84815e 100644
208208- uint256 private immutable _cachedChainId;
209209- address private immutable _cachedThis;
210210-
211- + /// @custom:oz-renamed-from _HASHED_NAME
212211 bytes32 private immutable _hashedName;
213- + /// @custom:oz-renamed-from _HASHED_VERSION
214212 bytes32 private immutable _hashedVersion;
215213
216214- ShortString private immutable _name;
@@ -224,7 +222,7 @@ index 2bc45a4b2..09e84815e 100644
224222
225223 /**
226224 * @dev Initializes the domain separator and parameter caches.
227- @@ -66,29 +52,23 @@ abstract contract EIP712 is IERC5267 {
225+ @@ -66,29 +50,19 @@ abstract contract EIP712 is IERC5267 {
228226 * contract upgrade].
229227 */
230228 constructor(string memory name, string memory version) {
@@ -238,10 +236,6 @@ index 2bc45a4b2..09e84815e 100644
238236- _cachedThis = address(this);
239237+ _name = name;
240238+ _version = version;
241- +
242- + // Reset prior values in storage if upgrading
243- + _hashedName = 0;
244- + _hashedVersion = 0;
245239 }
246240
247241 /**
@@ -262,18 +256,7 @@ index 2bc45a4b2..09e84815e 100644
262256 }
263257
264258 /**
265- @@ -125,6 +105,10 @@ abstract contract EIP712 is IERC5267 {
266- uint256[] memory extensions
267- )
268- {
269- + // If the hashed name and version in storage are non-zero, the contract hasn't been properly initialized
270- + // and the EIP712 domain is not reliable, as it will be missing name and version.
271- + require(_hashedName == 0 && _hashedVersion == 0, "EIP712: Uninitialized");
272- +
273- return (
274- hex"0f", // 01111
275- _EIP712Name(),
276- @@ -139,22 +123,62 @@ abstract contract EIP712 is IERC5267 {
259+ @@ -139,22 +113,38 @@ abstract contract EIP712 is IERC5267 {
277260 /**
278261 * @dev The name parameter for the EIP712 domain.
279262 *
@@ -296,10 +279,7 @@ index 2bc45a4b2..09e84815e 100644
296279- * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
297280+ * NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
298281+ * are a concern.
299- */
300- - // solhint-disable-next-line func-name-mixedcase
301- - function _EIP712Version() internal view returns (string memory) {
302- - return _version.toStringWithFallback(_versionFallback);
282+ + */
303283+ function _EIP712Version() internal view virtual returns (string memory) {
304284+ return _version;
305285+ }
@@ -310,44 +290,23 @@ index 2bc45a4b2..09e84815e 100644
310290+ * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Name` instead.
311291+ */
312292+ function _EIP712NameHash() internal view returns (bytes32) {
313- + string memory name = _EIP712Name();
314- + if (bytes(name).length > 0) {
315- + return keccak256(bytes(name));
316- + } else {
317- + // If the name is empty, the contract may have been upgraded without initializing the new storage.
318- + // We return the name hash in storage if non-zero, otherwise we assume the name is empty by design.
319- + bytes32 hashedName = _hashedName;
320- + if (hashedName != 0) {
321- + return hashedName;
322- + } else {
323- + return keccak256("");
324- + }
325- + }
293+ + return keccak256(bytes(_EIP712Name()));
326294+ }
327295+
328296+ /**
329297+ * @dev The hash of the version parameter for the EIP712 domain.
330298+ *
331299+ * NOTE: In previous versions this function was virtual. In this version you should override `_EIP712Version` instead.
332- + */
300+ */
301+ - // solhint-disable-next-line func-name-mixedcase
302+ - function _EIP712Version() internal view returns (string memory) {
303+ - return _version.toStringWithFallback(_versionFallback);
333304+ function _EIP712VersionHash() internal view returns (bytes32) {
334- + string memory version = _EIP712Version();
335- + if (bytes(version).length > 0) {
336- + return keccak256(bytes(version));
337- + } else {
338- + // If the version is empty, the contract may have been upgraded without initializing the new storage.
339- + // We return the version hash in storage if non-zero, otherwise we assume the version is empty by design.
340- + bytes32 hashedVersion = _hashedVersion;
341- + if (hashedVersion != 0) {
342- + return hashedVersion;
343- + } else {
344- + return keccak256("");
345- + }
346- + }
305+ + return keccak256(bytes(_EIP712Version()));
347306 }
348307 }
349308diff --git a/package.json b/package.json
350- index 0e387a8e7..4f2a6bea6 100644
309+ index 6f2d411dd..956933f33 100644
351310--- a/package.json
352311+++ b/package.json
353312@@ -35,7 +35,7 @@
@@ -368,7 +327,7 @@ index 304d1386a..a1cd63bee 100644
368327+ @openzeppelin/contracts-upgradeable/=contracts/
369328+ @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
370329diff --git a/test/account/AccountEIP7702.test.js b/test/account/AccountEIP7702.test.js
371- index f442d49af..8f22dc926 100644
330+ index d832e6877..6a0ab4a53 100644
372331--- a/test/account/AccountEIP7702.test.js
373332+++ b/test/account/AccountEIP7702.test.js
374333@@ -26,8 +26,8 @@ async function fixture() {
@@ -383,7 +342,7 @@ index f442d49af..8f22dc926 100644
383342 verifyingContract: mock.address,
384343 };
385344diff --git a/test/account/examples/AccountEIP7702WithModulesMock.test.js b/test/account/examples/AccountEIP7702WithModulesMock.test.js
386- index 8ceab19d1..c3f4194a6 100644
345+ index 86816e55e..de6adc2c5 100644
387346--- a/test/account/examples/AccountEIP7702WithModulesMock.test.js
388347+++ b/test/account/examples/AccountEIP7702WithModulesMock.test.js
389348@@ -36,8 +36,8 @@ async function fixture() {
0 commit comments