Skip to content

Commit

Permalink
prevent targetThreshold < minThreshold
Browse files Browse the repository at this point in the history
  • Loading branch information
spengrah committed Mar 27, 2023
1 parent 1d6b322 commit 8634435
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/HatsSignerGateBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ abstract contract HatsSignerGateBase is BaseGuard, SignatureDecoder, HatsOwnedIn
}

/// @notice Internal function to set the target threshold
/// @dev Reverts if `_targetThreshold` is greater than `maxSigners`
/// @dev Reverts if `_targetThreshold` is greater than `maxSigners` or lower than `minThreshold`
/// @param _targetThreshold The new target threshold to set
function _setTargetThreshold(uint256 _targetThreshold) internal {
// target threshold cannot be lower than min threshold
if (_targetThreshold < minThreshold) {
revert InvalidTargetThreshold();
}
// target threshold cannot be greater than max signers
if (_targetThreshold > maxSigners) {
revert InvalidTargetThreshold();
}
Expand Down
10 changes: 10 additions & 0 deletions test/HatsSignerGate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,16 @@ contract HatsSignerGateTest is HSGTestSetup {
assertEq(safe.getThreshold(), 4, "threshold");
}

function testSetTargetTresholdCannotSetBelowMinThreshold() public {
assertEq(hatsSignerGate.minThreshold(), 2, "min threshold");
assertEq(hatsSignerGate.targetThreshold(), 2, "target threshold");

// set target threshold to 1 — should fail
mockIsWearerCall(address(this), ownerHat, true);
vm.expectRevert(InvalidTargetThreshold.selector);
hatsSignerGate.setTargetThreshold(1);
}

// function testSignersCannotChangeModules() public {
// //
// }
Expand Down

0 comments on commit 8634435

Please sign in to comment.