uint256 length = targets.length;
for (uint256 i = 0; i < length; ) {
require(
!_isProtocoValueSetter(datas[i]),
"ConfigTimelockController: Can not schedule changes to a protocol value with an arbitrary delay"
);
unchecked {
++i;
}
}
Potential workarounds
for (uint256 i; i < targets.length; ) {
require(
!_isProtocoValueSetter(datas[i]),
"ConfigTimelockController: Can not schedule changes to a protocol value with an arbitrary delay"
);
unchecked {
++i;
}
}
Gas improvements
Confirmed that gas fee of deployment of ConfigTimelockController.sol decreased slightly.
ProviderOracleManager.sol calls assetOracles[_asset] multiple times
Confirmed that both methods and deployments gas fee decreased for following functions and contracts.
ChainlinkFixedTimeOracleManager, setExpiryPriceInRegistry function
ChainlinkOracleManager, setExpiryPriceInRegistry function
ChainlinkFixedTimeOracleManager.sol
ChainlinkOracleManager.sol
isValidOption function in ChainlinkFixedTimeOracleManager.sol can use unchecked to decrease the gas fee
uint256 length = ids.length;
for (uint256 i = 0; i < length; ) {
emit CollateralTokenBurned(owner, ids[i], amounts[i]);
unchecked {
++i;
}
}
Potential workarounds
for (uint256 i; i < ids.length; ) {
emit CollateralTokenMinted(recipient, ids[i], amounts[i]);
unchecked {
++i;
}
}
for (uint256 i; i < ids.length; ) {
emit CollateralTokenBurned(owner, ids[i], amounts[i]);
unchecked {
++i;
}
}
Gas improvements
Gas fee for CollateralToken deployment can be reduced. Gas fee for burnCollateralTokenBatch and mintCollateralTokenBatch functions in CollateralToken.sol are slighly decreased.
No need to define
data
variable at various functions in ConfigTimelockController.solTarget codebase
_encodeSetProtocolAddress
function is called at the top of thescheduleSetProtocolAddress
function.https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/timelock/ConfigTimelockController.sol#L71-L75
data
variable does not need to be defined.Potential workarounds
Move the call of
_encodeSetProtocolAddress
intosuper.schedule
as follows:There are other codebase which defines
bytes memory data
at the top of the functions which can do the same refactors. https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/timelock/ConfigTimelockController.sol#L110-L114 https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/timelock/ConfigTimelockController.sol#L149-L153 https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/timelock/ConfigTimelockController.sol#L187-L191Gas improvements
Confirmed that the gas fees when calling these methods decreased. However, deployments gas fee of
ConfigTimelockController.sol
slightly increased.Gas reduction is possible by refactoring
scheduleBatch
functionTarget codebase
Following codebase has two potential improvements:
uint256 length
does not need to be defineduint256 i = 0
does not need to set 0 https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/timelock/ConfigTimelockController.sol#L231-L232Potential workarounds
Gas improvements
Confirmed that gas fee of deployment of
ConfigTimelockController.sol
decreased slightly.ProviderOracleManager.sol
callsassetOracles[_asset]
multiple timesTarget codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/pricing/oracle/ProviderOracleManager.sol#L76-L78
assetOracles[_asset]
is called in require function althoughassetOracle
variable is defined.Potential workarounds
Here is a potential workaround:
No need to define
roundAfterExpiry
variable atsetExpiryPriceInRegistry
function in ChainlinkOracleManager.solTarget codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/pricing/oracle/ChainlinkOracleManager.sol#L63-L70
roundAfterExpiry
variable is defined, which is not necessary.Potential workarounds
Simply calling
searchRoundToSubmit(_asset, _expiryTimestamp)
in_setExpiryPriceInRegistryByRound
function.Gas improvements
Confirmed that both methods and deployments gas fee decreased for following functions and contracts.
isValidOption
function inChainlinkFixedTimeOracleManager.sol
can use unchecked to decrease the gas feeTarget codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/pricing/oracle/ChainlinkFixedTimeOracleManager.sol#L63-L64
_expiryTime % 86400
can be wrapped by unchecked function since%
operations on uint256 will not underflow.Potential workarounds
Simply wrap by unchecked directory like this:
Gas improvements
Following gas reductions can be achieved:
CollateralToken.sol can reduce gas usage by simple refactoring
Target codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/options/CollateralToken.sol#L151-L157
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/options/CollateralToken.sol#L177-L183
Potential workarounds
Gas improvements
Gas fee for CollateralToken deployment can be reduced. Gas fee for
burnCollateralTokenBatch
andmintCollateralTokenBatch
functions in CollateralToken.sol are slighly decreased.Can use
!=
rather than using>
at Controller.solTarget codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/Controller.sol#L268
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/Controller.sol#L393
Potential workarounds
Can use
!=
rather than using>
.Gas reduction is possible by refactoring
operate
function inController.sol
Target codebase
https://github.com/code-423n4/2022-03-rolla/blob/main/quant-protocol/contracts/Controller.sol#L55-L56
length
uint256 i
does not need to be set by 0Potential workarounds
Can use following codebase which results in gas reduction.