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

## [G-11] Multiple address /ID mappings can be combined into a single mapping of an address/ID to a struct , where appropriate

Summary

[G-11] Multiple address /ID mappings can be combined into a single mapping of an address/ID to a struct , where appropriate

Saves a storage slot for the mapping. Depending on the circumstances and sizes of types, can avoid a Gsset (20000 gas) per mapping combined. Reads and subsequent writes can also be cheaper when a function requires both values and they both fit in the same storage slot. Finally, if both fields are accessed in the same function, can save ~42 gas per access due to not having to re
the key’s keccak256 hash (Gkeccak256 - 30 gas) and that calculation’s associated stack operations.

file: /src/Staking.sol
19 mapping(address => uint256) public supplyIndex;
/// @notice mapping of user balances
22 mapping(address => uint256) public balances;
/// @notice mapping of user claimable rewards
24 mapping(address => uint256) public claimable;

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Staking.sol#L19-L24

Support

FAQs

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