Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #186 from z0r0z/patch-1
Browse files Browse the repository at this point in the history
⚡ Some low key gas optimizations
  • Loading branch information
kulkarohan authored Nov 15, 2023
2 parents 1d4c0c9 + 395b5f2 commit 9a4eb9d
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions contracts/ZoraModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ contract ZoraModuleManager {
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes("ZORA")),
keccak256(bytes("3")),
_chainID(),
keccak256("3"),
block.chainid,
address(this)
)
);
Expand Down Expand Up @@ -196,14 +196,18 @@ contract ZoraModuleManager {
bytes32 _s
) public {
require(_deadline == 0 || _deadline >= block.timestamp, "ZMM::setApprovalForModuleBySig deadline expired");

bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
EIP_712_DOMAIN_SEPARATOR,
keccak256(abi.encode(SIGNED_APPROVAL_TYPEHASH, _module, _user, _approved, _deadline, sigNonces[_user]++))
)
);

// Unchecked because the only math done is incrementing
// the user's nonce which cannot realistically overflow
unchecked {
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
EIP_712_DOMAIN_SEPARATOR,
keccak256(abi.encode(SIGNED_APPROVAL_TYPEHASH, _module, _user, _approved, _deadline, sigNonces[_user]++))
)
);
}

address recoveredAddress = ecrecover(digest, _v, _r, _s);

Expand Down Expand Up @@ -298,11 +302,4 @@ contract ZoraModuleManager {

emit ModuleApprovalSet(msg.sender, _module, _approved);
}

/// @notice The EIP-155 chain id
function _chainID() private view returns (uint256 id) {
assembly {
id := chainid()
}
}
}

0 comments on commit 9a4eb9d

Please sign in to comment.