Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #149

Open
code423n4 opened this issue Apr 13, 2022 · 0 comments
Open

Gas Optimizations #149

code423n4 opened this issue Apr 13, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

  1. Change using > instead of!= for saving more gas

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/farming/LPFarming.sol#L193

using > can be saving more gas

##Tool Used
Remix

##Recommendation Mitigation
Change it into !=

  1. Unnecessary code

https://github.com/code-423n4/2022-04-jpegd/blob/e72861a9ccb707ced9015166fbded5c97c6991b6/contracts/staking/JPEGStaking.sol#L50

this can be deleted to saving more gas since it unnecessary and it can be bug if can be burn amount more than msg.sender had.

##Tool Used
Manual Review & Remix

  1. using ++i than i++ for saving more gas

Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.

Tools Used

Remix

Occurances

main/contracts/farming/LPFarming.sol#L348
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L145
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L231
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L319
  1. change uint256 i = 0 into uint i for saving more gas

this implementation can saving more gas for each loops.

##Tool Used
Manual Review & Remix

##Recommended Mitigation
Change it

Occurances

main/contracts/farming/LPFarming.sol#L348
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L145
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L231
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L319
  1. Caching array length can saving more gas

this implementation can be saving more gas, since if caching the array length is more gas efficient.
This is because access to a local variable in solidity is more efficient.

##Tool Used
Manual Review

##Occurances

main/contracts/farming/LPFarming.sol#L348
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L145
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L231
main/contracts/vaults/yVault/strategies/StrategyPUSDConvex.sol#L319
  1. Saving gas by removing = 0

If a variable was not set/initialized, it is assumed to have default value to 0
this implementation was used for saving more gas by removing = 0

##POC
https://blog.polymath.network/solidity-tips-and-tricks-to-save-gas-and-reduce-bytecode-size-c44580b218e6

##TOOLS USED
Remix, Manual Review

##Mitigation Step
Remove = 0

##Occurances

contracts/farming/LPFarming.sol#L340
contracts/farming/LPFarming.sol#L357
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Apr 13, 2022
code423n4 added a commit that referenced this issue Apr 13, 2022
@spaghettieth spaghettieth added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Apr 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

2 participants