header-langage
简体中文
繁體中文
English
Scan to Download the APP
Partnered With:

How the NBA's hexadecimal contract loophole was exploited by scientists

Read this article in 11 Minutes
How do scientists clean up the wool?
原文标题:《 深度解析:NBA 的 16 进制合约漏洞是怎么被科学家薅秃噜皮的? 》
Do you understand the world a little better today
This article is from wechat official account:Did you understand the world a little better today


This is I have written the most wonderful, the longest, is also the most hard article, like solving a case in general for everyone to speak clearly how scientists gather wool, please complete the full text reading, I believe that you will have a great harvest!      


This morning when I got up, everyone in the group was talking about the carnival NBA brought to scientists last night. It is said that someone directly free mint 100, according to the current floor price of 0.4ETH also has a million RMB, the original is the contract and there are loopholes, so let's see what is going on.


The NBA released The Association NFT series yesterday. The Association NFT is made of 75 NFT for each of 240 players. A total of 18,000 NFT are available. The article about Gh0stlyGh0sts mentioned before is also free mint, which only needs to pay gas fee to wait for the mint to appreciate. In the visible profit space, if some contract loopholes can be found, such as bypassing the whitelist or bypassing the mint 1 limit, So whenever there is this kind of NFT project, there will be a lot of scientists looking for loopholes. The NBA has a king explosion this time, the white list restriction and mint 1 restriction are broken.



This vulnerability is also a big blow to the users who have worked so hard to whitelist. If there is no whitelist, mint can even calculate it, and mint can be infinite, resulting in the number of users who have whitelist are robbed, and even many users had to spend thousands of dollars to buy the whitelist outside the market. In mint, there were a lot of scientists, which led to a spike in gas prices, and whitelisted users were forced to pay more gas (after all, one of the purposes of whitelisting is to avoid gas war), so there were a lot of users crying for their rights and whitelisted users crying in DC.



The problem here is caused by two things:


1. Users bypass the official website and directly interact with the contract through Matemask with the hexadecimal Input Data generated by others.


2. Mint has a whitelist verification vulnerability.  


Let's start with the first one. Let's test you a little bit. What are the ways mint can interact with smart contracts?


The first thing you're going to say is, why don't you just click the mint button on the website to call mint?


This is one of the most common things that everyone on the project expects us to do. You've probably all had the experience of squatting in front of the screen and poking the Mint button to get a public sale.


In addition, experienced students will say that you can also directly open the blockchain browser such as EtherScan to find the contract address of the project party and operate the contract in read and Write Contracts. Many students snatch public sales in this way. If you click mint on the official website, the front end will trigger a request to execute the contract, and then the contract will be executed. If you directly operate the contract in EtherScan, the first step will be skipped and the contract will be executed faster. For those who are not familiar with this method, you can read my previous article how to understand the NFT project through reading EtherScan?


But met two things won't work this way, one is a project contract party didn't open it, or in the contracts interface is the project party must ask you to some parameters, such as signature, and the parameters of centralized server to generate only through a project, so you must be forced to be operated by the project party's website.


In fact, there is a third way, directly through the Matemask wallet to work with the contract.


You may be unfamiliar with this one, but you're already using it a lot without realizing it. The process of transferring money is actually the process of exchanging contracts directly with your wallet.


When I send money to an address, I hit Send first.



Then enter the receiving address and enter the amount you want to transfer.



People are very familiar with this process, it is the process of you with the interaction of the contract, because I put the money transfer this movement is transferred to an address, the address just need money, don't need to let me enter more additional information, you will ask, mint is different, at least I need several input mint, it may also include white list checking, etc., How do you enter these parameters?


We open the little Fox wallet and other Settings, go to advanced, then pull down will see there is a switch called "show hexadecimal data", turn it on.



What does this switch do? I need to clarify for you what hexadecimal data is.


Any contract that you interact with gives it some data, and the contract takes that data and processes it, and that data defines which interface function of the contract you interact with, what parameters you pass to that interface function, and so on, and that data is compressed in hexadecimal form.


You open EtherScan, click on the details, and then scroll down, and you'll see the input data at the bottom, with a long string of characters on the right. This is what the input data looks like when you interact with the function of the contract in hexadecimal format.



The key is that this long string of irregular numbers are not at all understand ah, don't worry, there are rules, although the NBA loophole does not require you to read the hexadecimal system can be directly used, but in the spirit of truth, we still want to understand the meaning here.


First we can see that the 0x is followed by a few characters, and then all zeros.



These characters represent the code of the contract function you call, and each function has its own code.


If we open the transaction record of a contract, you will see that some of the methods called are understandable words such as mint and Transfer, and some are coded with the beginning of 0X, because mint and Transfer are very standard operation functions. So EtherScan automatically translates their code into text for you, but some functions are developed by the project itself, so only the original code is displayed.



We tried out the process of interacting directly with contracts in this way on testnet. I found a previously deployed set of contracts and clicked through to the mint transaction details that had been completed.



