code-423n4 / 2022-06-nested-findings

0 stars 1 forks source link

Gas Optimizations #71

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

1. Can save gas when call _submitOutOrders() with _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

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

if (_toReserve) {
    feesAmount = (amountBought * entryFees) / 10000;
_transferToReserveAndStore(_batchedOrders.outputToken, amountBought - feesAmount, _nftId);
}
Yashiru commented 2 years ago

1. Can save gas when call _submitOutOrders() with _toReserve = false (Confirmed)

Gas optimization confirmed