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

feat: Convert DOMAIN_SEPARATOR to view function (SC-4960) #23

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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_);

}