Unlimited ERC20 allowances considered harmful

ETHCC 4 · July 2021 · 15:59

Rosco Kalis explains how unlimited ERC-20 allowances expose users’ funds to additional smart-contract risks. He discusses developer choices that limit allowances and the value of revoking permissions for dapps a user no longer needs.

Speakers

Topics

From ETHCC 4, hosted by Ethereum France.

Transcript

we need to wait uh okay it's okay all right um i'll stand here so hello everyone uh welcome to unlimited erc 20 allowances considered harmful um a little bit about myself i am a software engineer and i am currently doing contracting work for two companies called general protocols and truffle and besides that i work on a lot of different side projects mainly in the ethereum developer tooling space including truffle assertions and truffle plugin verify and most relevant to the talk today

i created revoke.cache which is a dashboard that shows all your eoc20 allowances um so a bit of an overview what we're going to talk about today um first of all we're going to discuss what erc20 allowances are why unlimited allowances can be dangerous uh also going to look at some real world case studies and some possible mitigations to the problems so in the basics what is on elc 20 allowance so let's say we have this die smart contract and alice wants to

allow bob to take some of their die then what ls can do is approve bob or send an approval transaction to the die contract that allows bob to take alice's money then bob can send the transaction to the die contract saying they want to transfer the die from alice to bob and because he allows the setup it happens so in this sort of use case you're probably wondering you know that is just seems like a very convoluted way to transfer money um but it gets a lot more interesting when it's not alice and bob but it is users

of different smart contracts so for example if you're using ave and you want to deposit die into the other contract then you will have to send an approval transaction that allows the ave contract to take dye out of your address and into the ave smart contract and similarly if you want to make a swap on unit swap you also have to allow uniswap to take your die so that they can take it out of your account and send it to the receiver or to the pool um [Music] and probably everyone who has used d5 application in the past has seen this before where

before making a swap on units well for example you have to press this button that says uh allow the unit cell protocol to use your tokens and it gives you a metamask pop-up that looks something like this uh where it says that you're allowing them to spend your tokens and if you click through you might even be able to set a custom limit there so uh this probably seems obvious to some people but there's also a lot of people that don't understand all the the risks involved there but if you're allowing someone or some contract to spend all of your money then you're allowing them to spend all of your money so that means if you're doing that to a

contract that maybe has a bug and that bug gets exploited then they cannot only take the money that you deposited into the smart contract but also the money that you didn't deposit and you have safely in your uh own wallet so where in the case for example of unit swap if you're just swapping like you never actually deposit any money but you do give them an allowance um so there have been a few different cases of this happening in the past with uh some serious consequences um one was the the bancor hack in 2020 where a new version of banker was

released where a function was made public by accident which allowed anyone to call the function which then transferred money from some of the users of bancor to wherever they wanted it to send in this case uh the the funds were all white had hacked so it didn't have any um no funds were lost which is good but last february we also saw for combo got hacked and what happened there is that a new contract was added to the list of allowed contracts for fur combo which pretended to be a next version of ave

but it wasn't it was actually just some some hacker and um by gaining access to the um or by being added to the fur combo list of of supported uh contracts they were not only able to steal a lot of funds from the fur combo contracts but also from a lot of users from their wallets so these are some established some established projects that actually got these or got exploited in this way but there are also some more malicious applications that are just set out to scam users such as

during d5 summer of 2020 of course there were a lot of different shady projects that would allow you to farm like food themed tokens and also one of them was unicats which allows you to deposit your uni tokens and then farm meow tokens um well yeah so that turned out to be a scam and not only uh did they take the uni that was deposited but also the uni that wasn't deposited so if you think if people would think that you know they're only depositing a small part of what they have to be safe but then it turned out that you know they weren't that safe um so another question that gets asked a

lot about this is hardware wallets you know um if i have a hardware wallet i should be protected you know nobody can get to my private key but the thing with these kinds of exploits is that no one needs to get to your private key because you're specifically telling the smart contract that they're allowed to take it from you so even if you have a hardware wallet in this case that won't do anything so what are some mitigations that we can do as developers or as users so let's go over the developer side first um one thing that can be very effective to help protect your users against these

