Uniswap / permit2

🔑🔑🔑 next generation token approvals mechanism

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible improvement Permit2Lib.sol:permit2

invocamanman opened this issue · comments

I think it could be better instead of check the DOMAIN_SEPARATOR which some tokens that implement permit do not implement like UNI.
Check instead the PERMIT_TYPEHASH in a very similar behaviour.
In this way you can support native permit to the tokens that do not support DOMAIN_SEPARATOR like UNI ( so overall will be more optimal) and also support other DAI like tokens that support permit, that you see in this list

EDIT: Also the DOMAIN_SEPARATOR will change in every network, so you should update the DAI_DOMAIN_SEPARATOR constant in case of a deployment in different networks, but the PERMIT_TYPEHASH won't change ^^

I agree it would be more general, however I don't think all tokens using permit expose a PERMIT_TYPEHASH getter and thus it makes this impossible to do...

Every single token that i check it implements it, for instance you can check this list list
It's much more common than the DOMAIN_SEPARATOR, which a lot of tokens do not implement like UNI

Thx for the list!

But all token based on the ERC20 from solmate does not have this getter. It's not publicly exposed on Open Zeppelin's version neither. So I guess, some tokens in the wild might not implement it as well.

Perhaps this can easily be handle using a try/catch system though

I see!, but ye, my proposal was in a similar behavior like now that a try/catch is being used to check the DOMAIN_SEPARATOR, to check PERMIT_TYPEHASH instead. For example if i'm not mistaken, since UNI do not implement the DOMAIN_SEPARATOR right know the Permit2 is being used, but the native permit of UNI could be used instead ( much more optimal).
I think its better to prioritize the common tokens in the network, and the new ones like WETH10 also implement PERMIT_TYPEHASH view function.
In a future i think the best way can be the EIP-5267 but for the common use case currently, i think the PERMIT_TYPEHASH fits better

@invocamanman I just created a draft PR #176 if you want to check.

I feel like I could remove some tests for small/large domain separators or type hash.

commented

PERMIT_TYPEHASH is not part of any standard whatsoever.

It's a relic of DAI which was written before EIP-2612 was formalized and proliferated by Uniswap in UniswapV2ERC20 which also needlessly implements the function. While there are quite a few tokens that implement PERMIT_TYPEHASH, most of them also implement DOMAIN_SEPARATOR like the EIP-2612 standard requires. Tokens implementing only PERMIT_TYPEHASH are in violation of EIP-2612 and are implemented incorrectly.

It is sad that a major token like UNI is in-violation of EIP-2612, but either way we loose some token compatibility here (unless you check both which idt we should do for gas reasons) and ultimately I think we should stick with DOMAIN_SEPARATOR because it's actually mandated by the standard we're targeting and not just a copy-pasta error.

Going to close in favor of following the EIP-2612 standard as @transmissions11 outlines above!