Open code423n4 opened 2 years ago
Strings in solidity are handled in 32 byte chunks. A require string longer than 32 bytes uses more gas. Shortening these strings will save gas.
Several cases of this gas optimization were found. These are a few examples, but more may exist
Manual analysis
Shorten require strings
There are two asserts in WithdrawFacet that are not necessary. The transfer that happens immediately after the assert will revert if there is insufficient balance, so the assert does not provide any value.
The redundant assert calls are found at WithdrawFacet https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/WithdrawFacet.sol#L30 https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/WithdrawFacet.sol#L34
Remove the two asserts to save gas
Declaring a function as external instead of public saves gas
Some functions can be declared external instead of public
Slither
Change function from public to external to save gas
Duplicate of #197
Duplicate of #100
1 - Short require strings save gas
Impact
Strings in solidity are handled in 32 byte chunks. A require string longer than 32 bytes uses more gas. Shortening these strings will save gas.
Proof of Concept
Several cases of this gas optimization were found. These are a few examples, but more may exist
Tools Used
Manual analysis
Recommended Mitigation Steps
Shorten require strings
2 - Redundant assert
Impact
There are two asserts in WithdrawFacet that are not necessary. The transfer that happens immediately after the assert will revert if there is insufficient balance, so the assert does not provide any value.
Proof of Concept
The redundant assert calls are found at WithdrawFacet https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/WithdrawFacet.sol#L30 https://github.com/code-423n4/2022-03-lifinance/blob/main/src/Facets/WithdrawFacet.sol#L34
Tools Used
Manual analysis
Recommended Mitigation Steps
Remove the two asserts to save gas
3 - Public functions can be external
Impact
Declaring a function as external instead of public saves gas
Proof of Concept
Some functions can be declared external instead of public
Tools Used
Slither
Recommended Mitigation Steps
Change function from public to external to save gas