Settling a loan in full when deleveraging always reverts #449
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-172
grade-b
insufficient quality report
This report is not of sufficient quality
Q-06
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_172_group
AI based duplicate group recommendation
Lines of code
https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/V3Vault.sol#L954-L1014
Vulnerability details
Impact
A user will be denied the ability to call
LeverageTransformer::leverageDown()
throughV3Vault::transform()
if this results in the loan being repaid in full — breaking the protocol’s intended functionality.Proof of Concept
LeverageTransformer::leverageDown()
allows users to deleverage their position. It is intended to be called throughV3Vault::transform()
. The issue occurs when theamount
passed torepay()
inleverageDown()
is equal to the loan’s debt, LeverageTransformer.sol#L166:If a loan is fully repaid
_cleanupLoan()
is called, V3Vault.sol#L1003-L1005:The NFT is sent back to the user in
_cleanupLoan()
, V3Vault.sol#L1083:The transaction will then revert at this check in
transform()
, since the NFT was transferred back to the owner, V3Vault.sol#L530-L534:Add the following test that demonstrates this to
test/integration/V3Vault.t.sol
:Tools Used
Foundry
Recommended Mitigation Steps
Adjust the accounting in
LeverageTransformer::leverageDown()
to handle this scenario, LeverageTransformer.sol#L165-L166:In this case we call
repay()
passingamount
asdebt - 1
, deleveraging the position as much as necessary without breaking the protocol’s intended functionality.Assessed type
Error
The text was updated successfully, but these errors were encountered: