Skip to content

Commit 3ec4307

Browse files
Amxxfrangio
andauthored
Fix bug allowing anyone to cancel an admin renounce (#4238)
Co-authored-by: Francisco Giordano <fg@frang.io>
1 parent f355bd3 commit 3ec4307

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

contracts/access/AccessControlDefaultAdminRules.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRu
106106
* non-administrated role.
107107
*/
108108
function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {
109-
if (role == DEFAULT_ADMIN_ROLE) {
109+
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
110110
(address newDefaultAdmin, uint48 schedule) = pendingDefaultAdmin();
111111
require(
112112
newDefaultAdmin == address(0) && _isScheduleSet(schedule) && _hasSchedulePassed(schedule),
@@ -138,7 +138,7 @@ abstract contract AccessControlDefaultAdminRules is IAccessControlDefaultAdminRu
138138
* @dev See {AccessControl-_revokeRole}.
139139
*/
140140
function _revokeRole(bytes32 role, address account) internal virtual override {
141-
if (role == DEFAULT_ADMIN_ROLE && account == _currentDefaultAdmin) {
141+
if (role == DEFAULT_ADMIN_ROLE && account == defaultAdmin()) {
142142
delete _currentDefaultAdmin;
143143
}
144144
super._revokeRole(role, account);

test/access/AccessControl.behavior.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -621,14 +621,15 @@ function shouldBehaveLikeAccessControlDefaultAdminRules(errorPrefix, delay, defa
621621
});
622622

623623
describe('renounces admin', function () {
624+
let expectedSchedule;
624625
let delayPassed;
626+
let delayNotPassed;
625627

626628
beforeEach(async function () {
627629
await this.accessControl.beginDefaultAdminTransfer(constants.ZERO_ADDRESS, { from: defaultAdmin });
628-
delayPassed = web3.utils
629-
.toBN(await time.latest())
630-
.add(delay)
631-
.addn(1);
630+
expectedSchedule = web3.utils.toBN(await time.latest()).add(delay);
631+
delayNotPassed = expectedSchedule;
632+
delayPassed = expectedSchedule.addn(1);
632633
});
633634

634635
it('reverts if caller is not default admin', async function () {
@@ -639,6 +640,15 @@ function shouldBehaveLikeAccessControlDefaultAdminRules(errorPrefix, delay, defa
639640
);
640641
});
641642

643+
it("renouncing the admin role when not an admin doesn't affect the schedule", async function () {
644+
await time.setNextBlockTimestamp(delayPassed);
645+
await this.accessControl.renounceRole(DEFAULT_ADMIN_ROLE, other, { from: other });
646+
647+
const { newAdmin, schedule } = await this.accessControl.pendingDefaultAdmin();
648+
expect(newAdmin).to.equal(constants.ZERO_ADDRESS);
649+
expect(schedule).to.be.bignumber.equal(expectedSchedule);
650+
});
651+
642652
it('keeps defaultAdmin consistent with hasRole if another non-defaultAdmin user renounces the DEFAULT_ADMIN_ROLE', async function () {
643653
await time.setNextBlockTimestamp(delayPassed);
644654

@@ -677,12 +687,6 @@ function shouldBehaveLikeAccessControlDefaultAdminRules(errorPrefix, delay, defa
677687
});
678688

679689
describe('schedule not passed', function () {
680-
let delayNotPassed;
681-
682-
beforeEach(function () {
683-
delayNotPassed = delayPassed.subn(1);
684-
});
685-
686690
for (const [fromSchedule, tag] of [
687691
[-1, 'less'],
688692
[0, 'equal'],

0 commit comments

Comments
 (0)