本文へ移動
Contact

TECHFUND
Media

Hi AUDIT
2024/5/14

Tsuru $410,000 Exploit | Hack Analysis    

Tsurushima Tatsumi is a beloved japanese illustrator who has worked on many different web2 & web3 projects with his iconic colorful and cute character designs. His art was recently displayed on the Times Square during NFT NYC 2024.

Summary

May 10, 11:55 PM UTC - The team noticed that claim transactions weren't going through, despite being approved by users (the $JOURNEY tokens remained in their wallets). This was a phenomenon they hadn't encountered during their various tests in Base Sepolia before the launch. Initially, they suspected an issue related to the mint/burn functions in the TSURU Wrapper contract and began investigating.

May 10, 12:30 PM UTC - Despite their efforts, the team had yet to pinpoint the issue. However, they discovered that users could claim $TSURU by directly calling the safeTransferFrom function in the $JOURNEY NFT contract in Base Scan. Users could manually input parameters and call the TSURU wrapper contract to claim their $TSURU tokens with their $JOURNEY NFT.

May 10, 1:00 PM UTC - It was found that the congestion causing the approved but not processed transactions was due to an out-of-gas issue. When the frontend called the tokensOfOwner function to retrieve the tokenId from the NFT ($JOURNEY) in the JOURNEY contract to initiate a claim call to the TSURU wrapper contract, the data retrieved from the contract's read function appeared to be large, leading to out-of-gas errors caused by multiple call requests.

Simultaneously, the team observed the TSURU wrapper contract beginning to mint $TSURU tokens, indicating that $JOURNEY holders were claiming their $TSURU. This strengthened their belief that the congestion was indeed caused by the out-of-gas error from the tokensOfOwner function in the JOURNEY contract. Consequently, they commenced replacing it with the tokensOfOwnerIn function in their frontend, which limited the scope of data retrieval.

During the implementation of the aforementioned fix, an exploit occurred wherein 167,200,000 $TSURU were minted from the address owner of 0x7a5eb99c993f4c075c222f9327abc7426cfae386. The exploiter then swapped the 167,200,200 $TSURU for $137,783 worth of ETH in the TSURU <> ETH Uniswap Liquidity Pool.

After our investigation, it was revealed that this exploit was triggered by the code change made earlier. The old 'require' function would only execute the next line if the preceding condition was true. However, the 'if' statement executed the line within the block if the condition was true. The transition from the conditional expression in 'require' to the 'if' statement inadvertently caused the problem.

Root causes

Step 1:

The TSURUWrapper contract had a vulnerability in its onERC1155Received function. This function lacked proper access control, meaning it didn't effectively verify who could interact with it and perform certain actions. This vulnerability allowed unauthorized attacker to exploit the contract

function onERC1155Received(address, address from, uint256 id, uint256 amount, bytes calldata) external override nonReentrant returns (bytes4) {require(id == tokenID, "Token ID does not match");

if (msg.sender == address(erc1155Contract)) {

return this.onERC1155Received.selector;

}

safeMint(from, amount * ERC1155RATIO); // Adjust minting based on the ERC1155_RATIO

return this.onERC1155Received.selector;

}

Step 2:

In the provided code snippet, the id or tokenID parameter within the vulnerable onERC1155Received function is crucial for minting TSURU tokens. Since there was no proper access control in place, anyone could utilize this parameter to mint TSURU tokens, regardless of their authorization status. This essentially opened the door for unauthorized minting of tokens.

Step 3:

After obtaining the minted TSURU tokens, the exploiter could then proceed to swap them for ETH in the Uniswap Liquidity pool. Uniswap is a decentralized exchange protocol that allows users to swap various ERC-20 tokens, like TSURU, for other tokens, including ETH. By swapping TSURU tokens for ETH, the exploiter could convert their ill-gotten tokens into a more widely accepted and valuable cryptocurrency.

Step 4:

On the Base chain, the exploiter successfully swapped the stolen 167 million TSURU tokens for 137.78 ETH. This amount of ETH was valued at approximately $410,000. Subsequently, the exploiter transferred these ETH to an address on the Ethereum Mainnet. Additionally, this Ethereum Mainnet address received 40.95 ETH worth of assets from a previous incident involving Perpy Finance, suggesting a pattern of exploiting vulnerabilities across different projects.

The hack occurred approximately two hours after the deployment of the project. As of the current moment, the exploiter's address on the Ethereum Mainnet holds 179.68 ETH, which is valued at approximately $516,129. This indicates that the exploiter has profited significantly from their malicious activities, further underscoring the severity of the security breach and its consequences.

Solution

Access control measures in smart contracts is critical. For the Tsuru case, specifically ensuring that the onERC1155Received function includes authentication checks to verify not only the contract addresses interacting but also the roles of the interacting accounts would prevent unauthorized access.

Lesson Learned 

Even a single line of code change can introduce critical security vulnerabilities. This real-world example highlights the importance of thorough code auditing, no matter how small the modification.

Read more About Pike Finance Exploit $1.6 million

Author : Piyush shukla

Hi AUDIT

Hi AUDIT is a high speed, high quality, best price security audit service, providing automated audit SaaS and consulting for web3 startups.
View More