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 #168

Open
code423n4 opened this issue Jun 3, 2022 · 2 comments
Open

Gas Optimizations #168

code423n4 opened this issue Jun 3, 2022 · 2 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

GAS OPT

  1. Title : Value can be caching in calldata instead of memory

1.) File : contracts/tokenomics/FeeBurner.sol (Line.43)

    function burnToTarget(address[] memory tokens_, address targetLpToken_)
  1. Title : better way for epoch++ for saving more gas

using prefix is common that more saved gas than using postfix.

Tool Used

Remix

Recommended Mitigation

        ++epoch;

##Occurances

KeeperGauge.sol#L59
KeeperGauge.sol#L98

  1. Title : Using short reason string can be used for saving more gas

Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.

Tool Used

Manual Review

Occurances

e.g. (xxxxxx, IAS) //Inflation has Already Started

contracts/tokenomics/Minter.sol#L105                "Inflation has already started."
contracts/tokenomics/Minter.sol#L152                "Maximum non-inflation amount exceeded."
contracts/tokenomics/VestedEscrow.sol#L82           "Supply already initialized once"
contracts/tokenomics/VestedEscrow.sol#L84           "No reward tokens in contract"
contracts/tokenomics/VestedEscrow.sol#L91           "Supply must be initialized"
contracts/tokenomics/VestedEscrowRevocable.sol#L53  "Recipient already revoked"
contracts/tokenomics/VestedEscrowRevocable.sol#L54  "Treasury cannot be revoked!"
contracts/tokenomics/InflationManager.sol#L95         "Weight-based dist. deactivated."
  1. Title : Saving gas by removing = 0

This implementation code can be saving more gas by removing = 0, it because If a variable was not set/initialized, it is assumed to have default value to 0

Tool Used

Manual Review

Mitigation Step

Remove = 0

Occurances

contracts/utils/Preparable.sol#L87          deadlines[key] = 0;
contracts/utils/Preparable.sol#L88          pendingUInts256[key] = 0;
contracts/utils/Preparable.sol#L99          deadlines[key] = 0;
contracts/utils/Preparable.sol#L143         deadlines[key] = 0;
contracts/utils/Preparable.sol#L150         pendingUInts256[key] = 0;
contracts/utils/Preparable.sol#L151         deadlines[key] = 0;
contracts/tokenomics/LpGauge.sol#L60        perUserShare[beneficiary] = 0;
  1. Title : Shorter code for save gas.

This can be shorter code for gas opt

File : contracts/StakerVault.sol (Line.169)

        balances[dst] = balances[dst] + amount;     

changed to

        balances[dst] +=  amount;
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 3, 2022
code423n4 added a commit that referenced this issue Jun 3, 2022
@chase-manning
Copy link
Collaborator

Looks like most of these are not valid. Seems like is just some script that is run to auto gen gas findings.

For example contracts/tokenomics/Minter.sol#L105 is this require(lastEvent == 0, "Inflation has already started.");.
They are talking about initialising a variable. But we're not doing that here, we're doing a comparison...

@chase-manning chase-manning added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Jun 6, 2022
@GalloDaSballo
Copy link
Collaborator

Value can be caching in calldata instead of memory

In lack of math I can only rate it as 0 as when done as an external call it won't save gas

Title : better way for epoch++ for saving more gas

5 gas

Title : Using short reason string can be used for saving more gas

Only 2 of the lines were above 32 chars, assuming 1 char = 1 bytes in lack of any explanation
6 * 2 = 12

Saving gas by removing = 0

Screenshot 2022-06-18 at 00 06 24

The warden is suggesting to brick the functionality of the code to save gas, I'm gonna have to dispute

Shorter code for save gas.

Disagree, it's the same code

Total Gas Saved
17 gas

Indeed could have done way better than this

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

3 participants