Commit 538cafed by github-actions

Transpile c52d549a

parent 5e1f53a0
...@@ -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;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment