code-423n4 / 2022-04-backd-findings

6 stars 4 forks source link

Gas Optimizations #176

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

1) ++i is less expensive than i++ (https://github.com/fei-protocol/xTRIBE/blob/master/src/xTRIBE.sol#L99 and https://github.com/fei-protocol/flywheel-v2/blob/main/src/rewards/FlywheelGaugeRewards.sol#L189)

2) !=0 is cheaper and has the same effect as >0, since they’re uint variables (https://github.com/fei-protocol/flywheel-v2/blob/main/src/FlywheelCore.sol#L167 and https://github.com/fei-protocol/flywheel-v2/blob/main/src/FlywheelCore.sol#L218)

3) In these lines x – x % y has the same effect as ( x / x ) * y and saves about 26 gas from remix calculations (This optimization can be also made when calculating the after multiple, as x + y - x % y) https://github.com/fei-protocol/flywheel-v2/blob/main/src/rewards/FlywheelGaugeRewards.sol#L103 https://github.com/fei-protocol/flywheel-v2/blob/main/src/rewards/FlywheelGaugeRewards.sol#L135

itsmetechjay commented 2 years ago

Warden submitted this to the wrong contest. It's meant for Tribe. Withdrawing.