@@ -23,9 +23,8 @@ abstract contract ReentrancyGuardTransient {
23
23
* @dev Pre-computed BooleanSlot type wrapper for the reentrancy guard storage slot.
24
24
* This optimization avoids the overhead of repeatedly calling asBoolean() which performs
25
25
* a bytes32.wrap() operation on each invocation. By pre-computing the wrapped type at compile-time,
26
- * this eliminates redundant type casting operations in _nonReentrantBefore(), _nonReentrantAfter(),
27
- * and _reentrancyGuardEntered(), reducing gas consumption by 10 gas per call
28
- * to asBoolean() (30 gas total per nonReentrant modifier execution).
26
+ * this eliminates 3 redundant type casting operations per nonReentrant modifier execution,
27
+ * reducing gas consumption by 19 gas.
29
28
*/
30
29
TransientSlot.BooleanSlot private constant REENTRANCY_SLOT =
31
30
TransientSlot.BooleanSlot.wrap (REENTRANCY_GUARD_STORAGE);
@@ -48,11 +47,28 @@ abstract contract ReentrancyGuardTransient {
48
47
_nonReentrantAfter ();
49
48
}
50
49
51
- function _nonReentrantBefore () private {
52
- // On the first call to nonReentrant, REENTRANCY_SLOT.tload() will be false
50
+ /**
51
+ * @dev A `view` only version of {nonReentrant}. Use to block view functions
52
+ * from being called, preventing reading from inconsistent contract state.
53
+ *
54
+ * CAUTION: This is a "view" modifier and does not change the reentrancy
55
+ * status. Use it only on view functions. For payable or non-payable functions,
56
+ * use the standard {nonReentrant} modifier instead.
57
+ */
58
+ modifier nonReentrantView () {
59
+ _nonReentrantBeforeView ();
60
+ _;
61
+ }
62
+
63
+ function _nonReentrantBeforeView () private view {
53
64
if (_reentrancyGuardEntered ()) {
54
65
revert ReentrancyGuardReentrantCall ();
55
66
}
67
+ }
68
+
69
+ function _nonReentrantBefore () private {
70
+ // On the first call to nonReentrant, REENTRANCY_SLOT.tload() will be false
71
+ _nonReentrantBeforeView ();
56
72
57
73
// Any calls to nonReentrant after this point will fail
58
74
REENTRANCY_SLOT.tstore (true );
0 commit comments