Closed code423n4 closed 2 years ago
0xsanson
The current implementation uses _locked = 0 for the unlocked state and _locked = 1 for the locked one. It's better to have two non-zero values from an optimization point of view; it can surprisingly save thousands of gas in some test cases.
_locked = 0
_locked = 1
Consider rewriting the modifier to:
modifier noReenter() { require(_locked == 1, "LOCKED"); _locked = uint256(2); _; _locked = uint256(1); }
(also add a _locked = 1 in the constructor).
hardhat gas reporter
Agreed. While not always cheaper, it is cheaper in this case for batch unlocks or relocks. Will implement this.
Duplicate #1
Handle
0xsanson
Vulnerability details
The current implementation uses
_locked = 0
for the unlocked state and_locked = 1
for the locked one. It's better to have two non-zero values from an optimization point of view; it can surprisingly save thousands of gas in some test cases.Consider rewriting the modifier to:
(also add a
_locked = 1
in the constructor).Tools Used
hardhat gas reporter