Trading

·

July 15, 2024

Permit2 for serious security

Anthony Allen

Smart contracts with unlimited or time-based allowances are a hidden risk that could drain your funds. Matcha keeps you safe with Permit2 one-time allowances.

Permit2 is a transaction approval process that improves security over standard ERC-20 approvals by defining strict rules about when and how tokens can be spent by a smart contract. Matcha on 0x v2 uses Permit2 configured for the strictest one-time allowance, preventing funds from being spent without an explicit signature. 

Over $6.5 billion of crypto is currently at risk through unlimited approvals to decentralized applications for the top-20 tokens on Ethereum alone, with $2 billion of that figure on DEXs, according to security research firm Dedaub. Using a DEX with Permit2 using one-time allowances, as implemented on Matcha, can prevent your funds from being lost even if the smart contracts were compromised.

What are token approvals?

Token approvals let smart contracts transfer funds from your account on your behalf. This process is necessary when using a DEX or other DeFi apps, as their smart contracts must be able to spend funds in order to complete trades, so you don’t need to build and broadcast complex transactions by yourself. 

The established token approval process is based on EIP-20, which was defined in 2018. It allows a ‘spender’ to withdraw a specified ‘value’ of tokens from your account as many times as they want as long as the total value is below the limit. This method has been used almost universally across the ecosystem, but introduces significant risks when the approved spender falls under control of an attacker, especially if the value is set as unlimited.

$6.5 billion are exposed to unlimited token allowances on Ethereum top 20 tokens

Matcha on 0x v2 implements Permit2 in a way that removes this risk and provides a better and more secure experience that is otherwise lacking in the DEX space. 

How approvals work on most DEXs

When you swap any new token for the first time on a DEX, you will first be prompted to approve spending the token before you can continue to complete the trade. This involves signing a message with your wallet that allows the DEXs smart contracts to spend your funds. 

To make the user experience a little more convenient and avoid the gas costs of repeated approvals, most DEXs will ask for permission to spend an unlimited amount of any new token, so you don’t need to repeat the process next time you trade. If the spending limit is set to only the amount you are trading, you will need to approve a new limit if you later want to trade larger amounts.

In both situations, you risk having your assets drained if the DEX or app you are using has its contracts hacked. Since those smart contracts have been given permission to spend your funds, an attacker with control over the smart contracts could send any approved tokens from your wallet to their own. With unlimited approvals, you would lose everything at once.

Token allowances can be revoked by sending a new message to the smart contract explicitly removing the allowance. This process is awkward and expensive, however, as each token revoked for each app requires a new onchain message to be signed, which costs gas.

What is Permit2?

Permit2 is a standard that allows approvals to be shared across smart contracts and provide more consistent approval experience across apps. It substitutes the EIP-20 token approval method with a smart contract, allowing Permit2 to be implemented more flexibly with more specific permissions. This enables time-based and signature-based parameters, and introduces useful features like the ability to revoke all token approvals at once, batch transfers to be sent to multiple recipients, and more.

Permit2 as implemented by Uniswap and other DEXs, consists of two parts: SignatureTransfer, which requires a one-time signature, and AllowanceTransfer, which sets parameters allowing transfers for a specific amount of time, as long as spending conditions are valid. When AllowanceTransfer is used, tokens may remain vulnerable even at rest.

Time-based approvals in Permit2

While the time-based allowances of the AllowanceTransfer contract are more secure than the previous use of unlimited token allowances - it still leaves a window of opportunity which can be exploited, as in the case of the Paraswap Permit2 exploit covered below. 

Permit2 components SignatureTransfer and AllowanceTransfer
Matcha uses only the SignatureTransfer component of Permit2.

Since the two parts of Permit2 can operate independently, it is possible to use only the SignatureTransfer contract and only allow one-time authorization for token spends, keeping funds more secure. 

One-time authorization with Permit2

Matcha on 0x v2 uses the Permit2 contract SignatureTransfer to ensure the highest level of security when funds are at rest. It does not support AllowanceTransfer, preventing time-based allowances from being exploited. 

