diff --git a/contracts/ERC20Permit.sol b/contracts/ERC20Permit.sol index b3363be..1688eb3 100644 --- a/contracts/ERC20Permit.sol +++ b/contracts/ERC20Permit.sol @@ -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; /** @@ -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; @@ -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)) ) ); diff --git a/contracts/interfaces/IERC20Permit.sol b/contracts/interfaces/IERC20Permit.sol index 424abb3..608686b 100644 --- a/contracts/interfaces/IERC20Permit.sol +++ b/contracts/interfaces/IERC20Permit.sol @@ -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_); }