Cointime

Download App
iOS & Android

SharkTeam: Analysis of the Midas Capital Attack Incident

On June 18, 2023, Beijing time, Midas Capital was targeted in an attack, and the attackers have profited approximately $600,000.

SharkTeam conducted an immediate technical analysis of this incident and summarized security measures. We hope that future projects can learn from this and strengthen the security defenses in the blockchain industry.

1. Incident analysis

Attacker address: 0x4b92cc3452ef1e37528470495b86d3f976470734

Attack contract: 0xc40119c7269a5fa813d878bf83d14e3462fc8fde

Attacked contract: 0xF8527Dc5611B589CbB365aCACaac0d1DC70b25cB

Attack transactions: 0x1ebc03f0f2257c275f4990b4130e6c3e451125aa98ee8bbde8aba5dc0320c659

Attack Process:

(1) The attacker (0x4b92cc34) invokes the function 0x117741f7 of the attack contract (0xc40119c7), and first calls the mint function of the targeted contract (0xF8527Dc5) to convert 518,614,966,827,953,435,094 sAMM-HAY/BUSD tokens into 2 fsAMM-HAY-BUSD tokens, which are the collateral tokens.

Select an Image

(2) Subsequently, the attacker calls the redeemUnderlying function of the targeted contract (0xF8527Dc5) to extract 518,614,966,827,953,435,091 sAMM tokens. However, instead of extracting all of them, they leave 3 tokens behind. It's important to note that at this point, only 1 fsAMM token has been transferred out of the attack contract.

Select an Image

(3) Then, the attacker calls the redeemUnderlying function of the targeted contract (0xF8527Dc5) again, extracting an additional 518,096,869,957,995,439,653 sAMM tokens. Since there is still 1 fsAMM token remaining in the attack contract (0xc40119c7) account, the extraction is successful.

Select an Image

(4) The above operations are repeated in a loop, and as the arbitrage process progresses, the quantity of minted tokens doubles, and the number of calls to the redeemUnderlying function also doubles.

Select an Image

(5) After multiple rounds of attack transactions, the obtained sAMM tokens are ultimately exchanged for profits by exiting with BUSD, HAY, ANKR, WBNB, ankrBNB, and other assets.

Select an Image

2. Vulnerability Analysis

Since the logic contract of the targeted contract (0xF8527Dc5) is currently not open-source, we can only rely on traces and previous logic contracts to find clues. We found that the code forked Compound's code and shares similarities with Hundred Finance, introducing a third-party math library.

Select an Image

In the divUInt function, the division operation a/b is used, which is fine in terms of calculation. However, due to Solidity's lack of support for floating-point arithmetic, the result is rounded down. The attacker (0x4b92cc34) strictly controls the input quantity every time they call the redeemUnderlying function. This leads to a situation where the calculated result becomes 1.99999999999... but is rounded down to 1 by default.

In the third step, the attack contract (0xc40119c7) retrieves slightly fewer sAMM tokens. As a result, the calculated result becomes 1. Consequently, each time the attacker (0x4b92cc34) stakes and extracts the principal, it doubles.

3. Security Recommendations

The root cause of this incident was the integration of a math library in the targeted contract (0xF8527Dc5), where the redeemUnderlying function rounds down the quantity of fsAMM tokens that the attacker (0x4b92cc34) needs to transfer. This resulted in the attacker (0x4b92cc34) halving the cost they would otherwise have to pay and enabling them to repeatedly exploit the arbitrage opportunity.

To prevent similar attacks, it is essential to follow the following considerations during the development process:

(1) Solidity does not support floating-point arithmetic. When implementing integer operations, it is recommended to perform multiplication before division or use appropriate precision mechanisms.

(2) Before deploying a project, seek technical assistance from professional third-party audit teams to conduct a thorough security review.

About us

