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

Multiple mappings can be combined into a single mapping to save gas

Summary

Multiple mappings can be combined into a single mapping of a value type struct.

Vulnerability Details

The three mappings of Staking.sol supplyIndex,balances and claimable can be combined into a struct for example:
struct User{
uint256 supplyIndex;
uint256 balances;
uint256 claimable;
} ---->
mapping(address => User) public userStats.
This saves a storage slot for the mapping.If a function requires two of the values and they both fit in the same storage slot then subsequent reads and writes can also be cheaper.

Impact

Saving Gas

Tools Used

Manual Review

Recommendations

Consider combining these three mappings into a single one of value type struct if you find it suitable

Support

FAQs

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