You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
G-02: Length of the array (<array>.length) need not be looked up in every iteration of a for-loop
Reading array length at each iteration of the loop takes total 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array.length saves around 3 gas per iteration.
src/utils/KernelUtils.sol
58: for (uint256 i =0; i <32; ) {
G-06: Using uints/ints smaller than 256 bits increases overhead
Gas usage becomes higher with uint/int smaller than 256 bits because EVM operates on 32 bytes and uses additional operations to reduce the size from 32 bytes to the target size.
Gas Optimizations
G-01: pre-increment
++i/--i
costs less gas than post-incrementi++/i--
Saves 6 gas per loop in a for loop
Total instances of this issue: 2
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/utils/KernelUtils.sol#L49
instance #2
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/utils/KernelUtils.sol#L64
G-02: Length of the array (
<array>.length
) need not be looked up in every iteration of a for-loopReading array length at each iteration of the loop takes total 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the
array.length
saves around3 gas
per iteration.Total instances of this issue: 1
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Governance.sol#L278
G-03: Multiplication or Division by two should use bit shifting
<x> * 2
is the same as<x> >> 1
and<x> / 2
is the same as<x> >> 1
.MUL and DIV opcodes cost
2 gas
more than SHL and SHR.Total instances of this issue: 3
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L419
instance #2
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L420
instance #3
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L782-L787
G-04: No need to compare boolean expressions with boolean literals, directly use the expression
if ( == true) ==> if ()
if ( == false) => if (!)
Total instances of this issue: 2
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Governance.sol#L223
instance #2
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Governance.sol#L306
G-05: No need to initialize non-constant/non-immutable variables to zero
Since the default value is already zero, overwriting is not required.
Saves
8 gas
per instance.Total instances of this issue: 3
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/Kernel.sol#L397
instance #2
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/utils/KernelUtils.sol#L43
instance #3
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/utils/KernelUtils.sol#L58
G-06: Using uints/ints smaller than 256 bits increases overhead
Gas usage becomes higher with uint/int smaller than 256 bits because EVM operates on 32 bytes and uses additional operations to reduce the size from 32 bytes to the target size.
Total instances of this issue: 48
instance #1
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/Kernel.sol#L100
instance #2
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/TRSRY.sol#L51
instance #3
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/MINTR.sol#L25
instance #4
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/RANGE.sol#L115
instance #5
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L27
instance #6
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L28
instance #7
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L44
instance #8
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L47
instance #9
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L50
instance #10
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L53
instance #11
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L56
instance #12
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L59
instance #13
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L71-L77
instance #14
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L84
instance #15
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L87
instance #16
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L113
instance #17
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L127
instance #18
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L185
instance #19
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L205-L208
instance #20
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L240
instance #21
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L266
instance #22
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/VOTES.sol#L27
instance #23
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/INSTR.sol#L28
instance #24
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L51
instance #25
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L52
instance #26
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L53
instance #27
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L54
instance #28
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L83
instance #29
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L86
instance #30
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L89
instance #31
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L371
instance #32
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L372
instance #33
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L418
instance #34
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L426
instance #35
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L427
instance #36
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L485
instance #37
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L516
instance #38
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L527-L531
instance #39
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L548
instance #40
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L559-L563
instance #41
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/Operator.sol#L665
instance #42
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/PriceConfig.sol#L45-L48
instance #43
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/PriceConfig.sol#L58-L61
instance #44
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/PriceConfig.sol#L69-L72
instance #45
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/interfaces/IOperator.sol#L85
instance #46
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/interfaces/IOperator.sol#L92-L96
instance #47
Link: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/interfaces/IOperator.sol#L101
instance #48
Permalink: https://github.com/code-423n4/2022-08-olympus/blob/main/src/policies/interfaces/IOperator.sol#L109-L113
The text was updated successfully, but these errors were encountered: