Blocklisting in payment ERC20 can cause rented NFT to be stuck in Safe
When a rental is stopped, the payment escrow contract attempts to transfer ERC20 payments to the renter or lender. If either party is blocklisted by the ERC20 token, the transfer reverts, preventing the rental from being stopped and leaving the rented NFT stuck in the renter's Safe.
stackachu Follow with albertwh1te, oakcobalt and 27 others
Originally disclosed on Code4rena
Submitted by stackachu, also found by albertwh1te, oakcobalt, EV_om, sin1st3r__, 0xc695, serial-coder, hash, rbserver, DeFiHackLabs, krikolkk, 0xabhay, evmboi32, hals, peanuts, Krace, lanrebayode77, KupiaSec, HSP, said, ladboy233, J4X, ZanyBonzy, 0xHelium, peter, 0xpiken, Qkite, marqymarq10, cccz, and holydevoti0n
When a rental is stopped, Stop.stopRent() transfers the rented NFT back from the renter’s Safe to the lender’s wallet and transfers the ERC20 payments from the payment escrow contract to the respective recipients (depending on the type of rental, those can be the renter, the lender, or both).
To transfer the ERC20 payments, PaymentEscrow.settlePayment() is called.
PaymentEscrow.settlePayment() will use _safeTransfer() (via _settlePayment() and _settlePaymentProRata() or _settlePaymentInFull()) to transfer the ERC20 payments to the recipients:
- If the rental was a BASE order, the payment is sent to the lender.
- If the rental was a PAY order and the rental period is over, the payment is sent to the renter.
- If the rental was a PAY order and the rental period is not over, the payment is split between the lender and the renter.
If either the payment recipient or the payment escrow contract are blocklisted in the payment ERC20, the transfer will fail and _safeTransfer() will revert. In this case the rental is not stopped, the rented NFT will still be in the renter’s Safe, and the payment will still be in the payment escrow contract.
Blocklisting is implemented by several stablecoins issued by centralized entities (e.g. USDC and USDT) to be able to comply with regulatory requirements (freeze funds that are connected to illegal activities).
There are multiple scenarios that can have impact here:
A. The renter of a PAY order rental is blocklisted: Even if the renter is already blocklisted before making the rental, the rental can still start, but ending the rental will not be possible, so the lender loses the rented NFT (it will be stuck in the Safe) and at least temporarily loses access to the payment (it will be stuck in the payment escrow, but a protocol admin could recover it).
B. The lender of a BASE order rental is blocklisted: Ending the rental will not be possible, so the lender loses the rented NFT and the payment. However, it is unlikely that the lender has been blocklisted arbitrarily during the rental or wasn’t aware of the blocklisting before the rental, so this scenario seems unlikely.
C. The payment escrow contract becomes blocklisted during the rental (if it were blocklisted before the rental, the rental couldn’t start): In this case the lender loses the rented NFT and the payment is lost. However, it seems unlikely that the payment escrow contract becomes blocklisted.
Impact
Out of the scenarios listed above, scenario A has the highest impact. Anyone who is blocklisted by a ERC20 contract can grief any lender of a PAY order lending offer that offers this ERC20 as payment of their rental NFT. The attacker only has to pay the gas fee to start the rental to carry out this attack.
Scenarios B and C are less severe (due to low likelihood) but still relevant, as the blocklisting carried out in the external payment ERC20 contract causes the loss of the rental NFT.
Proof of Concept
Add blocklisting to the MockERC20 contract:
diff --git a/test/mocks/tokens/standard/MockERC20.sol b/test/mocks/tokens/standard/MockERC20.sol
index 3e170c1..abcfaf7 100644
--- a/test/mocks/tokens/standard/MockERC20.sol
+++ b/test/mocks/tokens/standard/MockERC20.sol
@@ -4,8 +4,26 @@ pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin-contracts/token/ERC20/ERC20.sol";
contract MockERC20 is ERC20 {
+ mapping(address => bool) public isBlocklisted;
+
constructor() ERC20("MockERC20", "MERC20") {}
+ function setBlock(address account, bool status) public {
+ isBlocklisted[account] = status;
+ }
+
+ function transfer(address to, uint256 value) public override returns (bool) {
+ if (isBlocklisted[to] || isBlocklisted[msg.sender])
+ revert("You are blocked");
+ return super.transfer(to, value);
+ }
+
+ function transferFrom(address from, address to, uint256 value) public override returns (bool) {
+ if (isBlocklisted[to] || isBlocklisted[from])
+ revert("You are blocked");
+ return super.transferFrom(from, to, value);
+ }
+
function mint(address to, uint256 amount) public {
_mint(to, amount);
}
Add the following import to StopRent.t.sol:
import {Errors} from "@src/libraries/Errors.sol";
Add the following test to StopRent.t.sol:
function test_StopRent_PayOrder_InFull_StoppedByLender_RenterBlocklisted() public {
// Blocklist the renter
erc20s[0].setBlock(bob.addr, true);
// create a PAY order
createOrder({
offerer: alice,
orderType: OrderType.PAY,
erc721Offers: 1,
erc1155Offers: 0,
erc20Offers: 1,
erc721Considerations: 0,
erc1155Considerations: 0,
erc20Considerations: 0
});
// finalize the pay order creation
(
Order memory payOrder,
bytes32 payOrderHash,
OrderMetadata memory payOrderMetadata
) = finalizeOrder();
// create a PAYEE order. The fulfiller will be the offerer.
createOrder({
offerer: bob,
orderType: OrderType.PAYEE,
erc721Offers: 0,
erc1155Offers: 0,
erc20Offers: 0,
erc721Considerations: 1,
erc1155Considerations: 0,
erc20Considerations: 1
});
// finalize the pay order creation
(
Order memory payeeOrder,
bytes32 payeeOrderHash,
OrderMetadata memory payeeOrderMetadata
) = finalizeOrder();
// create an order fulfillment for the pay order
createOrderFulfillment({
_fulfiller: bob,
order: payOrder,
orderHash: payOrderHash,
metadata: payOrderMetadata
});
// create an order fulfillment for the payee order
createOrderFulfillment({
_fulfiller: bob,
order: payeeOrder,
orderHash: payeeOrderHash,
metadata: payeeOrderMetadata
});
// add an amendment to include the seaport fulfillment structs
withLinkedPayAndPayeeOrders({payOrderIndex: 0, payeeOrderIndex: 1});
// finalize the order pay/payee order fulfillment
(RentalOrder memory payRentalOrder, ) = finalizePayOrderFulfillment();
// speed up in time past the rental expiration
vm.warp(block.timestamp + 750);
// try to stop the rental order (will revert)
vm.prank(alice.addr);
vm.expectRevert(
abi.encodeWithSelector(
Errors.PaymentEscrowModule_PaymentTransferFailed.selector,
address(erc20s[0]),
bob.addr,
100
)
);
stop.stopRent(payRentalOrder);
// get the rental order hashes
bytes32 payRentalOrderHash = create.getRentalOrderHash(payRentalOrder);
// assert that the rental order still exists in storage
assertEq(STORE.orders(payRentalOrderHash), true);
// assert that the token are still rented out in storage
assertEq(STORE.isRentedOut(address(bob.safe), address(erc721s[0]), 0), true);
// assert that the ERC721 is still in the safe
assertEq(erc721s[0].ownerOf(0), address(bob.safe));
// assert that the offerer made a payment
assertEq(erc20s[0].balanceOf(alice.addr), uint256(9900));
// assert that the fulfiller did not received the payment
assertEq(erc20s[0].balanceOf(bob.addr), uint256(10000));
// assert that a payment is still in the escrow contract
assertEq(erc20s[0].balanceOf(address(ESCRW)), uint256(100));
}
Now the PoC can be run with:
forge test --match-path test/integration/StopRent.t.sol --match-test test_StopRent_PayOrder_InFull_StoppedByLender_RenterBlocklisted -vvv
Recommended Mitigation Steps
I see two ways to mitigate this:
- Implement a non-reverting transfer helper function used for payments when stopping the rental. In case of blocklisting, the NFT would still be returned to the lender while the payment ERC20 stays in the payment escrow contract (but could be recovered by an admin unless the payment escrow contract itself is blocklisted).
- Split stopping the rental and transferring the assets into separate steps, so that after stopping the rental, the lender and the renter have to call separate functions to claim their assets.
0xean (Judge) decreased severity to Medium
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 stopRent function performs the ERC20 payment transfer and the NFT return in a single transaction, and a revert in the payment transfer prevents the NFT from being returned.
Impact
A blocklisted renter can grief any lender of a PAY order by renting the NFT and then being unable to stop the rental, causing the NFT to be stuck in the renter's Safe and the payment to be stuck in escrow; scenarios where the lender or escrow contract is blocklisted are less likely but also cause loss of the NFT.
What the attacker needed
Renter is blocklisted by the payment ERC20; lender offers a PAY order with that ERC20; attacker pays gas to start the rental
The fix
The protocol should use a non-reverting transfer helper for payments when stopping the rental, so the NFT can still be returned to the lender while the payment stays in escrow, or split stopping the rental and transferring assets into separate steps.
How it was found
- Blocklist the renter address in the payment ERC20 token.
- Create a PAY order where the renter pays ERC20 to rent an NFT.
- Fulfill the order so the NFT is transferred to the renter's Safe.
- Advance time past the rental expiration.
- Call stopRent; the payment transfer to the blocklisted renter reverts.
- Observe that the rental order still exists, the NFT remains in the renter's Safe, and the payment stays in escrow.
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.
Some tokens like USDC can freeze specific addresses, meaning those addresses cannot send or receive the token. In this rental system, stopping a rental requires sending a payment. If the recipient is frozen, the payment fails and the whole stop operation reverts, so the rented NFT remains locked in the renter's wallet.
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.