Skip to content

Commit

Permalink
Merge pull request #79 from lidofinance/featuere/replace-modifiers
Browse files Browse the repository at this point in the history
Replace modifiers
  • Loading branch information
Psirex authored Aug 7, 2024
2 parents 9b92f73 + 94e29fa commit bec810f
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 38 deletions.
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,7 +19,8 @@ contract ResealManager is IResealManager {
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) {
Expand All @@ -30,19 +31,19 @@ contract ResealManager is IResealManager {
}
}

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));
}

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 @@ abstract contract HashConsensus is Ownable {
/// @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,7 +128,9 @@ abstract contract HashConsensus is Ownable {
/// @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();
}
Expand Down Expand Up @@ -159,15 +162,17 @@ abstract contract HashConsensus is Ownable {
/// @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 @@ abstract contract HashConsensus is Ownable {
}

/// @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

0 comments on commit bec810f

Please sign in to comment.