Skip to content

Commit

Permalink
discard version from EIP712
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepoint committed Aug 3, 2024
1 parent cd8b760 commit 9419e44
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_permit.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
79624
79636
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62536
62524
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_permit_twice.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45436
45412
2 changes: 1 addition & 1 deletion src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ contract PositionManager is
constructor(IPoolManager _poolManager, IAllowanceTransfer _permit2)
BaseActionsRouter(_poolManager)
Permit2Forwarder(_permit2)
ERC721Permit("Uniswap V4 Positions NFT", "UNI-V4-POSM", "1")
ERC721Permit("Uniswap V4 Positions NFT", "UNI-V4-POSM")
{}

/// @notice Reverts if the deadline has passed
Expand Down
8 changes: 3 additions & 5 deletions src/base/EIP712.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ contract EIP712 is IEIP712 {
bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
uint256 private immutable _CACHED_CHAIN_ID;
bytes32 private immutable _HASHED_NAME;
bytes32 private immutable _HASHED_VERSION;

bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");

constructor(string memory name, string memory version) {
constructor(string memory name) {
_HASHED_NAME = keccak256(bytes(name));
_HASHED_VERSION = keccak256(bytes(version));

_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator();
Expand All @@ -34,7 +32,7 @@ contract EIP712 is IEIP712 {

/// @notice Builds a domain separator using the current chainId and contract address.
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, block.chainid, address(this)));
return keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, block.chainid, address(this)));
}

/// @notice Creates an EIP-712 typed data hash
Expand Down
5 changes: 1 addition & 4 deletions src/base/ERC721Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ abstract contract ERC721Permit is ERC721, IERC721Permit, EIP712, UnorderedNonce
using SignatureVerification for bytes;

/// @notice Computes the nameHash and versionHash
constructor(string memory name_, string memory symbol_, string memory version_)
ERC721(name_, symbol_)
EIP712(name_, version_)
{}
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) EIP712(name_) {}

/// @inheritdoc IERC721Permit
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature)
Expand Down
6 changes: 2 additions & 4 deletions test/ERC721Permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ contract ERC721PermitTest is Test {

string constant name = "Mock ERC721Permit";
string constant symbol = "MOCK721";
string constant version = "1";

function setUp() public {
(alice, alicePK) = makeAddrAndKey("ALICE");
(bob, bobPK) = makeAddrAndKey("BOB");

erc721Permit = new MockERC721Permit(name, symbol, version);
erc721Permit = new MockERC721Permit(name, symbol);
}

// --- Test the overriden approval ---
Expand Down Expand Up @@ -72,9 +71,8 @@ contract ERC721PermitTest is Test {
erc721Permit.DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256(bytes(version)),
block.chainid,
address(erc721Permit)
)
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/MockERC721Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ERC721Permit} from "../../src/base/ERC721Permit.sol";
contract MockERC721Permit is ERC721Permit {
uint256 public lastTokenId;

constructor(string memory name, string memory symbol, string memory version) ERC721Permit(name, symbol, version) {}
constructor(string memory name, string memory symbol) ERC721Permit(name, symbol) {}

function tokenURI(uint256) public pure override returns (string memory) {
return "";
Expand Down
3 changes: 1 addition & 2 deletions test/position-managers/Permit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ contract PermitTest is Test, PosmTestSetup {
ERC721Permit(address(lpm)).DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)"),
keccak256("Uniswap V4 Positions NFT"), // storage is private on EIP712.sol so we need to hardcode these
keccak256("1"),
block.chainid,
address(lpm)
)
Expand Down

0 comments on commit 9419e44

Please sign in to comment.