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.
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.
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.
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:
Alice is the owner of lien.borrower for a lien.
The lender of the lien starts the auction for the lien.
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.
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.
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.
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.
@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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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
Alice owns a borrower contract for a lien.
The lender starts an auction for the lien.
Alice sets a state variable so the borrower contract's receive function reverts.
Other users try to win the auction by calling auctionBuyNft, but their calls revert.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.