Skip to content

Commit

Permalink
fix: Possible ignored overflow in _lock
Browse files Browse the repository at this point in the history
  • Loading branch information
dgusakov committed Aug 20, 2024
1 parent b53679a commit 583338b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/abstract/CSBondLock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,14 @@ abstract contract CSBondLock is ICSBondLock, Initializable {
if (amount == 0) {
revert InvalidBondLockAmount();
}
unchecked {
if ($.bondLock[nodeOperatorId].retentionUntil > block.timestamp) {
amount += $.bondLock[nodeOperatorId].amount;
}
_changeBondLock({
nodeOperatorId: nodeOperatorId,
amount: amount,
retentionUntil: block.timestamp + $.bondLockRetentionPeriod
});
if ($.bondLock[nodeOperatorId].retentionUntil > block.timestamp) {
amount += $.bondLock[nodeOperatorId].amount;
}
_changeBondLock({
nodeOperatorId: nodeOperatorId,
amount: amount,
retentionUntil: block.timestamp + $.bondLockRetentionPeriod
});
}

/// @dev Reduce locked bond amount for the given Node Operator without changing retention period
Expand Down
12 changes: 12 additions & 0 deletions test/CSAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3630,6 +3630,18 @@ contract CSAccountingLockBondETHTest is CSAccountingBaseTest {
accounting.lockBondETH(0, 1 ether);
}

function test_lockBondETH_RevertWhen_LockOverflow() public {
mock_getNodeOperatorsCount(1);

vm.prank(address(stakingModule));
accounting.lockBondETH(0, 1 ether);
assertEq(accounting.getActualLockedBond(0), 1 ether);

vm.expectRevert();
vm.prank(address(stakingModule));
accounting.lockBondETH(0, type(uint256).max);
}

function test_releaseLockedBondETH() public assertInvariants {
mock_getNodeOperatorsCount(1);

Expand Down

0 comments on commit 583338b

Please sign in to comment.