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

0 stars 0 forks source link

Gas Optimizations #253

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Gas Report

\<VAR>++ OR \<VAR> += 1 TO ++\<VAR> ALSO USE UNCHECKED FOR OPERATIONS NOT EXPECTED TO OVERFLOW

When the value of the post-loop increment/decrement is not stored or used in any calculations, the prefix increment/decrement operators (++i/--i) cost less gas PER LOOP than the postfix increment/decrement operators (i++/i--)

Use ++i rather than i++ to save gas

Instances include

i++ to ++i:

Also add unchecked:

CACHING LENGTH ON FOR

zeroswap/contracts/uniswapv2/UniswapV2Oracle.sol: 83 cachear el granularity

zeroswap/contracts/uniswapv2/UniswapV2Router02.sol: 214, 323 el path.leng-1 cachearlo

zeroswap/contracts/mocks/ComplexRewarderTime.sol: L157 zeroswap/contracts/uniswapv2/UniswapV2Oracle.sol: 83

State variables can be constant;

MasterChef.sol

MasterChef.sol#L59 MasterChef.sol#L63 MasterChef.sol#L65 MasterChef.sol#L77

Save gas avoiding initialize variables with 0

MasterChef.sol#L75 This will save you gas

uint256 public totalAllocPoint;
JeeberC4 commented 2 years ago

Appears to be an exact copy of #273. Marking this one invalid and keeping the other.