Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

SortitionModule upgrade to add changeGovernor() #1862

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const deployUpgradeSortitionModule: DeployFunction = async (hre: HardhatRuntimeE
console.log("upgrading SortitionModuleNeo...");
await deployUpgradable(deployments, "SortitionModuleNeo", {
newImplementation: "SortitionModuleNeo",
initializer: "initialize",
initializer: "initialize3",
from: deployer,
// Warning: do not reinitialize everything, only the new variables
args: [],
Expand Down
6 changes: 5 additions & 1 deletion contracts/src/arbitration/SortitionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {SortitionModuleBase, KlerosCore, RNG} from "./SortitionModuleBase.sol";
/// @title SortitionModule
/// @dev A factory of trees that keeps track of staked values for sortition.
contract SortitionModule is SortitionModuleBase {
string public constant override version = "0.8.0";
string public constant override version = "0.9.0";

// ************************************* //
// * Constructor * //
Expand Down Expand Up @@ -44,6 +44,10 @@ contract SortitionModule is SortitionModuleBase {
__SortitionModuleBase_initialize(_governor, _core, _minStakingTime, _maxDrawingTime, _rng, _rngLookahead);
}

function initialize3() external reinitializer(3) {
// NOP
}

// ************************************* //
// * Governance * //
// ************************************* //
Expand Down
6 changes: 6 additions & 0 deletions contracts/src/arbitration/SortitionModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
// * Governance * //
// ************************************* //

/// @dev Changes the governor of the contract.
/// @param _governor The new governor.
function changeGovernor(address _governor) external onlyByGovernor {
governor = _governor;
}
Comment on lines +130 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add event emission and input validation for governor change.

While the implementation is functionally correct, consider these security improvements:

  1. Emit an event when the governor changes for better transparency and off-chain tracking
  2. Validate that the new governor address is not zero to prevent accidental lockout

Apply this diff to improve the implementation:

 function changeGovernor(address _governor) external onlyByGovernor {
+    require(_governor != address(0), "Governor address cannot be 0x0");
     governor = _governor;
+    emit GovernorChanged(msg.sender, _governor);
 }

+event GovernorChanged(address indexed previousGovernor, address indexed newGovernor);

Committable suggestion skipped: line range outside the PR's diff.


/// @dev Changes the `minStakingTime` storage variable.
/// @param _minStakingTime The new value for the `minStakingTime` storage variable.
function changeMinStakingTime(uint256 _minStakingTime) external onlyByGovernor {
Expand Down
6 changes: 5 additions & 1 deletion contracts/src/arbitration/SortitionModuleNeo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {SortitionModuleBase, KlerosCore, RNG, StakingResult} from "./SortitionMo
/// @title SortitionModuleNeo
/// @dev A factory of trees that keeps track of staked values for sortition.
contract SortitionModuleNeo is SortitionModuleBase {
string public constant override version = "0.8.0";
string public constant override version = "0.9.0";

// ************************************* //
// * Storage * //
Expand Down Expand Up @@ -58,6 +58,10 @@ contract SortitionModuleNeo is SortitionModuleBase {
maxTotalStaked = _maxTotalStaked;
}

function initialize3() external reinitializer(3) {
// NOP
}

// ************************************* //
// * Governance * //
// ************************************* //
Expand Down
Loading