Cointime

Download App
iOS & Android

What Are Common Bridge Security Vulnerabilities?

This article is a community submission. The author is Minzhi He, an auditor at CertiK.

Views in this article are of the contributor/author and do not necessarily reflect those of Binance Academy.

TL;DR

Blockchain bridges are critical in achieving interoperability in the blockchain space. Hence, bridge security is of paramount importance. Some common bridge security vulnerabilities include weak on-chain and off-chain validation, improper handling of native tokens, and misconfigurations. Testing the bridge against all possible attack vectors is recommended to ensure sound verification logic.

Introduction

A blockchain bridge is a protocol connecting two blockchains to allow interactions between them. If you own bitcoin but want to participate in DeFi activity on the Ethereum network, a blockchain bridge enables you to do so without selling your bitcoin.

Blockchain bridges are fundamental to achieving interoperability within the blockchain space. They function using various on-chain and off-chain validations and therefore have different security vulnerabilities.

Why Is Bridge Security Critical?

A bridge usually holds the token a user wants to transfer from one chain to another. Often deployed as smart contracts, bridges hold a significant amount of tokens as the cross-chain transfers accumulate, making them lucrative targets for hackers.

In addition, blockchain bridges have a large attack surface as they involve many components. With that in mind, malicious actors are highly motivated to target cross-chain applications to drain large sums of funds.

Bridge attacks led to losses of over 1.3 billion USD in 2022, accounting for 36% of the year’s total losses, according to CertiK’s estimates.

Common Bridge Security Vulnerabilities

To enhance the security of bridges, it’s valuable to understand common bridge security vulnerabilities and test the bridges for them before launch. These vulnerabilities can be categorized into the following four areas.

Weak on-chain validation

For simple bridges, especially those designed for specific DApps, on-chain validation is kept to a minimum. These bridges rely on a centralized backend to execute basic operations like minting, burning, and token transfers while all verifications are performed off-chain.

In contrast, other types of bridges use smart contracts to validate messages and perform verifications on-chain. In this scenario, when a user deposits funds into a chain, the smart contract generates a signed message and returns the signature in the transaction. This signature serves as proof of the deposit and is used to verify the user's withdrawal request on the other chain. This process should be able to prevent various security attacks, including replay attacks and forged deposit records.

However, if there is a vulnerability during the on-chain validation process, the attacker can cause severe damage. For example, if a bridge uses Merkle tree to validate the transaction record, an attacker can generate forged proofs. This means they can bypass proof validation and mint new tokens to their account if the validation process is vulnerable.

Certain bridges implement the concept of “wrapped tokens.” For instance, when a user transfers DAI from Ethereum to BNB Chain, their DAI is taken from the Ethereum contract, and an equivalent amount of wrapped DAI is issued on the BNB Chain.

However, if this transaction isn’t properly validated, an attacker could deploy a malicious contract to route the wrapped tokens from the bridge to an incorrect address by manipulating the function.

The attackers also need victims to approve the bridge contract to transfer tokens using the function “transferFrom” to drain assets from the bridge contract.

Unfortunately, this is made worse because many bridges request infinite token approval from DApp users. This is a common practice that lowers gas fees but creates additional risks by allowing a smart contract to access an unlimited number of tokens from the user’s wallet. Attackers are able to exploit the lack of validation and excessive approval to transfer tokens from other users to themselves.

Weak off-chain validation

In some bridge systems, the off-chain backend server plays a critical role in verifying the legitimacy of messages sent from the blockchain. In this instance, we’re focusing on the verification of deposit transactions. 

A blockchain bridge with off-chain validation works as follows: 

  1. Users interact with the DApp to deposit tokens into the smart contract on the source chain.
  2. The DApp then sends the deposit transaction hash to the backend server via an API.
  3. The transaction hash is subject to several validations by the server. If deemed legitimate, a signer signs a message and sends the signature back to the user interface via the API.
  4. Upon receiving the signature, the DApp verifies it and permits the user to withdraw their tokens from the target chain.

The backend server must ensure that the deposit transaction it processes has actually occurred and was not forged. This backend server determines whether a user can withdraw tokens on the target chain and is, therefore, a high-value target for attackers.

The backend server needs to validate the structure of the transaction’s emitted event, as well as the contract address that emitted the event. If the latter is neglected, an attacker could deploy a malicious contract to forge a deposit event with the same structure as a legitimate deposit event. 

If the backend server does not verify which address emitted the event, it would consider this a valid transaction and sign the message. The attacker could then send the transaction hash to the backend, bypassing verification and allowing them to withdraw the tokens from the target chain.

Improper handling of native tokens

