Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smooth-penguins-pause.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'openzeppelin-solidity': patch
---

Allow `_pause()` to be called when the contract is already paused, preventing denial of service in emergency scenarios.

7 changes: 3 additions & 4 deletions contracts/utils/Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ abstract contract Pausable is Context {
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
* This function can be called even when the contract is already paused, which
* can be useful in emergency scenarios to prevent denial of service.
*/
function _pause() internal virtual whenNotPaused {
function _pause() internal virtual {
_paused = true;
emit Paused(_msgSender());
}
Expand Down
6 changes: 3 additions & 3 deletions fv/specs/Pausable.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ rule pause(env e) {

bool pausedAfter = paused();

// liveness
assert success <=> !pausedBefore, "works if and only if the contract was not paused before";
// liveness - pause() can be called even when already paused to prevent DOS
assert success, "pause() always succeeds, even when already paused";

// effect
assert success => pausedAfter, "contract must be paused after a successful call";
assert pausedAfter, "contract must be paused after a successful call";
}

/*
Expand Down
6 changes: 4 additions & 2 deletions test/utils/Pausable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ describe('Pausable', function () {
expect(await this.mock.drasticMeasureTaken()).to.be.true;
});

it('reverts when re-pausing', async function () {
await expect(this.mock.pause()).to.be.revertedWithCustomError(this.mock, 'EnforcedPause');
it('allows re-pausing when already paused', async function () {
const tx = await this.mock.pause();
await expect(tx).to.emit(this.mock, 'Paused').withArgs(this.pauser);
expect(await this.mock.paused()).to.be.true;
});

describe('unpausing', function () {
Expand Down