buyAndSwap1155WETH Does Not Work As Intended
The buyAndSwap1155WETH function incorrectly uses msg.value instead of maxWethIn when calling _buyVaultToken, so it only works if the user sends both WETH and native ETH equal to maxWethIn. This causes the function to fail for normal users who only supply WETH.
Submitted by leastwood
The buyAndSwap1155WETH function in NFTXMarketplaceZap aims to facilitate buying and swapping ERC1155 tokens within a single transaction. The function expects to transfer WETH tokens from the msg.sender account and use these tokens in purchasing vault tokens. However, the _buyVaultToken call in buyAndSwap1155WETH actually uses msg.value and not maxWethIn. As a result, the function will not work unless the user supplies both WETH and native ETH amounts, equivalent to the maxWethIn amount.
Proof of Concept
function buyAndSwap1155WETH(
uint256 vaultId,
uint256[] memory idsIn,
uint256[] memory amounts,
uint256[] memory specificIds,
uint256 maxWethIn,
address[] calldata path,
address to
) public payable nonReentrant {
require(to != address(0));
require(idsIn.length != 0);
IERC20Upgradeable(address(WETH)).transferFrom(msg.sender, address(this), maxWethIn);
uint256 count;
for (uint256 i = 0; i < idsIn.length; i++) {
uint256 amount = amounts[i];
require(amount > 0, "Transferring < 1");
count += amount;
}
INFTXVault vault = INFTXVault(nftxFactory.vault(vaultId));
uint256 redeemFees = (vault.targetSwapFee() * specificIds.length) + (
vault.randomSwapFee() * (count - specificIds.length)
);
uint256[] memory swapAmounts = _buyVaultToken(address(vault), redeemFees, msg.value, path);
_swap1155(vaultId, idsIn, amounts, specificIds, to);
emit Swap(count, swapAmounts[0], to);
// Return extras.
uint256 remaining = WETH.balanceOf(address(this));
WETH.transfer(to, remaining);
}
Tools Used
Manual code review. Discussions with Kiwi.
Recommended Mitigation Steps
Consider updating the buyAndSwap1155WETH function such that the following line of code is used instead of this.
uint256[] memory swapAmounts = _buyVaultToken(address(vault), redeemFees, maxWethIn, path);
0xKiwi (NFTX) confirmed and resolved
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
Impact
The function does not work as intended unless the user supplies both WETH and native ETH, which defeats its purpose and could lock funds or cause failed transactions.
What the attacker needed
User calls buyAndSwap1155WETH with WETH
The fix
The function should be updated to use maxWethIn instead of msg.value in the _buyVaultToken call.
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.
This is a smart contract bug where a function that should let you buy and swap tokens with one type of token (WETH) mistakenly also requires you to send the native cryptocurrency (ETH) in the same amount. So if you try to use it normally, it won't work because the contract checks the wrong value.
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.