Hyperinflation Vulnerability - Reading Assignment

1. How was the bug discovered?
By an alert from an automated system to scan and analyze Ethereum-based (ERC-20) token transfers. This has system been has been developed while analyzing ERC-20 tokens from EOS. The blockchain security company PeckShield Inc. then studied the contract code of the related BEC token and found the vulnerability.

2. What is this vulnerability called?
The blockchain security company PeckShield Inc. called this this particular vulnerability “batchOverflow”.

3. Which function is vulnerable?
The vulnerability has been found in the function batchTransfer().

4. Why was the vulnerability present in several ERC20 tokens?
The code has been copied from other ERC20 tokens.

5. Why is “code is law” mentality problematic when it comes to fixing bugs?
There is no traditional well-known security response mechanism in place to remedy these vulnerable contracts.

6. How did exchanges react to this vulnerability?
The exchange OKEx made an announcement to suspend the withdrawal and trading of BeautyChain (BEC), a batchOverflow-affected token. But it could have been possible for attackers laundering their tokens via non-centralized exchanges with offline trading services.

  1. How was the bug discovered?
    The bug was discovered by a 3rd party system which scanned ERC20 token transactions which sent out alerts when a suspicious transaction occurred.

  2. What is this vulnerability called?
    batchOverFlow

  3. Which function is vulnerable?
    batchTransfer

  4. Why was the vulnerability present in several ERC20 tokens?
    Because the same code was being used across those tokens.

  5. Why is “code is law” mentality problematic when it comes to fixing bugs?
    Because there is no standard security response mechanism to fix the vulnerable contracts.

  6. How did exchanges react to this vulnerability?
    OKEx suspended trading of the BEC token which was affected.

1 Like
  1. How was the bug discovered?
    By detecting suspicious transactions (huge transactions) for particular tokens.

  2. What is this vulnerability called?
    batch overflow.

  3. Which function is vulnerable?
    batchTransfer

  4. Why was the vulnerability present in several ERC20 tokens?
    Because the other tokens copied the functionnality.

  5. Why is “code is law” mentality problematic when it comes to fixing bugs?
    Because if there is a vulnerability in the code it is not possible to fix it.

  6. How did exchanges react to this vulnerability?
    They blocked/delisted the affected tokens.

1 Like

1. How was the bug discovered?
Due to an alert from a suspicious transaction monitoring system developed by a blockchain security company

2. What is this vulnerability called?
batchOverflow

3. Which function is vulnerable?
batchTransfer

4. Why was the vulnerability present in several ERC20 tokens?
Yes, more than a dozen since they where based on the same code

5. Why is “code is law” mentality problematic when it comes to fixing bugs?
Because the code can not be changed (immutability). This does not allow bugs to be fixed.

6. How did exchanges react to this vulnerability?
OKex has suspended trading and withdrawal of the affected BEC token. Non centralized and offline exchanges still would have been possible to use to launder affected tokens.

1 Like

1. How was the bug discovered?
Alert was triggered by monitoring system developed by blockchain security company.

2. What is this vulnerability called?
batchOverflow

3. Which function is vulnerable?
batchTransfer

4. Why was the vulnerability present in several ERC20 tokens?
Yes, as result of copy-past.

5. Why is “code is law” mentality problematic when it comes to fixing bugs?
Immutability makes it hard to update deployed smart contracts (unless it’s developed to be upgradable)

6. How did exchanges react to this vulnerability?
Affected tokens/cryptocurrencies were EVENTUALLY suspended/delisted.

1 Like
  1. It was discovered by an automated scan & analyse system on transfers from ERC20 tokens smart contracts.
  2. It’s called a BatchOverflow bug.
  3. The batchTransfert function is vulnerable.
  4. Because of the copy-paste flu.
  5. Because you can’t upgrade a smart contract when it’s immutable or “not build to be up-gradable”.
  6. They fortunately froze trading and withdrawals.

Thank you.

1 Like

1. How was the bug discovered?

An alert function fired when large amount has been transferred.

2. What is this vulnerability called?

batchOverflow

3. Which function is vulnerable?

batchTransfer

4. Why was the vulnerability present in several ERC20 tokens?

They’ve copied same ERC20 token functionality.

5. Why is “code is law” mentality problematic when it comes to fixing bugs?

Because of the immutability of the already deployed contract.

6. How did exchanges react to this vulnerability?

Paused trading and stopped withdrawals

1 Like

