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

Combine Multiple Mapping Address

Summary

Combine multiple address mappings

Vulnerability Details

DSCEngine.sol line 78 and 79
mapping(address user => mapping(address token => uint256 amount)) private s_collateralDeposited;
mapping(address user => uint256 amountDscMinted) private s_DSCMinted;
Above can be combined into single mapping

Impact

Gas: Instead of having 2 mappings we can combine into a single mapping of struct for the user addresses data
We will make use on a single mapping instead of 2 saving the computation, hashing of mapping storage slots computations and saving storage costs. Also since we have 2 tokens we can also remove the inner mapping ==> mapping(address token => uint256 amount to add seperate amounts deposited into user struct

Tools Used

Manual Analysis

Recommendations

struct User {
address user;
uint256 amountWBTCDeposited;
uint256 amountWETHDeposited;
uint256 amountDSCMinted;
}
mapping(address user => User) userInfo;

Support

FAQs

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