Malicious receiver can make distribute function denial of service
A malicious fee receiver contract can revert when its receiveRewards function is called, causing the distribute function to fail and block fee distribution. This denial of service affects all fee receivers until the malicious receiver is removed.
Submitted by cccz
In the NFTXSimpleFeeDistributor.sol contract, the distribute function calls the _sendForReceiver function to distribute the fee
function distribute(uint256 vaultId) external override virtual nonReentrant {
require(nftxVaultFactory != address(0));
address _vault = INFTXVaultFactory(nftxVaultFactory).vault(vaultId);
uint256 tokenBalance = IERC20Upgradeable(_vault).balanceOf(address(this));
if (distributionPaused || allocTotal == 0) {
IERC20Upgradeable(_vault).safeTransfer(treasury, tokenBalance);
return;
}
uint256 length = feeReceivers.length;
uint256 leftover;
for (uint256 i = 0; i <length; i++) {
FeeReceiver memory _feeReceiver = feeReceivers[i];
uint256 amountToSend = leftover + ((tokenBalance * _feeReceiver.allocPoint) / allocTotal);
uint256 currentTokenBalance = IERC20Upgradeable(_vault).balanceOf(address(this));
amountToSend = amountToSend> currentTokenBalance? currentTokenBalance: amountToSend;
bool complete = _sendForReceiver(_feeReceiver, vaultId, _vault, amountToSend);
if (!complete) {
leftover = amountToSend;
} else {
leftover = 0;
}
}
In the _sendForReceiver function, when the _receiver is a contract, the receiver’s receiveRewards function will be called. If the receiver is malicious, it can execute revert() in the receiveRewards function, resulting in DOS.
function _sendForReceiver(FeeReceiver memory _receiver, uint256 _vaultId, address _vault, uint256 amountToSend) internal virtual returns (bool) {
if (_receiver.isContract) {
IERC20Upgradeable(_vault).approve(_receiver.receiver, amountToSend);
// If the receive is not properly processed, send it to the treasury instead.
bytes memory payload = abi.encodeWithSelector(INFTXLPStaking.receiveRewards.selector, _vaultId, amountToSend);
(bool success,) = address(_receiver.receiver).call(payload);
// If the allowance has not been spent, it means we can pass it forward to next.
return success && IERC20Upgradeable(_vault).allowance(address(this), _receiver.receiver) == 0;
} else {
IERC20Upgradeable(_vault).safeTransfer(_receiver.receiver, amountToSend);
}
}
Proof of Concept
Recommended Mitigation Steps
The contract can store the fee sent to the receiver in a state variable, and then the receiver can take it out by calling a function.
0xKiwi (NFTX) confirmed, but disagreed with high severity and commented:
This is a permissioned entity, but this is a valid concern. User funds not at risk and the dao can remove the malciious receiver (if it ever gets there in the first place). Good thinking.
LSDan (judge) decreased severity to medium and commented:
This is a medium risk, not high. The attack has external requirements and is relatively easy for the DAO to mitigate.
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
A malicious receiver could block fee distribution to all receivers, but the text notes the receiver is permissioned and the DAO can remove it, so user funds are not at risk.
What the attacker needed
Malicious receiver is added to feeReceivers; receiver contract reverts on receiveRewards
The fix
The contract should store the fee for each receiver in a state variable and let the receiver withdraw it later, so a failing receiver cannot block others.
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.
A smart contract distributes fees to several receivers. One receiver can be a contract that refuses to accept the payment by causing an error (reverting). Because the distribution loop stops on that error, no other receiver gets paid either.
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.