The settleContract function uses safeTransferFrom to send an NFT to the bull, which calls the bull's onERC721Received hook. A malicious bull contract can consume all gas in that hook, causing the transfer to revert and preventing the bear from settling the contract.
The bull can intentionally cause out-of-gas and revert the transaction and prevent settleContract().
Vulnerability Detail
As IERC721(order.collection).safeTransferFrom() is used in settleContract() which will call IERC721Receiver(to).onERC721Received() when the to address is an contract.
This gives the bull a chance to intentionally prevent the transaction from happening by consuming a lot of gas and revert the whole transaction.
Impact
The bear (victim) can not settleContract() therefore cannot exercise their put option rights. The bull (attacker) always wins.
function settleContract(Order calldata order, uint tokenId) public nonReentrant {
bytes32 orderHash = hashOrder(order);
// ContractId
uint contractId = uint(orderHash);
address bear = bears[contractId];
// Check that only the bear can settle the contract
require(msg.sender == bear, "ONLY_BEAR");
// Check that the contract is not expired
require(block.timestamp < order.expiry, "EXPIRED_CONTRACT");
// Check that the contract is not already settled
require(!settledContracts[contractId], "SETTLED_CONTRACT");
address bull = bulls[contractId];
- // Try to transfer the NFT to the bull (needed in case of a malicious bull that block transfers)
- try IERC721(order.collection).safeTransferFrom(bear, bull, tokenId) {}
- catch (bytes memory) {
// Transfer NFT to BvbProtocol
IERC721(order.collection).safeTransferFrom(bear, address(this), tokenId);
// Store that the bull has to retrieve it
withdrawableCollectionTokenId[order.collection][tokenId] = bull;
- }
uint bearAssetAmount = order.premium + order.collateral;
if (bearAssetAmount > 0) {
// Transfer payment tokens to the Bear
IERC20(order.asset).safeTransfer(bear, bearAssetAmount);
}
settledContracts[contractId] = true;
emit SettledContract(orderHash, tokenId, order);
}
However,
Bulls can not directly stop bears from settling, as these 2 reports depict.
All they can do is increase transaction costs and add extra overhead, as correctly explained in
In this test, you will see that the bull transfers the position to a malicious bull which has an infinite loop on received, but still bear can settle by paying additional overhead.
Hence the issue is not that bulls can cause out-of-gas reverts but bulls adding additional gas overhead.
The recommendation is also wrong for https://github.com/sherlock-audit/2022-11-bullvbear-judging/issues/111.
Consider removing them from included issues.
test trace (check how it comes out of "out of gas revert" and still allows to settle)
The original report as published on Sherlock, by KingNFT. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
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 a minute. 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
Likely the use of safeTransferFrom without a gas limit allows a malicious receiver to consume all gas and revert the transaction.
Impact
The bear cannot settle the contract and exercise their put option rights, so the bull always wins.
What the attacker needed
Bull is a malicious contract; bear calls settleContract
The fix
The issue was fixed by removing the try-catch around safeTransferFrom and always transferring the NFT to the contract itself, storing the bull's address for later retrieval.
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 a minute. 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 contract sends an NFT to another contract, it calls a function on the receiving contract to confirm the transfer. A malicious receiver can waste all the gas in that function, making the whole transaction fail. This means the person trying to settle the contract cannot complete it.
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.