-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Add Governor signature nonces #4378
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
Changes from all commits
0619b5c
5ecb405
9e9e238
b84ea6e
2781b5f
ba44fa1
3f6e520
79c5982
35de382
a75ca26
b32bfdd
d518d65
71cd6ba
48a048c
8a810c9
f808576
2ed9be3
2ae0a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'openzeppelin-solidity': major | ||
--- | ||
|
||
`Governor`: Add `voter` and `nonce` parameters in signed ballots, to avoid forging signatures for random addresses, prevent signature replay, and allow invalidating signatures. Add `voter` as a new parameter in the `castVoteBySig` and `castVoteWithReasonAndParamsBySig` functions. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import {SafeCast} from "../utils/math/SafeCast.sol"; | |
import {DoubleEndedQueue} from "../utils/structs/DoubleEndedQueue.sol"; | ||
import {Address} from "../utils/Address.sol"; | ||
import {Context} from "../utils/Context.sol"; | ||
import {Nonces} from "../utils/Nonces.sol"; | ||
import {IGovernor, IERC6372} from "./IGovernor.sol"; | ||
|
||
/** | ||
|
@@ -25,12 +26,15 @@ import {IGovernor, IERC6372} from "./IGovernor.sol"; | |
* | ||
* _Available since v4.3._ | ||
*/ | ||
abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receiver, IERC1155Receiver { | ||
abstract contract Governor is Context, ERC165, EIP712, Nonces, IGovernor, IERC721Receiver, IERC1155Receiver { | ||
using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque; | ||
|
||
bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)"); | ||
bytes32 public constant BALLOT_TYPEHASH = | ||
keccak256("Ballot(uint256 proposalId,uint8 support,address voter,uint256 nonce)"); | ||
bytes32 public constant EXTENDED_BALLOT_TYPEHASH = | ||
keccak256("ExtendedBallot(uint256 proposalId,uint8 support,string reason,bytes params)"); | ||
keccak256( | ||
"ExtendedBallot(uint256 proposalId,uint8 support,address voter,uint256 nonce,string reason,bytes params)" | ||
); | ||
|
||
// solhint-disable var-name-mixedcase | ||
struct ProposalCore { | ||
|
@@ -514,17 +518,23 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive | |
function castVoteBySig( | ||
uint256 proposalId, | ||
uint8 support, | ||
address voter, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is changing the ERC-165 ids, i.e. removing the previously supported interfaces (correctly) and adding new ones. However, we've discussed before that ERC-165 is not a good fit for this contract so we should really think whether we want to continue using it and particularly adding new interfaces. No need to change anything on this PR, but it is an unsolved question we need to address. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is relevant to #4360 |
||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) public virtual override returns (uint256) { | ||
address voter = ECDSA.recover( | ||
_hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support))), | ||
address signer = ECDSA.recover( | ||
_hashTypedDataV4(keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support, voter, _useNonce(voter)))), | ||
v, | ||
r, | ||
s | ||
); | ||
return _castVote(proposalId, voter, support, ""); | ||
|
||
if (voter != signer) { | ||
revert GovernorInvalidSigner(signer, voter); | ||
} | ||
|
||
return _castVote(proposalId, signer, support, ""); | ||
} | ||
|
||
/** | ||
|
@@ -533,19 +543,22 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive | |
function castVoteWithReasonAndParamsBySig( | ||
uint256 proposalId, | ||
uint8 support, | ||
address voter, | ||
string calldata reason, | ||
bytes memory params, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
Comment on lines
549
to
551
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that we are changing the signature of the I don't think we should do this here so it's not a blocker for this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also aligns really well with the addition of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to what we discussed, I'll add the signature changes and 1271 compatibility in a follow up PR |
||
) public virtual override returns (uint256) { | ||
address voter = ECDSA.recover( | ||
address signer = ECDSA.recover( | ||
_hashTypedDataV4( | ||
keccak256( | ||
abi.encode( | ||
EXTENDED_BALLOT_TYPEHASH, | ||
proposalId, | ||
support, | ||
voter, | ||
_useNonce(voter), | ||
keccak256(bytes(reason)), | ||
keccak256(params) | ||
) | ||
|
@@ -556,7 +569,11 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive | |
s | ||
); | ||
|
||
return _castVote(proposalId, voter, support, reason, params); | ||
if (voter != signer) { | ||
revert GovernorInvalidSigner(signer, voter); | ||
} | ||
|
||
return _castVote(proposalId, signer, support, reason, params); | ||
} | ||
|
||
/** | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.