code-423n4 / 2022-08-olympus-findings

5 stars 4 forks source link

Gas Optimizations #478

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Pre-incrementing is cheaper than post-incrementing Consider replacing e.g. i++ with ++i.

Instances: KernelUtils.sol: 49 64

 

Function not called by the contract can be external instead of public

Instances: Kernel.sol: 95 100 439 451 TRSRY.sol: 47 79 MINTR.sol: 20 25 33 37 RANGE.sol: 110 115 219 PRICE.sol: 108 113 VOTES.sol: 22 27 45 55 INSTR.sol: 23 28 37 Governance.sol: 145 151

 

Pre-compute .length before repeated usage, especially in loops

Instances: Governance.sol#L278

 

observations.length is already computed in numObservations uint256 numObs = observations.length;can be changed into uint256 numObs = numObservations; as suggested by its preceding comment, because its length is already calculated during construction. PRICE.sol#L212