Skip to content

Commit

Permalink
fix: add proposalType validity check
Browse files Browse the repository at this point in the history
Signed-off-by: 0xRaccoon <[email protected]>
  • Loading branch information
0xRaccoon committed Dec 18, 2023
1 parent a7719cd commit d7d9aa0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 17 additions & 4 deletions solidity/contracts/governance/utils/WonderVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ abstract contract WonderVotes is Context, EIP712, Nonces, IERC6372, IWonderVotes
/**
* @dev Delegates votes from the sender to `delegatee`.
*/
function delegate(Delegate[] calldata delegatees, uint8 proposalType) public virtual {
function delegate(Delegate[] calldata delegatees, uint8 proposalType) public virtual validProposalType(proposalType) {
address account = _msgSender();
_delegate(account, proposalType, delegatees);
}

/**
* @dev See {IWonderVotes-delegate}.
*/
function delegate(address delegatee, uint8 proposalType) public virtual {
function delegate(address delegatee, uint8 proposalType) public virtual validProposalType(proposalType) {
address account = _msgSender();
Delegate[] memory _singleDelegate = new Delegate[](1);
_singleDelegate[0] = Delegate({account: delegatee, weight: _totalWeight()});
Expand Down Expand Up @@ -187,7 +187,7 @@ abstract contract WonderVotes is Context, EIP712, Nonces, IERC6372, IWonderVotes
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
) public virtual validProposalType(proposalType) {
if (block.timestamp > expiry) {
revert VotesExpiredSignature(expiry);
}
Expand All @@ -209,7 +209,7 @@ abstract contract WonderVotes is Context, EIP712, Nonces, IERC6372, IWonderVotes
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
) public virtual validProposalType(proposalType) {
Delegate[] memory _singleDelegate = new Delegate[](1);
_singleDelegate[0] = Delegate({account: delegatee, weight: _totalWeight()});
delegateBySig(_singleDelegate, proposalType, nonce, expiry, v, r, s);
Expand Down Expand Up @@ -364,4 +364,17 @@ abstract contract WonderVotes is Context, EIP712, Nonces, IERC6372, IWonderVotes
* @dev Returns the maximum number of delegates that `proposalType` can delegate to.
*/
function _maxDelegates() internal view virtual returns (uint8);

/**
* @dev Returns true if the `proposalType` is valid, false otherwise.
*/
function _validProposalType(uint8 proposalType) internal view virtual returns (bool);

/**
* @dev checks the `proposalType` validity
*/
modifier validProposalType(uint8 proposalType) {
if (!_validProposalType(proposalType)) revert InvalidProposalType(proposalType);
_;
}
}
5 changes: 5 additions & 0 deletions solidity/interfaces/governance/utils/IWonderVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ interface IWonderVotes {
*/
error ZeroWeight();

/**
* @dev The proposal type is invalid.
*/
error InvalidProposalType(uint8 proposalType);

/**
* @dev The delegates number for a `proposalType` exceeds the maximum number of delegates.
*/
Expand Down

0 comments on commit d7d9aa0

Please sign in to comment.