Skip to content

Commit 3210a86

Browse files
abhi3700Amxxfrangio
authored
Modify ReentrancyGuard to reduce contract size (#3515)
Co-authored-by: Hadrien Croubois <[email protected]> Co-authored-by: Francisco <[email protected]>
1 parent 96163c8 commit 3210a86

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `ERC20`: optimize `_transfer`, `_mint` and `_burn` by using `unchecked` arithmetic when possible. ([#3513](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3513))
1010
* `ERC721`: optimize transfers by making approval clearing implicit instead of emitting an event. ([#3481](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3481))
1111
* `ERC721`: optimize burn by making approval clearing implicit instead of emitting an event. ([#3538](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3538))
12+
* `ReentrancyGuard`: Reduce code size impact of the modifier by using internal functions. ([#3515](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3515))
1213

1314
### Compatibility Note
1415

contracts/security/ReentrancyGuard.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,20 @@ abstract contract ReentrancyGuard {
4848
* `private` function that does the actual work.
4949
*/
5050
modifier nonReentrant() {
51+
_nonReentrantBefore();
52+
_;
53+
_nonReentrantAfter();
54+
}
55+
56+
function _nonReentrantBefore() private {
5157
// On the first call to nonReentrant, _notEntered will be true
5258
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
5359

5460
// Any calls to nonReentrant after this point will fail
5561
_status = _ENTERED;
62+
}
5663

57-
_;
58-
64+
function _nonReentrantAfter() private {
5965
// By storing the original value once again, a refund is triggered (see
6066
// https://eips.ethereum.org/EIPS/eip-2200)
6167
_status = _NOT_ENTERED;

0 commit comments

Comments
 (0)