dmihal / eth-permit

Lightweight library for signing ERC-2612 permit signatures.
https://www.npmjs.com/package/eth-permit
139 stars 30 forks source link

incorrect permit signature for version other than "1" #19

Closed 0f0crypto closed 11 months ago

0f0crypto commented 11 months ago

The generated permit is incorrect when EIP712 is instantiated with any version other than "1" because the value is hardcoded in the gerDomain method https://github.com/dmihal/eth-permit/blob/34f3fb59f0e32d8c19933184f5a7121ee125d0a5/src/eth-permit.ts#L97

For example, the current version of the USDC token on Ethereum uses version "2"

    function initializeV2(string calldata newName) external {
        // solhint-disable-next-line reason-string
        require(initialized && _initializedVersion == 0);
        name = newName;
        DOMAIN_SEPARATOR = EIP712.makeDomainSeparator(newName, "2");
        _initializedVersion = 1;
    }

Therefore, using the signERC2612Permit does not work for USDC, i.e. called permit() reverts with EIP2612: invalid signature

0f0crypto commented 11 months ago

Oh nevermind. I see the key is to use a domain object instead of the address as the second parameter 🤦