From b2e7bab92044031a495a53b4ccc31c84137f4319 Mon Sep 17 00:00:00 2001 From: Molly Date: Fri, 25 Aug 2023 13:49:34 -0400 Subject: [PATCH] caching result of reading storage variable to save gas (#4535) --- contracts/proxy/utils/Initializable.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/proxy/utils/Initializable.sol b/contracts/proxy/utils/Initializable.sol index 7f33a6267..ac97a06fb 100644 --- a/contracts/proxy/utils/Initializable.sol +++ b/contracts/proxy/utils/Initializable.sol @@ -106,7 +106,8 @@ abstract contract Initializable { InitializableStorage storage $ = _getInitializableStorage(); bool isTopLevelCall = !$._initializing; - if (!(isTopLevelCall && $._initialized < 1) && !(address(this).code.length == 0 && $._initialized == 1)) { + uint64 initialized = $._initialized; + if (!(isTopLevelCall && initialized < 1) && !(address(this).code.length == 0 && initialized == 1)) { revert AlreadyInitialized(); } $._initialized = 1;