code-423n4 / 2021-11-badgerzaps-findings

0 stars 0 forks source link

Avoiding Initialization of Loop Index If It Is 0 #29

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Meta0xNull

Vulnerability details

Impact

The local variable used as for loop index need not be initialized to 0 because the default value is 0. Avoiding this anti-pattern can save a few opcodes and therefore a tiny bit of gas.

Proof of Concept

https://github.com/Badger-Finance/badger-ibbtc-utility-zaps/blob/6f700995129182fec81b772f97abab9977b46026/contracts/IbbtcVaultZap.sol#L149 https://github.com/Badger-Finance/ibbtc/blob/d8b95e8d145eb196ba20033267a9ba43a17be02c/contracts/Zap.sol#L70

Tools Used

Manual Review

Recommended Mitigation Steps

Remove explicit 0 initialization of for loop index variable.

Before: for (uint256 i = 0;

After for (uint256 i;

GalloDaSballo commented 2 years ago

Agree with finding