Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Replace modifiers #79

Merged
merged 3 commits into from
Aug 7, 2024
Merged
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
3 changes: 2 additions & 1 deletion contracts/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ contract Executor is IExternalExecutor, Ownable {
address target,
uint256 value,
bytes calldata payload
) external payable onlyOwner returns (bytes memory result) {
) external payable returns (bytes memory result) {
_checkOwner();
result = Address.functionCallWithValue(target, payload, value);
}

Expand Down
9 changes: 5 additions & 4 deletions contracts/ResealManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@
EMERGENCY_PROTECTED_TIMELOCK = emergencyProtectedTimelock;
}

function reseal(address[] memory sealables) public onlyGovernance {
function reseal(address[] memory sealables) public {
_checkSenderIsGovernance();
for (uint256 i = 0; i < sealables.length; ++i) {
uint256 sealableResumeSinceTimestamp = ISealable(sealables[i]).getResumeSinceTimestamp();
if (sealableResumeSinceTimestamp < block.timestamp || sealableResumeSinceTimestamp == PAUSE_INFINITELY) {
revert SealableWrongPauseState();
}
Address.functionCall(sealables[i], abi.encodeWithSelector(ISealable.resume.selector));
Address.functionCall(sealables[i], abi.encodeWithSelector(ISealable.pauseFor.selector, PAUSE_INFINITELY));
}
}

Check warning

Code scanning / Slither

Unused return Medium


function resume(address sealable) public onlyGovernance {
function resume(address sealable) public {
_checkSenderIsGovernance();
uint256 sealableResumeSinceTimestamp = ISealable(sealable).getResumeSinceTimestamp();
if (sealableResumeSinceTimestamp < block.timestamp) {
revert SealableWrongPauseState();
}
Address.functionCall(sealable, abi.encodeWithSelector(ISealable.resume.selector));
}

Check warning

Code scanning / Slither

Unused return Medium


modifier onlyGovernance() {
function _checkSenderIsGovernance() internal view {
address governance = EMERGENCY_PROTECTED_TIMELOCK.getGovernance();
if (msg.sender != governance) {
revert SenderIsNotGovernance();
}
_;
}
}
3 changes: 2 additions & 1 deletion contracts/committees/EmergencyActivationCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ contract EmergencyActivationCommittee is HashConsensus {

/// @notice Approves the emergency activation by casting a vote
/// @dev Only callable by committee members
function approveEmergencyActivate() public onlyMember {
function approveEmergencyActivate() public {
_checkSenderIsMember();
_vote(EMERGENCY_ACTIVATION_HASH, true);
}

Expand Down
6 changes: 4 additions & 2 deletions contracts/committees/EmergencyExecutionCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ contract EmergencyExecutionCommittee is HashConsensus, ProposalsList {
/// @dev Only callable by committee members
/// @param proposalId The ID of the proposal to vote on
/// @param _supports Indicates whether the member supports the proposal execution
function voteEmergencyExecute(uint256 proposalId, bool _supports) public onlyMember {
function voteEmergencyExecute(uint256 proposalId, bool _supports) public {
_checkSenderIsMember();
(bytes memory proposalData, bytes32 key) = _encodeEmergencyExecute(proposalId);
_vote(key, _supports);
_pushProposal(key, uint256(ProposalType.EmergencyExecute), proposalData);
Expand Down Expand Up @@ -88,7 +89,8 @@ contract EmergencyExecutionCommittee is HashConsensus, ProposalsList {

/// @notice Approves an emergency reset proposal
/// @dev Only callable by committee members
function approveEmergencyReset() public onlyMember {
function approveEmergencyReset() public {
_checkSenderIsMember();
bytes32 proposalKey = _encodeEmergencyResetProposalKey();
_vote(proposalKey, true);
_pushProposal(proposalKey, uint256(ProposalType.EmergencyReset), bytes(""));
Expand Down
18 changes: 11 additions & 7 deletions contracts/committees/HashConsensus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
/// @dev Only callable by the owner
/// @param newMember The address of the new member
/// @param newQuorum The new quorum value
function addMember(address newMember, uint256 newQuorum) public onlyOwner {
function addMember(address newMember, uint256 newQuorum) public {
_checkOwner();
_addMember(newMember);

if (newQuorum == 0 || newQuorum > _members.length()) {
Expand All @@ -127,19 +128,21 @@
/// @dev Only callable by the owner
/// @param memberToRemove The address of the member to remove
/// @param newQuorum The new quorum value
function removeMember(address memberToRemove, uint256 newQuorum) public onlyOwner {
function removeMember(address memberToRemove, uint256 newQuorum) public {
_checkOwner();

if (!_members.contains(memberToRemove)) {
revert IsNotMember();
}
_members.remove(memberToRemove);
emit MemberRemoved(memberToRemove);

if (newQuorum == 0 || newQuorum > _members.length()) {
revert InvalidQuorum();
}
quorum = newQuorum;
emit QuorumSet(newQuorum);
}

Check warning

Code scanning / Slither

Unused return Medium


/// @notice Gets the list of committee members
/// @dev Public function to return the list of members
Expand All @@ -159,15 +162,17 @@
/// @notice Sets the timelock duration
/// @dev Only callable by the owner
/// @param timelock The new timelock duration in seconds
function setTimelockDuration(uint256 timelock) public onlyOwner {
function setTimelockDuration(uint256 timelock) public {
_checkOwner();
timelockDuration = timelock;
emit TimelockDurationSet(timelock);
}

/// @notice Sets the quorum value
/// @dev Only callable by the owner
/// @param newQuorum The new quorum value
function setQuorum(uint256 newQuorum) public onlyOwner {
function setQuorum(uint256 newQuorum) public {
_checkOwner();
if (newQuorum == 0 || newQuorum > _members.length()) {
revert InvalidQuorum();
}
Expand Down Expand Up @@ -200,11 +205,10 @@
}

/// @notice Restricts access to only committee members
/// @dev Modifier to ensure that only members can call a function
modifier onlyMember() {
/// @dev Reverts if the sender is not a member
function _checkSenderIsMember() internal view {
if (!_members.contains(msg.sender)) {
revert SenderIsNotMember();
}
_;
}
}
3 changes: 2 additions & 1 deletion contracts/committees/ResealCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ contract ResealCommittee is HashConsensus, ProposalsList {
/// @dev Allows committee members to vote on resealing a set of addresses
/// @param sealables The addresses to reseal
/// @param support Indicates whether the member supports the proposal
function voteReseal(address[] memory sealables, bool support) public onlyMember {
function voteReseal(address[] memory sealables, bool support) public {
_checkSenderIsMember();
(bytes memory proposalData, bytes32 key) = _encodeResealProposal(sealables);
_vote(key, support);
_pushProposal(key, 0, proposalData);
Expand Down
6 changes: 4 additions & 2 deletions contracts/committees/TiebreakerCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ contract TiebreakerCore is HashConsensus, ProposalsList {
/// @notice Votes on a proposal to schedule
/// @dev Allows committee members to vote on scheduling a proposal
/// @param proposalId The ID of the proposal to schedule
function scheduleProposal(uint256 proposalId) public onlyMember {
function scheduleProposal(uint256 proposalId) public {
_checkSenderIsMember();
(bytes memory proposalData, bytes32 key) = _encodeScheduleProposal(proposalId);
_vote(key, true);
_pushProposal(key, uint256(ProposalType.ScheduleProposal), proposalData);
Expand Down Expand Up @@ -96,7 +97,8 @@ contract TiebreakerCore is HashConsensus, ProposalsList {
return _sealableResumeNonces[sealable];
}

function sealableResume(address sealable, uint256 nonce) public onlyMember {
function sealableResume(address sealable, uint256 nonce) public {
_checkSenderIsMember();
if (nonce != _sealableResumeNonces[sealable]) {
revert ResumeSealableNonceMismatch();
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/committees/TiebreakerSubCommittee.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ contract TiebreakerSubCommittee is HashConsensus, ProposalsList {
/// @notice Votes on a proposal to schedule
/// @dev Allows committee members to vote on scheduling a proposal
/// @param proposalId The ID of the proposal to schedule
function scheduleProposal(uint256 proposalId) public onlyMember {
function scheduleProposal(uint256 proposalId) public {
_checkSenderIsMember();
(bytes memory proposalData, bytes32 key) = _encodeAproveProposal(proposalId);
_vote(key, true);
_pushProposal(key, uint256(ProposalType.ScheduleProposal), proposalData);
Expand Down
6 changes: 3 additions & 3 deletions docs/plan-b.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Initializes the contract with an owner, committee members, a quorum, and the add

### Function: `EmergencyActivationCommittee.approveEmergencyActivate`
```solidity
function approveEmergencyActivate() public onlyMember
function approveEmergencyActivate() public
```
Approves the emergency activation by voting on the `EMERGENCY_ACTIVATION_HASH`.

Expand Down Expand Up @@ -379,7 +379,7 @@ Initializes the contract with an owner, committee members, a quorum, and the add

### Function: `EmergencyExecutionCommittee.voteEmergencyExecute`
```solidity
function voteEmergencyExecute(uint256 proposalId, bool _supports) public onlyMember
function voteEmergencyExecute(uint256 proposalId, bool _supports) public
```
Allows committee members to vote on an emergency execution proposal.

Expand All @@ -406,7 +406,7 @@ Executes an emergency execution proposal by calling the `emergencyExecute` funct

### Function: `EmergencyExecutionCommittee.approveEmergencyReset`
```solidity
function approveEmergencyReset() public onlyMember
function approveEmergencyReset() public
```
Approves the governance reset by voting on the reset proposal.

Expand Down
24 changes: 8 additions & 16 deletions docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ Initializes the contract with the address of the EmergencyProtectedTimelock cont
### Function ResealManager.reseal

```solidity
function reseal(address[] memory sealables) public onlyGovernance
function reseal(address[] memory sealables) public
```

Extends the pause of the specified `sealables` contracts. This function can be called by the governance address defined in the `EmergencyProtectedTimelock`.
Expand All @@ -435,7 +435,7 @@ Extends the pause of the specified `sealables` contracts. This function can be c
### Function: ResealManager.resume

```solidity
function resume(address sealable) external onlyGovernance
function resume(address sealable) external
```

Resumes the specified `sealable` contract if it is scheduled to resume in the future.
Expand All @@ -450,14 +450,6 @@ Resumes the specified `sealable` contract if it is scheduled to resume in the fu
- `SealableWrongPauseState`: Thrown if the sealable contract is in the wrong pause state.
- `SenderIsNotGovernance`: Thrown if the sender is not the governance address.

### Modifier: ResealManager.onlyGovernance

```solidity
modifier onlyGovernance()
```

Ensures that the function can only be called by the governance address.

#### Preconditions

- The sender MUST be the governance address obtained from the `EmergencyProtectedTimelock` contract.
Expand Down Expand Up @@ -1139,7 +1131,7 @@ Initializes the contract with an owner, committee members, a quorum, the address
### Function: TiebreakerCore.scheduleProposal

```solidity
function scheduleProposal(uint256 proposalId) public onlyMember
function scheduleProposal(uint256 proposalId) public
```

Schedules a proposal for execution by voting on it and adding it to the proposal list.
Expand Down Expand Up @@ -1182,7 +1174,7 @@ Returns the current nonce for resuming operations of a sealable contract.
### Function: TiebreakerCore.sealableResume

```solidity
function sealableResume(address sealable, uint256 nonce) public onlyMember
function sealableResume(address sealable, uint256 nonce) public
```

Submits a request to resume operations of a sealable contract by voting on it and adding it to the proposal list.
Expand Down Expand Up @@ -1239,7 +1231,7 @@ Initializes the contract with an owner, committee members, a quorum, and the add
### Function: TiebreakerSubCommittee.scheduleProposal

```solidity
function scheduleProposal(uint256 proposalId) public onlyMember
function scheduleProposal(uint256 proposalId) public
```

Schedules a proposal for execution by voting on it and adding it to the proposal list.
Expand Down Expand Up @@ -1329,7 +1321,7 @@ emergencyProtectedTimelock MUST be a valid address.
### Function: EmergencyActivationCommittee.approveEmergencyActivate

```solidity
function approveEmergencyActivate() public onlyMember
function approveEmergencyActivate() public
```

Approves the emergency activation by voting on the EMERGENCY_ACTIVATION_HASH.
Expand Down Expand Up @@ -1387,7 +1379,7 @@ Initializes the contract with an owner, committee members, a quorum, and the add
### Function: EmergencyExecutionCommittee.voteEmergencyExecute

```solidity
function voteEmergencyExecute(uint256 proposalId, bool _supports) public onlyMember
function voteEmergencyExecute(uint256 proposalId, bool _supports) public
```

Allows committee members to vote on an emergency execution proposal.
Expand Down Expand Up @@ -1422,7 +1414,7 @@ Emergency execution proposal MUST have reached quorum and passed the timelock du
### Function: EmergencyExecutionCommittee.approveEmergencyReset

```solidity
function approveEmergencyReset() public onlyMember
function approveEmergencyReset() public
```

Approves the governance reset by voting on the reset proposal.
Expand Down