Skip to content
DoS Audit finding Intermediate

Liquidation will fail if value set as liquidationInitialAsk > 2**88-1 , causing collateral to be permanently locked

A lien's liquidationInitialAsk can be set to any uint256, but when liquidating, the value is cast to uint88, causing a revert if it exceeds the maximum uint88. This prevents the auction from starting, permanently locking the collateral.

kaden Follow with rvierdiiev

Originally disclosed on Code4rena

Submitted by kaden, also found by rvierdiiev

https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/LienToken.sol#L340

When a lien is initially created, the liquidationInitialAsk can be set as any uint256 value >= the amount of underlying borrowed. Later on however, if the position is liquidated, an auction is created which casts the liquidationInitialAsk value to a uint88. Taking a look at the function in SafeCastLib.sol, we can see that if the value is greater than the max uint88 value, execution is reverted:

function safeCastTo88(uint256 x) internal pure returns (uint88 y) {
  require(x < 1 << 88);

  y = uint88(x);
}

This reversion prevents auctions from ever being initialized, and since the only way to retrieve the collateral after the loan has expired is through auction, the collateral is permanently locked in the contract.

For reference, setting the initialLiquidationAsk > 309,485,009.8213451 DAI would trigger this error, and with a lesser value or higher decimal collateral, this may require a much lower USD equivalent. Additionally, setting a price this high is not particularly unrealistic considering it’s the starting price for a dutch auction in which it should be intentionally priced much higher than it’s worth.

Proof of Concept:

We can create the following test in AstariaTest.t.sol to verify:

function testCannotLiquidateTooHighInitialAsk() public {
  TestNFT nft = new TestNFT(3);
  vm.label(address(nft), "nft");
  address tokenContract = address(nft);
  uint256 tokenId = uint256(1);
  address publicVault = _createPublicVault({
    strategist: strategistOne,
    delegate: strategistTwo,
    epochLength: 14 days
  });

  _lendToVault(
    Lender({addr: address(1), amountToLend: 50 ether}),
    publicVault
  );

  uint256 vaultTokenBalance = IERC20(publicVault).balanceOf(address(1));
  ILienToken.Stack[] memory stack;
  (, stack) = _commitToLien({
    vault: publicVault,
    strategist: strategistOne,
    strategistPK: strategistOnePK,
    tokenContract: tokenContract,
    tokenId: tokenId,
    lienDetails: ILienToken.Details({
      maxAmount: 50 ether,
      rate: (uint256(1e16) * 150) / (365 days),
      duration: 10 days,
      maxPotentialDebt: 0 ether,
      liquidationInitialAsk: type(uint256).max
    }),
    amount: 5 ether,
    isFirstLien: true
  });

  uint256 collateralId = tokenContract.computeId(tokenId);

  skip(14 days); // end of loan
  vm.expectRevert();
  OrderParameters memory listedOrder = ASTARIA_ROUTER.liquidate(
    stack,
    uint8(0)
  );
}

Recommendation

This can be avoided by using a uint256 as the auctionData.startAmount.

SantiagoGregory (Astaria) confirmed


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

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

The liquidationInitialAsk is stored as a uint256 but later cast to uint88 without checking that it fits, causing a revert when it exceeds the uint88 maximum.

Impact

The auction cannot be initialised, so the collateral remains permanently locked in the contract.

What the attacker needed

A lien with liquidationInitialAsk > max uint88; loan expires without repayment

The fix

The auctionData.startAmount should be changed to a uint256 to accommodate the full range of liquidationInitialAsk.

How it was found

  1. Create a public vault and lend to it.
  2. Commit to a lien with liquidationInitialAsk set to a value greater than the maximum uint88.
  3. Skip time until the loan expires.
  4. Call liquidate on the lien; the transaction reverts.

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.

When a loan is created, the borrower sets a starting price for an auction that happens if they don't repay. That price can be very large, but the code that starts the auction can only handle smaller numbers. If the price is too big, the auction fails to start, and the collateral (the item used to secure the loan) gets stuck forever.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by kaden

View all

2 more disclosed reports, best first.

More from Astaria contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.