Skip to content

Commit

Permalink
refactor: avoid external call to get domain separator
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-fruitful committed Nov 21, 2024
1 parent dff400f commit 9215deb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/facets/NaymsTokenFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AppStorage, LibAppStorage } from "../shared/AppStorage.sol";
import { Modifiers } from "../shared/Modifiers.sol";
import { LibHelpers } from "../libs/LibHelpers.sol";
import { LibERC20Token } from "../libs/LibERC20Token.sol";
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

/**
* @title Nayms token facet.
Expand Down Expand Up @@ -117,7 +117,7 @@ contract NaymsTokenFacet is Modifiers {
bytes32 structHash =
keccak256(abi.encode(PERMIT_TYPEHASH, _owner, _spender, _value, s.nonces[_owner]++, _deadline));

bytes32 digest = keccak256(abi.encodePacked("\x19\x01", this.DOMAIN_SEPARATOR(), structHash));
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR(), structHash));

address signer = ECDSA.recover(digest, _v, _r, _s);
if (signer == address(0) || signer != _owner) {
Expand All @@ -142,7 +142,7 @@ contract NaymsTokenFacet is Modifiers {
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
function DOMAIN_SEPARATOR() external view returns (bytes32) {
function DOMAIN_SEPARATOR() public view returns (bytes32) {
return keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
Expand Down
31 changes: 0 additions & 31 deletions src/init/InitPermit.sol

This file was deleted.

4 changes: 2 additions & 2 deletions src/shared/AppStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct AppStorage {
bool diamondInitialized;
//// EIP712 domain separator ////
uint256 initialChainId;
bytes32 initialDomainSeparator;
bytes32 initialDomainSeparator; // note: this is unused. Check the method DOMAIN_SEPARATOR() in the NaymsTokenFacet
// for the domain separator
//// Reentrancy guard ////
uint256 reentrancyStatus;
//// NAYMS ERC20 TOKEN ////
Expand All @@ -30,7 +31,6 @@ struct AppStorage {
address minter;
// upgrade initializations
mapping(uint256 => bool) initComplete;
bytes32 DOMAIN_SEPARATOR;
mapping(address permitCaller => uint256 nonce) nonces;
}

Expand Down

0 comments on commit 9215deb

Please sign in to comment.