[G-02] In for loop use outside variable for array length
For loop written like thisfor (uint256 i; i < array.length; ++i) { will cost more gas than for (uint256 i; i < _lengthOfArray; ++i) { because for every iteration we use mload and memory_offset
that will cost about 6 gas
[G-06] Recomend to use uint256(1)/uint256(2) for true and false
If you don't use boolean for storage you will avoid Gwarmaccess 100 gas. Also boolean from true to false cost 20000 gas rather than uint256(2) to uint256(1) that cost less.
There have 5 istance of this issues:
File: BlurExchange.sol line 71
mapping(bytes32 => bool) public cancelledOrFilled;
[G-07] Recomend to use one operator for comparison
If you use >= or <= this will cost more gas because in the EVM there is no implementation of Opcodes for >= and <=and two operations are done. You can use instead x < y + 1 or x + 1 > y and save some gas.
[G-01] Use defualt value rather than overwriite variable with their default value.
Overriting varibles with defualt values with their default value will waste only gas and not necessary.
There are 7 instances of this issue:
File: BlurExchange.sol lines 199, 475, 476
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L199
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L475
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L476
File: PolicyManager.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/PolicyManager.sol#L77
File: EIP712.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/EIP712.sol#L77
File: MarkleVarifier.sol line 38
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/MerkleVerifier.sol#L38
File: ReentrancyGuarded.sol line 10
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/ReentrancyGuarded.sol#L10
[G-02] In for loop use outside variable for array length
For loop written like this
for (uint256 i; i < array.length; ++i) {
will cost more gas thanfor (uint256 i; i < _lengthOfArray; ++i) {
because for every iteration we use mload and memory_offset that will cost about 6 gasThere are 4 instances of this issue:
File: BlurExchange.sol lines 199, 476
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L199
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L476
File: EIP712.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/EIP712.sol#L77
File: MerkleVerifier.sol line 38
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/MerkleVerifier.sol#L38
[G-03] Recommend to use short require string to save deployment gas
If you use longer require strings than 32 bytes that will cost more expensive than short require string.
There are 2 instances of this issue:
File: BlurExchange.sol line 482
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L482
File: ExecutionDelegate.sol line 22
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/ExecutionDelegate.sol#L22
[G-04] i++, i += 1 and i = i + 1 IN FOR LOOPS COSTS MORE GAS COMPARED TO ++i
++i will save about 5 gas for each iteration
There are 5 instances of this issue:
File: BlurExchange.sol lines 199, 475, 476
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L199
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L476
File: PolicyManager.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/PolicyManager.sol#L77
File: EIP712.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/EIP712.sol#L77
File: MarkleVarifier.sol line 38
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/MerkleVerifier.sol#L38
[G-05] Use
uncheck()
in for loops whenere overflow and undeflow is not possibleUsing of
uncheck(i++)
/uncheck(++i)
will save about 30 gas per iteration because compiler not save check everytime. This feature come from 0.8There are 5 instances of this issue:
File: BlurExchange.sol lines 199, 475, 476
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L199
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/BlurExchange.sol#L476
File: PolicyManager.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/PolicyManager.sol#L77
File: EIP712.sol line 77
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/EIP712.sol#L77
File: MarkleVarifier.sol line 38
https://github.com/code-423n4/2022-10-blur/blob/2fdaa6e13b544c8c11d1c022a575f16c3a72e3bf/contracts/lib/MerkleVerifier.sol#L38
[G-06] Recomend to use
uint256(1)
/uint256(2)
for true and falseIf you don't use boolean for storage you will avoid Gwarmaccess 100 gas. Also boolean from true to false cost 20000 gas rather than uint256(2) to uint256(1) that cost less.
There have 5 istance of this issues:
File: BlurExchange.sol line 71
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L71
File: ExecutionDelegate.sol lines 18, 19
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/ExecutionDelegate.sol#L18
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/ExecutionDelegate.sol#L19
File: ReentrancyGuarded.sol line 10
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/lib/ReentrancyGuarded.sol#L10
[G-07] Recomend to use one operator for comparison
If you use
>=
or<=
this will cost more gas because in the EVM there is no implementation of Opcodes for>=
and<=
and two operations are done. You can use insteadx < y + 1
orx + 1 > y
and save some gas.There have 3 istance of this issues:
File: BlurExchange.sol lines 168, 422, 482
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L168
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L422
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L482
[G-08] = + cost less than += for state variables
There have 1 istance of this issues:
File: BlurExchange.sol line 479
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L479
[G-09] Using of custom errors than are came from 0.8.4 instead of
require()
/revert()
strings will save deployment gasThere have 10 istance of this issues:
File: BlurExchange.sol lines 36, 134, 139, 140, 142, 143, 183, 219, 228, 237, 318, 407, 424, 428, 431, 452, 482, 534
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L36
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L134
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L139
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L140
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L142
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L143
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L183
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L219
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L228
https://github.com/code-423n4/2022-10-blur/blob/ad6c43bf2da2cee806e1dee20b6d05f651809ecc/contracts/BlurExchange.sol#L23