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

Ignoring `caseId`value when season is below peg

Summary

The Sun contract ignores the current debt level (pre-calculated Weather case) when the season is below peg (pre-calculated deltaB is equal or less than zero). The Sun.setSoilBelowPeg function always chooses the minimal value from instDeltaB and twaDeltaB. This approach is good only for "Reasonably High" and "Excessively High" debt levels. But in case of "Excessively Low" debt level the maximal from instDeltaB and twaDeltaB can be more appropriate.

Vulnerability Details

The Sun.stepSun function uses caseId when season is above peg:

function stepSun(int256 deltaB, uint256 caseId) internal {
// Above peg
if (deltaB > 0) {
uint256 newHarvestable = rewardBeans(uint256(deltaB));
setSoilAbovePeg(newHarvestable, caseId);
s.season.abovePeg = true;
}
// Below peg
else {
setSoilBelowPeg(deltaB);
s.season.abovePeg = false;
}
}

This lets to keep the debt at the optimal level by moving the debt to the ideal equilibrium (https://docs.bean.money/almanac/peg-maintenance/temperature#direction).
But in case the season is below peg the debt level is ignored and the minimum from instDeltaB and twaDeltaB amount is set as new soil.

function setSoilBelowPeg(int256 twaDeltaB) internal {
// Calculate deltaB from instantaneous reserves of all whitelisted Wells.
int256 instDeltaB;
address[] memory tokens = LibWhitelistedTokens.getWhitelistedWellLpTokens();
for (uint256 i = 0; i < tokens.length; i++) {
int256 wellInstDeltaB = LibWellMinting.instantaneousDeltaB(tokens[i]);
instDeltaB = instDeltaB.add(wellInstDeltaB);
}
// Set new soil.
setSoil(Math.min(uint256(-twaDeltaB), uint256(-instDeltaB)));
}

When the debt level is low, choosing the minimal value can slow down the optimal debt reaching.

Impact

Unexpected behavior, debt is increased on a lower amount than the closest to ideal.

Tools used

Manual Review

Recommendations

Consider taking into account the pre-calculated Weather case to choose the most appropriate value from instDeltaB and twaDeltaB.

Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Design choice
pontifex Submitter
about 1 year ago
giovannidisiena Lead Judge
about 1 year ago
giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Soil issuance below peg doesn't consider Weather case

Support

FAQs

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