Skip to content
DoS Audit finding Intermediate

ParticleExchange.auctionBuyNft and ParticleExchange.withdrawEthWithInterest function calls can be DOS’ed

A borrower contract can revert its receive function to block auctionBuyNft and withdrawEthWithInterest calls, preventing the lender from concluding an auction or claiming funds. This denial-of-service can be triggered at low cost by the borrower.

rbserver Follow with d3e4, adriro and 2 others

Originally disclosed on Code4rena

Submitted by rbserver, also found by d3e4, adriro, bin2chen, and minhquanym

When lien.borrower is a contract, its receive function can be coded to conditionally revert based on a state boolean variable controlled by lien.borrower’s owner. As long as payback > 0 is true, lien.borrower’s receive function would be called when calling the following ParticleExchange.auctionBuyNft function. In this situation, if the owner of lien.borrower intends to DOS the ParticleExchange.auctionBuyNft function call, especially when lien.credit is low or 0, she or he would make lien.borrower’s receive function revert.

https://github.com/code-423n4/2023-05-particle/blob/bbd1c01407a017046c86fdb483bbabfb1fb085d8/contracts/protocol/ParticleExchange.sol#L688-L748

    function auctionBuyNft(
        Lien calldata lien,
        uint256 lienId,
        uint256 tokenId,
        uint256 amount
    ) external override validateLien(lien, lienId) auctionLive(lien) {
        ...

        // pay PnL to borrower
        uint256 payback = lien.credit + lien.price - payableInterest - amount;
        if (payback > 0) {
            payable(lien.borrower).transfer(payback);
        }

        ...
    }

Moreover, after the auction of the lien is concluded, calling the following ParticleExchange.withdrawEthWithInterest function can call lien.borrower’s receive function, as long as lien.credit > payableInterest is true. In this case, the owner of lien.borrower can also make lien.borrower’s receive function revert to DOS, the ParticleExchange.withdrawEthWithInterest function call.

https://github.com/code-423n4/2023-05-particle/blob/bbd1c01407a017046c86fdb483bbabfb1fb085d8/contracts/protocol/ParticleExchange.sol#L192-L223

    function withdrawEthWithInterest(Lien calldata lien, uint256 lienId) external override validateLien(lien, lienId) {
        ...

        uint256 payableInterest = _calculateCurrentPayableInterest(lien);

        // verify that the liquidation condition has met (borrower insolvent or auction concluded)
        if (payableInterest < lien.credit && !_auctionConcluded(lien.auctionStartTime)) {
            revert Errors.LiquidationHasNotReached();
        }

        // delete lien (delete first to prevent reentrancy)
        delete liens[lienId];

        // transfer ETH with interest back to lender
        payable(lien.lender).transfer(lien.price + payableInterest);

        // transfer PnL to borrower
        if (lien.credit > payableInterest) {
            payable(lien.borrower).transfer(lien.credit - payableInterest);
        }

        ...
    }

Similar situations can happen if lien.borrower does not implement the receive or fallback function intentionally; in which lien.borrower’s owner is willing to pay some position margin, which can be a low amount depending on the corresponding lien, to DOS the ParticleExchange.auctionBuyNft and ParticleExchange.withdrawEthWithInterest function calls.

Proof of Concept

The following steps can occur for the described scenario for the ParticleExchange.auctionBuyNft function. The situation for the ParticleExchange.withdrawEthWithInterest function is similar:

  1. Alice is the owner of lien.borrower for a lien.
  2. The lender of the lien starts the auction for the lien.
  3. Alice does not want the auction to succeed, so she makes lien.borrower’s receive function revert by changing the controlled state boolean variable for launching the DOS attack to true.
  4. For a couple of times during the auction period, some other users are willing to win the auction by supplying an NFT from the same collection, but their ParticleExchange.auctionBuyNft function calls all revert.
  5. Since no one’s ParticleExchange.auctionBuyNft transaction is executed at the last second of the auction period, the auction is DOS’ed.

Recommended Mitigation Steps

The ParticleExchange.auctionBuyNft and ParticleExchange.withdrawEthWithInterest functions can be updated to record the payback and lien.credit - payableInterest amounts that should belong to lien.borrower, instead of directly sending these amounts to lien.borrower. Then, a function can be added to let lien.borrower call and receive these recorded amounts.

Assessed type

DoS

hansfriese (judge) increased severity to High and commented:

PoC -> Marked as primary

wukong-particle (Particle) confirmed, disagreed with severity and commented:

Acknowledged the issue and agreed with the suggestion. But this might be medium severity since it’s contained with only this borrower’s asset and fund, not speared to the protocol level.

hansfriese (judge) commented:

@wukong-particle - For the severity, I suggest High is appropriate.

According to C4 guideline:

High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).

For this vulnerability, a malicious borrower can prevent the lender from taking action for defaulted lien. So a borrower can wait as long as he wants and the lender can not claim NFT or ETH. The likelihood and the impact are both high. I would like to note that there is no cost to the borrower for this exploit.

wukong-particle (Particle) commented:

@hansfriese - thanks for the suggestion, I agree. We can mark this issue as high severity.

wukong-particle (Particle) commented:

Fixed. Want to check with you about the changes we made. There are three major modifications here:

(1) As suggested, we put the trader earning into a pull based approach — we created a mapping(address => uint256) public accountBalance;, and do accountBalance[account] += gainedAmount for trader profit. In addition, besides auctionBuyNft and withdrawEthWithInterest, we default all trader profit (i.e., from buyNftFromMarket, repayWithNft) into accountBalance, as opposed to a direct transfer back, for consistency.

(2) We merged accruedInterest into accountBalance too, for simplicity. So this is like each account has a wallet in the contract. For treasury calculation, we move all calculations into interest accrual time as opposed to accountBalance withdrawal time, so that treasury still only takes the interest part, but not the trader gain as before.

(3) At sellNftToMarket, by default the trader will use the balance from the contract as their margin. If the balance is not enough, the trader can choose to top up the margin. Thus, the margin will be an input into the function, as opposed to msg.value. The logic is as follows:

    if (margin > msg.value + accountBalance[msg.sender]) {
          revert Errors.Overspend();
    }
    if (margin > msg.value) {
          // newly deposited value not enough, use from account balance
          accountBalance[msg.sender] -= (margin - msg.value);
    } else if (margin < msg.value) {
          // newly deposited value more than enough, top up account balance
          accountBalance[msg.sender] += (msg.value - margin);
    }

The original report as published on Code4rena, by rbserver. 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 contract uses direct Ether transfers to the borrower, which can be blocked if the borrower's receive function reverts.

Impact

A malicious borrower can prevent the lender from concluding an auction or withdrawing funds, potentially locking the lender's assets indefinitely.

What the attacker needed

Borrower is a contract; borrower controls receive function; lender starts auction

The fix

The contract was updated to use a pull-based approach, recording amounts in a balance mapping instead of sending Ether directly.

How it was found

  1. Alice owns a borrower contract for a lien.
  2. The lender starts an auction for the lien.
  3. Alice sets a state variable so the borrower contract's receive function reverts.
  4. Other users try to win the auction by calling auctionBuyNft, but their calls revert.
  5. No successful auctionBuyNft transaction occurs before the auction ends, so the auction is blocked.

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 smart contract sends Ether to another contract, the receiving contract's code runs and can refuse the payment by causing an error. Here, a borrower contract can refuse payments so that the exchange's functions fail, stopping the lender from finishing an auction or getting their money back.

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 rbserver

View all

51 more disclosed reports, best first.

More from Particle Leverage AMM Protocol Invitational

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.