Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
538cafed
Commit
538cafed
authored
Dec 04, 2020
by
github-actions
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Transpile
c52d549a
parent
5e1f53a0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
EIP712Upgradeable.sol
contracts/drafts/EIP712Upgradeable.sol
+24
-17
No files found.
contracts/drafts/EIP712Upgradeable.sol
View file @
538cafed
...
@@ -22,14 +22,9 @@ import "../proxy/Initializable.sol";
...
@@ -22,14 +22,9 @@ import "../proxy/Initializable.sol";
*/
*/
abstract contract EIP712Upgradeable is Initializable {
abstract contract EIP712Upgradeable is Initializable {
/* solhint-disable var-name-mixedcase */
/* solhint-disable var-name-mixedcase */
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
bytes32 private _HASHED_NAME;
// invalidate the cached domain separator if the chain id changes.
bytes32 private _HASHED_VERSION;
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
bytes32 private constant _TYPE_HASH = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH;
/* solhint-enable var-name-mixedcase */
/* solhint-enable var-name-mixedcase */
/**
/**
...
@@ -51,23 +46,15 @@ abstract contract EIP712Upgradeable is Initializable {
...
@@ -51,23 +46,15 @@ abstract contract EIP712Upgradeable is Initializable {
function __EIP712_init_unchained(string memory name, string memory version) internal initializer {
function __EIP712_init_unchained(string memory name, string memory version) internal initializer {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
_HASHED_NAME = hashedName;
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = _getChainId();
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}
}
/**
/**
* @dev Returns the domain separator for the current chain.
* @dev Returns the domain separator for the current chain.
*/
*/
function _domainSeparatorV4() internal view returns (bytes32) {
function _domainSeparatorV4() internal view returns (bytes32) {
if (_getChainId() == _CACHED_CHAIN_ID) {
return _buildDomainSeparator(_TYPE_HASH, _EIP712NameHash(), _EIP712VersionHash());
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
}
}
}
function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {
function _buildDomainSeparator(bytes32 typeHash, bytes32 name, bytes32 version) private view returns (bytes32) {
...
@@ -107,5 +94,25 @@ abstract contract EIP712Upgradeable is Initializable {
...
@@ -107,5 +94,25 @@ abstract contract EIP712Upgradeable is Initializable {
chainId := chainid()
chainId := chainid()
}
}
}
}
/**
* @dev The hash of the name parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712NameHash() internal virtual view returns (bytes32) {
return _HASHED_NAME;
}
/**
* @dev The hash of the version parameter for the EIP712 domain.
*
* NOTE: This function reads from storage by default, but can be redefined to return a constant value if gas costs
* are a concern.
*/
function _EIP712VersionHash() internal virtual view returns (bytes32) {
return _HASHED_VERSION;
}
uint256[50] private __gap;
uint256[50] private __gap;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment