Setting custom spend limits is a simple yet overlooked technique to protect your wallet from potential Web3 exploits.

If you've ever used apps like Uniswap, AAVE, etc, chances are that you've overlooked doing this

Quick 🧵 on what they are and how to use them properly
When interacting with services that transact with your crypto assets, you often encounter something called the "Approve" transaction step before performing the main transaction.

Here's what that transaction looks like when you interact with Uniswap Image
What the Approve transaction does is two things:

1. Allow the smart contract you're interacting with to validate how much of the token you have

2. Give permission to the smart contract to transfer/spend a certain amount of those assets on your behalf for future operations
This "approval" is a necessity for many Web3 protocols because it allows smart contracts to spend your assets in the future without needing you to do an explicit transaction at that given time

This applies to assets like ERC20 tokens and NFTs
By default the Approve transaction allows the smart contract to spend an almost infinite amount of your tokens, even if you're only wanting to transact with a small amount like 100

This is done for UX reasons as I'll explain later. However, it also opens you up to huge risks
The biggest risk is:

If the smart contract gets exploited (or if it is a straight up rug pull), you can have all of your tokens drained without realizing it
I'll illustrate this with a hypothetical scenario:

Alice has 1000 $SHIB

Alice interacts with a AMM protocol called Rugswap that lets her swap 200 $SHIB for ETH.

Before performing a swap, Rugswap asks her to perform a standard Approve transaction on her $SHIB.
Alice accepts the default spend limit and then subsequently performs a swap transaction and Rugswap sends her ETH in exchange for her 200 $SHIB
Later, due to an undiscovered security vulnerability, a hacker is able to exploit a bug in the Rugswap smart contract and get access to its token transfers functionality
The hacker proceeds to use the exploited smart contract to transfer the remaining 800 $SHIB from Alice's wallet into their own wallet

Since she used the default spend limit on the approval transaction, the hacked smart contract had permission to transfer the additional $SHIB
This could have all been prevented with a simple 1 second step: setting custom spend limits

Here's how to do it
When you are asked to perform an Approve transaction, there is an "edit permission" option where you can customize the approval settings. Image
Here you can specify an exact amount of tokens you want the smart contract to be able to spend using the "Custom Spend Limit" option. Image
Once you hit save and submit the transaction, the smart contract will ONLY be allowed to spend up to that amount.

If Alice had set her limit to 200 $SHIB, she would have been protected against the hacker transferring out any additional tokens from her wallet.
So now you might be asking, "Why is the default spend limit an insanely high number"

It comes down to two things:

User experience and gas optimization
Each time the smart contract reaches the approved spend limit for a given wallet, it must ask for a new spend limit.

This can result in a cumbersome UX of requiring an approval transaction each time you want to do the main transaction
Setting the approved spend limit to a super high number makes it so that the smart contract rarely or never has to ask for an approve transaction again for that token.
Also -- each approval transaction is an on-chain transaction, and as a result results in spending gas.

More transactions = more money wasted on gas.
With this newfound knowledge, you have to decide on some trade-offs.

Here are my recommendations
If you're operating on a L1 or L2 with low gas fees, ALWAYS set a custom spend limit.

The work to perform extra Approve transactions are insignificant compared to potentially losing your tokens.
If you're operating on mainnet, you can make a call depending what contract you're interacting with.

If it's a battle-tested platform with a good track record of security, (e.g. Uniswap, Aave, Opensea) then you're probably fine with using the default spend limit.
If it's a brand new platform or shadowy ponzi, then set a custom approval limit to give yourself some insurance.
This exploit is common and has occurred several times in the past in high profile cases.

One of the notable ones was an exploit on the Bancor protocol

If you've already approved default spend limits in the past, Etherscan has a handy tool to see what protocols have access to transfer your tokens and how many you've granted.

You can also revoke permissions as well through this tool

etherscan.io/tokenapprovalc…
Hope this little tip helps you navigate the web3 metaverse a bit more safely.

Stay safe frens.
If you found this thread helpful, feel free to share it and follow me @Montana_Wong for more content like this.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Montana Wong

Montana Wong Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Montana_Wong

18 Dec 21
Wrote up a quick follow up on strategies future NFT projects can avoid someone bypassing address minting limits.

Get ready for another 🧵
If you're out of the loop on what happened during the Adidas NFT drop (and probably others) read more here 👇

Wanted to clarify a few things to start:

- This was not a "hack" by any means. The contract developer just used a clever technique to bypass the basic address check in the minting contract.

As far as I could tell, the Adidas contract was standard compared to other contracts.
Read 21 tweets
18 Dec 21
Adidas dropped their first NFT today.

The sale was capped at a max of 2 items per person and it sold out in less than a second

One person was able to purchase 330 in a single transaction using a custom smart contract

Quick 🧵 on how they did it
Some quick context:

Adidas partnered with @BoredApeYC @gmoneyNFT and @punkscomic to release their first NFT



Due to the hype and demand, they limited the NFT sale to 2 per person.
The custom smart contract was deployed a few hours before the minting

Contract address: etherscan.io/address/0xb2d0…
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(