Open code423n4 opened 2 years ago
keccak256 hash computation can be precomputed to save deployment gas
Given that this only impacts the constructor and therefore will not impact users, it seems reasonable to leave the code as-is for improved readability. If the precomputed form was used one would need to run the hash manually in order to validate it is as expected.
The other two findings should provide small savings.
1. keccak256 hash computation can be precomputed to save deployment gas
_deriveTypehashes()
ofConsiderationBase.sol
the keccak256 hash of the encoded values can be precomputed.2. Use prefix increment/decrement operation whenever possible
3. array length in loops can be cached instead of calculating in every iteration
The loop bounds are calculated with
array.length
which are calculated in every loop iterations which can result in high gas. The array length can be cached instead of calculating in every loop iteration to save gas.The instances where this pattern can be applied is found as follows