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 module to protect against late quorum #2973

Merged
merged 14 commits into from
Dec 1, 2021

Conversation

Amxx
Copy link
Collaborator

@Amxx Amxx commented Nov 15, 2021

This PR adds a new governor module that fixes an issue described by @Arachnid.

In cases where voters' participation is low, and quorum is far from being reached, voters might not be incentivized to participate for a proposal that they don't think will reach the quorum anyway. This would allow a "whale" voter to take over the vote at the end of the voting period. The whale would have enough tokens to reach the quorum and impose its result, leaving no time for voters to react.

This module ensures a minimal voting delay after quorum is reached. If quorum is reached late, then the proposal deadline will be extended to ensure this minimal post-quorum voting duration.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx
Copy link
Collaborator Author

Amxx commented Nov 15, 2021

Note: if proposal details become packed as part of a breaking release (proposed in #2962), commit #ff0d213 should be reverted for gas optimization.

Arachnid
Arachnid previously approved these changes Nov 16, 2021
@Amxx Amxx force-pushed the feature/Governor/ExtendedVoting branch from c6c2a62 to 718df6b Compare November 16, 2021 14:26
@@ -110,24 +110,34 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor {
* @dev See {IGovernor-state}.
*/
function state(uint256 proposalId) public view virtual override returns (ProposalState) {
ProposalCore memory proposal = _proposals[proposalId];
ProposalCore storage proposal = _proposals[proposalId];
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: this is more gas effective in the current format, where proposal is not packed and uses 3 slots. If proposal are packed in an upcoming breaking change, then this should be changed back to memory.

@Amxx Amxx requested a review from frangio November 17, 2021 21:44
contracts/governance/extensions/GovernorExtendedVoting.sol Outdated Show resolved Hide resolved
contracts/governance/extensions/GovernorExtendedVoting.sol Outdated Show resolved Hide resolved
contracts/governance/Governor.sol Outdated Show resolved Hide resolved
contracts/governance/extensions/GovernorExtendedVoting.sol Outdated Show resolved Hide resolved
) internal virtual override returns (uint256) {
uint256 result = super._castVote(proposalId, account, support, reason);

Timers.BlockNumber storage extension = _extendedVoteEnd[proposalId];
Copy link
Contributor

@frangio frangio Nov 18, 2021

Choose a reason for hiding this comment

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

We're using three different names for essentially the same concept: extension, extended vote end, extended deadline. And then extension also refers to the number of blocks that are added.

I wish we could find a more unified naming scheme.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried renaming variables and contract to make everything clearer. Let me know what you think

@ghost
Copy link

ghost commented Nov 19, 2021

Very good work!

@Amxx Amxx requested a review from frangio November 29, 2021 08:17
@frangio frangio dismissed a stale review via 1e932b6 December 1, 2021 02:15
@frangio frangio changed the title Add a governor module to prevent against suddent & late quorum Add a governor module to protect against late quorum Dec 1, 2021
@frangio frangio merged commit abf6024 into OpenZeppelin:master Dec 1, 2021
@Amxx Amxx deleted the feature/Governor/ExtendedVoting branch December 1, 2021 17:18
EchoicDeveloper pushed a commit to EchoicDAO/openzeppelin-contracts that referenced this pull request Jan 9, 2022
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants