You don't understand ERC20

EthCC[8] · 30 Jun 2025 · 18:42

Duncancmt examines unusual ERC-20 tokens that comply with the standard while violating developers’ expectations. The presentation discusses how applications should handle those behaviors correctly.

Speakers

Topics

From EthCC[8], hosted by Ethereum France.

Transcript

Ah, okay. We do have slides. Hi, I'm Duncan from Xerox and I'm here to pill you on why ERC20 as such a vague and broad standard is actually a good thing. And if you are a token developer, all of the cool stuff that you can do with it and if you're a DeFi protocol developer, all of the things that you need to be aware that tokens might do that you didn't expect. Ah, that's the button. Okay. Uh, first a few disclaimers. I don't know I don't own any of the tokens we're discussing except for the token I'm going to airdrop you at the end and um ZRX. Sorry I didn't put that on this slide, but I do own some ZRX.

If I roast a token here, it's not because I don't like it. And if I don't roast your your token here, I'm sorry. If you follow my recommendations without doing your own research, you will get wrecked. So, please don't do that. There's way more stuff than I can cover in 20 minutes. We're going to go really fast, but there's more to read. I stole almost all of this from somebody else. And there is an airdrop at the end, or if you don't get it, come see me at the booth after. What is ERC20? Well, everybody knows ERC20 is the token standard, right? Okay. Well, it's the EVM token standard, and it's also an EVM token standard.

There are token standards for fungeible tokens that aren't ERC20 and it's really more of an interface than a standard. There is a standard. People don't really follow it. And it's only for funible tokens, right? Well, okay. It's also an ABI. It's maybe not just a standard. It's also got some events in it. And it's also for semifable tokens because people have managed to shove some like NFT functionality into ERC20. So, uh, we'll get into that. That's exciting. Fundamentally, ERC20 is for exchange of tokenized value. You want to tokenize something of value or of negative value. We'll talk about that, too. ERC20 is how you do it.

What does ERC20 do, though? We talk about what it is. What does it do? ERC20 tokenizes. It tokenizes really just about anything you could imagine. Cash, equities bonds commodities yield debt, voting rights. It is your entry to tokenized communities. You know, ERC20 can represent membership in a particular community via those voting rights. It also allows people to provide liquidity, right? ERC20 is the token standard that lets you LP, that lets you swap, that lets you fundamentally transfer risk. That's what adding liquidity is. That's what being an LP is. And ERC20 is the rails for DeFi. Without ERC20, DeFi doesn't work because you don't have interoperability. You don't have

composability. you don't have rehypothecation. And if you're not sure what those words are, hang out with me and I'll explain to you why those are important things and why you should build on ERC20. ERC20 does everything you want it to do. You might think that, oh, you all you can do is build tokens. You can send them around. That's not that interesting. No, you're wrong. ERC20 can do anything you want it to do. That's ERC20. Six functions, three views, two events. Noticeably, there's no name, symbol, or decimals. Those are optional. This is all you need to define in order to be an ERC20 token. It's quite simple. There also is a standard that goes with it.

There's things that it's supposed to do and things that it's not supposed to do. And nobody reads it, but I'm going to read it to you. All of the mutative functions return booleans. You have to treat falses like revert. Transfer and transfer from must emit the transfer event. An amount of zero is always successful. Emitting approval is optional unless you call approve and approve is not the only way to make transfer from work. Calling approve has a frontr running vulnerability and too many people try to get clever and fix that. Don't. It makes my life hard. Please don't do it. And lastly, this should have been in the standard but isn't is you should have some reasonable assumptions about how tokens move around. But what do people actually do? I write tokens without

reading the standards. They might return bool. They might return nothing. You got to handle that. You might get more than one transfer event. An amount of zero might revert. It might might also return might not emit anything. Approving zero is supposed to work but might not. Approve uh transfer also might increase the balance of the recipient by no more than the amount. And we're going to get into this. This is transfer tax tokens. The tokens that you know and love aren't actually implementing ERC20 correctly. You know USDT? USDT all does all of these weird things that you need to be aware of if you're a DeFi developer. But really, that first one is the important one because that's against the standard.

Likewise, XAT has all of these weird behaviors that I'm not going to go too deep into. But again, that first one against the standard and also really bad because if you try to use safe ERC20 with this, it just doesn't work, which is why this token isn't used anymore. But it's a token that people did and it's a token that you should be aware of. Likewise, BNB, the token, not the chain, the token on Ethereum, has all of these weird behaviors, most of which are not technically against the standard, but a few of them are. So, really, you should be aware that all of these famous tokens, including LDO, have all of these weird behaviors, and if you don't handle them correctly, you're going to get wrecked.

