Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor EIP712 #458

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MorphoGetters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract contract MorphoGetters is IMorphoGetters, MorphoInternal {

/// @notice Returns the domain separator of the EIP712.
function DOMAIN_SEPARATOR() external view returns (bytes32) {
return _DOMAIN_SEPARATOR;
return _domainSeparator();
}

/// @notice Returns the e-mode category ID of Morpho on the Aave protocol.
Expand Down
15 changes: 14 additions & 1 deletion src/MorphoInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ abstract contract MorphoInternal is MorphoStorage {

/// INTERNAL ///

/// @dev Dynamically computed to use the root proxy address in a delegate call.
function _domainSeparator() internal view returns (bytes32) {
return keccak256(
abi.encode(
Constants.EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(Constants.EIP712_NAME)),
keccak256(bytes(Constants.EIP712_VERSION)),
block.chainid,
address(this)
pakim249CAL marked this conversation as resolved.
Show resolved Hide resolved
)
);
}

/// @dev Creates a new market for the `underlying` token with a given `reserveFactor` (in bps) and a given `p2pIndexCursor` (in bps).
function _createMarket(address underlying, uint16 reserveFactor, uint16 p2pIndexCursor) internal {
if (underlying == address(0)) revert Errors.AddressIsZero();
Expand Down Expand Up @@ -141,7 +154,7 @@ abstract contract MorphoInternal is MorphoStorage {

/// @dev Returns the hash of the EIP712 typed data.
function _hashEIP712TypedData(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked(Constants.EIP712_MSG_PREFIX, _DOMAIN_SEPARATOR, structHash));
return keccak256(abi.encodePacked(Constants.EIP712_MSG_PREFIX, _domainSeparator(), structHash));
}

/// @notice Approves a `manager` to borrow/withdraw on behalf of the sender.
Expand Down
11 changes: 0 additions & 11 deletions src/MorphoStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ abstract contract MorphoStorage is Initializable, Ownable2StepUpgradeable {

IPool internal immutable _POOL; // The address of the pool.
IPoolAddressesProvider internal immutable _ADDRESSES_PROVIDER; // The address of the pool addresses provider.
bytes32 internal immutable _DOMAIN_SEPARATOR; // The domain separator as part of the EIP712.
uint8 internal immutable _E_MODE_CATEGORY_ID; // The e-mode category of the deployed Morpho.

/// STORAGE ///
Expand Down Expand Up @@ -51,16 +50,6 @@ abstract contract MorphoStorage is Initializable, Ownable2StepUpgradeable {
_ADDRESSES_PROVIDER = IPoolAddressesProvider(addressesProvider);
_POOL = IPool(_ADDRESSES_PROVIDER.getPool());

_DOMAIN_SEPARATOR = keccak256(
abi.encode(
Constants.EIP712_DOMAIN_TYPEHASH,
keccak256(bytes(Constants.EIP712_NAME)),
keccak256(bytes(Constants.EIP712_VERSION)),
block.chainid,
address(this)
)
);

_E_MODE_CATEGORY_ID = eModeCategoryId;
}
}