1. How was the bug discovered?
PeckShield developed an automated system to scan and analyze Ethereum-based (ERC-20) token transfers which sent an alert for a suspicious transaction.
2. What is this vulnerability called?
batchOverflow
3. Which function is vulnerable?
batchTransfer()
4. Why was the vulnerability present in several ERC20 tokens?
People copied the same functionality.
5. Why is “code is law” mentality problematic when it comes to fixing bugs?
You cannot fix an immutable contract.
6. How did exchanges react to this vulnerability?
Suspend withdrawals and trading

1 Like
  1. How was the bug discovered?

The system was configured to send, automatically, out alerts of any suspicious transactions (e.g., involving unreasonably large tokens).

  1. What is this vulnerability called?

The particular vulnerability was called batchOverflow. Which is categorized as an integer overflow attack. An integer overflow attack occurs when an arithmetic operation attempts to create a numeric value that is outside of the range that can be represented with a given number of digits – either higher than the maximum or lower than the minimum representable value. An overflow/underflow condition may give results leading to unintended behavior. In particular, if the possibility has not been anticipated, overflow/underflow can compromise a program’s reliability and security.

  1. Which function is vulnerable?

The batchTransfer. Below we can see the code:

The vulnerable function is located in batchTransfer and the code is shown in Figure above. As indicated in line 257, the amount local variable is calculated as the product of cnt and _value .

  1. The variable cnt counts the number if the receivers (declared as an array of addresses)
  2. The variable _value accepts the amount to be transferred as a user input (declared as 256 bits integer)
  3. The variable _value was overflowed with zeros and got zeroed out.
  4. When the variable _value is zeroed out the require checks got bypassed.

The code (line 258):

require(_value >0 && balances[msg.sender] <=0);

The actual value checks became: 0>0 && balances <=0

The code (line 261):

require(balances[msg.sender] = balances[msg.sender].sub(amount));

The actual value checks became: attacker balance = attacker balance - 0 = attacker balance

Above we can see the logic of the attacker and how he by passed the checks. What is interesting how the require check behaved when validating the 0 > 0 mathematical operation.

  1. Why was the vulnerability present in several ERC20 tokens?

Because is not an easy and obvious code error to see. Also all ERC20 tokens have to implement certain functions in order to comply with the standard. More specifically the ERC20 standard, forces tokens to standardize set of commands to communicate with the range of tokens they manage. This includes interaction rules between different tokens, as well as token purchase rules. Put simply, the ERC20 standard defines a set of functions to be implemented by all ERC20 tokens so as to allow integration with other contracts, wallets, or marketplaces.

The subset of functions is rather short and basic, but demonstrates the type of functions, that have to be included in all ERC20 tokens:

function totalSupply() public view returns (uint256);
function balanceOf(address tokenOwner) public view returns (uint);
function allowance(address tokenOwner, address spender)
public view returns (uint);
function transfer(address to, uint tokens) public returns (bool);
function approve(address spender, uint tokens)  public returns (bool);
function transferFrom(address from, address to, uint tokens) public returns (bool);

Note: Above we can see that all ERC20 tokens have to implement the transfer function. We can conclude from that the batchTransfer function was created as part of the ERC20 mentality.

  1. Why is “code is law” mentality problematic when it comes to fixing bugs?

The code is law principle is the principle that no one has the right to censor the execution of code on the ETC blockchain. This principle mandates that every digital asset is governed by code. The security, usefulness, availability, transferability, and general malleability of any digital asset are all determined through the code by which it is created and stored. In this way, code is law, and the rule of law controls the asset. And therefore there is no traditional well-known security response mechanism in place to remedy these vulnerable contracts. This principle is essentially the immutability of the contract.

  1. How did exchanges react to this vulnerability?

Due to lack of coordination between CEX’s and DEX’s no immediate response took place. This results into hacking attacks taking place for a long period of time, even when the hack does not go unnoticed.

3 Likes

1.How was the bug discovered?

  • As a huge transaction appeared on Etherscan, PeckShield Inc. system raised an alarm.
    2. What is this vulnerability called?
  • batchOverflow bug.
    3. Which function is vulnerable?
  • batchTransfer()
    4. Why was the vulnerability present in several ERC20 tokens?
  • It was present in the ERC20 contract that ERC20 tokens inherited.
    5. Why is “code is law” mentality problematic when it comes to fixing bugs?
  • If we consider that code is consensus, it means that all parties involved accept the procedures defined in the code, with all the features and bugs.
  • Where do we draw a line between a feature and a bug?
    6. How did exchanges react to this vulnerability?
  • OKEx suspended trading and withdrawal.
  • Decentralized exchanges cannot be stopped that way.
