Skip to content

Solady ERC20 Does Not Grant Infinite Permit2 Allowance by Default #151

@Swapnapratim

Description

@Swapnapratim

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


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions