Skip to content
Business logic Audit finding Advanced

Lien count per epoch is not updated ultimately locking the collateralized NFT

The lien count per epoch is not updated when a lien is bought out, so subsequent payments or liquidations for that lien revert. This can lock the collateralized NFT because the borrower cannot repay and liquidation may be blocked.

0xRajeev Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-astaria-judging/issues/194

Found by

0xRajeev

Summary

The lien count per epoch is not updated, causing payments to the lien and liquidation of the lien to revert.

Vulnerability Detail

The PublicVault contract keeps track of open liens per epoch to prevent starting a new epoch with open liens. The lien count for a given epoch is decreased whenever a lien is fully paid back (either through a regular payment or a liquidation payment). However, if a lien is bought out, the lien start will be set to the current block.timestamp and the duration to the newly provided duration.

If the borrower now wants to make a payment to this lien, the LienToken._payment function will evaluate the lien's current epoch and will use a different epoch as when the lien was initially created. The attempt to then call IPublicVault(lienOwner).decreaseEpochLienCount will fail, as the lien count for the new epoch has not been increased yet. The same will happen for liquidations.

Impact

After a lien buyout, payments to the lien and liquidating the lien will revert, which will ultimately lock the collateralized NFT.

This will certainly prevent the borrower from making payments towards that future-epoch lien in the current epoch because decreaseEpochLienCount() will revert. However, even after the epoch progresses to the next one via processEpoch(), the liensOpenForEpoch for the new epoch still does not account for the previously bought out lien aligned to this new epoch because liensOpenForEpoch is only updated in two places: 1. _increaseOpenLiens() which is not called by anyone 2. _afterCommitToLien() <- commitToLien() <-- <-- commitToLiens() which happens only for new lien commitments

This will prevent the borrower from making payments towards the previously bought lien that aligns to the current epoch, which will force a liquidation on exceeding lien duration. Depending on when the liquidation can be triggered, if this condition is satisfied PublicVault(owner).timeToEpochEnd() <= COLLATERAL_TOKEN.auctionWindow() then decreaseEpochLienCount() will revert to prevent auctioning and lock the borrower's collateral in the protocol.

Code Snippet

  1. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/PublicVault.sol#L259-L262
  2. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L634-L636
  3. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/LienToken.sol#L153
  4. https://github.com/sherlock-audit/2022-10-astaria/blob/main/src/AstariaRouter.sol#L399

Tool used

Manual Review

Recommendation

liensOpenForEpoch should be incremented when a lien is bought with a duration spilling into an epoch higher than the current one.

The original report as published on Sherlock, by 0xRajeev. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 lien count for the new epoch is not incremented when a lien is bought out with a duration that extends into a future epoch, so later decrements underflow or revert.

What the attacker needed

A lien exists; the lien is bought out with a duration extending into a…; the borrower attempts to repay or the lien is liquidated

The fix

The lien count for the epoch should be incremented when a lien is bought with a duration that extends into a future epoch.

How it was found

  1. A lien is bought out, setting its start to the current block timestamp and its duration to the new duration.
  2. The borrower attempts to make a payment to the lien.
  3. The payment function evaluates the lien's current epoch, which differs from the original epoch.
  4. The call to decreaseEpochLienCount fails because the lien count for the new epoch was not increased.
  5. The same failure occurs during liquidation, potentially locking the collateralized NFT.

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 tracks how many loans are open in each time period (epoch). When a loan is bought by someone else, its time period changes, but the count for the new period is not increased. Later, when the borrower tries to repay or the loan is liquidated, the contract tries to decrease a count that was never increased, so the action fails and the collateral (the NFT) gets stuck.

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.

More by 0xRajeev

View all

61 more disclosed reports, best first.

More from Astaria

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.