Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 5bd20c1

Browse files
committed
Use latest OZ dependency to patch DoS vuln for proposal creation
1 parent adb2eae commit 5bd20c1

File tree

10 files changed

+90
-20
lines changed

10 files changed

+90
-20
lines changed

contracts/ArenaGovernor.sol

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity 0.8.10;
2+
pragma solidity 0.8.19;
33

44
import "@openzeppelin/contracts/governance/Governor.sol";
55
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
@@ -47,7 +47,7 @@ contract ArenaGovernor is
4747
function getVotes(address account, uint256 blockNumber)
4848
public
4949
view
50-
override(IGovernor, GovernorVotes)
50+
override(IGovernor, Governor)
5151
returns (uint256)
5252
{
5353
return super.getVotes(account, blockNumber);
@@ -80,6 +80,15 @@ contract ArenaGovernor is
8080
return super.propose(targets, values, calldatas, description);
8181
}
8282

83+
function cancel(
84+
address[] memory targets,
85+
uint256[] memory values,
86+
bytes[] memory calldatas,
87+
bytes32 descriptionHash
88+
) public override(IGovernor, Governor, GovernorCompatibilityBravo) returns (uint256) {
89+
return super.cancel(targets, values, calldatas, descriptionHash);
90+
}
91+
8392
function proposalThreshold()
8493
public
8594
view
@@ -112,9 +121,10 @@ contract ArenaGovernor is
112121
uint256 proposalId,
113122
address account,
114123
uint8 support,
115-
string memory reason
124+
string memory reason,
125+
bytes memory params
116126
) internal override(Governor, GovernorPreventLateQuorum) returns (uint256) {
117-
return super._castVote(proposalId, account, support, reason);
127+
return super._castVote(proposalId, account, support, reason, params);
118128
}
119129

120130
function _executor()

deployments/polygonAddresses.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"tokenLock": "0xB17828789280C77C17B02fc8E6F20Ddc5721f2C2",
55
"timelock": "0xdFB26381aFBc37f0Fae4A77D385b91B90347aA12",
66
"governorV1": "0xc6eaDcC36aFcf1C430962506ad79145aD5140E58",
7-
"governor": "0x4Db7E521942BDA8b1fB1B310280135ba4B9c2bee",
7+
"governorV2": "0x4Db7E521942BDA8b1fB1B310280135ba4B9c2bee",
8+
"governorLatest": "0xd8c32446d8a3f17df5c7d38cdd3e78696434cf4a",
89
"tokenSale": "0xD0e7d5a2220e32914540D97A6D0548658050180b"
910
}

hardhat.config.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ dotenv.config();
1818

