Open code423n4 opened 2 years ago
_submitOutOrders()
_toReserve = false
In case _toReserve = false, it still calculates feesAmount using entryFees but do not use the result anywhere. We can save gas by calculating feesAmount only when _toReserve = true
feesAmount
entryFees
_toReserve = true
https://github.com/code-423n4/2022-06-nested/blob/b4a153c943d54755711a2f7b80cbbf3a5bb49d76/contracts/NestedFactory.sol#L443
Only calculate feesAmount only when _toReserve = true
if (_toReserve) { feesAmount = (amountBought * entryFees) / 10000; _transferToReserveAndStore(_batchedOrders.outputToken, amountBought - feesAmount, _nftId); }
Gas optimization confirmed
1. Can save gas when call
_submitOutOrders()
with_toReserve = false
In case
_toReserve = false
, it still calculatesfeesAmount
usingentryFees
but do not use the result anywhere. We can save gas by calculatingfeesAmount
only when_toReserve = true
Affected Code
https://github.com/code-423n4/2022-06-nested/blob/b4a153c943d54755711a2f7b80cbbf3a5bb49d76/contracts/NestedFactory.sol#L443
Recommended Mitigation Steps
Only calculate
feesAmount
only when_toReserve = true