buyAndSwap1155WETH() function may cause loss of user assets
The buyAndSwap1155WETH function passes msg.value (which is zero) instead of the user-supplied maxWethIn to the internal _buyVaultToken call, so the swap fails. If a user mistakenly sends both ETH and WETH, the ETH becomes locked in the contract, causing asset loss.
Submitted by cccz
In the NFTXMarketplaceZap.sol contract, the buyAndSwap1155WETH function uses the WETH provided by the user to exchange VaultToken, but when executing the _buyVaultToken method, msg.value is used instead of maxWethIn. Since msg.value is 0, the call will fail.
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);
In extreme cases, when the user provides both ETH and WETH (the user approves the contract WETH in advance and calls the buyAndSwap1155WETH function instead of the buyAndSwap1155 function by mistake), the _buyVaultToken function will execute successfully, but because the buyAndSwap1155WETH function will not convert ETH to WETH, The user’s ETH will be locked in the contract, causing loss of user assets.
function _buyVaultToken(
address vault,
uint256 minTokenOut,
uint256 maxWethIn,
address[] calldata path
) internal returns (uint256[] memory) {
uint256[] memory amounts = sushiRouter.swapTokensForExactTokens(
minTokenOut,
maxWethIn,
path,
address(this),
block.timestamp
);
return amounts;
}
Recommended Mitigation Steps
- uint256[] memory swapAmounts = _buyVaultToken(address(vault), redeemFees, msg.value, path);
+ 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
Root cause
The function passes msg.value instead of maxWethIn to _buyVaultToken, so the swap uses zero WETH and any ETH sent is not converted or refunded.
Impact
The swap fails when only WETH is provided; if a user mistakenly sends both ETH and WETH, the ETH is locked in the contract, causing loss of user assets.
What the attacker needed
User approves WETH to the contract; user mistakenly calls buyAndSwap1155WETH with ETH and WETH
The fix
The function should pass maxWethIn instead of msg.value to _buyVaultToken; the report states this was confirmed and resolved.
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 uses the wrong variable. The function is supposed to use the amount of Wrapped Ether (WETH) the user provides, but it accidentally uses the amount of regular Ether (ETH) sent with the call, which is zero. As a result, the swap fails, and if the user also sent ETH, that ETH gets stuck in the contract.
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.