Skip to content

Commit

Permalink
update stakeRate/draftRate only when well-defined (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrent committed Sep 10, 2024
1 parent 56f5e65 commit 95231c0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions contracts/p1/StRSR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ abstract contract StRSRP1 is Initializable, ComponentP1, IStRSR, EIP712Upgradeab
seizedRSR = stakeRSRToTake;

// update stakeRate, possibly beginning a new stake era
if (stakeRSR != 0) {
if (stakeRSR != 0 && totalStakes != 0) {
// Downcast is safe: totalStakes is 1e38 at most so expression maximum value is 1e56
stakeRate = uint192((FIX_ONE_256 * totalStakes + (stakeRSR - 1)) / stakeRSR);
}
Expand All @@ -458,11 +458,10 @@ abstract contract StRSRP1 is Initializable, ComponentP1, IStRSR, EIP712Upgradeab
seizedRSR += draftRSRToTake;

// update draftRate, possibly beginning a new draft era
if (draftRSR != 0) {
if (draftRSR != 0 && totalDrafts != 0) {
// Downcast is safe: totalDrafts is 1e38 at most so expression maximum value is 1e56
draftRate = uint192((FIX_ONE_256 * totalDrafts + (draftRSR - 1)) / draftRSR);
}

if (draftRSR == 0 || draftRate > MAX_DRAFT_RATE) {
seizedRSR += draftRSR;
beginDraftEra();
Expand Down

0 comments on commit 95231c0

Please sign in to comment.