code-423n4 / 2022-01-yield-findings

1 stars 0 forks source link

Gas: No need to initialize variables with default values #56

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

Dravee

Vulnerability details

Impact

If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.

Proof of Concept

Instances include:

ConvexStakingWrapper.sol:54:    bool private constant _NOT_ENTERED = false;
ConvexStakingWrapper.sol:172:        for (uint256 u = 0; u < accountsLength; u++) {
ConvexStakingWrapper.sol:227:        for (uint256 u = 0; u < accountsLength; u++) {
ConvexStakingWrapper.sol:271:        for (uint256 i = 0; i < rewardCount; i++) {
ConvexStakingWrapper.sol:287:        for (uint256 i = 0; i < rewardCount; i++) {
ConvexStakingWrapper.sol:315:        for (uint256 i = 0; i < rewardCount; i++) {
ConvexYieldWrapper.sol:63:        for (uint256 i = 0; i < vaultsLength; i++) {
ConvexYieldWrapper.sol:80:            for (uint256 i = 0; i < vaultsLength; i++) {
ConvexYieldWrapper.sol:111:        for (uint256 i = 0; i < userVaultLength; i++) {

Tools Used

Manual Analysis

Recommended Mitigation Steps

Remove explicit initialization for default values.

iamsahu commented 2 years ago

22 #129

alcueca commented 2 years ago

Taking as main

GalloDaSballo commented 2 years ago

Finding is valid, I've seen the sponsor inconsistently seeing gas savings, that's because I believe the optimizer may perform this optimization