Skip to content
Access control Audit finding Intermediate

Anyone can wipe complete state of any collateral at any point

The settlement function in the ClearingHouse contract could be called by anyone for any collateral, even when no auction had taken place, because a check used an AND instead of an OR. This allowed an attacker to wipe all lien records and burn the borrower's collateral token, permanently removing their claim to the underlying asset.

obront Follow with c7e7eff, KIntern_NA and 1 other

Originally disclosed on Code4rena

Submitted by obront, also found by c7e7eff, KIntern_NA, and Koolex

https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/ClearingHouse.sol#L114-L167 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/CollateralToken.sol#L524-L545 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/LienToken.sol#L497-L510 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/LienToken.sol#L623-L656

The Clearing House is implemented as an ERC1155. This is used to settle up at the end of an auction. The Clearing House’s token is listed as one of the Consideration Items, and when Seaport goes to transfer it, it triggers the settlement process.

This settlement process includes deleting the collateral state hash from LienToken.sol, burning all lien tokens, deleting the idToUnderlying mapping, and burning the collateral token. These changes effectively wipe out all record of the liens, as well as removing any claim the borrower has on their underlying collateral.

After an auction, this works as intended. The function verifies that sufficient payment has been made to meet the auction criteria, and therefore all these variables should be zeroed out.

However, the issue is that there is no check that this safeTransferFrom function is being called after an auction has completed. In the case that it is called when there is no auction, all the auction criteria will be set to 0, and therefore the above deletions can be performed with a payment of 0.

This allows any user to call the safeTransferFrom() function for any other user’s collateral. This will wipe out all the liens on that collateral, and burn the borrower’s collateral token, and with it their ability to ever reclaim their collateral.

Proof of Concept

The flow is as follows:

  • safeTransferFrom(offerer, buyer, paymentToken, amount, data)
  • _execute(offerer, buyer, paymentToken, amount)
  • using the auctionStack in storage, it calculates the amount the auction would currently be listed at
  • it confirms that the Clearing House has already received sufficient paymentTokens for this amount
  • it then transfers the liquidator their payment (currently 13%)
  • it calls LienToken#payDebtViaClearingHouse(), which pays back all liens, zeros out all lien storage and deletes the collateralStateHash
  • if there is any remaining balance of paymentToken, it transfers it to the owner of the collateral
  • it then calls Collateral#settleAuction(), which deletes idToUnderlying, collateralIdToAuction and burns the collateral token

In the case where the auction hasn’t started, the auctionStack in storage is all set to zero. When it calculates the payment that should be made, it uses _locateCurrentAmount, which simply returns endAmount if startAmount == endAmount. In the case where they are all 0, this returns 0.

The second check that should catch this occurs in settleAuction():

    if (
      s.collateralIdToAuction[collateralId] == bytes32(0) &&
      ERC721(s.idToUnderlying[collateralId].tokenContract).ownerOf(
        s.idToUnderlying[collateralId].tokenId
      ) !=
      s.clearingHouse[collateralId]
    ) {
      revert InvalidCollateralState(InvalidCollateralStates.NO_AUCTION);
    }

However, this check accidentally uses an && operator instead of a ||. The result is that, even if the auction hasn’t started, only the first criteria is false. The second is checking whether the Clearing House owns the underlying collateral, which happens as soon as the collateral is deposited in CollateralToken.sol#onERC721Received():

      ERC721(msg.sender).safeTransferFrom(
        address(this),
        s.clearingHouse[collateralId],
        tokenId_
      );

Recommended Mitigation Steps

Change the check in settleAuction() from an AND to an OR, which will block any collateralId that isn’t currently at auction from being settled:

    if (
      s.collateralIdToAuction[collateralId] == bytes32(0) ||
      ERC721(s.idToUnderlying[collateralId].tokenContract).ownerOf(
        s.idToUnderlying[collateralId].tokenId
      ) !=
      s.clearingHouse[collateralId]
    ) {
      revert InvalidCollateralState(InvalidCollateralStates.NO_AUCTION);
    }

SantiagoGregory (Astaria) confirmed


The original report as published on Code4rena, by obront. 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

Likely the access control check in settleAuction() used a logical AND (&&) instead of OR (||), so it only reverted when both conditions were true, allowing settlement when no auction existed.

Impact

Any user could permanently wipe all lien records and burn the borrower's collateral token, destroying the borrower's ability to reclaim their collateral.

What the attacker needed

None

The fix

The check in settleAuction() should be changed from an AND to an OR, so that any collateral not currently at auction is blocked from being settled.

How it was found

  1. Call safeTransferFrom with the victim's collateral as the offerer and any buyer address.
  2. The function _execute is triggered, which reads the auctionStack from storage.
  3. Since no auction has started, the auctionStack is all zeros, so the required payment amount is calculated as zero.
  4. The function proceeds to pay the liquidator, pay off all liens, delete the collateral state hash, and burn the collateral token.

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.

In this smart contract system, collateral is held as a token, and liens (debts) are recorded separately. When an auction finishes, a function clears all that data. But the check that should stop this function from running outside an auction was written with 'AND' instead of 'OR', so it passed when it should have failed. Anyone could call it and erase a borrower's collateral record, meaning they could never get their asset back.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by obront

View all

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

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.