Loans can exceed the maximum potential debt leading to vault insolvency and possible loss of LP funds
The LienToken.createLien function checks the total potential debt before adding the new lien to the liens array, so the check ignores the new lien. An attacker could take multiple loans on different collateral tokens, each within the limit, but together exceeding the maximum potential debt, risking vault insolvency and loss of LP funds.
Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/169
Found by
0xRajeev
Summary
Missing to account for the new lien can allow loans on a collateral to exceed maximum potential debt leading to vault insolvency and potential loss of LP funds.
Vulnerability Detail
The LienToken.createLien function tries to prevent loans and the total potential debt from surpassing the defined params.terms.maxPotentialDebt limit. When the getTotalDebtForCollateralToken function is called, the new lien (which will be created within this transaction) is not yet added to the liens[collateralId] array. However, the getTotalDebtForCollateralToken function iterates over this very same array and will return the total debt without considering the new lien being added and for which this check is being performed.
Impact
The strategist's defined max potential debt limit can be exceeded, which changes/increases the risk for LPs, as it imposes a higher debt to the public vault. This could lead to vault insolvency and loss of LP funds.
PoC: https://gist.github.com/berndartmueller/8b0f870962acc4c999822d742e89151b
Example exploit: Given a public vault and a lien with a max potential debt amount of 50 ETH (that's the default standardLien in TestHelpers.t.sol)
1. 100 ETH have been deposited in the public vault by LPs
2. Bob borrows 50 ETH with his 1st NFT -> success
3. Bob borrows another 50 ETH with his 2nd NFT -> successful as well even though theirs a limit of 50 ETH
4. Bob now has 100 ETH -> The max potential debt limit is exceeded by 50 ETH
Code Snippet
Tool used
Manual Review
Recommendation
Check the total debt limit after adding the new lien to the liens[collateralId] array.
Discussion
androolloyd
this is working as intended, the value is intended to represent the max potential debt the collateral can potentnially be under at the moment the new terms are originated.
secureum
Escalate for 2 USDC.
We still think this is a valid issue with a high-severity impact as described above and demonstrated in the PoC.
cc @berndartmueller @lucyoa
sherlock-admin
Escalate for 2 USDC.
We still think this is a valid issue with a high-severity impact as described above and demonstrated in the PoC.
cc @berndartmueller @lucyoa
You've created a valid escalation for 2 USDC!
To remove the escalation from consideration: Delete your comment. To change the amount you've staked on this escalation: Edit your comment (do not create a new comment).
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Evert0x
Escalation accepted
Having the possibility of exceeding the maximum potential debt should be mitigated
sherlock-admin
Escalation accepted
Having the possibility of exceeding the maximum potential debt should be mitigated
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the total debt check is performed before the new lien is added to the liens array, so the check does not include the new lien.
Impact
The strategist's defined max potential debt limit can be exceeded, which could lead to vault insolvency and loss of LP funds.
What the attacker needed
A public vault with LP deposits; multiple NFTs as collateral; ability to take multiple loans
The fix
The total debt limit should be checked after adding the new lien to the liens array.
How it was found
- LPs deposit 100 ETH into the public vault.
- Bob borrows 50 ETH using his first NFT.
- Bob borrows another 50 ETH using his second NFT, even though the limit is 50 ETH.
- Bob now has 100 ETH, exceeding the max potential debt limit by 50 ETH.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract lets people borrow money using digital collectibles as collateral. It is supposed to stop total borrowing from going over a set limit, but it checks the limit before counting the new loan, so someone can take several loans that each look fine but together go over the limit. This could leave the lending pool short of money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.