Crypto Podcast Goods

Deciphering Smart Contracts with Montana Wong - Genius Call 3

Episode Summary

Montana shares his insight into the functionality and security of smart contracts, how to view key performance indicators, and what to do to make sense of code. Recorded on June 8, 2022 for Crypto Packaged Goods Genius Call series.

Episode Notes

Montana Wong is the Founder at Sengage and Co-Founder of Sprise.

Connect with Montana on Twitter https://twitter.com/Montana_Wong

Follow Club CPG at https://twitter.com/CPGCLUB

To learn move about Crypto Packages Goods, visit https://www.cryptopackagedgoods.com/

Episode Transcription

Chris Cantino (CC)

All right, everybody, welcome to Genius call number three, Deciphering Smart Contracts with Montana Wong. Montana Wang is a CPG Genesis member and one of the core developers in our group. He's done all the metadata work on the Pop contract on the BF contract, on a bunch of your other favorite contracts. He's a brilliant person that we had the pleasure bringing into CPG last December during our twelve days of CPG campaign. He was noticed on Twitter for writing this really crazy thread about the Adidas drop and all the gas war madness. And I think he was just like spotted by Genesis members said, wow, we really need this brain inside the group. And ever since Montana joined, we've learned so much and you've helped us answer so many questions about smart contracts and helped us make from contracts many times and verify the safety of contracts. So Montana, you rock and super excited to get into it today.

Montana Wong (MW)

Thanks for the amazing intro, Chris. Yeah, I'm Super grateful for having been able to join the CPG community late last year and since then help grow or watch it grow. So yeah, excited to chat more. Just a quick 22nd intro. About Me I have a background in engineering. I first really Dove into crypto. Seriously. In 2017 I went to Burning Man and I met a bunch of hardcore decentralization Maxis there who were talking about building like decentralized societies and smart contracts and building a society with no government. And they told me about Ethereum and they really sold me on vision of the types of things could power. So when I came back from that I decided I need to work on this. I need to be immersed in this. At the time I was working on Amazon as a software engineer and long story short, I ended up being on the launch team of their first blockchain product over AWS, which is their cloud business. And we launched a service called Amazon Managed Blockchain in 2018 and pretty much it's an infirra alchemy competitor. It's pretty much like Blockchain infrastructure for developers. And after that I left Amazon, started my own company and since then just been working with creators and brands mostly. And earlier last year I started a company with my co founder who I think he's in this call sprize and we're product studio and Web Three agency and we have been partnering with creators and brands to help launch Web Three projects. We most recently worked with BFF on their launch. And so yeah, just right now full time working in Web Three and just love watching how this whole space is growing. I really started building the last bear market and so just seeing how things have shifted so much since then has been awesome and I'm really excited for the next decade. Really. I feel like the crypto space is a really good point where we have the right level of mainstream adoption, but we're still all early enough to really find all of our roles within the ecosystem. Cool. So should I just continue going? Yeah. Okay. So I'll just keep going. Okay. Yeah. So let's get started. So the key outcomes that I want all of you to sort of get out of this, I knew that there was going to be a lot of people who aren't developers in this call, and that's good. And so I wanted to cater this to general audience of people who are somewhat familiar with web three have maybe have metamass wallet, have maybe minted NFPs before. And so the key outcomes I want of this call is to one like learn the basics of how smart contracts work. Transactions work, how to read and verify a contract before interacting with it. And you're not going to leave us with being able to decipher like the unit swap contract or anything, but just being able to really identify the key parts of a contract and getting a gist of sort of what it's doing, and being able to learn how to know how to deep dive more if you want to on a certain contract. And then finally we'll end up with identifying common red flags and malicious contracts. This will really help you just understand how most of these scams work and how to prevent yourself from getting hit by them. The call is going to be broken up into these main parts. I'll try to stick to the timelines. I don't know how good they'll be, but we'll start with just some basics about the smart contracts. I'll walk through a couple of contracts, we have a little hands on demo midway through, and then we're going to end it with looking at the red flags and Q and A if there's time. So one on one smart contract transactions. So smart contract transactions are transactions that trigger code that are stored on the blockchain. And when this code is called, it actually runs something, right? It could be running like an entity Mint, or it could run a coin slop. And these transactions, they either fully pass or fully fail. It's not like in web two, where something can execute halfway and then fail with the way that blockchains are designed, like a transaction either fully passes or fully failed. So if you're trying to Mint two NFPs, let's say that there's only one remaining left to Mint, but you try to Mint two. Well, it's not the case where you would just Mint one and the other one would fail. Your whole transaction would fail because it needs to either fully succeed or fully fail. And the best web to analogy I think of how to think about smart contracts transactions are Http requests, and that's a bit technical, but developers who are not really understand that analogy. And I had a really basic diagram that I found online on some Media article that really helps sort of paint a picture of the analogies between web two and web three when it comes to the tech layers and where smart contracts sort of fit into like a web two model. And so essentially, if you take a look at this diagram and I don't know if you can see my mouse, but when it comes to a traditional web three application that you're interacting with, the way sort of like the layers start with the user and their wallet, which is attached to the browser, and they interact with the front end, like a website usually, or a mobile app. And that front end is able to connect with smart contracts through node providers, which are nodes that are running the blockchain. And most of them are managed now through services like Kira and Alchemy. So the user is able to perform transactions through the wallet that use a note provider to actually talk to a smart contract. So when you actually submit a transaction to the network, your metamass prepares the transaction, you hit accept it gets sent in from the front end through the node provider to the smart contract where it's actually run. And obviously the smart contracts live on the blockchain. So as you're thinking about if you're a builder, creative, or you're more on the community management marketing side, looking here at the stacks, this will help you understand sort of like what layers of the stack you lead into familiarize with as you find your own Web three. Like, if you're a product designer, you spend a lot of your time thinking about the web. Sorry, the wallet and front end experience. If you're developer, you'll probably spend a lot of time depending on if you're a back end or front end Dev, focusing on the smart contract layer. If you're an artist, you probably will think mostly about the blockchain layer, because I think when it comes to creating art, I think we're finding that the choice of blockchain really is part of the messaging nowadays with what blockchain artists decide to go with. And if you're a core develop, you're probably only working on the blockchain side, improving the blockchain. We know that the next evolution of Ethereum is coming out soon. So the core devs are working on improving the core blockchain code. So yeah, that's just a quick overview of what a smart contract transaction is. Just think about as a special type of Ethereum transaction that triggers code that's stored in the blockchain. And so let's look at a really basic structure of a really basic smart contract. This is a contract that just stores a number called count, and that number can either go up or down based on people interacting with the contract. And so this is written in a language called Solidity, which is the most popular programming language for Ethereum. There are multiple, but Solidity is just the most used and the very top. Usually there's like a code license, a significant part of the code that you'll see sort of deployed official Enter MIT license, which means open source. Do whatever you want with it. You can't sue the author if you use their code and build something else with it. That hurts people. Under that you see the version of Solidity. So think about every programming languages have versions just like apps, they get upgraded over time. For example, the NFT ERC 721 standard wasn't around when the first version of Solidity was out. So over time the language evolves to support more use cases. And so you always have the contract name next to the word contract. And that helps you just identify what the contract is doing or who it belongs to, usually underneath the contract line. This is where all the contract storage variables are declared. And those are just places where information will be stored on the contract or on the blockchain through the contract. And so in this case we only have one variable. It's called count. And you'll see the word you Int. That means unsigned integer, which just means a positive number, a positive whole number. And so it just means that the number count will be from zero to a very large number, potentially. Under that we have our functions. Our first section is Read functions. And these are pieces of code that allow you to read information on the blockchain. It doesn't require a gas transaction to do because you're not modifying blockchain state when you need to modify the state of the blockchain, there is no gaps required to do that. You can just sort of do it for free. And so this function get, all it does is return the current value of count. And underneath that we have write functions, which are these are functions that when you execute the transaction to the Smart contract, it actually updates the state of the blockchain and will require gas to do that. And so the way that when you ever do a transaction and you spend gas, that's because each line of code that you have to run in order to each line of code in that function that you're calling that consumes a certain amount of gas. And so the amount of gas that you spend is a factor of how much code you're running with your transaction. And also like what you set your gas price to be. So in this case, there's only two functions. There's increment, which increases that number by one and then decrement, which decreases the number by one. And so if I call get at any point, it'll be whatever value of count is at a certain time. So this is a really basic contract. Just to get you the idea of sort of the components of one, let's look at something a little more complicated that might also be more familiar. Here. I have the Doodles contract, so there's a lot more information here. I'll walk through it really slowly, but essentially it's an NFC contract. And this is a contract that manages sort of the Doodle entities. And also you can Mint it was used to Mint the entities from as well. And just a quick Disclaimer, the technology. The optimizations that happened in this case happened really fast. When you look at the Doodles contract now sort of came out probably, let's say like six months ago or so. I think now developers now would consider this to be a pretty unoptimized, naive contract. A lot of optimizations have happened since then, including the Zucchi standard. But that being said, it's a really straightforward, simple and clean contract. So I thought it was a really good example to use. So you can see on the top using slightly older version of Solidity, there's this thing called the other contract didn't have it, but there's these import statements, and you can think about imports as importing other smart contracts that you can reuse in your code. It's a simple way of allowing developers to reuse code that's already written so you don't have to reinvent the wheel. And it's importing a couple of contracts that belong that are from the Open Zeppelin Group, which is an open source. It's a set of open source contracts that have been audited heavily and most major projects used from them. So if you see if people are importing contracts, Open Zeppelin, just know that those are super safe. Those have been super audited. And so a slight difference in this contract is you'll see this thing here. So next to Contract Doodles, there's this is ERC 721, ERC 721 innumerable and Ownable. This is called inheritance. It's a programming concept. I won't get too into it, but essentially it allows the contract that I write to inherit sort of all the functions, all the storage variables of those other contracts. So this Doodles contract is inheriting like the ESC 721 contract. And that contract is a standard of entities. So that contains sort of all the internal storage and functions that are required to power like an ERC seven to an NFC token on the blockchain. So when you see an anti contract, it will always say it will always inherit from ERC 721 or something like ERC 721 A, which is sort of an improved version of ERC 721. These two other sorry, these two other ones are not as important to know right now, but they're just enhancements to make the contract a little easier. And so going through the storage variables, most of them will be very straightforward. Providence is just string in. Programming is just a collection of numbers and letters, and so you can use it to store like names, addresses, et cetera. Providence. It's just a way to verify that the metadata is not tampered with sales active. So Boolean is just a true or false value. And so it can either be true or false. It's really good to use for logic statements. So you can see that Doodle team had one had a field called Stored. Sale is active. And so it's used to turn on the Mint or to have it so you can't Mint until that variable is changed to true crisis related to metadata. They have another boolean variable around activating the Allow list. And then you can see some number of values as Max supply, which has 10,000 Max per public Mint. That's how many you can Mint per transaction in the public Mint. And then they have the price per token defined here. These are things you can go usually they're posted on the discords or on the website. So you can actually go to the contract directly and look at these and verify for yourself what these values are. And then they have this field called allow list, which is storing something called mapping and a mapping. You can think about a dictionary, and in this dictionary, instead of words and definitions, you have Ethereum addresses that point to how many they're allowed to Mint on the allow list. So the way they built it is like if you look at their address, you can get back the number of how many they're allowed to Mint. So in this case I think everyone was allowed to Mint too. I can't really remember. And so let's go through their Mint allowance function. It's not that long, it's like five lines. And you'll find that most Mint functions that happen on Ethereum, they're mostly just like logic checks to make sure that you're allowed to Mint. And then the actual Mint code, which is usually pretty small. So in this case, let's kind of just walk through this slowly so you can see that this function is called Mint allow list. So here there's a variable called Number of tokens. And so when you see these parentheses after the name of the function, those are inputs that you provide into the function and those inputs are changeable. So for example, Number of tokens is something that you pass into the function. Usually their front end would handle this for you. But if you're missing from Contract, which will do later, you can actually modify this yourself. So you're passing in the number of Tokens variable. Let's say it's two. And then external means that the function is meant to be called by user outside of the contract. And then Payable means that you can send e to the contract through this function. Most Mint functions unless the Fremant will have a Payable field. And so quickly going through the conditions here. So the first line of the function says you went TS equals total supply. Total Supply is another function that's defined elsewhere in the contract. And so within a contract a function can call another function. And so Total Supply just returns like how many have been minted so far. And so the function is just grabbing that number and then it's doing a series of checks. The first check is when you see a require statement that just means hey, if this following condition isn't true then failed the transaction. So a lot of times when you're minting, let's say you're minting and it's about to sell out, your transaction will fail. And it's usually failing because of one of the required statements in the mid function. And so in this case, the first condition said is Allow us active. And so remember that's a boolean. So if it's true, then it is active, then the code will continue to the next step. If it's off, then the code will fail at that point and your transaction will fail. So the next line says require that the number of tokens is less than or equal to and then it's calling allow list message sender which it's using message sender which is equals. Like it's how you look up a user's Ethereum address whoever's calling the function. So checking in that dictionary and saying how many items on the how many can they knit on the allow list? This report function checking is the number of tokens less than or equal to two. And so if the number is two, if the number of tokens is two, then it will pass on to the next line of the code. Otherwise it'll fill there. The next line says Es plus number of tokens is less than or equal to Max supply. And so remember that T s they set TS to what the total supply is right now, let's say that only two of them minted. And so two plus two is less than or equal to $10,000. So it would continue. But let's say that 9999 have been minted. Well, two plus 9999 is 10,001, so that would obviously be greater than that supply. So that would fail there. And finally, the last check is just making sure that you've sent enough money to the contract as part of your transaction call. And so in this case within solidity Aetherium transaction is referenced to as a message. It's kind of confusing, but message dot value that equals like how much Aetherium is sent as part of the transaction. And so not all transactions on Ethereum need to contain. They don't all need to send Eve, but in this case this one does. And so if you're not sending enough Eve, then it will fail the transaction. If you send the right amount of Eve, or if you send more Eve, they'll accept it. You can definitely send more Eve than you need to. They would happily take that. And the final part of the function is really straightforward. There's this little bit of line of code here that's referencing the allowance. It's just updating the allowance to subtract how many tokens you've purchased. And so that way you can't Mint again because it will show that you've already minted your Loyalist. And then these last three lines here with the four, that's something called a for loop in programming. That's just a way of allowing a certain lines of code to be run over and over again until the condition has failed where it's not no longer met. In this case, it's saying as long as just simplify, like the number of tokens is equal to two. So we're going to run this piece of code twice, and this piece of code inside the for loop is safe Mint. And that's an ESC 721 function that just updates that actually meant the token to someone's address. I know that's a lot, but hopefully that sort of gets you into an understanding of how to go and walk through a Mint function like that. I know there's a lot of programming concepts that probably if you're not a developer, they don't make sense yet. But with looking at smart metric codes, you can always Google. What does this do for loop? What does that mean? You can always go as deep as you want, but at least this should give you like a service level idea of how most of these functions work.

CC

Yeah, that's super helpful. It's like some of this stuff is. It just seems like it's so straightforward when you actually understand what it's doing, requiring just making sure it's on the list. But then it's just sort of like abstracted by these, like the code, the formatting of the code and the parentheses and the underscores and the kind of like just a little code words once you start understanding what the requirements and all that what it means when it's importing from opens up. That is so helpful.

MW

Thank you. Sure. So I'm going to kind of fast forward through this slide. But essentially so they had a public Mint function which is just called Mint. It has a bunch less required checks. It doesn't check that you're an allow list, it just lets you Mint, essentially. I really wanted to point out this one thing. So when you look through most contracts, most of these Mint functions, they'll call safe Mint or they'll call a function that's defined somewhere else. And that's really just to keep the code clean. Like you don't want to have a function that has like 50 or hundred lines of code. It's hard to read and hard to maintain. When this sort of function is calling the statement in this for loop, it's actually calling lines of code that are defined somewhere else. And it's calling underscore statement, which is actually part of the, ERC, some journey, one library that opens up Len. And then this is actually calling another function called underscore Mint. And this is actually where the true logic of Minting happens. And so when you think about minting an NFC, the best way to think about it is when you have an NFC contract. It itself has think about it in a really simple way. Like the NFC contract is a smart contract that has some storage. Right, that uses to maintain some state on the blockchain. And so you can think about it. It has like an Excel file, all the owners of the Holden token are written on that sort of file. And then whenever you miss one, it adds that person's address to that file. This person now has a token, and this is the token ID they hold. And when you buy and sell it, it also updates. Or when you transfer it, it says, okay, this person no longer has one. This new person has one. So when you're actually minting one, you're actually updating this internal ledger of who holds how many tokens and which tokens they hold. And so this Mint function here is actually doing that with these lines of code right here. It's updating how many someone's holding. And it's updating this owner's dictionary of like who's holding what token. What it's doing is actually quite simple. And you'll find that most of the tokens that are sort of built on a theory Mark the underlying technology or the underlying logic is actually really simple and straightforward, but it's like wrapped in all these other constructs that are very complicated. So why don't we do something a little more hands on? I actually have something prepared. I'll drop this link in the chat, but essentially I put together and launch a really basic NFP contract to do like a quick walk through of how to actually meant from a contract on either Scan and kind of how to get a sense of what Ether Scan is showing you and how that relates to what's on the contract. So I'm going to drop a link in the chat. Feel free to follow along if you want. You don't have to. It's a free Mint, so nobody gets any money from this. And Stewart, who is the artist behind the Pop Collection, Graciously, offered a piece of art for this as well. So you can have a nice little collectible if you meant it. So if you're following along, that link will take you directly to this right contract tab. And if you can't see if I need to increase the text size, let me know. But essentially I think most of you will probably be familiar with what this is. But essentially it's a block Explorer, allows you to kind of see the balances of certain addresses on Ethereum. It lets you see transactions that are pending that you've done, how much money someone has. It also lets you look at smart contracts and the transactions that have happened on the smart contract. And depending on who created the contract, they can actually upload the code. So it's readable on Ether Scan. So that's optional. Like some developers don't upload the code, but most developers will do it just as a form of gaining trust with the community. And so here you can see that there's a really simple NFD contract. This one is an ERC 721 A, which is the Azuki standard. So it's an optimized version of ERC 721 opens up one contract. And here we have a Mint function. This is a mid function where we can actually go and Mint. There's a check to make sure that you hold a pop so you can only Mint it if you're holding a pop in that wallet. And so one thing about mining from ether scan is when you have a contract you have like read and write functions, you can actually go and see what those are here in a simplified view on this tab. So if you hit contract and you go to read contract, you can see all the read functions. And so I can go and look at I can actually go. And like I mentioned, read functions don't cost any gaps. If I hit the total supply, it will say three. I mentioned three to test earlier. So there's three. You can see how many the maximums per wallet which is one. And then the functions that have that you can pass information to. You can actually pass information. So I'll pass in this address it'll say zero. I haven't been standing to this wallet yet. Similarly on the right contract side. So let me actually disconnect because just to show you guys how to do this okay. So to actually Mint from contract on either scan, you'll go to the right contract tab, you'll hit connect to web three. It'll ask you to connect either scan, you hit accept and then you have to hit it again for some reason. And then once you're connected it will have a green dot here. And like I mentioned, the functions that are on the contract directly are visible here. So I can go and look at the Mint function here. I can read through the code, make sure it's doing what I think it's supposed to do. I can go over to write, I can hit Mint. And since it's a payable function, it'll always ask you how much either you want to send. You can just hit zero if there's any other there's no other inputs on this one. But a lot of other Mint functions will have like how many do you want to Mint, things like that. So in this case I'm just going to put zero. I'll hit right? I don't think I have enough gas actually. So what I'll do is this wall doesn't have a pop so actually won't succeed. But anyone who's yeah, it looks like some people have already minted cool minted for like $10. Yeah, it's like super cheap so you can see that people are minting it. And so if you essentially execute transaction it would finish here and then you could go and track it and you can go and check and open see and you'll have it in your wallet. But essentially this is exactly what you're doing when you're using a midsite, you're doing the same thing. The front end is creating a transaction to talk to a certain function on a smart contract store somewhere. And then it's going to prompt metamass to get you to approve it. And so this is just like a really technical way of doing that. Obviously having a website and Mint button is more user friendly. But end of the day you can go as like a more savvy user and just go directly into the contract and call the function on it directly. So you can see here, let's just look at pick on this person. You can see that here in either state. You can see the method they called earlier. I toggled the minting. So I set that field to be true. I did some admin to test it out and then this is just like a contract appointment. So it's like a jump of mess. We can actually go and track and see what people are calling on a contract. In case you're curious about interacting with the contract, you can see what other people have done and you can actually look into the transaction and you can just see what actually happened. So this person called out, they called Mint. This is how much gas they spent. So they spent $10 on gas and they transferred 721 tokens to their wallet. So no address. When you mention NFC, it always says it's sent from null address. And yeah, that's pretty much how you meant from a contract. I'll show you a little bit more about how you can incorporate this into your web three flows because it's not always easy to know where is the contract? What's the address of the contract on this website? What function? So I'll go through sort of like an example of how to actually go from Min's website to line of code that you should be looking at next in this demo. So I actually have an example here. This is like an example Djen agreement. Those are really popular right now and it's kind of hard to find because most of these have minted out. So this is one that hasn't minted out. If I'm just trying to get a free Mint and I don't want to get wrecked, one thing I can do is when I go to the site when I hit Mint. So when I hit Mint, Met Amass actually shows you a couple of pieces of information that's actually really important for you to actually look at and sort of dyo or do your own research on before you actually hit the confirm button. Because once you hit confirm, it's unlikely that you can. There's no going back unless you were able to cancel it really fast. So what you see here is you're seeing my wallet interacting with this contract at some address and it's calling the Mint function here. Mms is going to show you what function on the contract am I about to interact with and what is the address of that function? And so I can actually click here on the address and hit View on Block Explorer. And I do this for every contract I interact with other than very established platforms like Uniswap or Openc. Is it opening? Okay, so now you can see that I'm on either scan and I'm looking at the contract that I'm about to interact with. And so it's called Djen. Orgs. Cool. It checks out with what's on the site. I can see who created the contract. I can look at the developer's address, see if they have any transactions in Tornado. There's obviously, like red flags you can always look for to actually go and see what line of code I'm actually going to interact with. I'll hit contract, I'll look at the code and I'm going to search for where they actually define the code. So here it is. You search up Djen. Orgs, you can see that it's near 721, so it's not nearly 721 A, so it's not going to be gas optimized. So here I actually want to go and look at the Mint function, because that's what I'm going to call. So I'll go scroll until I find it. So here function Mint. So I can actually go and look through the function. It looks pretty straightforward. There's a couple of require statements that makes sense. There's a condition to know whether or not the Mint is free. And then there's a for loop of statement. So I know that. Okay, this Mint function looks safe. Like whether or not the project is a rug, I don't know. But at least I know I won't get my NFC stolen by minting it. I know it'll be free. So this is what I always do. And I recommend people do before they meant something that's free or like from a shadowy group. You just want to go and double check, kind of just eyeball the code, make sure there's nothing weird there, and cover the contract, check out developers address and all those things I always check and see, make sure that there's other transactions happening to it. You can see that other people are calling Mint. There's people who are pending calling them right now as we speak. And you can see and you can actually click in these transactions, see that people are mentally and you can see that there's token IDs being sent to their wallet. So, you know, okay, this seems to be doing what we think it is. And then after you verify something, you can always go back in and finish them in. And so this kind of brings us into the next final phase of this call is when it comes to sort of browsing web three, there's a lot of easy ways to slip up or do something where you don't expect it. You're cooking to doing something that you don't expect, and it can cause a bunch of financial harm to you. You can lose your tokens. You can lose your entities. You can straight up get your wallet hacked by losing your seat phrase or revealing your seat for my goal here is just to kind of go over the most common ones right now and just kind of give you a very sort of high level sense of how to avoid these and how to spot them. So I think before even going through all these red flags, the best thing you can do is just have a dedicated wallet or an address account in MetaMask that's used to do everything. That's not to do anything that's new. So like Minting, an NFP, connecting, connecting to a new website, claiming an air drop, et cetera. That's the easiest way because most of these scams target you by getting you to connect a wallet and do a transaction on your main wallet that contains money or valuable items. And then from there they just can train you. If your primary wallet for exploration is something that holds very little value, then you can avoid sort of almost all of these issues. That being said, let's go through all these just so you know, you have a game plan and a framework for browsing. The first thing that I was checked for, interacting with something special like that's prompting me to do a transaction is actually verifying. Is the contract actually even verified on Ether Scan? So like I mentioned earlier, many developers, especially in the energy space, will verify the code. So you can actually read it on Ether Scan. But by default, when you upload code to the blockchain, it's not readable. So when you actually write Solidity code, when you write smart contracts and Solidity as a developer, before you actually upload it to the blockchain, you run it through a program called a compiler, which converts it into code that machines can read. So Solidity is code that humans can read, but machines can't read solidity. So developers feed Solidity into a program that outputs something called bytecode, which is what machines can read. And this is what it looks like. So this is actually what it gets uploaded onto the blockchain. Bunch of numbers and letters which we can't we don't know what that does. Right. Here's a contract that developers uploaded. They didn't verify it. So as a normal user, I have no idea what's going on. So if I call the Mint function on this, it might actually meant me and Nancy. It might not. I don't know. Right. So if I go and see a contract that doesn't verify, most likely I'm not going to interact unless it's like a Solid team. And they have a valid reason why they don't. Let's say it's a new start up and they raise a bunch of money and they want to have protect their it. There's some that do that. Most of the time I just straight up will walk away if I see this. There's a project only here that did that. And so that's step one, check and see if the contract is verified and you just click contract. If you see machine code, you just stop. So secondly, when you actually go and I'm trying to make something you want to actually check the contract address in multiple places. So let's go back to Djorks. So if I want a minute, I want to make sure this is the right Djorks site, not like Djenorx, IO or XYZ. It's very easy to get tricked into going to a fake Mint link. So what I would do is I'm going to go and take the contract address and actually search a multiplex search and open C, make sure, hey, is this like the right contract? And so you can type the contract address directly in Openc and it'll show up the collection and you'd be like, okay, this will show up as the valid collection openSee. It might be verified here, I can check. Okay, this is the right one. It has the right number of owners items you can check. Usually they post the smart contract link on Discord, on Twitter, so you can always verify against there. But yeah, you always check the contract link and the contract address in multiple places just to verify. Okay, this is the right. This is the right one. And so number three, when a transaction prompt is asking to set proof for all. So this is the exploit that gets people to boost their million dollar aches, million dollar punks, et cetera. It's very hard to spot. It's very easy to fall prey to because it's very difficult to understand unless you speak out to understand this concept. But essentially, the way that Ethereum tokens are designed, whether EFC 20 or 21 FPS, is they're designed in a way that allows you to grant permission to another address. And the address could be someone's wallet or smart contract allows you to grant that other person's address permission to control your entities. And the reason why that's built into technology is to allow things like marketplaces to exist. For example, you might recognize this from selling an open fee, but whenever you sell an open fee before you actually list it, it'll say set approval to open C to sell the collection for you. And so when you actually do that transaction, that's what it's doing. It's granting the approval to open Sea to actually manage your NFP. The way that works is you grant open C approval to manage your entity. And so that way later on, when you're doing your own business or you're enjoying your life, like if somebody wants to buy your entity, when they perform the transaction to buy your entity, open Ce can fulfill that order by taking an AP out of your wallet and putting into the wallet of the buyer. And so in order to actually have that happen where you don't even need to be present, you can be on a beach somewhere and that NFP leaves your wallet, you have to grant Openc sort of authority over that NFC. In this case, we can trust Openc more or less like their contracts are audited, battle tested haven't been hacked at a big scale yet, as far as I know. So most people are okay with granting that approval, but you can grant the approval to anyone. And so these hackers that exploit from people, they actually exploit this feature of Netflix. Let's just go through an example of what that really means. So I have these fake entities that I made on the test. Net. So there's like a test blockchain that developers use the test on before they actually deploy stuff to the main. Net. And since we don't want to spend gas testing on mainnet, they created a test network where you can use free money to test stuff. So I have this entity called fake pop, and I hold four of them. And what I'm going to show you is how I can be tricked into signing. Like, I can be tricked into thinking I'm minting something, but I'm actually approving a hacker to actually take control of my at seas. And it's very hard to spot this. But if you know how to, then it almost becomes, like, second nature to always check for this when you're minting. Yeah. So on this test version open fee, I have this thing called fake pop. I own token number one. It's owned by me right now. So there's a tool called revoke cash. I'm going to show you guys how to use this. But essentially this tool allows you to see who you've granted this approval to. So in this case, you can see that I have four fake pops and I have not granted anyone access or anyone the ability to actually manage it for me. But if I go and run this on my main met wallet, you would see I granted a bunch of approvals to open C, and you should definitely check and see who you've granted approval to on your own hot wallet later and remove it for any that you don't recognize. So I have this entity called fake pop token ID one. So let's say that let me actually pull up. Yeah, here it is. So here's the contract for fake pop on ether scan. Whenever you connect your wallet to a website, specifically scammers website, what they're doing is once you click connect wallet, they get your all address. At that point, they can't do anything. But what they can do is they have an algorithm that they use that they take your contract, they take your wallet address, and they calculate what the most expensive thing in your wallet is, whether it's an ape, moon, bird, a pop, et cetera. And then from that point on, their goal is to get you to lose that item. And so what they'll do is you think you're minting eight air drop or whatever it is, and you have a certain amount of time to mintate. Like it's minting out, you have to Mint and down. So it drives a lot of FOMO. Some people usually just click, click, and they approve and they don't understand what they're doing. But what they actually do is they find out what the most expensive thing in your wallet is, and then they create a transaction for you that actually gets you to approve them to manage it. So what they actually end up doing is they get you to approve send the Set approval for all. And so here, plug in a couple of values. You can see that with operator. So that's the address that's able to manage entities for you. Like, I'm putting in like the Scammers Wallet, and then I'm sending approved to true. So think about it like this. I'm like ready to Mint this thing. Like, let's say the disk the hackers put like a fake link. I'm here, I want to hit Mint. So I hit Mint. Instead of actually pulling up a Mint function, a Mint transaction, it'll actually pull up something like this where it's actually trying to get me to Set approval for. All right, so you always want to check before you hit Mint. Is it saying Set approval for all? Because right now I think as a user who has a bunch of FOMO, I think I'm about to Mint this NFT secret AirDrop from Fort Ape. I'm probably not going to look at any of this, but as a smart web, three users you're like, okay, what am I actually doing? So it's saying Set approved for all. And the address here, it says Scammers Wallet because I have it stored on my meta math, but it would say like an address and the address would be just camera's wallet. So you want to say, okay, if you see Saturproof roll, you instantly stop and say, okay, it's trying to get me to grant control of my entities to someone else I'm going to reject here. But just for the sake of the demo, let's hit it. Confirm what I just did. Just to recap. I thought I was missing something. The scammers identified the most expensive thing in my wallet, which is a fake pop. And so they created a transaction for me to approve, which gives this address access to control them. And so let's just see if it's completed. So it's completed. So at this point in time, I still have this NFP my wallet. It's still here, owned by you. But now the scammers can actually move it out. So what I'll do is I'm going to sign into a different wallet called Scammer's Wallet. I'm going to reconnect to this. So this is exactly what they do, except they have like scripts to do it much faster so they can feel it before you even realize it's gone. I'm doing this manually just to show you what's going on. Sometimes if the scan does this work, take a second to once usually works great. But on the test network, it's always like super slow refresh a few times. Let's try a different browser or different tab. Here we go. I'm going to connect the scammers wallet to Ether scan. And so now as a scammer who has control over this portal's, NFT I can actually call this function called Safe transfer from this is the function that actually is used to move entities from different wallets. And so when you're transferring your entity to your other wallets or your ledger, you're actually internally calling you're actually calling this function on the contract when open fees helping you sell or buy entities, it's calling Safe Transfer to move the entity from your wallet to the buyer's wallet. Me as a hacker who's now been granted access to yours. So let me actually just show you this real quick. So if I look at this now, you'll see that on the revoke, it says I have given unlimited allowance to this address now, which means that this address is able to freely manage all of my popnste, which is bad if you see something like this, hit revoke immediately. But I won't for the sake of this example. So now I'm going to go and actually transfer entity from the unknowing users address to my address. And then Token B was one. Let me grab that first real quick. So here you can see that I'm literally saying take that entity, give it to me. I'm going to hit submit, confirm, and then let's do it. Now the scammer can actually go and do this for all the entities in that wallet. So there was four. I can do it for all four, but in this case I'm just showing it for one. And this is what they do. So once you granted approvals, usually like a few minutes later, you'll start to see everything slowly trained out of the wallet and you won't even know like done. So you see that Bam. And if he was transferred from good guy wallet to bad guy wallet here on Open C, you can see now it's owned by you. So let me actually sign back into the good guy. So as a good guy, this is what you'll see. It's owned by the bad guy. And it used to be owned by me 40 seconds ago. It was taken out, made the username bad guy.

CC

I love it.

MW

Yeah. But yeah, I mean, the good guy has no idea that it happened. You thought you minted like other side land or whatever and you ended up not getting anything and your entities are getting stolen and you're freaking out. You don't know how to stop it because at this point they have free control. And yeah, the best thing you can do at this point is just hit revoke the permission. So that way they can no longer go and take anything out. But usually once they have permission, they have scripts to just take it out as fast as possible. So once you get to that point, you're a bit too late. Yes, that is how most of these scams work, you think you're hitting Mint, you're actually calling set approval for all and then after that it's over. So you can see how if you're using a burner wallet, if you hit set approve ball, it's not going to do anything because you don't have those entities in your wallet to actually get approval for. Right. So that's why you always want to use a burner wallet or these like, Djen things. Yeah, that's it. That was brilliant.

CC

I can't believe you went through so much setting up all the different accounts and contracts to actually show how somebody would be compromised on the back end, not just like say because you could have just said, hey, if you see set approval, just don't do that. But we got to actually see how a scammer would actually do that and then interact with the contract to drain your wallet and then we got to see on reboot cash how we could get those perms out to keep people safe. So that was very cool, Montana.