But far from uh you know criticizing all of these other tokens, I did my own token that violates the standard as much as possible while still being technically interoperable. It's got lots and lots and lots of dumb features. Uh it's unreasonable in many many many ways. Uh it's got lots of user hostile features. Please check it out on my GitHub. And uh this is the token I'm going to airdrop to you. So uh good luck selling it. Now, as far as the creative things that people have done with ERC20, ERC20 really just says when you call transfer or transfer from, it moves some value and when you call approve, it turns on transfer from. That's basically it.

That's all that's required. And if you implement that, you are an ERC20 and you can do all of these weird and wonderful things beyond that. And that's what makes ERC20 so cool. And I'm going to give you some examples of cool things that people have done with ERC20 within this framework. Let's talk about tax tokens. Tax tokens are probably the most common form of weird and custom ERC20 token. If you call transfer from or transfer equivalently, the sender's balance goes down by the specified amount. Okay, that makes sense. Pretty reasonable. Most tokens do that. But then the recipient's balance goes up by slightly less. The difference, of course, is the tax.

And okay, I can't go back one. Sorry. Um, the difference is the tax. And so if you are a DeFi developer building a protocol that depends on that, it's going to break. And if you're a token developer, that tax is how you make money. You take a little bit of extra on every transfer and that provides you revenue or it, you know, goes back to the community treasury or all sorts of cool different ways that people take that tax and make use of it. Rebase tokens. This is things like staked ETH rather than having the value of the token go up over time, the balance of your account goes up over time. And so just by holding that token, your balance slowly increases. It's also sometimes used for like loss socialization. If it's like a

reinsurance protocol, right? You can all of a sudden take a little bit of token from everybody's account to cover some kind of protocol loss. So don't always depend that rebases are positive. Negative rebases are also possible. You also have reflection tokens. Reflection tokens, frankly, are one of the weirdest ones on this list. They're like a combination of the previous two. The senders, when you do a transfer, the sender's balance goes down by slightly less than the specified amount, and the recipient's balance goes up by slightly more than the amount minus the tax.

And the difference goes back to every other token holder. So, you're constantly rebasing and you're constantly taxing. These tokens used to be extremely popular but have fallen off somewhat in later days. For example, Safeoon. Um, if you're a token developer, this could be a really cool way to provide yield to your users and revenue to the protocol. And if you're a DeFi developer, uh, this is going to destroy your protocol. So, make sure you think about this when you're trying to handle it. Swap during transfer tokens is another way that transfer tax tokens provide yield to developers or I should say revenue to developers. If you try to do something like this where you're selling your token, right? First the token

transfers the tax to the pool. Then it swaps the tax for ETH and withdraws it and sends it to the developer and then it sends the rest. So in other words, every single time you transfer that token, the token front runs you. And if you're trying to sell the token, you're going to get a slightly worse price every time. And so again, if you're a DeFi developer, particularly if you're building a DEX aggregator or a DEX, you need to be aware of this because every time you try to transfer that token, every time you try to sell that token, you get a weird and different price.

Dion 404. This is one of my favorites. It's a hybrid of an ERC20 and an ERC 721. It's a self fractionalizing NFT, right? NFT fractionalization used to be really big, right? What if I can't afford a Crypto Punk? Well, maybe I buy a tenth of a Crypto Punk or a 100th of a Crypto Punk, right? This is a way for NFT projects to self-fractionalize their NFTs. And the way it works is that it treats a transfer as an NFT transfer if the amount is small and a ERC20 transfer if the amount is large. Right? We're depending here on the fact that you know 10 to the decimals is a huge number whereas an NFT ID is likely a very small number assuming you allocate them starting with zero.

So, for example, if I tried to do this, you know, let's say I own NFT number 42, it's going to transfer NFT number 42, which is going to make my balance go down by two to the decimals, which presumably is a much larger number than 42, and the recipient's balance is going to go up by that same amount. So, if you try to transfer dust, you might end up transferring way more than you'd expect. Huge, huge opportunity for confusion and bugs here. Just absolutely enormous. I love DN 404. I think it's cool. I think it's complicated, but also you're going to get wrecked.

Block list tokens are a little bit more tame compared to the ones we just discussed. When you do a transfer, whether or not that transfer succeeds depends on more than do you just have enough balance. It might depend on whether you're blacklisted, whether the person you're sending to is blacklisted, whether you're in cool down or vesting, whether the there is a bulk transfer limit, or whether the recipient would go over the whale limit. Complicated. For the most part, though, DeFi developers don't need to think about this, but token developers should because this can align incentives between participants and can make sure that no one participant ends up with too much ownership of the protocol.

Debt tokens. I mentioned negative value ERC20 tokens. D tokens, debt tokens are a great example of that. A D token is something you don't want. It's negative money. It's bad to have it. And the way D tokens work is the allowance logic is backwards. You have to set an allowance to receive the token. Anyone can send the token to anyone else, but only if the recipient has set an allowance. the this these were only really used in the first version of Oiler. Second version uses a slightly different version, but uh keep in mind that this negative value tokens is a thing you can build.