Bridges take different approaches toward handling native tokens and utility tokens. For example, on the Ethereum network, the native token is ETH and most utility tokens adhere to the ERC-20 standard.

When a user intends to transfer their ETH to another chain, they must first deposit it into the bridge contract. To achieve this, the user simply attaches the ETH to the transaction, and the amount of ETH can be retrieved by reading the “msg.value” field of the transaction.

Depositing ERC-20 tokens differs significantly from depositing ETH. To deposit an ERC-20 token, the user must first allow the bridge contract to spend their tokens. After they’ve approved this and deposited the tokens into the bridge contract, the contract will either burn the user's tokens using the "burnFrom()" function or transfer the user's token to the contract using the "transferFrom()" function.

One approach to differentiate this is to use an if-else statement within the same function. Another approach is to create two separate functions to handle each scenario. Attempting to deposit ETH using the ERC-20 deposit function can result in the loss of these funds.

When handling ERC-20 deposit requests, users usually provide the token address as input to the deposit function. This poses a significant risk as untrusted external calls can occur during the transaction. Implementing a whitelist that only includes the tokens supported by the bridge is a common practice to minimize risk. Only whitelisted addresses are allowed to be passed as arguments. This prevents external calls as the project team has already filtered the token address.

However, issues may also arise when bridges handle native token cross-chain transfer, as the native token does not have an address. A zero address (0x000...0) is representative of the native token. This can be problematic since passing the zero address to the function can bypass the whitelist verification even if implemented incorrectly.

When the bridge contract calls “transferFrom” to transfer user assets to the contract, the external call to the zero address returns false since there is no “transferFrom” function implemented in the zero address. However, the transaction may still occur if the contract does not handle the return value appropriately. This creates an opportunity for attackers to execute the transaction without transferring any tokens to the contract.

Misconfiguration

In most blockchain bridges, a privileged role is responsible for whitelisting or blacklisting tokens and addresses, assigning or changing signers, and other critical configurations. Ensuring that all configurations are accurate is crucial, as even seemingly trivial oversights can lead to significant losses.

In fact, there has been an incident where the attacker successfully bypassed the transfer record verification due to a misconfiguration. The project team implemented a protocol upgrade a few days before the hack, which involved changing a variable. The variable was used to represent the default value of the trusted message. This change resulted in all messages being automatically deemed proven, thus allowing an attacker to submit an arbitrary message and pass the verification process.

How To Improve Bridge Security

The four common bridge vulnerabilities explained above demonstrate the challenges to ensuring security in an interconnected blockchain ecosystem. There are significant considerations for handling each of these vulnerabilities, and no single playbook applies to all of them.

For example, providing general guidelines to ensure an error-free verification process is challenging since each bridge has unique verification requirements. The most effective approach to prevent verification bypass is to thoroughly test the bridge against all possible attack vectors and ensure the verification logic is sound.

To summarize, it’s essential to perform rigorous testing against potential attacks and pay special attention to the most common security vulnerabilities in bridges.

Closing Thoughts

Due to their high value, cross-chain bridges have long been a target for attackers. Builders can strengthen their bridges’ security by conducting thorough pre-deployment testing and engaging in third-party audits, reducing the risk of the devastating hacks that have plagued bridges over the last few years. Bridges are critical in a multi-chain world, but security must be a primary concern when designing and building an effective Web3 infrastructure.

Read more: https://academy.binance.com/en/articles/what-are-common-bridge-security-vulnerabilities

Comments

All Comments