kinds of exploits is either not um not requesting for an unlimited allowance but instead asking for uh just the amount of allowance that is needed for the current transaction but what you run into then is that it's kind of a trade-off because that way you have to make two transactions every time a user wants to interact with your protocol uh which has like a worse ux than if you had just set an unlimited allowance once and allow users to just send the one transaction when they want to do it so what i'm a fan of is giving your users the choice whether they want to do an unlimited allowance or just enough for the for the current

transaction for example there's a screenshot from a curve which do that and there are some other projects that also implement a similar technique another option is using eip2612 permits which allows you to sign a structured message rather than send a transaction to set your allowance and um if that's available then that is definitely the way to go but the problem with this is that a lot of older erc20 tokens don't have this functionality so you actually can't use this this permit functionality but

fortunately a lot of newer tokens do implement that such as um like the uh like liquidity provider tokens from things like union swap v2 or or a quick swap or any of those forks um and i don't have a slide for this but i saw adrian crubra's talk yesterday where he proposed a having a singleton contract that sort of proxies older erc20 contracts and basically adds that permit functionality uh where the user would have to put an unlimited transaction to this one central contract once and then after

that other um other defy apps could request permission or like could use the this permit signing functionality um with the central contract which i think could be an interesting solution there for older contracts as well so uh from the user side what can we do um first of all as a user you should probably be aware whether you want to set an unlimited or limited transaction or allowance for the app that you're using so if you're using an established protocol with non-upgradable contracts that has been running for a long time um

you're probably fine or if you're using it a lot uh a lot then you're probably fine with uh an unlimited allowance so for example something like unit swap you're probably fine uh something like unicats you're probably not so definitely figure out where that line is for yourself and if the uh the app itself has an option to to choose between unlimited or limited then you can use that but if not it's also possible to set a custom limit yourself in the meta mask ui so when you get this pop-up about allowances and you click this edit here it actually tells you okay i want to have unlimited

uh or a limited spend request was requested um but you can set a custom spend limit so you know if you want to set it to a thousand die instead of a million then that could also be an option there um the other thing is that you should probably uh think about the allowances that you already have standing out and maybe periodically re-evaluate those so this is revoked.cache which is a dashboard that i built that basically just gives you an overview of all your erc20 tokens and all the allowances that you gave for those erc20 tokens so as you can see i actually have

a lot of allowances standing out mainly for testing purposes but um and and it gives you that overview and it also gives you the option to um to revoke them from that dashboard or to set them to a lower amount if you're not comfortable with an unlimited allowance but you are with a lower amount um so yeah that's the presentation that's what we can do uh as a as developers and as users these are some links for further reading um the slides to this presentation are also online at um my website carles.me yeah are there any questions

hey roscoe thanks for the presentation um so uh you know as you said this is something as developers and as users who are sitting here uh can do today uh but uh if we if we plan on sort of on boarding the the the wide mainstream audience we cannot possibly expect them to be sort of managing this uh you know this we cannot expect them to think about like hey am i going to be using this app often and stuff like that what is the number that i should input here um obviously you've been contributing to the space you've been following the space in this particular region do you see an improvement in thinking

like hey you know eventually we want to onboard the mainstream users how are we going to improve everything to for you know to suit their needs yeah so i would definitely say there's a lot more awareness around this than when i created the first version of revoked.cache which was in 2019 back then most people were actually not really aware of it but after having these hacks that we saw for example for combo last year i think there's a lot more awareness around the issue um and i do think that people are trying to improve on it there are newer standards uh like erc 777 or uh like the

the the two six one two permit um which which are solutions to the problem somehow somewhat um but the reality is also that we currently still do have all these older erc20 tokens that don't that that have this uh this issue um there are some proposals for example like the um the thing the the contract i mentioned from adrian cruba who um uh which would add permit pyramid functionality to older uh erc20 tokens and there are also things like meta transactions uh with eip3074

um that would probably also that would also solve this problem um so the question is if those are going to be implemented uh in a relatively short time span um but i would definitely say there are people working on improving the way it is right now like yourself thank you very much all right if there's no further questions then thank you all for your attention you