BTC
ETH
HTX
SOL
BNB
View Market
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt

CertiK: The insurance company that sold the accident insurance also suffered an accident? Cover Protocol Vulnerability Analysis

CertiK
特邀专栏作者
This article is about 2552 words, reading the full article takes about 4 minutes
On the evening of December 28th, Beijing time, the CertiK security verification team discovered a vulnerability attack on Cover Protocol’s unlimited issuance of tokens. This article analyzes the details of the incident for you.
AI Summary
Expand
On the evening of December 28th, Beijing time, the CertiK security verification team discovered a vulnerability attack on Cover Protocol’s unlimited issuance of tokens. This article analyzes the details of the incident for you.

Recently, some stray dogs appeared in the community. I heard that a neighbor’s child ran away in fright when he saw the dog, but was chased and bitten by the dog instead.

Fortunately, the parents were resourceful and put an accident insurance on the child, and a few injections of rabies vaccine did not cost much.

As a currency citizen, if the encrypted assets are unfortunately stolen, but the project party or you personally purchased insurance, then you can rest assured that the insurance company will repay the lost assets.

But there is the worst situation: But what if even the insurance company has a security incident and is attacked?

technical analysis

The attacker repeatedly pledged and retrieved the smart contract of the project, triggering the operation of minting tokens, and infinitely issued Cover tokens, causing the price of Cover tokens to collapse.

technical analysis

The main attack is divided into the following steps:

1. The attacker sets up the NOCLAIM tokens necessary for the attack.
2. The attacker uses NOCLAIM tokens to provide liquidity for the Balancer Pool:

① Provided a total of 2,573 DAI liquidity to the Balancer Pool

②The attacker obtained approximately 132,688 Balancer liquidity proof tokens BPT by providing liquidity to the Balancer Pool

3. The attacker pledges (stakes) all Balancer liquidity proof tokens obtained in the previous step to the Blacksmith.sol smart contract in Cover Protocol.
When staking, the attacker calls the deposit function in the Blacksmith.sol smart contract located at 0xe0b94a7bb45dd905c79bb1992c9879f40f1caed5, as shown in Figure 1:

Figure 1: The deposit() function in blacksmith.sol

By calling the deposit function, the attacker pledges the obtained BPT liquidity proof to the cover protocol.

First read the pool data of the current liquidity proof token to memory through line 118 in Figure 1, and then call line 121 to update the data of the current pool.

Figure 2: The updatePool() function in blacksmith.sol
As shown in line 75 of Figure 2, the pool data of the current liquidity proof token modified in the updatePool() function is a piece of data stored in storage, which is the same as the current liquidity proof stored in memory in deposit() The pool data of the token is two pieces of data.
The value of lpTotal in line 84 of Figure 2 represents the total number of liquidity proof tokens deposited in the current contract. Since the value of this variable is small, the value of the formula pool.accRewardsPerToken in line 84 will increase, and the updated accRewardsPerToken Values ​​are stored in storage.

Figure 3: The _claimCoverRewards() function in blacksmith.sol

Next, as shown in line 318 in Figure 3, deposit() casts a certain number of cover tokens to the function caller (msg.sender) by calling the _claimCoverRewards() function.

The number of minted cover tokens is related to the three variables pool.accRewardsPerToken, CAL_MULTIPLIER and miner.rewardWriteoff.

Please note that the value of pool.accRewardsPerToken here uses the pool data stored in memory, not the updated value using the update() function in Figure 2.

At the same time, it is known from the deposit function in Figure 1 that the value update of miner.rewardWriteoff occurs after the execution of the _claimCoverRewards() function is completed.

Therefore, in the original design, the updated value of miner.rewardWriteoff should be used to calculate the number of cover tokens that need to be minted. Here, the unupdated data of miner.rewardWriteoff is incorrectly used, resulting in the actual number of minted cover tokens being greater than the number of minted tokens. The number increased, which eventually led to the issuance of tokens.

After the pledge is successful, the attacker calls the withdraw() function in the blacksmith.sol smart contract to retrieve the pledged BPT and obtain additional minted cover tokens to complete the attack.

By comparing the token balance table after executing the deposit() function and the withdraw() function, we can find that after calling this set of deposit and withdraw functions, the attacker can obtain about 704 COVER tokens.

After deposit():

After withdraw():

By repeatedly executing the deposit and withdraw functions, the attacker can make the Blacksmith function infinitely mint tokens and transfer the tokens to his own address, thereby making a profit.

After the attack, as of press time, the official cover has migrated blacksmith to a safe version:

Vulnerable blacksmith address:

0xe0b94a7bb45dd905c79bb1992c9879f40f1caed5

Blacksmith address after temporary fix:

0x1d5fab8a0e88020309e52b77b9c8edf63c519a26

The temporarily repaired blacksmith contract temporarily prohibits all pledge and withdrawal operations to prevent the attacker from continuing to attack.

In this attack, the attacker made a total profit of 4.4 million U.S. dollars, or about 29 million yuan.

There are other attackers using this vulnerability to launch similar attacks. For example, the Grap.finance project official participated in the attack using this vulnerability and earned 4350 ETH tokens.

safety advice

safety advice

In order to ensure that digital assets do not suffer losses due to any non-technical reasons, the project party should purchase insurance for the project products in a timely manner, increase the security plan of the project party and investors, and ensure that the losses caused by attacks can be compensated in a timely manner.
As the world's top auditing company, CertiK has currently conducted more than 369 security audits, audited more than 198,000 lines of code, and protected more than $10 billion worth of encrypted assets.
Recently, CeritK launched the CertiKShield decentralized fund protection plan.
CertiKShield can not only provide protection for the project and its community members, at the same time, as a security company whose main business is auditing, CertiK ensures that ourInsurance items have higher security
Compared with pure insurance companies, CertiKShield is an insurance built in the security field with the endorsement of security technology and the team's emphasis on security and a series of guarantees, and has huge room for growth and development.

Welcome to visithttps://www.certik.foundation/

Enter the official website of CertiK foundation to access more information about CertiK security products!

安全
投资
Welcome to Join Odaily Official Community