Destroy can avoid the bulk of fees
The destroy function in NestedFactory only charged fees on the small amount of tokens returned by the user's chosen orders, not on the remaining balance. An attacker could submit tiny swap orders and have the bulk of their portfolio transferred back to them fee-free.
Submitted by 0xliumin
A user can destroy their NFTs and not pay fees on most of their assets.
Proof of Concept
Alice has an NFT portfolio with 100 gwei dai and 100 gwei uni. Alice calls destroy on this NFT with buy token marked as dai. We would expect after this destroy step that she would pay 1 gwei dai in fees + 1 gwei uni worth of dai in fees, no matter what orders she selects.
Alice selects the following orders:
[{ operator: ZeroEx, token: uni, calldata: performSwap with a very small amount of uni for dai}
{ operator: Flat, token: dai, calldata: transfer a very small amount dai for dai}]
This set of orders doesn’t violate any of the require statements in the destroy function. Each order will complete successfully given the constraints here: MixinOperatorResolver.sol#L100-L101.
Fees aren’t collected on the leftover amount from the callOperator step, seen here: NestedFactory.sol#L446.
This means that Alice will only pay the fees on the dai that was output from the orders (a very small amount), and the rest of the 100 gwei uni and 100 gwei dai are transferred directly back to the attacker.
Recommended Mitigation Steps
Replace the safeTransfer with your safeTransferWithFees function. Or, if you don’t want users to have to pay fees on slippage, set a maximum “slippage” amount in the safeSubmitOrder function.
maximebrugel (Nested Finance) confirmed, but disagreed with High severity and commented:
Good one
harleythedog (judge) decreased severity to Medium and commented:
The warden has described a way to avoid fees even when large amounts are being withdrawn. An avoidance of fees more closely fits the criteria of a medium severity issue:
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
This is contrary to the previous audit that awarded a fee avoidance finding as high severity (which I disagree with).
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 fee is calculated only on the output of the submitted orders rather than on the full amount transferred back to the user, so leftover balances bypass the fee.
Impact
The attacker could avoid most withdrawal fees, leaking value from the protocol, though the judge rated this medium rather than high.
What the attacker needed
Holds a portfolio in the contract; can submit custom orders
The fix
The fee should be charged on the full amount transferred back, or a maximum slippage amount should be enforced in the order submission function; a fix PR was referenced.
How it was found
- Alice holds a portfolio with dai and uni balances.
- Alice calls destroy with dai as the buy token.
- Alice submits a tiny uni-to-dai swap order and a tiny dai-to-dai transfer order.
- The orders pass the require checks and complete.
- Fees are taken only on the tiny output, and the remaining balances are sent back to Alice.
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.
When you withdraw from this contract, it takes a small cut (a fee) of what you take out. The contract only calculated that cut on the tiny amount produced by the swap orders the user picked, so a user could pick almost worthless orders and still get nearly all their money back without paying the proper fee.
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.