20,000 USDC
View results
Submission Details
Severity: gas
Valid

Initializing variables to default values

Summary

There is no need to initialize variables to their default values

Vulnerability Details

The following storage variables are initialized to their default variables
Staking.sol lines 14 and 16 change to
/// @notice the balance of reward tokens
uint256 public balance =0;
/// @notice the index of the last update
uint256 public index =0;

Additionally in several for loops in Lender.sol e.g line 592, 549 etc as listed in links provides, the iterator i, is initialized as 0 which is not necessary

Impact

Gas Savings: Reinitializing storage variables to their default values is wasting gas. The default values for uint is 0, assigning value 0 is doing extra work to save the same value in storage which costs gas. Inside the for loops uint i, will always be initialized as 0 however its not as bad as the storage variables as MSTORE = 3 gas whereas SSTORE is 5000 gas. However the loops cant be ignored as they are many(see links) and so the gas can add up

Tools Used

Manual Analysis

Recommendations

Recommended there is no need to initialize the variables especially the 2 storage variables above at it wastes more gas compared to the uint i=0 for loops which is not as bad

Staking.sol lines 14 and 16 change to
/// @notice the balance of reward tokens
uint256 public balance;
/// @notice the index of the last update
uint256 public index;

Lender.sol lines 233 change to
for (uint256 i; i < borrows.length; i++) {....

Lender.sol lines 293 change to
for (uint256 i; i < loanIds.length; i++) {

Lender.sol lines 359 change to
for (uint256 i; i < loanIds.length; i++) {

Lender.sol lines 438 change to
for (uint256 i; i < loanIds.length; i++) {

Lender.sol lines 549 change to
for (uint256 i; i < loanIds.length; i++) {...

Lender.sol lines 592 change to
for (uint256 i; i < refinances.length; i++) {

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.