Skip to content
Business logic Audit finding Intermediate

Return variable can remain unassigned in _sendForReceiver

The _sendForReceiver function only returns a value in its if branch, so when a receiver has isContract set to false the function implicitly returns false. The distribute function then treats this as a failure and sends the remaining token balance to the treasury instead of the receiver.

sirhashalot Follow

Originally disclosed on Code4rena

Submitted by sirhashalot, also found by pauliax

The _sendForReceiver() function only sets a return function in the “if” code block, not the “else” case. If the “else” case is true, no value is returned. The result of this oversight is that the _sendForReceiver() function called from the distribute() function could sucessfully enter its else block if a receiver has isContract set to False and successfully transfer the amountToSend value. The ditribute() function will then have leftover > 0 and send currentTokenBalance to the treasury. This issue is partially due to Solidity using implicit returns, so if no bool value is explicitly returned, the default bool value of False will be returned.

This problem currently occurs for any receiver with isContract set to False. The _addReceiver function allows for isContract to be set to False, so such a condition should not result in tokens being sent to the treasury as though it was an emergency scenario.

Proof of Concept

The else block is missing a return value https://github.com/code-423n4/2021-12-nftx/blob/194073f750b7e2c9a886ece34b6382b4f1355f36/nftx-protocol-v2/contracts/solidity/NFTXSimpleFeeDistributor.sol#L167-L169

Tools Used

VS Code “Solidity Visual Developer” extension

Recommended Mitigation Steps

Verify that functions with a return value do actually return a value in all cases. Adding the line return true; can be added to the end of the else block as one way to resolve this.

Alternatively, if isContract should never be set to False, the code should be designed to prevent a receiver from being added with this value.

0xKiwi (NFTX) confirmed and resolved


The original report as published on Code4rena, by sirhashalot. 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.

How it worked

Root cause

Likely a missing return statement in the else branch of _sendForReceiver, combined with Solidity's implicit default of false for an unassigned bool return value.

Impact

Any receiver with isContract set to false can have its fee distribution misrouted to the treasury, so legitimate receivers may lose funds that were meant for them.

What the attacker needed

A receiver with isContract set to false; fee distribution triggered

The fix

The report recommends ensuring every code path returns a value, for example by adding a true return at the end of the else block, or preventing receivers from being added with isContract set to false; the project confirmed and resolved it.

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 function is supposed to give back an answer (a true or false value) to whoever called it. Here, one path through the function forgets to give an answer, so the programming language quietly supplies 'false'. The caller reads that 'false' as 'the transfer failed' and moves the tokens to a treasury wallet instead of the intended receiver.

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.

More by sirhashalot

View all

10 more disclosed reports, best first.

More from NFTX contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.