One-time allowance prevents funds being spent after you swap!

This implementation requires a new authorization to be made for every trade. Each time you make a new swap, you will approve spending the token and then the trade itself in one quick flow. 

Other apps don’t use Permit2 in this configuration because it introduces gas inefficiencies, which Matcha can overcome through 0x’s highly-optimized smart contracts. 

Using the Permit2 contract in this way ensures you get the highest level of security and never need to actively approve a token again!

Permit2 exploits

Simply using Permit2 does not guarantee that your funds are secure. The time-based authorization used by most apps, including Uniswap, which have integrated Permit2 can still be exploited. 

This has already been demonstrated in the Paraswap hack in March 2024, where Permit2 was implemented but used time-based approvals, which meant that at the time of the exploit funds were still authorized to be spent even though they were not being actively traded. This exploit affected over 380 users and resulted in a loss of over $1.1M, though around 80% was later recovered.

One-time approvals prevent this Permit2 exploit from happening as token allowances are only authorized for the duration of a specific trade and your tokens are never authorized for spending when not actively traded.

Security made simple

Crypto security is a difficult problem to solve, as the connected world of digital assets is always open to hidden exploits. Permit2 closes the doors to a particularly nasty attack vector which puts your funds at risk simply because you used a decentralized application which could be targeted in a hack. With Permit2 one-time approvals, your funds cannot be spent without your consent even if the application smart contracts are compromised.

Proper security of crypto assets remains complicated. You should use a hardware wallet and keep your keys isolated offline, but even this seemingly robust security model is subject to the exploits which are fixed by Permit2.

Security by design, as you’ll find in Matcha on 0x v2, keeps your funds safe whenever you aren’t using them, improving the security of software and hardware wallets alike while also reducing complexity. Try Permit2 now on matcha.xyz!

Contents
Subscribe to our newsletter
By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong, but it's not your fault.
Trading

·

July 15, 2024

Permit2 for serious security

Permit2 for serious security

Smart contracts with unlimited or time-based allowances are a hidden risk that could drain your funds. Matcha keeps you safe with Permit2 one-time allowances.

Permit2 is a transaction approval process that improves security over standard ERC-20 approvals by defining strict rules about when and how tokens can be spent by a smart contract. Matcha on 0x v2 uses Permit2 configured for the strictest one-time allowance, preventing funds from being spent without an explicit signature. 

Over $6.5 billion of crypto is currently at risk through unlimited approvals to decentralized applications for the top-20 tokens on Ethereum alone, with $2 billion of that figure on DEXs, according to security research firm Dedaub. Using a DEX with Permit2 using one-time allowances, as implemented on Matcha, can prevent your funds from being lost even if the smart contracts were compromised.

What are token approvals?

Token approvals let smart contracts transfer funds from your account on your behalf. This process is necessary when using a DEX or other DeFi apps, as their smart contracts must be able to spend funds in order to complete trades, so you don’t need to build and broadcast complex transactions by yourself. 

The established token approval process is based on EIP-20, which was defined in 2018. It allows a ‘spender’ to withdraw a specified ‘value’ of tokens from your account as many times as they want as long as the total value is below the limit. This method has been used almost universally across the ecosystem, but introduces significant risks when the approved spender falls under control of an attacker, especially if the value is set as unlimited.

$6.5 billion are exposed to unlimited token allowances on Ethereum top 20 tokens

Matcha on 0x v2 implements Permit2 in a way that removes this risk and provides a better and more secure experience that is otherwise lacking in the DEX space. 

How approvals work on most DEXs

When you swap any new token for the first time on a DEX, you will first be prompted to approve spending the token before you can continue to complete the trade. This involves signing a message with your wallet that allows the DEXs smart contracts to spend your funds. 

To make the user experience a little more convenient and avoid the gas costs of repeated approvals, most DEXs will ask for permission to spend an unlimited amount of any new token, so you don’t need to repeat the process next time you trade. If the spending limit is set to only the amount you are trading, you will need to approve a new limit if you later want to trade larger amounts.