SharkTeam’s vision is to comprehensively protect the security of the Web3 world. The team is composed of experienced security professionals and senior researchers from all over the world. They are proficient in the underlying theory of blockchain and smart contracts, and provide services including smart contract auditing, on-chain analysis, and emergency response. It has established long-term cooperative relationships with key players in various fields of the blockchain ecosystem, such as Polkadot, Moonbeam, polygon, OKC, Huobi Global, imToken, ChainIDE, etc.Official website: https://www.sharkteam.org/Twitter: https://twitter.com/sharkteamorgDiscord: https://discord.gg/jGH9xXCjDZTelegram: https://t.me/sharkteamorg

Comments

All Comments

Recommended for you

  • BTC breaks through $63,000

    The market shows BTC has broken through $63,000 and is currently trading at $63,014.9, with a daily increase of 6.11%. The market is volatile, so please exercise caution in risk management.

  • The total gas consumption on the Base chain exceeds 10,000 ETH

    According to the blockchain analysis platform Dune Analytics, the total gas consumption on the Base chain has exceeded 10,000 ETH, reaching 10,839.5062 ETH at the time of writing (equivalent to over $33.6 million at current prices). The average gas usage amount is about $0.1754 per transaction (0.000059661 ETH), and the total number of blocks has reached 13.41 million, with an average transaction volume of about 14.63 transactions per block. In addition, the data shows that the total transaction volume on the Base chain has exceeded 196.2 million, with over 8.366 million users and over 184 million user transactions at the time of writing. Furthermore, the total number of contracts created on the Base chain has exceeded 64 million, reaching 64,056,573 in the current period.

  • A wallet received 2,000 ETH from Alemeda/FTX

    As monitored by The Data Nerd, 6 hours ago, wallet 0xaEa received 2,000 ETH (approximately $6.23 million) from Alemeda/FTX. Within a week, it received a total of 8,000 ETH (approximately $24.71 million) from Alameda and deposited 6,000 ETH into Binance.

  • A single transaction with a transaction fee of up to 1.5 BTC appeared on the Bitcoin chain

    According to on-chain data tracking service monitoring , there has been a single transaction on the Bitcoin network with a transaction fee as high as 1.5 BTC, worth about $100,254. It is reported that the sender of the transaction is an address starting with "bc1p4n" and the recipient is an address starting with "bc1pqv".

  • 2 wallets deposited 211 billion SHIB into Coinbase within 10 hours

    According to The Data Nerd's monitoring, within 10 hours, 2 wallets (with the same amount of SHIB) deposited a total of 211 billion SHIB (about 5.16 million US dollars) into Coinbase. These wallets accumulated these SHIBs last week, and if sold at the current price, it would cause a small loss (about 120,000 US dollars).

  • USDT issuance on TON chain reaches $100 million

    According to official data, the issuance and circulation of USDT on the TON chain has reached 100 million US dollars, making TON the fastest-growing blockchain for Tether USDT issuance in Web3 history.

  • USDC circulation decreased by $200 million in the past week, with a total circulation of $33.1 billion

    According to official data, Circle issued a total of 2.8 billion USDC and redeemed approximately 3 billion USDC in the past 7 days, resulting in a decrease in circulation of approximately 200 million USDC. The total circulation of USDC is 33.1 billion US dollars, with a reserve of 33.2 billion US dollars, including approximately 3.4 billion US dollars in cash, and Circle Reserve Fund holding approximately 29.8 billion US dollars.

  • Starknet Ecosystem DEX Paradex Releases Q2 Roadmap: Plans to Implement Cross-Chain Bridging and Wallet Support

    Decentralized perpetual contract trading platform Paradex on the X platform released its Q2 roadmap, with the following highlights:

  • In April, Polygon’s on-chain NFT sales exceeded US$50 million, setting the second highest record of the year

    According to Cryptoslam data, the NFT sales on Polygon chain in April exceeded 50 million US dollars, reaching 51,539,690.69 US dollars, setting the second highest monthly sales record in 2024, second only to January's sales of 112 million US dollars this year. In addition, the NFT trading volume on Polygon chain in April increased significantly to 1.5 million transactions, with nearly 90,000 independent sellers and over 33,000 independent buyers.

  • ETFStore President: GBTC outflow trend has ended

    Nate Geraci, President of ETFStore, stated on X platform that the outflow trend of GBTC has ended, with a revenue of $63 million.