Lenders are unable to withdraw complete collateral #627
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
edited-by-warden
insufficient quality report
This report is not of sufficient quality
🤖_primary
AI based primary recommendation
🤖_89_group
AI based duplicate group recommendation
Lines of code
https://github.com/code-423n4/2024-05-predy/blob/main/src/PredyPool.sol#L237
Vulnerability details
Summary
The
PredyPool:withdraw()
function is used to withdraw either thequoteToken
or thebaseToken
from the lending pool. However, due to a rounding issue, lenders are unable to completely exit the poolImpact
Lenders are unable to exit completely from the PredyPool
Proof of Concept
https://github.com/code-423n4/2024-05-predy/blob/main/src/PredyPool.sol#L222 Lender supply the tokens via supply method and get equivalent bond shares which represent their actual balance in the predypool.
Alice is a lender and supplies amount tokens to the
PredyPool
Alice will receive
(amount * 1e18) / (tokenState.assetScaler)
bond tokens in return, referred to asaliceTotalBondShares
The
tokenState.assetScaler
increases after every deposit, withdrawal, and trade. Hence, at any time, the maximum amount of assets a lender can withdraw can be viewed bygetAvailableCollateralValue()
At any time, Alice should be able to withdraw
(total Alice's bond tokens * tokenState.assetScaler) / 1e18
. So, Alice calls thewithdraw
function to withdraw the above amount.predypool.withdraw()
calls removeAsset to compute balances and Alice's total balance.As we can see, it calculates
burnAmount
from(amount * 1e18) / assetScaler
, which will always be less thanaliceTotalBondShares
(from point 2). So Alice won't be able to withdraw her complete amount ever.Hence, the redeemed bond tokens will always be less than the maximum amount, leaving a small amount of tokens in the
PredyPool
for every lenderTools Used
Manual
Recommended Mitigation Steps
Lenders should be able to exit completely i.e make sure the lender can fully redeem their bond tokens and exit the pool.
Assessed type
Math
The text was updated successfully, but these errors were encountered: