This is maybe a contradictory idea but when you know the implementation of your token you can save gas if you use transfer/transferFrom instead of safeTransfer/safeTransferFrom.
You can consider removing the library in lines like that.
IERC20(INFINITY_TOKEN).safeTransferFrom(msg.sender, address(this), amount);@audit gas check if neccessary
Maybe you comment explaining why you use transfer. I believe that this would save lot of gas.
Function using nonReentrant modifier without making any external call
The function changeDuration#InfinityStaker.sol is using nonReentrant modifier but only modifies internal variables without making any external call.
getMaxEpochs() called twice in advanceEpoch#InifityToken.sol
In the function advanceEpoch#InifityToken.sol you are calling twice getMaxEpochs() which is an external contract call. Consider catching in a variable instead.
Gas Report for Infinity by PeritoFlores
Tautology in require (uint are always equal or higher than zero)
This is tautology
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/staking/InfinityStaker.sol#L193
I believe that you mean != 0, however this is not affecting the logic so I believe you could just remove it saving gas
Use delete instead of assigning zero to storage variable
The keyword delete refunds you with 15,000 gas. Consider using it for example in this function
Use constants when you can to save gas
The following variables could be constants .
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1161
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1170
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1187
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L1203
Use immutable variables when you can to save gas
Infinity token is a predefined address that you would not change
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/staking/InfinityStaker.sol#L25
Consider not using SafeERC20 for INFINITY TOKEN
This is maybe a contradictory idea but when you know the implementation of your token you can save gas if you use
transfer/transferFrom
instead ofsafeTransfer/safeTransferFrom
.You can consider removing the library in lines like that.
IERC20(INFINITY_TOKEN).safeTransferFrom(msg.sender, address(this), amount);@audit gas check if neccessary
Maybe you comment explaining why you use transfer. I believe that this would save lot of gas.
Function using nonReentrant modifier without making any external call
The function
changeDuration#InfinityStaker.sol
is using nonReentrant modifier but only modifies internal variables without making any external call.Avoid unnecessary initializations
Booleans initialized to false
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L42
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L108
Uint initialized to zero
In for loops avoid initializing
i
orj
to zeroAlso in the following lines the initialization is unnecessary
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L197
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L214
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L197
getMaxEpochs() called twice in advanceEpoch#InifityToken.sol
In the function
advanceEpoch#InifityToken.sol
you are calling twicegetMaxEpochs()
which is an external contract call. Consider catching in a variable instead.