Skip to content

Commit

Permalink
fix: zero-out targetLimit earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman authored and dgusakov committed Oct 1, 2024
1 parent cdc6e33 commit 04c57a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/CSModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,10 @@ contract CSModule is
_onlyExistingNodeOperator(nodeOperatorId);
NodeOperator storage no = _nodeOperators[nodeOperatorId];

if (targetLimitMode == 0) {
targetLimit = 0;
}

if (
no.targetLimitMode == targetLimitMode &&
no.targetLimit == targetLimit
Expand All @@ -818,10 +822,6 @@ contract CSModule is
no.targetLimitMode = uint8(targetLimitMode);
}

if (targetLimitMode == 0) {
targetLimit = 0;
}

if (no.targetLimit != targetLimit) {
// @dev No need to safe cast due to conditions above
no.targetLimit = uint32(targetLimit);
Expand Down
19 changes: 19 additions & 0 deletions test/CSModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4963,6 +4963,25 @@ contract CsmUpdateTargetValidatorsLimits is CSMCommon {
csm.updateTargetValidatorsLimits(noId, 1, 0);
}

function test_updateTargetValidatorsLimits_FromDisabledToDisabled_withNonZeroTargetLimit()
public
assertInvariants
{
uint256 noId = createNodeOperator();
csm.updateTargetValidatorsLimits(noId, 2, 10);

vm.expectEmit(true, true, true, true, address(csm));
emit CSModule.TargetValidatorsCountChanged(noId, 0, 0);
csm.updateTargetValidatorsLimits(noId, 0, 0);

vm.recordLogs();
csm.updateTargetValidatorsLimits(noId, 0, 8);
assertEq(vm.getRecordedLogs().length, 0);

NodeOperator memory no = csm.getNodeOperator(noId);
assertEq(no.targetLimit, 0);
}

function test_updateTargetValidatorsLimits_enableSoftLimit()
public
assertInvariants
Expand Down

0 comments on commit 04c57a3

Please sign in to comment.