15,000 USDC
View results
Submission Details
Severity: gas

Remove array collateral tokens

Summary

Remove storing only 2 addresses in dynamic array

Vulnerability Details

There are only 2 addresses for collateral asset. There will only ever be 2 as no way to update. There is no need to use more costly data structure dynamic array "s_collateralTokens" which increases gas costs. Each address must be stored in its own slot

Impact

Gas: Dynamic arrays in storage require lots of computation to hash slot, to set and find where actual values are stored. At the actual slot of array, the length is stored which is an additional gas cost. By having values in address we only have 2 slots and remove more complex dynamic array computation.

Additionally in DSCEngine.sol functions line 353 we will not need to use a for loop

Tools Used

Manual Analysis

Recommendations

  1. Intitial
    address[] private s_collateralTokens;

  2. Change To
    address wbtc
    address weth

Support

FAQs

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