the-compact icon indicating copy to clipboard operation
the-compact copied to clipboard

Solady ERC20 Does Not Grant Infinite Permit2 Allowance by Default

Open Swapnapratim opened this issue 5 months ago • 2 comments

Summary

The test suite and some comments in this repository assume that Solady’s ERC20 implementation grants infinite allowance to the canonical Permit2 contract (0x000000000022D473030F116dDEE9F6B43aC78BA3) by default. However, this is not the case unless the ERC20 implementation explicitly overrides the _givePermit2InfiniteAllowance() function to return true.

Details

  • Solady’s base ERC20 contract includes logic for infinite Permit2 allowance, but the default implementation of:

    function _givePermit2InfiniteAllowance() internal view virtual returns (bool) {
        return false;
    }
    

    means that Permit2 does not have infinite allowance unless this function is overridden.

  • Current test setup and comments (e.g., in Setup.sol) assume infinite approval is granted by default, which is misleading.

  • Observed behavior:

    • Tests involving Permit2 revert with InsufficientAllowance() unless an explicit approve(permit2, amount) is called.
    • Adding this approval in the test setup resolves the issue.

Steps to Reproduce

  1. Use Solady’s MockERC20 in a test.
  2. Attempt a Permit2 transfer without calling approve(permit2, amount).
  3. Observe a revert due to insufficient allowance.

Expected Behavior

  • Either:
    • The test setup should always explicitly approve Permit2, or
    • The custom ERC20 used in tests should override _givePermit2InfiniteAllowance() to return true.

Suggested Fix

  • Update test setup to always call token.approve(permit2, amount) for any token used with Permit2.
  • Update comments to clarify that infinite Permit2 approval is not enabled by default in Solady ERC20.
  • Optionally, provide a custom mock that enables infinite Permit2 allowance for tests that require it.

References


Swapnapratim avatar Jul 04 '25 08:07 Swapnapratim

I have solved this issue at PR#150 : https://github.com/Uniswap/the-compact/pull/150

Swapnapratim avatar Jul 04 '25 08:07 Swapnapratim

can you make this PR against the v1 branch?

0age avatar Jul 08 '25 16:07 0age