# OpenZeppelin Pausable

## OpenZeppelin Doc

{% embed url="https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable" %}
Pausable
{% endembed %}

<mark style="color:red;">**Contract module which allows children to implement an emergency stop mechanism that can be triggered by an authorized account.**</mark>

This module is used through inheritance. It will make available the modifiers `whenNotPaused` and `whenPaused`, which can be applied to the functions of your contract. Note that they will not be pausable by simply including this module, only once the modifiers are put in place.

## OpenZeppelin Pausable

{% embed url="https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/Pausable.sol" %}
Pausable.sol
{% endembed %}

### State Variables and Constants

There is only one state variable in this contract:

```solidity
bool private _paused;
```

Note that when a contract inherits Pausable, `_paused` will be stored in storage slot 0.

### Modifiers

```solidity
modifier whenNotPaused() {
    _requireNotPaused();
    _;
}

modifier whenPaused() {
    _requirePaused();
    _;
}
```

### \_pause() and \_unpause()

```solidity
function _pause() internal virtual whenNotPaused {
    _paused = true;
    emit Paused(_msgSender());
}
    
function _unpause() internal virtual whenPaused {
    _paused = false;
    emit Unpaused(_msgSender());
}
```

Note that these two functios are internal functions. If you want to let admin pause the contract externally, you have to implement separate external functions. I learnt this fact from pashov's audit report:

{% embed url="https://github.com/pashov/audits/blob/master/solo/ParcelPayroll-security-review.md#m-03-contract-inherits-from-pausable-but-does-not-expose-pausingunpausing-functionality" %}

<figure><img src="https://3988450783-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MWVjG_njKgBtvmnKaJh%2Fuploads%2FexCs2eWUsxVEG6AmEmMX%2Fimage.png?alt=media&#x26;token=fa405cf6-94df-497f-9b0b-3f9d1d49f2b3" alt=""><figcaption></figcaption></figure>
