Skip to content

Bug: Governor state #2886

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

Closed
zgfzgf opened this issue Sep 28, 2021 · 4 comments · Fixed by #2892
Closed

Bug: Governor state #2886

zgfzgf opened this issue Sep 28, 2021 · 4 comments · Fixed by #2892

Comments

@zgfzgf
Copy link

zgfzgf commented Sep 28, 2021

for example: when startBlock=100000

A have 200 COMP
B no COMP
when block.number=10000
OpenZeepelin state is Active (is error)
Compound state is Pending (is OK)

A castVote. and transfer to B. B is also castVote. in block.number=10000

function state(uint256 proposalId) public view virtual override returns (ProposalState) {
ProposalCore memory proposal = _proposals[proposalId];
if (proposal.executed) {
return ProposalState.Executed;
} else if (proposal.canceled) {
return ProposalState.Canceled;
} else if (proposal.voteStart.isPending()) {
return ProposalState.Pending;
} else if (proposal.voteEnd.isPending()) {
return ProposalState.Active;
} else if (proposal.voteEnd.isExpired()) {
return
_quorumReached(proposalId) && _voteSucceeded(proposalId)
? ProposalState.Succeeded
: ProposalState.Defeated;
} else {
revert("Governor: unknown proposal id");
}
}

https://github.com/compound-finance/compound-protocol/blob/a6251ecc30adb8dfa904e2231e9a9fdb4eea78be/contracts/Governance/GovernorAlpha.sol#L226-L246

@zgfzgf zgfzgf changed the title Bug: state Bug: Governor state Sep 28, 2021
@zgfzgf
Copy link
Author

zgfzgf commented Sep 28, 2021

https://github.com/compound-finance/compound-protocol/blob/a6251ecc30adb8dfa904e2231e9a9fdb4eea78be/contracts/Governance/Comp.sol#L190
require(blockNumber < block.number, "Comp::getPriorVotes: not yet determined");

Without this, there will be errors.

@Amxx
Copy link
Collaborator

Amxx commented Sep 28, 2021

Hello @zgfzgf

In Openzeppelin governor, just like in Compound's governor, when an address casts a vote, the governor asks the (Comp) token what the votes of the address were at a given point in time.

This avoids transferring tokens and voting twice.

As you saw, this mechanism is part of the token contract, not the governor. Note also that for a user to be able to cast a vote, we must be in the Active state. This can only be achieved if :

  • the proposal is not executed
  • the proposal is not canceled
  • block.number > proposal.startBlock
  • block.number <= proposal.endBlock

Consequently, when we query

uint96 votes = comp.getPriorVotes(voter, proposal.startBlock)

We are certain that proposal.startBlock is in the past, (check was performed in the state() function)

@zgfzgf
Copy link
Author

zgfzgf commented Sep 28, 2021

I see. but We don't guarantee others proposal.startBlock is in the past.

@zgfzgf
Copy link
Author

zgfzgf commented Sep 28, 2021

see email:[email protected]

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 a pull request may close this issue.

2 participants