Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 3 min read

How Does Uniswap Permit2 Work? Token Spending Permissions

A wallet using Uniswap Permit2 gives Permit2 an ERC-20 allowance and separately authorizes an application, so Permit2 checks both permission layers before moving tokens. A Router Spend, Layer by Layer In an i

A wallet using Uniswap Permit2 gives Permit2 an ERC-20 allowance and separately authorizes an application, so Permit2 checks both permission layers before moving tokens.

A Router Spend, Layer by Layer

In an illustrative swap, you approve Permit2 to spend a token, then authorize a router to spend a bounded amount through Permit2. The token recognizes Permit2 as its spender; Permit2 recognizes the router under the authorization you granted.

For an approval audit, revokecash separates the token-to-Permit2 approval from the router’s internal Permit2 allowance. The token approval checker at revokecash.io lets you inspect those permissions together and choose which one to revoke.

  • ERC-20 allowance: The token records how much Permit2 may pull from your wallet. This is the underlying permission that either transfer route needs when Permit2 calls the token’s transferFrom function.
  • AllowanceTransfer: Permit2 records a reusable allowance for an owner, token, and spender. The entry holds an amount, expiration, and nonce, allowing a router to make permitted transfers until the amount is used or the allowance expires.
  • SignatureTransfer: A signed authorization permits a one-time transfer up to its stated amount. Permit2 checks its deadline and nonce, then consumes that nonce so the same authorization cannot be used again.

For the router’s AllowanceTransfer call, Permit2 uses the calling router’s address to find its allowance, checks the remaining amount and expiration, reduces a finite allowance, and calls the token’s transferFrom. A signed request to set that allowance has a separate signature deadline and must carry the current nonce. EIP-712 typed data ties the signature to its stated terms.

With SignatureTransfer, the signature itself supplies the transfer authorization. Permit2 verifies the signer, spender, amount, deadline, and unused nonce before calling the token. The application that receives the signature must also enforce its intended caller and recipient rules; Permit2’s amount check alone cannot define the whole swap.

Revocation depends on the layer you mean. Setting the token’s allowance to Permit2 to zero blocks Permit2 from pulling that token, regardless of a router allowance or an unused transfer signature. The internal allowance keeps its own amount and expiration, and an unused signature keeps its deadline and nonce. If you later approve Permit2 again, an internal authorization that is still valid can become usable. Revoke the specific router allowance to end its reusable permission; invalidate an unused signature’s nonce to end that signed permission.

Related Questions

Permit2 vs EIP-2612: What Is the Difference?

Permit2 adds an intermediary contract that can manage signed permissions after the token grants it an ERC-20 allowance. EIP-2612 instead requires the token contract itself to implement permit, which changes that token’s allowance through a signature.

Is Signing Permit2 Gasless?

Signing a Permit2 message happens offchain and uses no transaction gas. The initial ERC-20 approval is an onchain transaction, and submitting a permit or executing a transfer also consumes gas.

Questions Readers Ask Next

How Do I Invalidate an Unused Permit2 Signature?

An unused SignatureTransfer authorization can be invalidated by calling Permit2’s invalidateUnorderedNonces with the word position and bit mask for its nonce. For an unsigned-onchain AllowanceTransfer permit, advancing the owner-token-spender nonce invalidates older signed permits.

Does Permit2 Support Smart Contract Wallets?

Permit2 supports smart contract wallet signatures through EIP-1271, provided the wallet implements that signature-validation standard. The wallet must still grant the token’s underlying allowance to Permit2.

What Does Permit2 Witness Data Mean?

Permit2 witness data adds signed context to a SignatureTransfer authorization. An application can bind a transfer to trade details, such as a minimum amount received, through permitWitnessTransferFrom.

How Does Permit2 Prevent Cross-Chain Signature Replay?

Permit2 hashes signatures with an EIP-712 domain containing the chain ID and Permit2 contract address. A signature for one chain therefore fails verification under another chain’s domain.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.