The AaveDIVAWrapperCore contract's internal function _redeemWToken allows users to directly burn wTokens in exchange for underlying collateral from Aave, without correspondingly burning the associated long/short position tokens in the DIVA Protocol pool. This function can be called by the external functions redeemWToken and batchRedeemWToken in the AaveDIVAWrapper contract. Since users can obtain wTokens not only through pool creation and liquidity addition but also via DIVA Protocol's transferFeeClaim and claimFee functions, this vulnerability breaks the documented invariant: short token supply = long token supply = wToken supply. The root cause is that _redeemWToken interacts solely with wTokens and Aave, bypassing DIVA Protocol's accounting, which is responsible for maintaining the balance between wTokens and position tokens. Consequently, this allows users to redeem more collateral than entitled, potentially leading to a loss of funds for other users.
The core issue lies in the _redeemWToken function within the AaveDIVAWrapperCore contract (AaveDIVAWrapperCore.sol#L314-L330). This function is designed to allow users to redeem their wTokens for the underlying collateral assets held within the Aave protocol, by calling the function _redeemWTokenPrivate. However, it fails to interact with the corresponding DIVA Protocol pool to adjust the balances of the associated long and short position tokens:
This violates the invariant short token supply = long token supply = wToken supply should be maintained as to the AaveDIVAWrapper - Documentation:
In contrast, the functions _removeLiquidity and _redeemPositionToken within the AaveDIVAWrapperCore contract, which also involve wToken redemption, correctly interact with the DIVA Protocol to burn the corresponding position tokens thus maintain the protocol invariant:
Meanwhile, the wToken can be obtained by interacting with DIVA protocol's existing functions transferFeeClaim, batchTransferFeeClaim and claimFee in addition to pool creation and liquidity addition, according to the interface description IDIVA.sol#L100-L125. When these functions are called, the received wTokens haven't been burnt thus the corresponding position tokens are not burnt as well:
By allowing direct burning of those claimed wTokens without corresponding position token adjustments, the _redeemWToken function introduces an imbalance: A user can obtain wTokens, redeem them for collateral through this vulnerable function, and still retain their position tokens in the DIVA Protocol pool. This effectively allows them to extract collateral without reducing their position, breaking the intended economic model and potentially leading to a situation where the remaining position tokens are under-collateralized. The vulnerability can be triggered by the external functions redeemWToken (AaveDIVAWrapper.sol#L71-L77) and batchRedeemWToken (AaveDIVAWrapper.sol#L172-L187) in the AaveDIVAWrapper contract.
The vulnerability has a significant impact, directly breaking the core invariant of the AaveDIVAWrapper and DIVA Protocol integration, which states that short token supply = long token supply = wToken supply. This leads to the following consequences:
Direct Financial Loss: Attackers can exploit this vulnerability to withdraw more collateral from Aave than they are entitled to. By obtaining wTokens through mechanisms like claimFee or transferFeeClaim in DIVA Protocol, and then using _redeemWToken to redeem them, they effectively extract value without relinquishing their corresponding position in the DIVA pool. This creates a scenario where the remaining position token holders are left with under-collateralized positions, facing potential losses.
Economic Imbalance: The broken invariant destabilizes the economic model of the DIVA Protocol pools. The intended 1:1 backing of position tokens with wTokens is violated, leading to a misrepresentation of the actual collateralization within the system.
Unfair Advantage: Attackers gain an unfair advantage by being able to redeem collateral without surrendering their position tokens. This undermines the fairness and integrity of the DIVA Protocol pools.
Loss of User Trust: Such a fundamental flaw can severely damage user trust in both the AaveDIVAWrapper and the DIVA Protocol, leading to a loss of confidence and potential withdrawal of funds from the system.
Potential for Systemic Risk: Depending on the scale of the exploit and the amount of funds locked in the system, this vulnerability could pose a systemic risk to the affected pools and potentially impact the broader DeFi ecosystem if not addressed promptly.
In summary, this vulnerability allows for direct financial exploitation, undermines the core economic model, creates an unfair advantage for attackers, and can lead to a loss of user trust and potential systemic risks. Therefore, it should be classified as a high-severity issue.
Manual Review
1. Remove the _redeemWToken function and its associated external functions:
Eliminate the _redeemWToken function from the AaveDIVAWrapperCore contract entirely.
Remove the user-facing functions redeemWToken and batchRedeemWToken from the AaveDIVAWrapper contract which call _redeemWToken internally.
This is the simplest and most secure solution. It forces users to interact with DIVA Protocol directly when they want to redeem their wTokens which ensures that the corresponding position tokens are burned, maintaining the crucial invariant.
2. Alternative (Future Consideration): Integrate Position Token Burning into _redeemWToken (Requires Changes to DIVA Protocol):
Introduce a new function in DIVA Protocol: This function, for example, burnPositionTokens(bytes32 poolId, address positionToken, uint256 amount), would allow the AaveDIVAWrapper contract (and potentially other whitelisted addresses) to burn position tokens directly, without receiving collateral in return.
Modify _redeemWToken in AaveDIVAWrapperCore:
Add a poolId parameter to identify the relevant DIVA pool.
Calculate the amount of long and short tokens to burn, based on the _wTokenAmount being redeemed.
Call the new burnPositionTokens function in DIVA Protocol before burning wTokens and withdrawing from Aave.
Consider a Whitelist for burnPositionTokens: To enhance security, limit the ability to call the new burnPositionTokens function to only whitelisted addresses (e.g., the AaveDIVAWrapper contract).
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.