In both situations, you risk having your assets drained if the DEX or app you are using has its contracts hacked. Since those smart contracts have been given permission to spend your funds, an attacker with control over the smart contracts could send any approved tokens from your wallet to their own. With unlimited approvals, you would lose everything at once.

Token allowances can be revoked by sending a new message to the smart contract explicitly removing the allowance. This process is awkward and expensive, however, as each token revoked for each app requires a new onchain message to be signed, which costs gas.

What is Permit2?

Permit2 is a standard that allows approvals to be shared across smart contracts and provide more consistent approval experience across apps. It substitutes the EIP-20 token approval method with a smart contract, allowing Permit2 to be implemented more flexibly with more specific permissions. This enables time-based and signature-based parameters, and introduces useful features like the ability to revoke all token approvals at once, batch transfers to be sent to multiple recipients, and more.

Permit2 as implemented by Uniswap and other DEXs, consists of two parts: SignatureTransfer, which requires a one-time signature, and AllowanceTransfer, which sets parameters allowing transfers for a specific amount of time, as long as spending conditions are valid. When AllowanceTransfer is used, tokens may remain vulnerable even at rest.

Time-based approvals in Permit2

While the time-based allowances of the AllowanceTransfer contract are more secure than the previous use of unlimited token allowances - it still leaves a window of opportunity which can be exploited, as in the case of the Paraswap Permit2 exploit covered below. 

Permit2 components SignatureTransfer and AllowanceTransfer
Matcha uses only the SignatureTransfer component of Permit2.

Since the two parts of Permit2 can operate independently, it is possible to use only the SignatureTransfer contract and only allow one-time authorization for token spends, keeping funds more secure. 

One-time authorization with Permit2

Matcha on 0x v2 uses the Permit2 contract SignatureTransfer to ensure the highest level of security when funds are at rest. It does not support AllowanceTransfer, preventing time-based allowances from being exploited. 

One-time allowance prevents funds being spent after you swap!

This implementation requires a new authorization to be made for every trade. Each time you make a new swap, you will approve spending the token and then the trade itself in one quick flow. 

Other apps don’t use Permit2 in this configuration because it introduces gas inefficiencies, which Matcha can overcome through 0x’s highly-optimized smart contracts. 

Using the Permit2 contract in this way ensures you get the highest level of security and never need to actively approve a token again!

Permit2 exploits

Simply using Permit2 does not guarantee that your funds are secure. The time-based authorization used by most apps, including Uniswap, which have integrated Permit2 can still be exploited. 

This has already been demonstrated in the Paraswap hack in March 2024, where Permit2 was implemented but used time-based approvals, which meant that at the time of the exploit funds were still authorized to be spent even though they were not being actively traded. This exploit affected over 380 users and resulted in a loss of over $1.1M, though around 80% was later recovered.

One-time approvals prevent this Permit2 exploit from happening as token allowances are only authorized for the duration of a specific trade and your tokens are never authorized for spending when not actively traded.

Security made simple

Crypto security is a difficult problem to solve, as the connected world of digital assets is always open to hidden exploits. Permit2 closes the doors to a particularly nasty attack vector which puts your funds at risk simply because you used a decentralized application which could be targeted in a hack. With Permit2 one-time approvals, your funds cannot be spent without your consent even if the application smart contracts are compromised.

Proper security of crypto assets remains complicated. You should use a hardware wallet and keep your keys isolated offline, but even this seemingly robust security model is subject to the exploits which are fixed by Permit2.

Security by design, as you’ll find in Matcha on 0x v2, keeps your funds safe whenever you aren’t using them, improving the security of software and hardware wallets alike while also reducing complexity. Try Permit2 now on matcha.xyz!

Subscribe for an instantly better inbox

By submitting you're confirming that you agree with our Terms and Conditions.
Yay! You’re signed up.
Oops! Something went wrong while submitting the form.