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

Include EIP-5267 discovery in EIP-712 #3969

Merged
merged 23 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use shortstrings
Amxx committed Feb 6, 2023
commit db8c0862790ccee16233acc3c5b2d215fe853b58
19 changes: 12 additions & 7 deletions contracts/utils/cryptography/EIP712.sol
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
pragma solidity ^0.8.8;

import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/ERC5267.sol";

/**
@@ -26,21 +27,24 @@ import "../../interfaces/ERC5267.sol";
* _Available since v3.4._
*/
abstract contract EIP712 is ERC5267 {
using ShortStrings for *;

/* 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
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
address private immutable _CACHED_THIS;

string private _NAME;
string private _VERSION;

bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;
bytes32 private immutable _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

ShortString private immutable _NAME;
ShortString private immutable _VERSION;
string private _NAME_FALLBACK;
string private _VERSION_FALLBACK;
/* solhint-enable var-name-mixedcase */

/**
@@ -56,8 +60,9 @@ abstract contract EIP712 is ERC5267 {
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_NAME = name;
_VERSION = version;
_NAME = name.toShortStringWithFallback(_NAME_FALLBACK);
_VERSION = version.toShortStringWithFallback(_VERSION_FALLBACK);

_HASHED_NAME = keccak256(bytes(name));
_HASHED_VERSION = keccak256(bytes(version));
_CACHED_CHAIN_ID = block.chainid;
@@ -119,8 +124,8 @@ abstract contract EIP712 is ERC5267 {
{
return (
hex"0f", // 01111
_NAME,
_VERSION,
_NAME.toStringWithFallback(_NAME_FALLBACK),
_VERSION.toStringWithFallback(_VERSION_FALLBACK),
block.chainid,
address(this),
bytes32(0),