Omniscia Sovryn Audit
InitializableReentrancyGuard Code Style Findings
InitializableReentrancyGuard Code Style Findings
IRG-01C: Inefficient Data Type
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | InitializableReentrancyGuard.sol:L23, L32, L47, L53 |
Description:
As indicated in the latest version of OpenZeppelin, the re-entrancy guard has been updated to instead utilize a uint256
variable given that a bool
is significantly more expensive to utilize due to the underlying unpadding and re-padding operations the EVM conducts.
Example:
contracts/helpers/InitializableReentrancyGuard.sol
42modifier nonReentrant() {43 // On the first call to nonReentrant, _notEntered will be true44 require(_notEntered, "ReentrancyGuard: reentrant call");45
46 // Any calls to nonReentrant after this point will fail47 _notEntered = false;48
49 _;50
51 // By storing the original value once again, a refund is triggered (see52 // https://eips.ethereum.org/EIPS/eip-2200)53 _notEntered = true;54}
Recommendation:
We advise the data type to be changed to uint256
and the values signalling "not entered" and "entered" to become 1
and 2
respectively.
Alleviation:
The uint256
data type was utilized across the codebase thus greatly optimizing the gas cost of the contract.