NFTXSimpleFeeDistributor._sendForReceiver doesn’t return success if receiver is not a contract
The fee distribution function does not return success when a receiver is not a contract, causing the same fee amount to be sent twice to consecutive receivers. This leads to double payments for some receivers and missed payments for others.
Submitted by hyh
Double spending of fees being distributed will happen in favor of the first fee receivers in the feeReceivers list at the expense of the last ones. As _sendForReceiver doesn’t return success for completed transfer when receiver isn’t a contract, the corresponding fee amount is sent out twice, to the current and to the next fee receiver in the list. This will lead to double payments for those receivers who happen to be next in the line right after EOAs, and missed payments for the receivers positioned closer to the end of the list as the funds available are going to be already depleted when their turn comes.
Proof of Concept
distribute use _sendForReceiver to transfer current vault balance across feeReceivers: https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXSimpleFeeDistributor.sol#L67
_sendForReceiver returns a boolean that is used to move current distribution amount to the next receiver when last transfer failed. When _receiver.isContract is false nothing is returned, while safeTransfer is done: https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXSimpleFeeDistributor.sol#L168
This way _sendForReceiver will indicate that transfer is failed and leftover amount to be added to the next transfer, i.e. the amountToSend will be spent twice: https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXSimpleFeeDistributor.sol#L64
Recommended Mitigation Steps
Now:
function _sendForReceiver(FeeReceiver memory _receiver, uint256 _vaultId, address _vault, uint256 amountToSend) internal virtual returns (bool) {
if (_receiver.isContract) {
...
} else {
IERC20Upgradeable(_vault).safeTransfer(_receiver.receiver, amountToSend);
}
}
To be:
function _sendForReceiver(FeeReceiver memory _receiver, uint256 _vaultId, address _vault, uint256 amountToSend) internal virtual returns (bool) {
if (_receiver.isContract) {
...
} else {
IERC20Upgradeable(_vault).safeTransfer(_receiver.receiver, amountToSend);
return true;
}
}
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 `_sendForReceiver` function lacks a `return true` statement in the branch where the receiver is not a contract, so it implicitly returns `false` despite a successful transfer.
Impact
Receivers after non-contract addresses could receive double fees, while later receivers may receive nothing due to depleted funds.
What the attacker needed
FeeReceivers list contains a non-contract address; distribute is called
The fix
The function should return `true` after a successful `safeTransfer` in the non-contract branch.
How it was found
- Call `distribute` which iterates over `feeReceivers`.
- For a receiver that is not a contract, `_sendForReceiver` performs `safeTransfer` but returns `false`.
- The caller interprets `false` as failure and adds the amount to the next transfer.
- The next receiver receives both its own share and the previous amount, causing double payment.
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.
In a smart contract, a function that sends fees to a list of receivers checks if each receiver is a contract. If it is not a contract, the function still sends the fee but forgets to say it succeeded. The caller then thinks the transfer failed and sends the same amount again to the next receiver, so some people get paid twice and others get nothing.
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.