Skip to content

Commit ee2f4b1

Browse files
0xChin0xOneTony
andauthored
feat: duplicated proposals check (#378)
* feat: add initial interface and logic * refactor: remove installed governor submodule * chore: remove xERC20 * feat: add proposal routing full flow * feat: check voting power and required proposals * refactor: rename to ProposalValidator * feat: add EAS validation for certain Proposal Types * feat: add duplicated proposals validation * chore: fix attestation schema approved address naming Co-authored-by: 0xOneTony <[email protected]> Signed-off-by: Chiin <[email protected]> * chore: remove management functions * chore: run pre-pr * refacto: follow style guide for function parameters and return variables * docs: add natspec, remove unused errors * chore: remove management functions from interface * chore: make voting token immutable * perf: make governor immutable * feat: add validator management functions * chore: add comments for imports in ProposalValidator * test: add unit tests * chore: run pre-pr * fix: semgrep warnings * chore: rename MaintenanceUpgradeProposals --> MaintenanceUpgrade * chore(semgrep): add excluded governance files * chore: fix coding style * chore: add ImmutableProposalTypeData * chore: improve errors naming * docs: improve natspec Co-authored-by: 0xOneTony <[email protected]> Signed-off-by: Chiin <[email protected]> * docs: add technical explanation on attestation validation function * feat: add _proposalTypeData mapping * chore: keep private functions consistency * chore: improve required attestation naming * chore: run pre-pr * chore: more descriptive errors * chore: confusing error name in submitProposal --------- Signed-off-by: Chiin <[email protected]> Co-authored-by: 0xOneTony <[email protected]>
1 parent 76e6bc2 commit ee2f4b1

File tree

5 files changed

+241
-163
lines changed

5 files changed

+241
-163
lines changed

packages/contracts-bedrock/interfaces/governance/IProposalValidator.sol

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import {IOptimismGovernor} from "./IOptimismGovernor.sol";
99
interface IProposalValidator {
1010
error ProposalValidator_InsufficientApprovals();
1111
error ProposalValidator_ProposalAlreadyApproved();
12-
error ProposalValidator_ProposalAlreadyInVoting();
12+
error ProposalValidator_ProposalAlreadySubmitted();
1313
error ProposalValidator_InsufficientVotingPower();
1414
error ProposalValidator_InvalidAttestation();
15+
error ProposalValidator_ProposalDoesNotExist();
1516

1617
struct ProposalData {
1718
address proposer;
18-
address[] targets;
19-
uint256[] values;
20-
bytes[] calldatas;
21-
string description;
2219
ProposalType proposalType;
20+
uint8 proposalTypeConfigurator;
2321
bool inVoting;
2422
mapping(address => bool) delegateApprovals;
2523
uint256 remainingApprovalsRequired;
@@ -40,22 +38,23 @@ interface IProposalValidator {
4038
}
4139

4240
event ProposalSubmitted(
43-
uint256 indexed proposalId,
41+
bytes32 indexed proposalHash,
4442
address indexed proposer,
4543
address[] targets,
4644
uint256[] values,
4745
bytes[] calldatas,
4846
string description,
49-
ProposalType proposalType
47+
ProposalType proposalType,
48+
uint8 proposalTypeConfigurator
5049
);
5150

5251
event ProposalApproved(
53-
uint256 indexed proposalId,
52+
bytes32 indexed proposalHash,
5453
address indexed approver
5554
);
5655

5756
event ProposalMovedToVote(
58-
uint256 indexed proposalId,
57+
bytes32 indexed proposalHash,
5958
address indexed executor
6059
);
6160

@@ -75,12 +74,18 @@ interface IProposalValidator {
7574
bytes[] memory _calldatas,
7675
string memory _description,
7776
ProposalType _proposalType,
77+
uint8 _proposalTypeConfigurator,
7878
bytes32 _attestationUid
79-
) external returns (uint256 proposalId_);
79+
) external returns (bytes32 proposalHash_);
8080

81-
function approveProposal(uint256 _proposalId) external;
81+
function approveProposal(bytes32 _proposalHash) external;
8282

83-
function moveToVote(uint256 _proposalId) external returns (uint256 governorProposalId_);
83+
function moveToVote(
84+
address[] memory _targets,
85+
uint256[] memory _values,
86+
bytes[] memory _calldatas,
87+
string memory _description
88+
) external returns (uint256 governorProposalId_);
8489

8590
function setMinimumVotingPower(uint256 _minimumVotingPower) external;
8691

packages/contracts-bedrock/snapshots/abi/ProposalValidator.json

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@
114114
{
115115
"inputs": [
116116
{
117-
"internalType": "uint256",
118-
"name": "_proposalId",
119-
"type": "uint256"
117+
"internalType": "bytes32",
118+
"name": "_proposalHash",
119+
"type": "bytes32"
120120
}
121121
],
122122
"name": "approveProposal",
@@ -172,9 +172,24 @@
172172
{
173173
"inputs": [
174174
{
175-
"internalType": "uint256",
176-
"name": "_proposalId",
177-
"type": "uint256"
175+
"internalType": "address[]",
176+
"name": "_targets",
177+
"type": "address[]"
178+
},
179+
{
180+
"internalType": "uint256[]",
181+
"name": "_values",
182+
"type": "uint256[]"
183+
},
184+
{
185+
"internalType": "bytes[]",
186+
"name": "_calldatas",
187+
"type": "bytes[]"
188+
},
189+
{
190+
"internalType": "string",
191+
"name": "_description",
192+
"type": "string"
178193
}
179194
],
180195
"name": "moveToVote",
@@ -292,6 +307,11 @@
292307
"name": "_proposalType",
293308
"type": "uint8"
294309
},
310+
{
311+
"internalType": "uint8",
312+
"name": "_proposalTypeConfigurator",
313+
"type": "uint8"
314+
},
295315
{
296316
"internalType": "bytes32",
297317
"name": "_attestationUid",
@@ -301,9 +321,9 @@
301321
"name": "submitProposal",
302322
"outputs": [
303323
{
304-
"internalType": "uint256",
305-
"name": "proposalId_",
306-
"type": "uint256"
324+
"internalType": "bytes32",
325+
"name": "proposalHash_",
326+
"type": "bytes32"
307327
}
308328
],
309329
"stateMutability": "nonpayable",
@@ -404,9 +424,9 @@
404424
"inputs": [
405425
{
406426
"indexed": true,
407-
"internalType": "uint256",
408-
"name": "proposalId",
409-
"type": "uint256"
427+
"internalType": "bytes32",
428+
"name": "proposalHash",
429+
"type": "bytes32"
410430
},
411431
{
412432
"indexed": true,
@@ -423,9 +443,9 @@
423443
"inputs": [
424444
{
425445
"indexed": true,
426-
"internalType": "uint256",
427-
"name": "proposalId",
428-
"type": "uint256"
446+
"internalType": "bytes32",
447+
"name": "proposalHash",
448+
"type": "bytes32"
429449
},
430450
{
431451
"indexed": true,
@@ -442,9 +462,9 @@
442462
"inputs": [
443463
{
444464
"indexed": true,
445-
"internalType": "uint256",
446-
"name": "proposalId",
447-
"type": "uint256"
465+
"internalType": "bytes32",
466+
"name": "proposalHash",
467+
"type": "bytes32"
448468
},
449469
{
450470
"indexed": true,
@@ -481,6 +501,12 @@
481501
"internalType": "enum ProposalValidator.ProposalType",
482502
"name": "proposalType",
483503
"type": "uint8"
504+
},
505+
{
506+
"indexed": false,
507+
"internalType": "uint8",
508+
"name": "proposalTypeConfigurator",
509+
"type": "uint8"
484510
}
485511
],
486512
"name": "ProposalSubmitted",
@@ -521,7 +547,12 @@
521547
},
522548
{
523549
"inputs": [],
524-
"name": "ProposalValidator_ProposalAlreadyInVoting",
550+
"name": "ProposalValidator_ProposalAlreadySubmitted",
551+
"type": "error"
552+
},
553+
{
554+
"inputs": [],
555+
"name": "ProposalValidator_ProposalDoesNotExist",
525556
"type": "error"
526557
}
527558
]

packages/contracts-bedrock/snapshots/storageLayout/ProposalValidator.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@
4646
"label": "_proposals",
4747
"offset": 0,
4848
"slot": "6",
49-
"type": "mapping(uint256 => struct ProposalValidator.ProposalData)"
50-
},
51-
{
52-
"bytes": "32",
53-
"label": "_proposalCounter",
54-
"offset": 0,
55-
"slot": "7",
56-
"type": "uint256"
49+
"type": "mapping(bytes32 => struct ProposalValidator.ProposalData)"
5750
}
5851
]

0 commit comments

Comments
 (0)