本文へ移動
Contact

TECHFUND
Media

Hi AUDIT
2024/8/1

Dough Finance $1.8 M Hack Analysis

On July 12th, 2024, Dough Finance suffered a significant security breach, falling victim to a flash loan attack that resulted in a loss of approximately $1.8 million. This analysis delves into the details of the exploit, examining the vulnerability within the smart contract and outlining mitigation strategies to prevent future attack

Root cause of Hack

The root cause of the vulnerability was found in the ConnectorDeleverageParaswap contract, which failed to validate flash loan callback data properly. This oversight led to the unauthorized transfer of WETH (Wrapped Ether).

  function deloopAllCollaterals(bytes[] memory multiTokenSwapData) private {        
        FlashloanVars memory flashloanVars;

        for (uint i = 0; i < multiTokenSwapData.length;) {
            // Deloop
            (flashloanVars.srcToken, flashloanVars.destToken, flashloanVars.srcAmount, flashloanVars.destAmount, flashloanVars.paraSwapContract, flashloanVars.tokenTransferProxy, flashloanVars.paraswapCallData) = _getParaswapData(multiTokenSwapData[i]);

            // using ParaSwap
            IERC20(flashloanVars.srcToken).safeIncreaseAllowance(flashloanVars.tokenTransferProxy, flashloanVars.srcAmount);
            (flashloanVars.sent, ) = flashloanVars.paraSwapContract.call(flashloanVars.paraswapCallData);
            if (!flashloanVars.sent) revert CustomError("ParaSwap deloop failed");

            unchecked { i++; }
        }
    }
  • The deloopAllCollaterals function did not verify the parameters extracted by _getParaswapData, allowing the attacker to craft malicious multiTokenSwapData containing an attacker-controlled tokenTransferProxy address.

  • During loop execution, the contract used safeIncreaseAllowance to increase the allowance for the attacker's address instead of the intended ParaSwap proxy.

  • The attacker leveraged this increased allowance to transfer tokens from the contract’s balance to their own address.

  • As illustrated in the attack flow image above, the contract's original intention was to call ParaSwap. However, due to the vulnerability, the transferFrom method was called instead, resulting in a loss of nearly 608 ETH or $1.8 million.

The attacker subsequently transferred the stolen funds to Tornado Cash, a service often used to obscure transaction trails. In response, DoughFina's team issued an on-chain ultimatum (0xa5eed) to the attacker, seeking to negotiate the return of the stolen funds.

Mitigation and Best Practices

To prevent such exploits in the future, the following best practices should be implemented:

  1. Comprehensive Validation Checks: Ensure all transaction callbacks include thorough validation checks for calldata and sender authenticity, allowing only authorized transactions to proceed.

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