Recommended for you

  • Modular Data Layer for Gaming and AI, Carv, Raises $10M in Series A Funding

    Santa Clara-based Carv has secured $10m in Series A funding led by Tribe Capital and IOSG Ventures, with participation from Consensys, Fenbushi Capital, and other investors. The company plans to use the funds to expand its operations and development efforts. Carv specializes in providing gaming and AI development with high-quality data enhanced with human feedback in a regulatory-compliant, trustless manner. Its solution includes the CARV Protocol, CARV Play, and CARV's AI Agent, CARA. The company is also preparing to launch its node sale to enhance decentralization and bolster trustworthiness.

  • The US GDP seasonally adjusted annualized rate in the first quarter was 1.6%

    The seasonally adjusted annualized initial value of US GDP for the first quarter was 1.6%, estimated at 2.5%, and the previous value was 3.4%.

  • The main culprit of China's 43 billion yuan illegal money laundering case was arrested in the UK, involved in the UK's largest Bitcoin money laundering case

    Local time in the UK, Qian Zhimin appeared in Westminster Magistrates' Court for the first time under the identity of Yadi Zhang. She was accused of obtaining, using or possessing cryptocurrency as criminal property from October 1, 2017 to this Tuesday in London and other parts of the UK. Currently, Qian Zhimin is charged with two counts of illegally holding cryptocurrency. Qian Zhimin is the main suspect in the Blue Sky Gerui illegal public deposit-taking case investigated by the Chinese police in 2017, involving a fund of 43 billion yuan and 126,000 Chinese investors. After the case was exposed, Qian Zhimin fled abroad with a fake passport and held a large amount of bitcoin overseas. According to the above Financial Times report, Qian Zhimin denied the charges of the Royal Prosecution Service in the UK, stating that she would not plead guilty or apply for bail.

  • Nigeria’s Central Bank Denies Call to Freeze Crypto Exchange Users’ Bank Accounts

    In response to the news that "the Central Bank of Nigeria has issued a ban on cryptocurrency trading and requested financial institutions to freeze the accounts of users related to Bybit, KuCoin, OKX, and Binance exchanges," the Central Bank of Nigeria (CBN) stated in a document that the CBN has not officially issued such a notice, and the public should check the official website for the latest information to ensure the reliability of the news. According to a screenshot reported by Cointelegraph yesterday, the Central Bank of Nigeria has requested all banks and financial institutions to identify individuals or entities trading with cryptocurrency exchanges and set these accounts to "Post-No-Debit" (PND) status within six months. This means that account holders will not be able to withdraw funds or make payments from these accounts. According to the screenshot, the Central Bank of Nigeria has listed cryptocurrency exchanges that have not obtained operating licenses in Nigeria, including Bybit, KuCoin, OKX, and Binance. The Central Bank of Nigeria will crack down on the illegal purchase and sale of stablecoin USDT on these platforms, especially those using peer-to-peer (P2P) transactions. In addition, the Central Bank of Nigeria pointed out that financial institutions are prohibited from engaging in cryptocurrency transactions or providing payment services to cryptocurrency exchanges.

  • Universal verification layer Aligned Layer completes $20 million Series A financing

    Ethereum's universal verification layer Aligned Layer has completed a $20 million Series A financing round, led by Hack VC, with participation from dao5, L2IV, Nomad Capital, and others. The Aligned Layer mainnet is scheduled to launch in the second quarter of 2024. As the EigenLayer AVS, Aligned Layer provides Ethereum with a new infrastructure for obtaining economically viable zero-knowledge proof verification for all proof systems.

  • The total open interest of Bitcoin contracts on the entire network reached 31.41 billion US dollars

    According to Coinglass data, the total open position of Bitcoin futures contracts on the entire network is 487,500 BTC (approximately 31.41 billion US dollars).Among them, the open position of CME Bitcoin contracts is 143,600 BTC (approximately 9.23 billion US dollars), ranking first;The open position of Binance Bitcoin contracts is 109,400 BTC (approximately 7.07 billion US dollars), ranking second.

  • Bitcoin mining difficulty increased by 1.99% to 88.1T yesterday, a record high

    According to BTC.com data reported by Jinse Finance, the mining difficulty of Bitcoin has increased by 1.99% to 88.1T at block height 840,672 (22:51:52 on April 24), reaching a new historical high. Currently, the average network computing power is 642.78EH/s.

  • US Stablecoin Bill Could Be Ready Soon, Says Top Democrat on House Financial Services Committee

    The top Democrat on the U.S. House Financial Services Committee, Maxine Waters, has stated that a stablecoin bill may be ready soon, indicating progress towards a new stablecoin law in the U.S. before the elections. Waters has previously criticized a version of the stablecoin bill, but emphasized the importance of protecting investors and ensuring that stablecoins are backed by assets. Congressional movement on stablecoin legislation has recently picked up pace, with input from the U.S. Federal Reserve, Treasury Department, and White House in crafting the bill. The stablecoin bill could potentially be tied to a must-pass Federal Aviation Administration reauthorization due next month, and may also be paired with a marijuana banking bill.

  • Crypto mining company Argo mined 1,760 bitcoins last year and earned $50.6 million

    Crypto mining company Argo Blockchain has released its 2023 financial year performance report, which includes:

  • Wormhole Raises $225M in Biggest Web3 Funding Round of the Year

    Wormhole, a messaging protocol startup, has raised $225 million in funding at a $2.5 billion valuation, making it the largest round in the Web3 space this year. The funding round included investors such as Coinbase Ventures, Jump Trading, Multicoin Capital, and Arrington XRP Capital, with their stakes consisting of token warrants for a yet-to-be-unveiled cryptocurrency. The Wormhole team has also announced the launch of Wormhole Labs, an independent company focused on building products and tools to help grow cross-chain development. Despite a slow year for funding in the Web3 sector, this round is exceedingly large and demonstrates continued interest in blockchain technology.