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

Add a governor extension that implements a proposal guardian #5303

Merged
merged 32 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6330d4c
Add a governor extension that implements a security council
Amxx Nov 19, 2024
578543d
add tests
arr00 Nov 27, 2024
fb6e8b7
rename `GovernorSecurityCouncil` to `GovernorProposalGuardian`
arr00 Dec 13, 2024
d613cc8
update `GovernorProposalGuardian`
arr00 Dec 13, 2024
25eeb02
remove `.only`
arr00 Dec 16, 2024
8379051
Merge branch 'master' into feature/governor/security_council
arr00 Dec 20, 2024
5ba4596
use `getProposalId` instead of `hashProposal`
arr00 Dec 20, 2024
954b03c
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 Dec 23, 2024
e56c8b2
Apply suggestions from code review
arr00 Dec 23, 2024
db18886
Add proposal guardian to docs
arr00 Jan 22, 2025
f751ec6
use `_validateCancel` instead of overriding `cancel`
arr00 Jan 10, 2025
d6f0032
fix test, move error to interface
arr00 Jan 21, 2025
5ffeab0
consistent cancellation errors
arr00 Jan 21, 2025
9d378ac
fix tests
arr00 Jan 22, 2025
13f18c5
remove `.only`
arr00 Jan 22, 2025
409e406
move caller into params
arr00 Jan 22, 2025
85c8c15
simplify
arr00 Jan 22, 2025
7a7674b
Update GovernorProposalGuardian.test.js
Amxx Jan 22, 2025
ce162a6
move internal function
arr00 Jan 22, 2025
f83d972
update docs
arr00 Jan 22, 2025
37147e7
Merge pull request #10 from arr00/refactor/cancel-validate-cancel
Amxx Jan 23, 2025
91fbe24
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 Jan 23, 2025
5f71ccf
fix lint and edit comments
arr00 Jan 23, 2025
855f819
Update GovernorProposalGuardian.test.js
Amxx Jan 24, 2025
6a2030f
Apply suggestions from code review
Amxx Jan 24, 2025
5621fa4
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 Jan 24, 2025
54ad414
Update contracts/governance/extensions/GovernorProposalGuardian.sol
arr00 Jan 24, 2025
af352f5
lint and fix tests
arr00 Jan 24, 2025
643e114
add test
arr00 Jan 24, 2025
b7a1a32
lint
arr00 Jan 24, 2025
0927af4
fix test
arr00 Jan 24, 2025
276185d
add changeset
arr00 Jan 24, 2025
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
Prev Previous commit
Next Next commit
use _validateCancel instead of overriding cancel
  • Loading branch information
arr00 committed Jan 22, 2025
commit f751ec6b5e6d81cb1ffa4e473acfd9c9c36dee89
14 changes: 11 additions & 3 deletions contracts/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
}
}

error UnableToCancel();

/**
* @dev See {IGovernor-cancel}.
*/
Expand All @@ -484,13 +486,19 @@ abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC72
// changes it. The `getProposalId` duplication has a cost that is limited, and that we accept.
uint256 proposalId = getProposalId(targets, values, calldatas, descriptionHash);

if (!_validateCancel(_msgSender(), proposalId)) revert UnableToCancel();

return _cancel(targets, values, calldatas, descriptionHash);
}

function _validateCancel(address caller, uint256 proposalId) internal view virtual returns (bool) {
// public cancel restrictions (on top of existing _cancel restrictions).
_validateStateBitmap(proposalId, _encodeStateBitmap(ProposalState.Pending));
if (_msgSender() != proposalProposer(proposalId)) {
revert GovernorOnlyProposer(_msgSender());
if (caller != proposalProposer(proposalId)) {
return false;
}

return _cancel(targets, values, calldatas, descriptionHash);
return true;
}

/**
Expand Down
19 changes: 7 additions & 12 deletions contracts/governance/extensions/GovernorProposalGuardian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,32 @@ abstract contract GovernorProposalGuardian is Governor {
event ProposalGuardianSet(address oldProposalGuardian, address newProposalGuardian);

/**
* @dev Override {IGovernor-cancel} that implements the extended cancellation logic.
* @dev Override `_validateCancel` that implements the extended cancellation logic.
*
* * The {proposalGuardian} can cancel any proposal at any point in the lifecycle.
* * if no proposal guardian is set, the {proposalProposer} can cancel their proposals at any point in the lifecycle.
* * if the proposal guardian is set, the {proposalProposer} keeps their default rights defined in {IGovernor-cancel} (calling `super`).
*/
function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public virtual override returns (uint256) {
address caller = _msgSender();
function _validateCancel(address caller, uint256 proposalId) internal view virtual override returns (bool) {
// no additional validation is required

address guardian = proposalGuardian();

if (guardian == address(0)) {
// if there is no proposal guardian
// ... only the proposer can cancel
// ... no restriction on when the proposer can cancel
uint256 proposalId = getProposalId(targets, values, calldatas, descriptionHash);
address proposer = proposalProposer(proposalId);
if (caller != proposer) revert GovernorOnlyProposer(caller);
return _cancel(targets, values, calldatas, descriptionHash);
return true;
} else if (guardian == caller) {
// if there is a proposal guardian, and the caller is the proposal guardian
// ... just cancel
return _cancel(targets, values, calldatas, descriptionHash);
return true;
} else {
// if there is a proposal guardian, and the caller is not the proposal guardian
// ... apply default behavior
return super.cancel(targets, values, calldatas, descriptionHash);
return super._validateCancel(caller, proposalId);
}
}

Expand Down
12 changes: 5 additions & 7 deletions contracts/mocks/governance/GovernorProposalGuardianMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ abstract contract GovernorProposalGuardianMock is
return super.proposalThreshold();
}

function cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) public override(Governor, GovernorProposalGuardian) returns (uint256) {
return super.cancel(targets, values, calldatas, descriptionHash);
function _validateCancel(
address caller,
uint256 proposalId
) internal view override(Governor, GovernorProposalGuardian) returns (bool) {
return super._validateCancel(caller, proposalId);
}
}