Skip to content

Commit 8879854

Browse files
JulissaDantesAmxxfrangio
authored
Use default admin role in TimelockController (#3799)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <frangio.1@gmail.com>
1 parent b18cf4b commit 8879854

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased (Breaking)
4+
5+
* `TimelockController`: Changed the role architecture to use `DEFAULT_ADMIN_ROLE` as the admin for all roles, instead of the bespoke `TIMELOCK_ADMIN_ROLE` that was used previously. This aligns with the general recommendation for `AccessControl` and makes the addition of new roles easier. Accordingly, the `admin` parameter and timelock will now be granted `DEFAULT_ADMIN_ROLE` instead of `TIMELOCK_ADMIN_ROLE`. ([#3799](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3799))
6+
37
## Unreleased
48

59
* `ReentrancyGuard`: Add a `_reentrancyGuardEntered` function to expose the guard status. ([#3714](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3714))

contracts/governance/README.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ Operations status can be queried using the functions:
155155

156156
The admins are in charge of managing proposers and executors. For the timelock to be self-governed, this role should only be given to the timelock itself. Upon deployment, the admin role can be granted to any address (in addition to the timelock itself). After further configuration and testing, this optional admin should renounce its role such that all further maintenance operations have to go through the timelock process.
157157

158-
This role is identified by the *TIMELOCK_ADMIN_ROLE* value: `0x5f58e3a2316349923ce3780f8d587db2d72378aed66a8261c916544fa6846ca5`
159-
160158
[[timelock-proposer]]
161159
===== Proposer
162160

contracts/governance/TimelockController.sol

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import "../utils/Address.sol";
2424
* _Available since v3.3._
2525
*/
2626
contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver {
27-
bytes32 public constant TIMELOCK_ADMIN_ROLE = keccak256("TIMELOCK_ADMIN_ROLE");
2827
bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
2928
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
3029
bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
@@ -80,17 +79,12 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
8079
address[] memory executors,
8180
address admin
8281
) {
83-
_setRoleAdmin(TIMELOCK_ADMIN_ROLE, TIMELOCK_ADMIN_ROLE);
84-
_setRoleAdmin(PROPOSER_ROLE, TIMELOCK_ADMIN_ROLE);
85-
_setRoleAdmin(EXECUTOR_ROLE, TIMELOCK_ADMIN_ROLE);
86-
_setRoleAdmin(CANCELLER_ROLE, TIMELOCK_ADMIN_ROLE);
87-
8882
// self administration
89-
_setupRole(TIMELOCK_ADMIN_ROLE, address(this));
83+
_grantRole(DEFAULT_ADMIN_ROLE, address(this));
9084

9185
// optional admin
9286
if (admin != address(0)) {
93-
_setupRole(TIMELOCK_ADMIN_ROLE, admin);
87+
_grantRole(DEFAULT_ADMIN_ROLE, admin);
9488
}
9589

9690
// register proposers and cancellers

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/governance/TimelockController.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function genOperationBatch (targets, values, payloads, predecessor, salt) {
5454
contract('TimelockController', function (accounts) {
5555
const [ , admin, proposer, canceller, executor, other ] = accounts;
5656

57-
const TIMELOCK_ADMIN_ROLE = web3.utils.soliditySha3('TIMELOCK_ADMIN_ROLE');
57+
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
5858
const PROPOSER_ROLE = web3.utils.soliditySha3('PROPOSER_ROLE');
5959
const EXECUTOR_ROLE = web3.utils.soliditySha3('EXECUTOR_ROLE');
6060
const CANCELLER_ROLE = web3.utils.soliditySha3('CANCELLER_ROLE');
@@ -84,7 +84,7 @@ contract('TimelockController', function (accounts) {
8484
it('initial state', async function () {
8585
expect(await this.mock.getMinDelay()).to.be.bignumber.equal(MINDELAY);
8686

87-
expect(await this.mock.TIMELOCK_ADMIN_ROLE()).to.be.equal(TIMELOCK_ADMIN_ROLE);
87+
expect(await this.mock.DEFAULT_ADMIN_ROLE()).to.be.equal(DEFAULT_ADMIN_ROLE);
8888
expect(await this.mock.PROPOSER_ROLE()).to.be.equal(PROPOSER_ROLE);
8989
expect(await this.mock.EXECUTOR_ROLE()).to.be.equal(EXECUTOR_ROLE);
9090
expect(await this.mock.CANCELLER_ROLE()).to.be.equal(CANCELLER_ROLE);
@@ -111,8 +111,8 @@ contract('TimelockController', function (accounts) {
111111
{ from: other },
112112
);
113113

114-
expect(await mock.hasRole(TIMELOCK_ADMIN_ROLE, admin)).to.be.equal(false);
115-
expect(await mock.hasRole(TIMELOCK_ADMIN_ROLE, other)).to.be.equal(false);
114+
expect(await mock.hasRole(DEFAULT_ADMIN_ROLE, admin)).to.be.equal(false);
115+
expect(await mock.hasRole(DEFAULT_ADMIN_ROLE, mock.address)).to.be.equal(true);
116116
});
117117

118118
describe('methods', function () {

test/governance/extensions/GovernorTimelockControl.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const CallReceiver = artifacts.require('CallReceiverMock');
1515
contract('GovernorTimelockControl', function (accounts) {
1616
const [ owner, voter1, voter2, voter3, voter4, other ] = accounts;
1717

18-
const TIMELOCK_ADMIN_ROLE = web3.utils.soliditySha3('TIMELOCK_ADMIN_ROLE');
18+
const DEFAULT_ADMIN_ROLE = '0x0000000000000000000000000000000000000000000000000000000000000000';
1919
const PROPOSER_ROLE = web3.utils.soliditySha3('PROPOSER_ROLE');
2020
const EXECUTOR_ROLE = web3.utils.soliditySha3('EXECUTOR_ROLE');
2121
const CANCELLER_ROLE = web3.utils.soliditySha3('CANCELLER_ROLE');
@@ -46,7 +46,7 @@ contract('GovernorTimelockControl', function (accounts) {
4646

4747
this.helper = new GovernorHelper(this.mock);
4848

49-
this.TIMELOCK_ADMIN_ROLE = await this.timelock.TIMELOCK_ADMIN_ROLE();
49+
this.DEFAULT_ADMIN_ROLE = await this.timelock.DEFAULT_ADMIN_ROLE();
5050
this.PROPOSER_ROLE = await this.timelock.PROPOSER_ROLE();
5151
this.EXECUTOR_ROLE = await this.timelock.EXECUTOR_ROLE();
5252
this.CANCELLER_ROLE = await this.timelock.CANCELLER_ROLE();
@@ -59,7 +59,7 @@ contract('GovernorTimelockControl', function (accounts) {
5959
await this.timelock.grantRole(CANCELLER_ROLE, this.mock.address);
6060
await this.timelock.grantRole(CANCELLER_ROLE, owner);
6161
await this.timelock.grantRole(EXECUTOR_ROLE, constants.ZERO_ADDRESS);
62-
await this.timelock.revokeRole(TIMELOCK_ADMIN_ROLE, deployer);
62+
await this.timelock.revokeRole(DEFAULT_ADMIN_ROLE, deployer);
6363

6464
await this.token.mint(owner, tokenSupply);
6565
await this.helper.delegate({ token: this.token, to: voter1, value: web3.utils.toWei('10') }, { from: owner });

0 commit comments

Comments
 (0)