1 Like
  1. How was the bug discovered?
    automated system raised an alarm which is related to an unusual token transaction. There was two such large token transfers, with each transfer involving the same amount of tokens from the same BeautyChain contract but to two different addresses.

  2. What is this vulnerability called?
    batchOverflow

  3. Which function is vulnerable?
    batchTransfer

  4. Why was the vulnerability present in several ERC20 tokens?
    Because is was using the same codebase,

  5. Why is “code is law” mentality problematic when it comes to fixing bugs?
    there is no traditional well-known security response mechanism in place to remedy these vulnerable contracts

  6. How did exchanges react to this vulnerability?
    OKEx suspended withdraws, other exchanges were informed, but this need time to be coordinated

1 Like

Hi All, :grinning:

1. How was the bug discovered?

The vulnerability was discovered by a security research company called PeckShield. The systems automatically detected 2 transactions where the amount was ridiculously large. The transaction was detected with a coin called BEC.

2. What is this vulnerability called?

The vulnerability is called batchOverflow, which is a classic integer overflow issue.

3. Which function is vulnerable?

It affects a function called batchTransfer(), whose purpose is to send _value tokens to a number of recipients.

  • The variable used to credit the recipients was the _value passed as parameter to the function batchTransfer().
  • The variable used to debit the sender was the amount calculated by multiplying _value by the number of recipients. Variable amount was also used within a require() statement to check the sender had enough balance.
  • Because amount is a uint256 it was possible to set it to zero by setting _value to a specific number.
  • With amount = 0, the balance check within the require() statement always succeeded and the sender was not debited.
  • However the recipients were still credited with the ridiculous number passed in _value variable.

4. Why was the vulnerability present in several ERC20 tokens?
The code was part of code samples used to help implement the ERC20 standard. Therefore other coins were potentially affected.

5. Why is “code is law” mentality problematic when it comes to fixing bugs?

The “code is law” idea was popular around the time of the first versions of Ethereum (2015 and early 2016). It implies that once code is deployed on a blockchain, it should remain immutable. Allowing contracts to be upgraded after they are deployed would defeat the decentralisation and immutability principles. The code is the contract, even if it contains bugs.

During the DAO hack mid 2016, the idea of “code is law” lead to a division in the Ethereum community and ETH branched out into Ethereum Classic.

We could imagine that in a distant future (20, 30 years from now), when Dapp platforms have become stable and ubiquitous, then “code is law” will be the norm, even though it sounds a bit dystopian.

6. How did exchanges react to this vulnerability?

Some exchanges (OKEx) suspended trading and withdrawal of BEC.

2 Likes
  1. Peckshield has developed an automated system that scans and analyses ERC-20 token transfers. It can detect suspicious transactions involving an unreasonably large number of tokens, especially if it exceeds the token supply. If such a transaction takes place, the system is automatically alerted. In 2018, Peckshield detected a suspicious transaction that occurred on the BeautyChain smart contract. It involved a transfer of an astronomically large number of BEC tokens caused by an integer overflow.

  2. The vulnerability is known as batchOverflow. When a value greater than the possible number of bytes that can be stored in a variable is assigned, it causes an integer overflow making it zero.

  3. The function named batchTransfer had contained the batchOverflow vulnerability.

  4. To tokenize a smart contract, it has to follow a technical standard that will allow it to operate on the Ethereum blockchain. This standard is known as ERC20, which defines a list of rules the token must follow. If there is a vulnerability in the ERC20 code (e.g. batchTransfer), tokens that follow this standard will have the same problem.

  5. The “code is law” mentality prevents developers from making changes to the smart contract after deployment. It can become problematic if the smart contract contains vulnerabilities because any data stored on the blockchain remains immutable.

  6. One of the exchanges called OKEx announced to suspend the trading of BeautyChain tokens because it contained the batchOverflow vulnerability.

1 Like
  • How was the bug discovered?
    • PeckShield’s transaction monitoring system flagged an unusual BEC token transaction that transferred an extremely large amount
  • What is this vulnerability called?
    • BatchOverflow
  • Which function is vulnerable?
    • BatchTransfer()
  • Why was the vulnerability present in several ERC20 tokens?
    • This is because ERC20 is a standard and ERC20 tokens use similar if not the same code. If other ERC20 tokens implemented the batchTransfer function using the same code, they would be subject to the same vulnerability
  • Why is “code is law” mentality problematic when it comes to fixing bugs?
    • Because the blockchain is immutable, there is not a clear channel to fix contracts with vulnerabilities
  • How did exchanges react to this vulnerability?
    • OKEx made an announcement to suspend trading and withdrawal of affected tokens