Then drag it to the bottom and copy the input data at that time.



After entering the contract address, paste the input data I just copied and click Next.



Then it's time to pay the gas bill.



We can click on the data to see, sure enough, the function type is Mint, yes, Mint function, which means we successfully called the contract with the previous hexadecimal input data.



Then click ok to pay your gas fee and check etherScan. Success!



Well, by this point it is clear that the contract function can be executed exactly as it is using the hexadecimal data of the existing transaction.


We just talked about the reason for this problem and the second point is that the contract verification whitelist has a bug. This loophole gave scientists the opportunity to use hexadecimal methods.


The mint contract has three levels of verification, including whether to enable mint check, quantity check, and whitelist check.


BatchNumber is used to validate the mint batch, which is not what we're going to focus on today so we can skip it.


The key is the second layer whitelist check and the third layer mint check.



The second layer of verification uses a function called verify, which passes in an info parameter to verify that the current user is whitelisted. This is where the problem occurs.


In the early days of the NFT industry, many items were whitelisted one by one. Then, in mint, the current user's address was checked to see if it matched the whitelist. Every time you enter one, you have to pay a gas fee. The cost is very high. Some people around me have spent tens of thousands of dollars just to enter the whitelist.


Gradually, some people realized that this method was expensive and stupid, so they adopted a more technically difficult but gas efficient method such as The Meckel tree cryptography signature verification, the principle is that the whitelist is not stored in the on-chain contract, but stored off-chain by the project party themselves. When users on Mint use an algorithm to generate a signature based on the user's wallet address, the NBA is using encrypted signature verification.


The specific encryption principle and code implementation is too complex to talk about, first skip, interested in their own to learn elliptic encryption algorithm, Merkel tree these content. Let's first understand the principle, we just need to know that the method of verification is to input a wallet address, verify whether the address exists in the whitelist, if it does, then return a signature.


You could faintly feel there is a problem, since the check way is input address to return the result, that if I use just said hexadecimal interactive methods, I put the white list the user has to perform transactions hexadecimal data entry into, can not complete mint "white list", it's quite so fingerprint to open the door, You could cut off the fingers of someone with clearance and put them on a scanner.


The problem is that if the project side adds another layer of verification, such as the mint address and the verification whitelist address must be the same, i.e. the finger you unlock must be the same as the person who enters the door, the loophole will be closed, but the NBA is not closed.


Reviewing the code, we first get the user address for the current contract execution using msg.sender, which is passed in when mint is finally executed.



In mint, a parameter called info is passed in. The info parameter contains the address of the user.



See the problem? The official website passed the address of Mr. Zhang into info and passed it to the contract verification. Then, when the contract is executed again, the address of Mr. Zhang is obtained again and the NFT is transferred to him, but! But did not go to judge whether this zhang SAN is that zhang SAN ah! He didn't check whether the two addresses were the same.


Therefore, I could have found John's transaction record first, and then copied and pasted his hexadecimal into the wallet to execute the transaction. At this time, when checking the whitelist, I used John's address, so the check would pass, but mint used my address, because I was interacting with the contract.


Solve crimes! Fine not wonderful! I cut John's finger off and put it in the vault!


Let's take a look at what mint looks like in hexadecimal format. We can see that it mint 1 NFT successfully.



And then if we look at the hexadecimal, there are two key points, the number 1 means he mint 1, and the address below is his own address, right.



Let's take another look at a 69 NFT jerk that spread around the scientific community yesterday. Here's his address and Mint's 100 NFT.



Let's see what his hexadecimal notation is. Let's look at 45 first. What does that mean? Doesn't that represent quantity? Not one or 64, because a hexadecimal 45 turned into a hexadecimal 45 would be 69, so the juggler changed the 1 to 45 to make 69.



You wonder, isn't there a limit of 1 per person? In mint you can't hold more than 1, but in mint you can't hold more than 0, and in mint you can't hold more than 10,000.... I wonder what the contract engineer was thinking.



Then we go back to the hexadecimal data, look at the address of the contract, and you'll see that it doesn't match The address of Giant Power, which means that Giant power power hacked off his finger to unlock it, so let's see which one it is.


You go into his address and you see this kid's got a lot of money with 30 aether on his ledger, so it's not bad to get stroked off.



Then I saw that his trade record did mint an NBA last night, so it looks like He picked the lock with his hexadecimal.



This should be the most wonderful article I have ever written, like solving a case layer by layer for everyone to explain how the scientists clean the wool, is also the most tired one I have written, took a full 5 hours, writing is not easy, if useful to you trouble everyone forward diffusion.


I have emphasized many times in my previous articles that the Web3 world has a lot of space for evil because of its open source. Of course, it is debatable whether the behavior of scientists is evil or not, but as a project side, it must be responsible to protect the interests of its users. It is necessary to hold technology in awe and code review must be rigorous.


大家可以关注我的公众号《今天有更懂这个世界一点了吗 》查阅往期文章,与我进行更深度的交流探讨,也可以关注我的推特:jason_chen998  


The original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit