From 59cd7ddb63f707b8c4e5ea3a86da3812ab2d8a93 Mon Sep 17 00:00:00 2001 From: bidyut-arianelabs Date: Fri, 23 Sep 2022 15:02:01 +0530 Subject: [PATCH] review fixes --- contracts/protocol/facets/ConfigHandlerFacet.sol | 1 - contracts/protocol/libs/EIP712Lib.sol | 15 +++++++++------ contracts/protocol/libs/ProtocolLib.sol | 2 -- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contracts/protocol/facets/ConfigHandlerFacet.sol b/contracts/protocol/facets/ConfigHandlerFacet.sol index 4aa2966d5..a3af6a177 100644 --- a/contracts/protocol/facets/ConfigHandlerFacet.sol +++ b/contracts/protocol/facets/ConfigHandlerFacet.sol @@ -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); } /** diff --git a/contracts/protocol/libs/EIP712Lib.sol b/contracts/protocol/libs/EIP712Lib.sol index 0c34ae8d2..ae1e214c1 100644 --- a/contracts/protocol/libs/EIP712Lib.sol +++ b/contracts/protocol/libs/EIP712Lib.sol @@ -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. * * @param _name - the name of the protocol * @param _version - The version of the protocol @@ -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( @@ -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; } else { + pmti.cachedChainId = block.chainid; return buildDomainSeparator(PROTOCOL_NAME, PROTOCOL_VERSION); } } @@ -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)); } diff --git a/contracts/protocol/libs/ProtocolLib.sol b/contracts/protocol/libs/ProtocolLib.sol index 0f40bc3ac..220de923f 100644 --- a/contracts/protocol/libs/ProtocolLib.sol +++ b/contracts/protocol/libs/ProtocolLib.sol @@ -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