Payments and liquidations of multiple liens will revert and can be exploited, causing payer fund loss
The contract stores liens in an array and deletes entries when fully paid, which shifts the indices of remaining liens. Paying or liquidating multiple liens in a loop then reverts or pays the wrong lien, and an attacker can front-run a payment to force the victim to pay the attacker's lien instead.
Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/172
Found by
0xRajeev
Summary
The liens array and its indexes are changed whenever a lien is fully paid back. Therefore, referencing liens by their position in the array is broken because indices change. Payments and liquidations of multiple liens within a loop will revert and can be exploited by sandwiching liens to force a payment to the attacker's lien.
Vulnerability Detail
Whenever a lien position is fully paid back, the lien is deleted from the liens array. This means that the array is shortened and the indices of the remaining liens are changed. This is problematic when paying back liens in a loop because the indices of the remaining liens are changed which will cause revert with an index out-of-bounds error.
One can be exploited to pay for a different (attacker's) lien position because the lien array gets shortened when another payment (by the attacker or someone else) beforehand causes a deleted lien position.
Impact
Liquidations of multiple liens and payments against a collateral token and all its liens will revert. This will result in the collateral NFT being locked forever.
Exploit scenario: A malicious junior debt holder can buy out a senior debt (sandwich the original borrower effectively) to trigger this sequence of actions. For e.g., if the liens array is [1, 5, 3] where the malicious junior lien holder of 3 also buys out 1 and front-runs the borrower's intended payment for 5 by repaying 1 and forcing the array to shorten to [5, 3] will make the borrower pay off their lien of 3 instead of borrower's lien of 5. Effectively, a lien holder can "force" a payment to their own lien instead of another one.
Code Snippet
- https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L663
- https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L418
- https://github.com/sherlock-audit/2022-10-astaria/blob/main/lib/astaria-gpl/src/AuctionHouse.sol#L296
Tool used
Manual Review
Recommendation
Revisit and fix the entire logic that manages positions with the liens array addition, traversal and deletion.
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 code identifies liens by their mutable index in an array that is shortened on deletion, instead of by a stable identifier.
Impact
Payments and liquidations of multiple liens will revert, which can lock the collateral NFT forever, and an attacker can force a payment to go to their own lien.
What the attacker needed
Multiple liens on one collateral token; attacker holds a junior lien; attacker can front-run the victim's payment
The fix
The logic that adds, traverses and deletes entries in the `liens` array should be revisited and fixed, for example by using stable identifiers instead of array positions.
How it was found
- A malicious junior debt holder buys out a senior debt.
- The attacker front-runs the borrower's intended payment by repaying their own lien, which deletes it and shortens the array.
- The borrower's payment then targets the shifted index and pays the attacker's lien instead of the intended one.
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 lien is a claim on a collateral token, like a debt secured by an NFT. The code keeps all liens in a list and refers to each by its position (first, second, third). When one lien is fully paid, it is removed from the list, so every later lien moves up one place. Any code that still uses the old positions then points at the wrong lien or runs off the end of the list.
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.