A critical issue has been identified in AaveDIVAWrapperCore::_removeLiquidity function of the AaveDIVAWrapperCore contract when the liquidity provider (LP) is not the recipient of both short and long position tokens. This bug results in the inability to remove liquidity when the LP inputs `type(uint256).max` to withdraw all collateral, leading to a transaction revert due to a zero protocol fee calculation.
When an LP adds liquidity but assigns different addresses for shortRecipient and longRecipient, they do not hold the position tokens themselves. Consequently, when attempting to remove liquidity, the LP's balance for both short and long tokens is zero. This results in the following:
If `_positionTokenAmount == type(uint256).max`
The `removeLiquidity` function is called with an amount of zero:
This results in a revert due to the zero protocol fee error in the DIVA Protocol's LibDIVA contract.
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/facets/LiquidityFacet.sol#L54
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/facets/LiquidityFacet.sol#L77
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L877
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L918
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L921
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L52
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L420
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L407
https://github.com/divaprotocol/diva-protocol-v1/blob/1263828cd5c5b2192e876edef90444448e66176d/contracts/libraries/LibDIVA.sol#L927
When a liquidity provider uses `type(uint256).max` to remove liquidity, the transaction fails due to zero balance checks on position tokens, resulting in locked collateral and inability to withdraw funds.
In `test/AaveDIVAWrapper.t.sol` :
Run this command :
Test pass:
Manuial Review
Foundry Framework
The `addLiquidity` allows the short and long recipients to be different addresses. Then if a given user has only one of the position tokens, he calls `redeemPositionToken` to redeem position token amount, if this user has amount of the both token types, he can call `removeLiquidity` and in that way an equal amount of short and long tokens will be burned.
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.