The noRenter modifier sets the value of the _locked variable to 1 to acquire the lock and prevent reentrancy and sets _locked to 0 to release the lock.
Instead it should use 1 for unlocked and 2 for locked since zeroing values in storage can use more gas.
This implementation of noRenter is more gas efficient:
Handle
mtz
Vulnerability details
Impact
The noRenter modifier sets the value of the
_locked
variable to1
to acquire the lock and prevent reentrancy and sets_locked
to0
to release the lock. Instead it should use1
for unlocked and2
for locked since zeroing values in storage can use more gas. This implementation ofnoRenter
is more gas efficient:This is similar to OpenZeppelin's ReentrancyGuard implementation
See the rationale there for why 1 and 2 are more efficient than 0 and 1.
Proof of Concept
In my tests (code snippet below), the more efficient reentrancy guard uses 11130 less gas
Tools Used
N/A
Recommended Mitigation Steps
Use the more efficient
noRenter
implementation recommended above.