
Super Sushi Samurai (SSS), a blockchain game, lost over $4.6 million due to a vulnerability in its smart contract. This exploit allowed attackers to essentially double their token holdings, Similar to minerercx hack
What is Super Sushi Samurai?
Super Sushi Samurai is an on-chain social strategy game built on the Blast network. Players interact with the game through Telegram and utilize SSS tokens.
The Double-Token Transfer Vulnerability
The exploit stemmed from a flaw in the way the SSS smart contract handled token transfers. the vulnerability allowed users to transfer tokens to themselves,
Code Snippet Analysis
function _transfer(address from, address to, uint256 value) internal {
// ... standard checks omitted for brevity
_update(from, to, value);
}
function _update(address from, address to, uint256 amount) internal virtual override {
// ... some checks present
uint256 amountAfterTax = amount - _taxApply(from, to, amount);
uint256 toBalance = _balances[to] + amountAfterTax;
// ... other updates
}- The transfer function calls update to handle balance adjustments during a transfer.
- The _update function calculates the final amount after tax deduction (which was zero in this exploit).
- Importantly, the update function updates the toBalance by simply adding the amountAfterTax to the existing balance stored in balances[to].
- Since the from and to addresses were identical in the exploit, this update essentially doubled the attacker's holdings.
BreakDown
1. Exploiting the Transfer Function. The attacker initiated a transfer transaction, but with both the sender and receiver addresses set to their own.
2. Flaw in the Update Function. The transfer triggered the _update function within the contract. This function is responsible for updating token balances but had a check missing.
3. Doubled Balance. The _update function didn't differentiate between a regular transfer and self-transfer. As a result, the attacker's token balance effectively doubled with each transaction.
Code Snippet Analysis (continued):
function _postCheck(address from, address to, uint256 amount) internal view returns (uint256 toBalance) {
// check if buyer has too much token
toBalance = _balances[to] + amount;
if (
limitIsInEffect() && maxAmountPerAccount > 0 && ((isLiquidityPool(from) && !isUnlimited(to))) // buy
) {
uint256 limit = maxAmountPerAccount + LIMITROUNDDEC;
require(toBalance < limit, "Max token per account");
}
}- Within the postCheck function, the ‘toBalance’ value will be equal to the current balances[to] plus amountAfterTax values.
- The balances[from] and balances[to] values in the underlying update function are updated after the postCheck implementation is completed. And, since the from and to addresses are the same in the transfer operation, both the balances[from] and _balances[to] point to the same storage location
- Therefore, as the balances[to] value is updated to the original value of balances[to] plus the amountAfterTax value, which is equal to the amount ,anyone would effectively have doubled their token holdings each time a transfer call is made
Immediate Mitigation
The immediate solution for the specific issue faced by SSS would have involved adding a conditional check within the transfer function to prevent transactions where the sender and receiver are the same address. This simple yet effective measure could have blocked the loophole that allowed for the unintended doubling of tokens.
require(address from != address to , "Both address are same ")
Recovery
- The team recovered a significant portion (around $4.5 million) of the stolen funds.
- Some black hat hackers did manage to steal a smaller amount (around $120,000).
- The team has shared details of the recovery process for affected users.
Lessons Learned
This incident highlights the importance of thorough smart contract audits to identify and address potential vulnerabilities before deployment. It also showcases the potential for white hat hackers to play a positive role in securing the blockchain ecosystem. By carefully examining code and implementing robust checks, similar exploits can be prevented in the future.
Author: Piyush shukla
Read similar minerercx hack