Skip to content

Commit 63ee9ed

Browse files
committed
fix: verify state transition for pause guardian (TRST-R03)
Signed-off-by: Tomás Migone <[email protected]>
1 parent 2e10813 commit 63ee9ed

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

packages/horizon/contracts/data-service/extensions/DataServicePausable.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ abstract contract DataServicePausable is Pausable, DataService, IDataServicePaus
5151
* @param _allowed The allowed status of the pause guardian
5252
*/
5353
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal {
54+
require(
55+
pauseGuardians[_pauseGuardian] == !_allowed,
56+
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
57+
);
5458
pauseGuardians[_pauseGuardian] = _allowed;
5559
emit PauseGuardianSet(_pauseGuardian, _allowed);
5660
}

packages/horizon/contracts/data-service/extensions/DataServicePausableUpgradeable.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ abstract contract DataServicePausableUpgradeable is PausableUpgradeable, DataSer
6262
* @param _allowed The allowed status of the pause guardian
6363
*/
6464
function _setPauseGuardian(address _pauseGuardian, bool _allowed) internal whenNotPaused {
65+
require(
66+
pauseGuardians[_pauseGuardian] == !_allowed,
67+
DataServicePausablePauseGuardianNoChange(_pauseGuardian, _allowed)
68+
);
6569
pauseGuardians[_pauseGuardian] = _allowed;
6670
emit PauseGuardianSet(_pauseGuardian, _allowed);
6771
}

packages/horizon/contracts/data-service/interfaces/IDataServicePausable.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ interface IDataServicePausable is IDataService {
2323
*/
2424
error DataServicePausableNotPauseGuardian(address account);
2525

26+
/**
27+
* @notice Emitted when a pause guardian is set to the same allowed status
28+
* @param account The address of the pause guardian
29+
* @param allowed The allowed status of the pause guardian
30+
*/
31+
error DataServicePausablePauseGuardianNoChange(address account, bool allowed);
32+
2633
/**
2734
* @notice Pauses the data service.
2835
* @dev Note that only functions using the modifiers `whenNotPaused`

packages/horizon/test/data-service/extensions/DataServicePausable.t.sol

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ contract DataServicePausableTest is HorizonStakingSharedTest {
7070
_assert_setPauseGuardian(address(this), false);
7171
}
7272

73+
function test_SetPauseGuardian_RevertWhen_AlreadyPauseGuardian() external {
74+
_assert_setPauseGuardian(address(this), true);
75+
vm.expectRevert(
76+
abi.encodeWithSignature("DataServicePausablePauseGuardianNoChange(address,bool)", address(this), true)
77+
);
78+
dataService.setPauseGuardian(address(this), true);
79+
}
80+
81+
function test_SetPauseGuardian_RevertWhen_AlreadyNotPauseGuardian() external {
82+
_assert_setPauseGuardian(address(this), true);
83+
_assert_setPauseGuardian(address(this), false);
84+
vm.expectRevert(
85+
abi.encodeWithSignature("DataServicePausablePauseGuardianNoChange(address,bool)", address(this), false)
86+
);
87+
dataService.setPauseGuardian(address(this), false);
88+
}
89+
7390
function test_PausedProtectedFn_RevertWhen_TheProtocolIsPaused() external {
7491
_assert_setPauseGuardian(address(this), true);
7592
_assert_pause();

0 commit comments

Comments
 (0)