Marketplace may call onERC721Received() and create a lien during buyNftFromMarket() , creating divergence
The contract's onERC721Received() check only blocks registered marketplaces, but when buying through Reservoir's router, the actual NFT transfer comes from an executor contract that is not whitelisted. This allows a new lien to be created during buyNftFromMarket(), so two liens track the same NFT.
The contract supports a “push-based” NFT supply, where the price and rate are embedded in the data bytes. This way, the lender doesn’t need to additionally approve the NFT, but can just transfer it directly to the contract. However, since the contract also interacts with the marketplace to buy/sell NFT, it has to prevent the issue where the marketplace also sends data bytes, which might tie 1 NFT with 2 different liens and create divergence.
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4) {
if (data.length == 64) {
// @audit marketplace is router so the executor contract might not be whitelisted
if (registeredMarketplaces[operator]) {
/// @dev transfer coming from registeredMarketplaces will go through buyNftFromMarket, where the NFT
/// is matched with an existing lien (realize PnL) already. If procceds here, this NFT will be tied
/// with two liens, which creates divergence.
revert Errors.Unauthorized();
}
/// @dev MAX_PRICE and MAX_RATE should each be way below bytes32
(uint256 price, uint256 rate) = abi.decode(data, (uint256, uint256));
/// @dev the msg sender is the NFT collection (called by safeTransferFrom's _checkOnERC721Received check)
_supplyNft(from, msg.sender, tokenId, price, rate);
}
return this.onERC721Received.selector;
}
The contract prevents it by using the registeredMarketplaces[] mapping, where it records the address of the marketplace. This check is explicitly commented in the codebase.
However, this is not enough. The protocol plans to integrate with Reservoir’s Router contract, so only the Router address is whitelisted in registeredMarketplaces[]. But the problem is, the address that transfers the NFT is not the Router, but the specific Executor contract, which is not whitelisted.
As a result, the marketplace might bypass this check and create a new lien in onERC721Received() during the buyNftFromMarket() flow, thus making 2 liens track the same NFT.
Proof of Concept
Function _execBuyNftFromMarket() does a low-level call to the exchange.
// execute raw order on registered marketplace
bool success;
if (useToken == 0) {
// use ETH
// solhint-disable-next-line avoid-low-level-calls
(success, ) = marketplace.call{value: amount}(tradeData);
} else if (useToken == 1) {
// use WETH
weth.deposit{value: amount}();
weth.approve(marketplace, amount);
// solhint-disable-next-line avoid-low-level-calls
(success, ) = marketplace.call(tradeData);
}
The contract calls to Reservoir’s router contract, which then calls to a specific module to execute the buy.
We are considering adding ReentrancyGaurd around all functions that modify the lien (to prevent other issues like https://github.com/code-423n4/2023-05-particle-findings/issues/14). Here, we should be able to re-use the ReentrancyGaurd variable to prevent divergence.
The original report as published on Code4rena, by minhquanym. 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
Impact
The marketplace could bypass the check and create a new lien during buyNftFromMarket(), so two liens track the same NFT, creating divergence.
What the attacker needed
Protocol integrates with Reservoir router; marketplace is registered; buyNftFromMarket() is called
The fix
The project fixed it by using a reentrancy guard flag to detect when the contract is in the buyNftFromMarket() flow and revert in onERC721Received().
How it was found
The contract calls the registered marketplace (Reservoir router) with trade data.
The router calls a specific module (executor) to execute the buy.
The executor transfers the NFT, triggering onERC721Received() with data length 64.
Because the executor is not in registeredMarketplaces, the check passes and a new lien is created.
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
A lien is a claim on an NFT. The contract tries to stop a marketplace from creating a second lien while it is buying an NFT, but it only checks the marketplace's main address. The marketplace uses a helper contract to move the NFT, and that helper is not on the list, so the check is bypassed.
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.