There are some token extension standards that you should be aware of as a token developer or as a DAP developer. I'm not going to go super deep into these. ERC 1046 lets you add uh metadata, images, mine types, all that sort of stuff to your token. Uh ERC 2612 improves the approve flow. It makes it gasless. All sorts of cool stuff are unlocked there. You can build metatransactions. Uh ERC 5805 gives you voting with delegation. So if you want to build a DA, if you want to build a token or if you want to build a community around your token, this is what you should be building. And ERC 7674 improves the user experience.

Particularly now that we have the Prague hard fork around that approve transfer from flow. It only really works on uh Cancun or greater chains and only if the wallet supports 5792. Please take a picture of this. Look up all these ERC's later. I know I went really fast. I unfortunately only have 20 minutes with all of you guys. I'm going to do a couple more. I'm going to do them even faster. So, keep those phones out. More extension standards. These are people's attempts to avoid, you know, oh, I sent my tokens to the wrong address and now my tokens are lost forever. Um, none of these have super wide adoption, but the last one you should pay attention to because ERC777 tokens will wreck you. They are re-entry

city and there have been a number of lending protocol hacks as a result of ERC777 or similar tokens. Okay, so we talked about tokens, we talked about non-standard tokens, we talked about token extensions. What should you not do as a token developer or as a DeFi developer? First of all, don't do this. Some tokens might have more than one address. And so if your, you know, for example, your token zero has two addresses, well, I just pass the second address into this function and then I rug you. So don't do this.

Re-entry. We just talked about ERC 777 and ERC 223. uh don't assume that calling transfer on a token just does a transfer. You might end up with arbitrary external calls. You might end up with re-entrancey. Treat it like transferring ETH. You know, the control flow is leaving your context. Um always use a non-reentrant modifier if you need it. Think about external calls, follow checks, effects, interactions. Get an audit. Yeah, we just talked about these. Swap during transfer is another good example. Um total supply might be enormous. A lot of people make assumptions that, oh, you know, multiplying a token balance by another token balance isn't going to overflow. Wrong. It might.

For the most part, you can sort of safely assume that a token balance won't go over 2 to the 112. Um, because that's the limit for unis swap v2 and everybody wants to be compatible with unis swap v2. But there are real tokens with real value that are, you know, top 200 by market cap tokens that get very, very close to that. For example, SHIB has a total supply of nearly two to 110. Uh, and likewise, um, the token that I'm going to airdrop you, very evil amount caps. Some tokens don't like big numbers. So, if you try to set an allowance that's too high, it might revert. Or if you uh end up with a bal well, you can't really end up with a balance that's too high, but uh you need

to be aware that some tokens do have caps on the allowances that you can set. So if you're setting an allowance that's just below the maximum value for some reason doesn't work, you're going to get reverts. To sum up, ERC20 is super super flexible. That flexibility is a superpower and it lets people build custom communities. It lets people build really fullfeatured tokens, but it does mean that DeFi developers need to program defensively around those tokens. I hope I've given you some ideas about the tokens that you can build to align incentives in your communities, provide revenue to those communities, manage your treasury, uh distribute risk, all those sorts of stuff. You can do anything with ERC20.

If you think hard about how to do that, you can do it. And also test with my token because if you handle my token correctly, he probably handles everything. Please connect with us. This is our link tree. Please scan the QR code. Come say hi to our booth. And the next slide gonna give you an airdrop. That's the token address. The next slide has a seed phrase which if you want the tokens you just have to sweep that address. Good luck.

The password for this seed phrase is detonate viral all lowercase with a space in between. Best of luck. I know it's going to be a mad rush. Please don't send ETH. Somebody will steal your ETH. And uh if you didn't get the airdrop, uh come by the booth, say hi to me, and I'll give you the airdrop. Anyways, booth number 29, days three and four. Thank you all very much. I think we have three minutes for questions. Any question for Duncan?

just in case. Okay. Uh 1155 is great. I think it's a little bit big of a standard. My only cons my only criticism of 1155 is it doesn't have the composability and um broad ecosystem support that ERC20 does have. It's a good standard. One question. Um, the most evil part of my token is that um, two accounts with the same amount of value will have different balances um, because the balances scale

randomly. But, you know, check out my GitHub. There's all sorts of evil user hostile features of that token. Consumes a random amount of gas on every transfer. Any other questions? Yes. Uh, it uses um pre randow, so it's as random as it can be on the blockchain. All right. Thank you very much for your time, for coming to my talk, and uh I hope somebody swept that address. If not, I'm going to go do it myself. Yeah.