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

0 stars 0 forks source link

Avoiding Initialization of Loop Index If It Is 0 #166

Closed code423n4 closed 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/code-423n4/2021-12-vader/blob/main/contracts/tokens/USDV.sol#L152

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;

jack-the-pug commented 2 years ago

Dup #126