AAVE ParaSwap Repay Adapter Hack

On August 28th, 2024, a peripheral contract of AAVE, was exploited, resulting in a $56,000 loss across different chains. The hack targeted the ParaSwapRepayAdapter contract, a peripheral component of the AAVE platform. This contract enables users to repay borrowed positions by swapping their existing collateral through ParaSwap, a decentralized exchange. The contract does not directly hold user funds, it only contains leftover tokens from these swaps so it does not affect user funds.

Overview

Attacker: https://etherscan.io/address/0x6ea83f23795F55434C38bA67FCc428aec0C296DC

Vulnerable Contract: https://etherscan.io/address/0x02e7b8511831b1b02d9018215a0f8f500ea5c6b3

Transaction attack: https://etherscan.io/tx/0xc27c3ec61c61309c9af35af062a834e0d6914f9352113617400577c0f2b0e9de

Exploit Analysis

The vulnerability in the _buyOnParaSwap function which has several issues. It approves assetToSwapFrom tokens based on amount of maxAmountToSwap, but make arbitrary call on a different amount in paraswapData. So the attacker can craft a small swap data but a very high maxAmountToSwap which will leave a very high allowance left for tokenTransferProxy after the swap.

The attacker then exploited the leftover token allowance of assetToSwapFrom for tokenTransferProxy to withdraw tokens from the contract.

Lesson learned

As a developer, when building your own project, does not trust any user input. Any parameter given must be carefully validated by the code. Calls to untrusted contracts can introduce several unexpected risks or errors. External calls can trigger malicious code, either within the target contract or across its ecosystem. Every external call should be treated as a potential security risk and must be processed with extreme caution.

Additionally, it is strongly recommended to conduct a security audit, not only for the first release version but also for any new features added in the future. Since the upgrading process can introduce various issues, it should also be thoroughly audited.

Source
Disclaimer: The content above is only the author's opinion which does not represent any position of Followin, and is not intended as, and shall not be understood or construed as, investment advice from Followin.
Like
Add to Favorites
Comments