1919
const config: HardhatUserConfig = {
2020
solidity: {
21-
version: '0.8.10',
22-
settings: {
23-
optimizer: {
24-
enabled: true,
25-
runs: 999999,
21+
compilers: [
22+
{
23+
version: '0.8.10',
24+
settings: {
25+
optimizer: {
26+
enabled: true,
27+
runs: 999999,
28+
},
29+
},
2630
},
27-
},
31+
{
32+
version: '0.8.19',
33+
settings: {
34+
optimizer: {
35+
enabled: true,
36+
runs: 24999
37+
}
38+
}
39+
}
40+
]
2841
},
2942
networks: {
3043
hardhat: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@nomiclabs/hardhat-ethers": "^2.0.4",
3232
"@nomiclabs/hardhat-etherscan": "3.0.3",
3333
"@nomiclabs/hardhat-waffle": "^2.0.0",
34-
"@openzeppelin/contracts": "^4.5.0",
34+
"@openzeppelin/contracts": "^4.9.1",
3535
"@typechain/ethers-v5": "^9.0.0",
3636
"@typechain/hardhat": "^4.0.0",
3737
"@types/chai": "^4.2.21",

scripts/deploy/deployGov.ts renamed to scripts/deploy/deployFull.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ADMIN_ROLE = '0x5f58e3a2316349923ce3780f8d587db2d72378aed66a8261c916544fa6
2626
const PROPOSER_ROLE = '0xb09aa5aeb3702cfd50b6b62bc4532604938f21248a27a1d5ca736082b6819cc1';
2727
const EXECUTOR_ROLE = '0xd8aa0f3194971a2a116679f7c2090f6939c8d4e01a2a8d7e41d55e5351469e63';
2828

29-
export async function deployGov(hre: HardhatRuntimeEnvironment) {
29+
export async function deployFull(hre: HardhatRuntimeEnvironment) {
3030
const networkId = hre.network.config.chainId as number;
3131
const [deployer] = await hre.ethers.getSigners();
3232
deployerAddress = await deployer.getAddress();

scripts/deploy/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import {task} from 'hardhat/config';
22

3-
task('deployGov', 'deploy governance and token contracts').setAction(async (taskArgs, hre) => {
3+
task('deployFull', 'deploy governance (timelock + governor) and token contracts').setAction(async (taskArgs, hre) => {
44
// only load this file when task is run because it depends on typechain built artifacts
55
// which will create a circular dependency when required by hardhat.config.ts for first compilation
6-
const {deployGov} = await import('./deployGov');
7-
await deployGov(hre);
6+
const {deployFull} = await import('./deployFull');
7+
await deployFull(hre);
8+
});
9+
10+
task('upgradeGov', 'deploy ArenaGovernor').setAction(async (taskArgs, hre) => {
11+
const {upgradeGov} = await import('./upgradeGov');
12+
await upgradeGov(hre);
813
});
914

1015
task('deployTokenSale', 'deploy token sale and make proposal for relevant actions').setAction(async (taskArgs, hre) => {

scripts/deploy/upgradeGov.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {
2+
ArenaGovernor__factory,
3+
ArenaGovernor,
4+
} from '../../typechain';
5+
6+
import deployedAddrsJson from "../../deployments/polygonAddresses.json";
7+
import {HardhatRuntimeEnvironment} from 'hardhat/types';
8+
import {verifyContract} from './verify';
9+
10+
let deployerAddress: string;
11+
let governor: ArenaGovernor;
12+
13+
14+
export async function upgradeGov(hre: HardhatRuntimeEnvironment) {
15+
const networkId = hre.network.config.chainId as number;
16+
const [deployer] = await hre.ethers.getSigners();
17+
deployerAddress = await deployer.getAddress();
18+
console.log(`Deployer: ${deployerAddress}`);
19+
20+
console.log(`token address: ${deployedAddrsJson.token}`);
21+
console.log(`timelock address: ${deployedAddrsJson.timelock}`);
22+
23+
console.log(`deploying governor...`);
24+
const ArenaGovernorFactory = (await hre.ethers.getContractFactory('ArenaGovernor')) as ArenaGovernor__factory;
25+
governor = await ArenaGovernorFactory.deploy(deployedAddrsJson.token, deployedAddrsJson.timelock);
26+
await governor.deployed();
27+
console.log(`governor address: ${governor.address}`);
28+
29+
console.log(`sleeping for 30s...`);
30+
// sleep for 30s for network propagation
31+
await new Promise(f => setTimeout(f, 30_000));
32+
33+
console.log('verifying address on etherscan...');
34+
await verifyContract(hre, governor.address, [deployedAddrsJson.token, deployedAddrsJson.timelock]);
35+
// await verifyContract(hre, "0x33Aa2B500F05fa1F6951f2FbE0bb283C629E1F56", [deployedAddrsJson.token, deployedAddrsJson.timelock]);
36+
process.exit(0);
37+
}

scripts/proposals/simulateExistingProposal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {HardhatRuntimeEnvironment} from 'hardhat/types';
22
import {getPolygonContracts, getForkParams} from '../../shared/Forking';
33
import {createAndExecuteProposal} from '../../shared/Governance';
44

5+
// Eg commands:
6+
// nvm use 16.16
7+
// yarn hardhat simulateExistingProposal --id 93022684150159074125678303578919779638229937046863883601906649520845717660577
58
export async function simulateExistingProposal(proposalId: string, hre: HardhatRuntimeEnvironment) {
69
const [user] = await hre.ethers.getSigners();
710
const deployment = getPolygonContracts(user);

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"target": "es2018",
44
"module": "commonjs",
55
"strict": true,
6+
"resolveJsonModule": true,
67
"esModuleInterop": true,
78
"outDir": "dist",
89
"declaration": true

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -663,10 +663,10 @@
663663
"@types/sinon-chai" "^3.2.3"
664664
"@types/web3" "1.0.19"
665665

666-
"@openzeppelin/contracts@^4.5.0":
667-
version "4.5.0"
668-
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.5.0.tgz#3fd75d57de172b3743cdfc1206883f56430409cc"
669-
integrity sha512-fdkzKPYMjrRiPK6K4y64e6GzULR7R7RwxSigHS8DDp7aWDeoReqsQI+cxHV1UuhAqX69L1lAaWDxenfP+xiqzA==
666+
"@openzeppelin/contracts@^4.9.1":
667+
version "4.9.1"
668+
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.9.1.tgz#afa804d2c68398704b0175acc94d91a54f203645"
669+
integrity sha512-aLDTLu/If1qYIFW5g4ZibuQaUsFGWQPBq1mZKp/txaebUnGHDmmiBhRLY1tDNedN0m+fJtKZ1zAODS9Yk+V6uA==
670670

671671
"@resolver-engine/core@^0.3.3":
672672
version "0.3.3"

0 commit comments

Comments
 (0)