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

Gas Optimization / Informational Report

[I-01] No external or public function to call _burn

Method _burn() is not getting called from any external or public method. Which will make this functionality unuseable.

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Beedle.sol#L29-L34

Recommendation

Consider exposing an external or public method to call _burn().

[G-01] Multiple mappings should be replaced with a single mapping or user and a struct

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

+ struct UserStake {
+ uint256 supplyIndex;
+ uint256 balances;
+ uint256 claimable;
+ }
+ //@audit A single mapping can be used
+ mapping(address => UserStake) usersStake;
/// @notice mapping of user indexes
- mapping(address => uint256) public supplyIndex;
+ // mapping(address => uint256) public supplyIndex;
/// @notice mapping of user balances
- mapping(address => uint256) public balances;
+ // mapping(address => uint256) public balances;
/// @notice mapping of user claimable rewards
- mapping(address => uint256) public claimable;
+ // mapping(address => uint256) public claimable;

[G-02] Local storage variable can be used in updateFor() method

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

function updateFor(address recipient) public {
update();
- uint256 _supplied = balances[recipient];
+ UserStake storage userStake = usersStake[recipient];
+ uint256 _supplied = userStake.balances;
+ uint256 _updatedSupplyIndex = userStake.supplyIndex;
if (_supplied > 0) {
- uint256 _supplyIndex = supplyIndex[recipient];
- supplyIndex[recipient] = index;
+ uint256 _supplyIndex = _updatedSupplyIndex;
+ _updatedSupplyIndex = index;
uint256 _delta = index - _supplyIndex;
if (_delta > 0) {
uint256 _share = _supplied * _delta / 1e18;
- claimable[recipient] += _share;
+ userStake.claimable += _share;
}
} else {
- supplyIndex[recipient] = index;
+ _updatedSupplyIndex = index;
}
+ userStake.supplyIndex = _updatedSupplyIndex;
}
}

Support

FAQs

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