Skip to content

Commit

Permalink
feat: Convert DOMAIN_SEPARATOR to view function (SC-4960)
Browse files Browse the repository at this point in the history
  • Loading branch information
deluca-mike committed Mar 9, 2022
1 parent 15ecb91 commit f48e5c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
22 changes: 9 additions & 13 deletions contracts/ERC20Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ contract ERC20Permit is IERC20Permit {
// PERMIT_TYPEHASH = keccak256("Permit(address owner,address spender,uint256 amount,uint256 nonce,uint256 deadline)");
bytes32 public constant override PERMIT_TYPEHASH = 0xfc77c2b9d30fe91687fd39abb7d16fcdfe1472d065740051ab8b13e4bf4a617f;

bytes32 public immutable override DOMAIN_SEPARATOR;

mapping (address => uint256) public override nonces;

/**
Expand All @@ -44,26 +42,24 @@ contract ERC20Permit is IERC20Permit {
name = name_;
symbol = symbol_;
decimals = decimals_;
}

/**************************/
/*** External Functions ***/
/**************************/

uint256 chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
function DOMAIN_SEPARATOR() public view override returns (bytes32 domainSeparator_) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
block.chainid,
address(this)
)
);
}

/**************************/
/*** External Functions ***/
/**************************/

function approve(address spender_, uint256 amount_) external override returns (bool success_) {
_approve(msg.sender, spender_, amount_);
return true;
Expand All @@ -84,7 +80,7 @@ contract ERC20Permit is IERC20Permit {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
)
);
Expand Down
12 changes: 6 additions & 6 deletions contracts/interfaces/IERC20Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ interface IERC20Permit is IERC20 {
function PERMIT_TYPEHASH() external pure returns (bytes32 hash_);

/**
* @dev Returns the nonce for the given owner.
* @param owner The addreses of the owner account.
* @return nonce_ The current nonce.
* @dev Returns the nonce for the given owner.
* @param owner The address of the owner account.
* @return nonce_ The current nonce.
*/
function nonces(address owner) external view returns (uint256 nonce_);

/**
* @dev Returns the signature domain separator.
* @return domain_ The domain for the contract.
* @dev Returns the signature domain separator.
* @return domainSeparator_ The domain for the contract.
*/
function DOMAIN_SEPARATOR() external view returns (bytes32 domain_);
function DOMAIN_SEPARATOR() external view returns (bytes32 domainSeparator_);

}

0 comments on commit f48e5c9

Please sign in to comment.