Open code423n4 opened 2 years ago
Would love to see a detailed POC as common sense dictates that storage is more expensive
Same as above
Only for require, <=0.8.13, using optimizer, saves 3 gas
3 * 2 = 6
Disagree, it's already cached, the casting has no gas cost and it's a higher language construct
Saves 5 gas
Saves 6 gas per discussion in #17
Saves 3 gas
3 * 2 = 6
Total Gas Saved 23
1 Memory to storage
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/RewardHandler.sol#L39
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/AddressProvider.sol#L54
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/RewardHandler.sol#L41
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L21
use storage instead of memory can reduce the gas. i suggest to change
to
apply to others
2 Use memory instead calldata
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/FeeBurner.sol#L43
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/Controller.sol#L124
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/AddressProvider.sol#L59
In the external functions where the function argument is read-only, the function() has an inputed parameter that using memory, if this function didnt change the parameter, its cheaper to use calldata then memory. so we suggest to change it.
to
apply to others.
3 use != 0 instead of >0
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L91
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L137
for unsigned integer, >0 is less efficient then !=0, so use !=0 instead of >0. do to all line code.
4 Caching lpgauge
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/StakerVault.sol#L161-L162
to the memory for reduce the gas fee because it use multiple times.
5 Pre increment
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L59
using pre increment more cheaper than post increment. so, i sugget to change
to
6 change string to bytes32
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L152
reduce size of error message can reduce the gas fee. i suggest to convert string to bytes32
7 Caching the length
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L22
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/zaps/PoolMigrationZap.sol#L39
caching the array length can reduce gas it caused access to a local variable is more cheap than query storage / calldata / memory in solidity.