NestedFactory : User can utilise accidentally sent ETH funds via processOutputOrders() / processInputAndOutputOrders()
The NestedFactory contract accepts plain ETH transfers from any sender and its order processing functions do not verify that ETH input comes from the reserve, allowing anyone to create an output order using the contract's accidentally sent ETH balance. An attacker could thereby convert stray ETH into tokens for their own benefit.
Submitted by GreyArt
NestedFactory.sol#L71 NestedFactory.sol#L286-L296 NestedFactory.sol#L370-L375 NestedFactory.sol#L482-L492
Should a user accidentally send ETH to the NestedFactory, anyone can utilise it to their own benefit by calling processOutputOrders() / processInputAndOutputOrders(). This is possible because:
receive()has no restriction on the senderprocessOutputOrders()does not checkmsg.value, and rightly so, because funds are expected to come fromreserve.transferInputTokens()does not handle the case whereETHcould be specified as an address by the user for an output order.
if (address(_inputToken) == ETH) {
require(address(this).balance >= _inputTokenAmount, "NF: INVALID_AMOUNT_IN");
weth.deposit{ value: _inputTokenAmount }();
return (IERC20(address(weth)), _inputTokenAmount);
}
Hence, the attack vector is simple. Should a user accidentally send ETH to the contract, create an output Order with token being ETH and amount corresponding to the NestedFactory’s ETH balance.
Recommended Mitigation Steps
-
Since plain / direct
ETHtransfers are only expected to solely come fromweth(excluding payable functions), we recommend restricting the sender to beweth, like how it is done in[FeeSplitter](https://github.com/code-423n4/2022-02-nested/blob/main/contracts/FeeSplitter.sol#L101-L104).We are aware that this was raised previously here: code-423n4/2021-11-nested-findings#188 and would like to add that restricting the sender in the
receive()function will not affectpayablefunctions. From from what we see, plain ETH transfers are also not expected to come from other sources likeNestedReserveor operators.
receive() external payable {
require(msg.sender == address(weth), "NF: ETH_SENDER_NOT_WETH");
}
- Check that
_fromReserveis false in the scenarioaddress(_inputToken) == ETH.
if (address(_inputToken) == ETH) {
require(!_fromReserve, "NF: INVALID_INPUT_TOKEN");
require(address(this).balance >= _inputTokenAmount, "NF: INVALID_AMOUNT_IN");
weth.deposit{ value: _inputTokenAmount }();
return (IERC20(address(weth)), _inputTokenAmount);
}
maximebrugel (Nested Finance) 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
Likely the contract's receive function accepts ETH from any address and the order processing logic does not ensure that ETH used as input originates from the reserve, so any ETH balance held by the contract can be spent by an attacker.
Impact
An attacker could take any ETH accidentally sent to the contract and use it for their own orders, causing a loss to the original sender or the protocol.
What the attacker needed
ETH accidentally sent to the contract; attacker can call order processing functions
The fix
The receive function should be restricted to accept ETH only from the WETH contract, and the ETH input path should require that the funds are not coming from the reserve.
How it was found
- A user accidentally sends ETH to the NestedFactory contract.
- An attacker calls processOutputOrders() or processInputAndOutputOrders() and creates an output order with token set to ETH and an amount equal to the contract's ETH balance.
- The contract uses its ETH balance to deposit into WETH and fulfil the order, benefiting the attacker.
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 can hold Ether (ETH) that people send to it by mistake. This report shows that the contract did not check who sent the ETH or where it came from when processing orders, so anyone could use that stray ETH to buy tokens for themselves. The fix is to only accept ETH from the approved wrapper contract and to reject ETH that did not come from the reserve.
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.