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

EIP-02M: Remediate Improper Domain Separator Retrieval #402

Merged
merged 7 commits into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion contracts/protocol/facets/ConfigHandlerFacet.sol
Expand Up @@ -71,7 +71,6 @@ contract ConfigHandlerFacet is IBosonConfigHandler, ProtocolBase {
ProtocolLib.ProtocolMetaTxInfo storage pmti = protocolMetaTxInfo();
pmti.domainSeparator = EIP712Lib.buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION);
pmti.cachedChainId = block.chainid;
pmti.cachedThis = address(this);
}

/**
Expand Down
15 changes: 9 additions & 6 deletions contracts/protocol/libs/EIP712Lib.sol
Expand Up @@ -12,6 +12,8 @@ import { ProtocolLib } from "../libs/ProtocolLib.sol";
library EIP712Lib {
/**
* @notice Generates the domain separator hash.
* @dev Using chainId as the salt allows you that your client is active on one chain,
* while you sign metaTx for another chain.
zajck marked this conversation as resolved.
Show resolved Hide resolved
*
* @param _name - the name of the protocol
* @param _version - The version of the protocol
Expand Down Expand Up @@ -49,7 +51,7 @@ library EIP712Lib {
bytes32 _sigR,
bytes32 _sigS,
uint8 _sigV
) internal view returns (bool) {
) internal returns (bool) {
// Ensure signature is unique
// See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/04695aecbd4d17dddfd55de766d10e3805d6f42f/contracts/cryptography/ECDSA.sol#63
require(
Expand All @@ -68,13 +70,14 @@ library EIP712Lib {
*
* @return the domain separator
*/
function getDomainSeparator() private view returns (bytes32) {
address cachedThis = ProtocolLib.protocolMetaTxInfo().cachedThis;
uint256 cachedChainId = ProtocolLib.protocolMetaTxInfo().cachedChainId;
function getDomainSeparator() private returns (bytes32) {
ProtocolLib.ProtocolMetaTxInfo storage pmti = ProtocolLib.protocolMetaTxInfo();
uint256 cachedChainId = pmti.cachedChainId;

if (address(this) == cachedThis && block.chainid == cachedChainId) {
if (block.chainid == cachedChainId) {
return ProtocolLib.protocolMetaTxInfo().domainSeparator;
zajck marked this conversation as resolved.
Show resolved Hide resolved
} else {
pmti.cachedChainId = block.chainid;
return buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION);
zajck marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand All @@ -91,7 +94,7 @@ library EIP712Lib {
* @param _messageHash - the message hash
* @return the EIP712 compatible message hash
*/
function toTypedMessageHash(bytes32 _messageHash) internal view returns (bytes32) {
function toTypedMessageHash(bytes32 _messageHash) internal returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", getDomainSeparator(), _messageHash));
}

Expand Down
2 changes: 0 additions & 2 deletions contracts/protocol/libs/ProtocolLib.sol
Expand Up @@ -204,8 +204,6 @@ library ProtocolLib {
mapping(address => mapping(uint256 => bool)) usedNonce;
// The cached chain id
uint256 cachedChainId;
// The cached address of the diamond
address cachedThis;
// map function name to input type
mapping(string => BosonTypes.MetaTxInputType) inputType;
// map input type => hash info
Expand Down