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

Upgrade to OZ v5 #66

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Upgrade to OZ v5 #66

wants to merge 13 commits into from

Conversation

alexkeating
Copy link
Contributor

@alexkeating alexkeating commented Jan 10, 2024

Description

  • Some errors changed
  • The check-pointing contract changed
  • The castVoteWithReasonAndParamsBySig has a nonce now so we can remove our method override.
  • The GovernorCompatibilityBravo contract was removed so we need to add our own VoteType struct

*
* See {fractionalVoteNonce} and {_castVote} for more information.
*/
function castVoteWithReasonAndParamsBySig(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added because the v4 version did not handle replay attacks. I think the v5 uses a nonce now so we don't need to override it.

https://github.com/OpenZeppelin/openzeppelin-contracts/blob/920225a1c7e6e749ba23b10ed076b04f454290e8/contracts/governance/Governor.sol#L577

@alexkeating alexkeating marked this pull request as ready for review January 12, 2024 21:05
@alexkeating alexkeating changed the title WIP Upgrade to OZ v5 Jan 12, 2024
@@ -92,7 +92,7 @@ abstract contract FlexVotingClient {
/// token that `_user` has claim to in this system. It may or may not be
/// equivalent to the withdrawable balance of `GOVERNOR`s token for `user`,
/// e.g. if the internal representation of balance has been scaled down.
function _rawBalanceOf(address _user) internal view virtual returns (uint256);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed because there is no Trace256. Should we write one for OZ?

Copy link

@Amxx Amxx May 16, 2024

Choose a reason for hiding this comment

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

Traces are a list of checkpoint. Each checkpoint contains:

  • a key
  • a value

such that sizeof(key) + sizeof(value) = 256

  • Trace224 is uint224 for value, and uint32 for key
  • Trace208 is uint208 for value, and uint48 for key

Trace256 would not have any room for the key ... unless you start have checkpoints that are 2 slots.

}

/// @notice Returns the `_user`'s raw balance at `_blockNumber`.
/// @param _user The account that's historical raw balance will be looked up.
/// @param _blockNumber The block at which to lookup the _user's raw balance.
function getPastRawBalance(address _user, uint256 _blockNumber) public view returns (uint256) {
return balanceCheckpoints[_user].getAtProbablyRecentBlock(_blockNumber);
uint32 key = SafeCast.toUint32(_blockNumber);
return balanceCheckpoints[_user].upperLookup(key);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -115,7 +116,7 @@ contract Deployment is FractionalPoolTest {

contract Deposit is FractionalPoolTest {
function test_UserCanDepositGovTokens(address _holder, uint256 _amount) public {
_amount = bound(_amount, 0, type(uint224).max);
_amount = bound(_amount, 0, type(uint208).max);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

Because Votes.sol uses Checkpoints.Trace208 for the checkpoints. This is a consequence of the adoption of uint48 for all clocks/timestamps, following ERC-5805

@@ -106,7 +106,7 @@ jobs:
uses: zgosalvez/github-actions-report-lcov@v2
with:
coverage-files: ./lcov.info
minimum-coverage: 70 # Set coverage threshold.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we add more tests

IGovernor.GovernorUnexpectedProposalState.selector,
_proposalId,
status,
bytes32(1 << uint8(IGovernor.ProposalState.Succeeded))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -48,7 +48,7 @@ import {IVotingToken} from "./interfaces/IVotingToken.sol";
/// of the rest.
abstract contract FlexVotingClient {
using SafeCast for uint256;
using Checkpoints for Checkpoints.History;
using Checkpoints for Checkpoints.Trace224;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be a 208?

Copy link

Choose a reason for hiding this comment

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

If you want to allign with ERC-5805, then yes

Copy link

Coverage after merging feature/support-oz-5 into master will be

66.42%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   FlexVotingClient.sol0%0%0%0%104, 113–114, 114, 114, 116, 116, 116–117, 119, 119, 119–121, 121, 121–123, 123, 123–124, 126, 136–137, 137, 137, 141, 159, 162, 171, 174, 177, 183, 186, 188–190, 197, 204–205, 211–212, 88, 99
   FractionalPool.sol78.13%80%66.67%80.33%111, 114, 191, 194–195, 198, 202, 228, 239, 60–62, 80, 82–83, 85
   GovernorCountingFractional.sol97.10%94.44%100%97.56%188, 191

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.

None yet

4 participants