code-423n4 / 2021-12-yetifinance-findings

0 stars 0 forks source link

Unnecessary uint zero initialization #177

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

sirhashalot

Vulnerability details

Impact

uint256 variables are initialized to a default value of zero per Solidity docs: https://docs.soliditylang.org/en/latest/control-structures.html#default-value

Setting a variable to the default value is unnecessary. Shortening or removing lines of code where variables are initialized to zero can save gas. Here are a few articles describing this gas optimization: https://blog.polymath.network/solidity-tips-and-tricks-to-save-gas-and-reduce-bytecode-size-c44580b218e6#53bd https://medium.com/coinmonks/gas-optimization-in-solidity-part-i-variables-9d5775e43dde#4135

Proof of Concept

LPRewards/Unipool.sol: https://github.com/code-423n4/2021-12-yetifinance/blob/main/packages/contracts/contracts/LPRewards/Unipool.sol Line 80 Line 81

LPRewards/Pool2Unipool.sol: https://github.com/code-423n4/2021-12-yetifinance/blob/main/packages/contracts/contracts/LPRewards/Pool2Unipool.sol Line 80 Line 81

Dependencies/YetiCustomBase.sol: https://github.com/code-423n4/2021-12-yetifinance/blob/main/packages/contracts/contracts/Dependencies/YetiCustomBase.sol Line 35 Line 56 Line 142 Line 163

Tools Used

Manual analysis

Recommended Mitigation Steps

Instead of initializing a variable to zero, such as uint256 abc = 0;, the line can be shortened to uint256 abc; as Solidity automatically initializes uint variables to zero.

kingyetifinance commented 2 years ago

@LilYeti : Duplicate #13

alcueca commented 2 years ago

Duplicate #170