Skip to content
Business logic Audit finding Advanced

The implied value of a public vault can be impaired, liquidity providers can lose funds

A partial repayment of a lien updates the stored lien amount to include accrued interest but does not update the last-updated timestamp, so a later slope calculation counts the same interest twice. This distorts the public vault's slope accumulator, making the vault's implied value either too low or too high, which can cause liquidity providers to lose funds.

Jeiwan Follow

Originally disclosed on Sherlock

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

Found by

Jeiwan

Summary

The implied value of a public vault can be impaired, liquidity providers can lose funds

Vulnerability Detail

Borrowers can partially repay their liens, which is handled by the _payment function (LienToken.sol#L594). When repaying a part of a lien, lien.amount is updated to include currently accrued debt (LienToken.sol#L605-L617):

Solidity
Lien storage lien = lienData[lienId];
lien.amount = _getOwed(lien); // @audit current debt, including accrued interest; saved to storage!

Notice that lien.amount is updated in storage, and lien.last wasn't updated.

Then, lien's slope is subtracted from vault's slope accumulator to be re-calculated after the repayment (LienToken.sol#L620-L630):

Solidity
if (isPublicVault) {
  // @audit calculates and subtracts lien's slope from vault's slope
  IPublicVault(lienOwner).beforePayment(lienId, paymentAmount);
}
if (lien.amount > paymentAmount) {
  lien.amount -= paymentAmount;
  // @audit lien.last is updated only after payment amount subtraction
  lien.last = block.timestamp.safeCastTo32();
  // slope does not need to be updated if paying off the rest, since we neutralize slope in beforePayment()
  if (isPublicVault) {
    // @audit re-calculates and re-applies lien's slope after the repayment
    IPublicVault(lienOwner).afterPayment(lienId);
  }
}

In the beforePayment function, LIEN_TOKEN().calculateSlope(lienId) is called to calculate lien's current slope (PublicVault.sol#L433-L442):

Solidity
function beforePayment(uint256 lienId, uint256 amount) public onlyLienToken {
  _handleStrategistInterestReward(lienId, amount);
  uint256 lienSlope = LIEN_TOKEN().calculateSlope(lienId);
  if (lienSlope > slope) {
    slope = 0;
  } else {
    slope -= lienSlope;
  }
  last = block.timestamp;
}

The calculateSlope function reads a lien from storage and calls _getOwed again (LienToken.sol#L440-L445):

Solidity
function calculateSlope(uint256 lienId) public view returns (uint256) {
  // @audit lien.amount includes interest accrued so far
  Lien memory lien = lienData[lienId];
  uint256 end = (lien.start + lien.duration);
  uint256 owedAtEnd = _getOwed(lien, end);
  // @audit lien.last wasn't updated in `_payment`, it's an older timestamp
  return (owedAtEnd - lien.amount).mulDivDown(1, end - lien.last);
}

This is where double counting of accrued interest happens. Recall that lien's amount already includes the interest that was accrued by this moment (in the _payment function). Now, interest is calculated again and is applied to the amount that already includes (a portion) it (LienToken.sol#L544-L550):

Solidity
function _getOwed(Lien memory lien, uint256 timestamp)
  internal
  view
  returns (uint256)
{
  // @audit lien.amount already includes interest accrued so far
  return lien.amount + _getInterest(lien, timestamp);
}

LienToken.sol#L177-L196:

Solidity
function _getInterest(Lien memory lien, uint256 timestamp)
  internal
  view
  returns (uint256)
{
  if (!lien.active) {
    return uint256(0);
  }
  uint256 delta_t;
  if (block.timestamp >= lien.start + lien.duration) {
    delta_t = uint256(lien.start + lien.duration - lien.last);
  } else {
    // @audit lien.last wasn't updated in `_payment`, so the `delta_t` is bigger here
    delta_t = uint256(timestamp.safeCastTo32() - lien.last);
  }
  return
    // @audit rate applied to a longer delta_t and multiplied by a bigger amount than expected
    delta_t.mulDivDown(lien.rate, 1).mulDivDown(
      lien.amount,
      INTEREST_DENOMINATOR
    );
}

Impact

Double counting of interest will result in a wrong lien slope, which will affect the vault's slope accumulator. This will result in an invalid implied value of a vault (PublicVault.sol#L406-L413):

  1. If miscalculated lien slope is bigger than expected, vault's slope will be smaller than expected (due to the subtraction in beforePayment), and vault's implied value will also be smaller. Liquidity providers will lose money because they won't be able to redeem the whole liquidity (vault's implied value, totalAssets, is used in the conversion of LP shares, ERC4626-Cloned.sol#L392-L412)
  2. If miscalculated lien slope is smaller than expected, vault's slope will be higher, and vaults implied value will also be higher. However, it won't be backed by actual liquidity, thus the liquidity providers that exit earlier will get a bigger share of the underlying assets. The last liquidity provider won't be able to get their entire share.

Code Snippet

See Vulnerability Detail

Tool used

Manual Review

Recommendation

In the _payment function, consider updating lien.amount after the beforePayment call:

Diff
--- a/src/LienToken.sol
+++ b/src/LienToken.sol
@@ -614,12 +614,13 @@ contract LienToken is ERC721, ILienToken, Auth, TransferAgent {
       type(IPublicVault).interfaceId
     );

-    lien.amount = _getOwed(lien);
-
     address payee = getPayee(lienId);
     if (isPublicVault) {
       IPublicVault(lienOwner).beforePayment(lienId, paymentAmount);
     }
+
+    lien.amount = _getOwed(lien);
+
     if (lien.amount > paymentAmount) {
       lien.amount -= paymentAmount;
       lien.last = block.timestamp.safeCastTo32();

In this case, lien's slope calculation won't be affected in the beforePayment call and the correct slope will be removed from the slope accumulator.

The original report as published on Sherlock, by Jeiwan. 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's amount is updated to include accrued interest before the slope is recalculated, but the lien's last timestamp is not updated at the same time, causing interest to be counted twice.

Impact

Liquidity providers could lose funds because the vault's implied value becomes incorrect, either preventing full redemption or allowing early exiters to take a larger share.

What the attacker needed

A public vault with an active lien; borrower makes a partial repayment

The fix

The _payment function should update lien.amount after calling beforePayment, so the slope calculation uses the correct pre-payment amount.

How it was found

  1. A borrower partially repays a lien, triggering the _payment function.
  2. The _payment function updates lien.amount to include accrued interest but does not update lien.last.
  3. The beforePayment function calls calculateSlope, which reads the updated lien.amount and the old lien.last.
  4. calculateSlope computes interest again on the already-increased amount over a longer time delta, double-counting interest.
  5. The incorrect slope is subtracted from the vault's slope accumulator, distorting the vault's implied value.

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 debt recorded on a blockchain. When someone pays back part of it, the code saves the new amount including interest but forgets to update the time of the last change. Later, when calculating how fast the debt grows, the code uses the old time and the already-increased amount, so it counts the same interest twice. This makes the vault's value estimate wrong, and people who put money in can get back less than they should.

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 Jeiwan

View all

69 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.