Gas Optimizations #84
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Title: Using delete statement to empty
rewardsAccrued
can save gasProof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L123
Recommended Mitigation Steps:
Change to:
========================================================================
Title: Using != is more gas efficient
Proof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L167
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L218
Recommended Mitigation Steps:
Change to:
========================================================================
Title: Using
storage
to declare Struct variable inside functionProof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L85
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L106
Recommended Mitigation Steps:
instead of caching
RewardsState
to memory. read it directly from storage.========================================================================
Title: Using
calldata
on struct parameterProof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L210
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/FlywheelCore.sol#L241
Recommended Mitigation Steps:
Using
calldata
to store struct data type can save gas========================================================================
Title: Using unchecked to calculate can save gas
Proof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/rewards/FlywheelStaticRewards.sol#L60
Recommended Mitigation Steps:
rewards.rewardsEndTimestamp
is checked that it won't>
thanlastUpdatedTimestamp
========================================================================
Title: Using > is cheaper than >=
Proof of Concept:
https://github.com/Rari-Capital/solmate/blob/9f16db2144cc9a7e2ffc5588d4bf0b66784283bd/src/tokens/ERC20.sol#L125
Recommended Mitigation Steps:
just use
>
can save gasChange to:
========================================================================
Title: Using
immutable
can save gasProof of Concept:
https://github.com/Rari-Capital/solmate/blob/9f16db2144cc9a7e2ffc5588d4bf0b66784283bd/src/tokens/ERC20.sol#L23
Recommended Mitigation Steps:
use
immutable
to declare variable which set once in constructor========================================================================
Title: Using multiple
require
instead&&
can save gasProof of Concept:
https://github.com/Rari-Capital/solmate/blob/9f16db2144cc9a7e2ffc5588d4bf0b66784283bd/src/tokens/ERC20.sol#L154
Recommended Mitigation Steps:
Change to:
========================================================================
Title: unnecessary value set. the default value of uint is 0.
Proof of Concept:
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L134
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L184
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L307
https://github.com/fei-protocol/flywheel-v2/blob/77bfadf388db25cf5917d39cd9c0ad920f404aad/src/token/ERC20Gauges.sol#L384
Recommended Mitigation Steps:
remove 0 value can save gas
========================================================================
The text was updated successfully, but these errors were encountered: