You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Public functions that could be declared external to save gas
Description
Following functions should be declared external, as functions that are never called by the contract internally should be declared external to save gas.
Given the use of Solidity compiler >= 0.8.0, there are default arithmetic checks for mathematical operations which consume additional gas for such checks internally. In expressions where we are absolutely sure of no overflows/underflows, one can use the unchecked primitive to wrap such expressions to avoid checks and save gas.
Gas Optimizations
Unused state variable
Description
Unused state variable.
Findings
LPToken.NATIVE
Recommended mitigation steps
Remove unused state variables to safe gas.
Public functions that could be declared external to save gas
Description
Following functions should be declared
external
, as functions that are never called by the contract internally should be declared external to save gas.Findings
ExecutorManager.getExecutorStatus()
ExecutorManager.getAllExecutors()
LiquidityFarming.setRewardPerSecond()
LiquidityFarming.getNftIdsStaked()
LiquidityFarming.getRewardRatePerSecond()
LiquidityPool.setTrustedForwarder()
LiquidityPool.setLiquidityProviders()
LiquidityPool.getExecutorManager()
LiquidityProviders.getTotalReserveByToken()
LiquidityProviders.getSuppliedLiquidityByToken()
LiquidityProviders.getTotalLPFeeByToken()
LiquidityProviders.getCurrentLiquidity()
LiquidityProviders.increaseCurrentLiquidity()
LiquidityProviders.decreaseCurrentLiquidity()
LiquidityProviders.getFeeAccumulatedOnNft()
LPToken.setSvgHelper()
LPToken.getAllNftIdsByUser()
LPToken.exists()
TokenManager.getEquilibriumFee()
TokenManager.getMaxFee()
TokenManager.getTokensInfo()
TokenManager.getDepositConfig()
TokenManager.getTransferConfig()
Recommended mitigation steps
Use the
external
attribute for functions never called from the contract.> 0
is less efficient than!= 0
for unsigned integersDescription
!= 0 is a cheaper (less gas) operation for unsigned integers within
require
statements compared to> 0
.Findings
LiquidityProviders.sol#L239
LiquidityProviders.sol#L283
LiquidityProviders.sol#L410
Recommended mitigation steps
Change
> 0
to!= 0
.Avoid long revert strings
Description
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met.
Revert strings that are longer than 32 bytes require at least one additional mstore, along with additional overhead for computing memory offset, etc.
Findings
ExecutorManager.sol#L17
LiquidityPool.sol#L77
Use
unchecked {}
primitive within for loopsGiven the use of Solidity compiler >= 0.8.0, there are default arithmetic checks for mathematical operations which consume additional gas for such checks internally. In expressions where we are absolutely sure of no overflows/underflows, one can use the
unchecked
primitive to wrap such expressions to avoid checks and save gas.Findings
ExecutorManager.sol#L31
Change to
Also here:
ExecutorManager.sol#L47
LiquidityFarming.sol#L233
WhitelistPeriodManager.sol#L180
WhitelistPeriodManager.sol#L228
WhitelistPeriodManager.sol#L248
LPToken.sol#L77
TokenManager.sol#L78
An array's length should be cached to save gas in for-loops
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Recommended implementation
Findings
ExecutorManager.sol#L31
ExecutorManager.sol#L47
LiquidityFarming.sol#L233
WhitelistPeriodManager.sol#L180
WhitelistPeriodManager.sol#L228
WhitelistPeriodManager.sol#L248
LPToken.sol#L77
TokenManager.sol#78
Reorder require statements in
LiquidityPool.sol:sendFundsToUser()
to save gas on revertDescription
Require statements can be placed earlier to reduce gas usage on revert.
Findings
LiquidityPool.sol#L271
Recommended implementation
Reorder require statements in
LiquidityProviders.sol:_increaseLiquidity()
to save gas on revertDescription
Require statements can be placed earlier to reduce gas usage on revert.
Findings
LiquidityProviders.sol#L283
Recommended implementation
Reorder require statements in
LiquidityProviders.sol:increaseNativeLiquidity()
to save gas on revertDescription
Require statements can be placed earlier to reduce gas usage on revert.
Findings
LiquidityProviders.sol#L334
Recommended implementation
Remove unused variable access in modifier
onlyValidLpToken()
Description
See
@audit-info
in following code snippet:Findings
LiquidityProviders.sol#L54
Unused named returns can be removed
Description
Removing unused named return variables can reduce gas usage and improve code clarity.
Recommended mitigation steps
Remove the unused named return variables or use them instead of creating additional variables.
Findings
hyphen/token/TokenManager.sol
L139 unnecessary named return
sender
hyphen/LiquidityProviders.sol
L457 unnecessary named return
sender
hyphen/LiquidityFarming.sol
L351 unnecessary named return
sender
hyphen/LiquidityPool.sol
L416 unnecessary named return
sender
The text was updated successfully, but these errors were encountered: