DeFiHardhat
21,000 USDC
View results
Submission Details
Severity: low
Invalid

Ensuring Reliable Return Values in `rewardBeans` Function

Summary

The rewardBeans function is used to distribute newly minted beans within the protocol, allocating them to different components such as Fertilizer, Pods, and the Silo. However, the function was found to potentially lack a return value for all execution paths, which could lead to unexpected behavior or errors. This report outlines the necessary modifications to ensure that the function consistently returns a value, enhancing robustness and reliability.

Vulnerability Details

The rewardBeans function lacked an initialization of the newHarvestable variable, which could lead to scenarios where not all execution paths assign a return value. Specifically, if the condition if (s.f.harvestable < s.f.pods) is not met, newHarvestable would remain uninitialized, resulting in potential inconsistencies and errors.

Impact

Unexpected Behavior: If rewardBeans does not return a value due to an uninitialized variable, it could lead to unexpected behavior in the calling functions, such as stepSun.

Tools Used

Manual review

Recommendations

To ensure that rewardBeans always returns a value and handles all execution paths correctly, the following recommendation is made:
Explicitly initialize the newHarvestable variable to ensure that it has a value in all execution paths.

function rewardBeans(uint256 newSupply) internal returns (uint256 newHarvestable) {
uint256 newFertilized;
// Initialize newHarvestable to 0
newHarvestable = 0;
// Mint new beans
C.bean().mint(address(this), newSupply);
// Distribute first to Fertilizer if some Fertilizer are active
if (s.season.fertilizing) {
newFertilized = rewardToFertilizer(newSupply);
newSupply = newSupply.sub(newFertilized);
}
// Distribute next to the Field if some Pods are still outstanding
if (s.f.harvestable < s.f.pods) {
newHarvestable = rewardToHarvestable(newSupply);
newSupply = newSupply.sub(newHarvestable);
}
// Distribute remainder to the Silo
rewardToSilo(newSupply);
emit Reward(s.season.current, newHarvestable, newSupply, newFertilized);
return newHarvestable;
}
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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