1 Like
  1. The bug was discovered following an unusual ERC20 tokens transfer detected by an automated scan system.

  2. The vulnerability is called a batchOverflow

  3. The batchTransfer function is vulnerable

  4. The ERC20 token is a template used by several contracts.

  5. The downside of the “code is law” mentality is that we don’t have a customer service to contact in case of a problem.

  6. The exchanges reacted by suspending transaction of the BEC token.

1 Like
  1. How was the bug discovered?
    Third-party independent security team was running automated system to scan and analyse Ethereum-based (ERC-20) token transfers to identify and alert if any suspicious transactions occur. This system raised alarm about particular transaction, where someone transferred an extremely large amount of BEC token and security team found the bug in the code that was exploited.
  2. What is this vulnerability called?
    This vulnerability is called batchOverflow.
  3. Which function is vulnerable?
    The vulnerable function was batchTransfer function with _value parameter.
  4. Why was the vulnerability present in several ERC20 tokens?
    More than a dozen of ERC20 contracts were also vulnerable to batchOverflow because they reused same open source code.
  5. Why is “code is law” mentality problematic when it comes to fixing bugs?
    “Code-is-law” principle in Ethereum blockchain is problematic because there is no traditional well-known security response mechanism in place to remedy vulnerable contracts but instead it relies on cooperation between independent security teams, exchanges and community.
  6. How did exchanges react to this vulnerability?
    OKEx immediately suspended the withdrawal and trading of batchOverflow-affected tokens and other exchanges coordinated delisting of tokens vulnerable to batchOverflow afterwards.
1 Like
  1. A security firm with a transaction tracking bot picked up 2 extremely large token transfers from the BEC contract. Diving into the contract they discovered the vulnerability in the code.
  2. batchOverflow was the name.
  3. The batch transfer function was exploited by using a uint256 so large that it overflowed the upper bounds and the code stored it as a zero value but was instead an extremely large amount.
  4. It is common practice to recycle code and use it on your own project.
  5. When vulnerabilities arise the question becomes who’s responsible for what. Is the person or group who found it responsible for making it known to the contract owner, public, or are they free to do with the information as they please.
  6. Okex stopped trading on the assets and some other CEXs followed suit but the vulnerabile token was left trading on many platforms.
1 Like

How was the bug discovered?
Ans: The PeckShield Inc system noticed that an unusual BEC token transaction and particular transaction, someone transferred an extremely large amount of BEC token.

What is this vulnerability called?
Ans: This vulnerability is called batchOverflow.

Which function is vulnerable?
Ans. The vulnerble function is located in batchTransfer.

Why was the vulnerability present in several ERC20 tokens?
Ans. Becuase more than a dozen smart contract were copied or similar code to implemented in their ERC20 tokens.

Why is “code is law” mentality problematic when it comes to fixing bugs?
Ans. The“code-is-law” principle in Ethereum blockchain, there is no traditional well-known security response mechanism in place to remedy these vulnerabilities and problematic.

How did exchanges react to this vulnerability?
Ans. The other exchanges are not in the position to react by suspending the trading of vulnerable tokens.

1 Like
  1. How was the bug discovered?
    An alarm was raised due to unusually large number of tokens were transacted.
  2. What is this vulnerability called?
    Batch overflow.
  3. Which function is vulnerable?
    ERC20 token had bachTransfer(address[] _receivers uint250 _value)
  4. Why was the vulnerability present in several ERC20 tokens?
    The same ERC20 token code was used in different token codes
  5. Why is “code is law” mentality problematic when it comes to fixing bugs?
    Since we code can not be changed on blockchain there is not a typical responce of correction possible.
  6. How did exchanges react to this vulnerability?
    the OKEx made an announcement to suspend the withdrawal and trading of BeautyChain (BEC), a batchOverflow-affected token
1 Like
  1. it was caught by an automated system that scans the Ethereum blockchain for suspicious (too big for example) transactions
  2. batchOverflow
  3. batchTransfer
  4. because the contract used uint256 as input which has an upper-limit of 256bytes. When someone entered a number which when multiplied by the number of recipients resulted in a number bigger than 256bytes, the system understood it as 0, therefore the functions below (sanity checks) passed and the subtraction (line 261) made irrelevant. Then, finally the actual amount that the attacker entered as value (which in itself, before the multiplication is smaller than 256bytes) was successfully sent to the recipients.
  5. because they couldn’t just update the code and fix it as soon as it happened (immutability of the blockchain)
  6. some of them stopped trading and withdrawing of the vulnerable coins
1 Like