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

Open
code423n4 opened this issue May 5, 2022 · 0 comments
Open

Gas Optimizations #247

code423n4 opened this issue May 5, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Issue: Variables should not be initialized to their default values
Explanation: Initializing variables to their default values is unnecessary and costs gas

https://github.com/code-423n4/2022-05-runes/blob/060b4f82b79c8308fe65674a39a07c44fa586cd3/contracts/ForgottenRunesWarriorsGuild.sol#L24

    uint256 public numMinted = 0;					

Change 'uint256 public numMinted;' to 'uint256 public numMinted;'

Issue: Require message too long
Explanation: The require message below can be shortened to 32 characters or fewer (as shown) to save gas

https://github.com/code-423n4/2022-05-runes/blob/060b4f82b79c8308fe65674a39a07c44fa586cd3/contracts/ForgottenRunesWarriorsMinter.sol#L148

            'Ether value sent is not sufficient'						

Change message to Ether value sent is insufficient

Multiple issues

There are three opportunities to save gas in each of the two identical code blocks below:

  1. Use != 0 instead of > 0 because > 0 costs more gas and numWarriors cannot be < zero (since it is a unit)
  2. Divide the require into two separate require messages instead of using '&&'
  3. Shorten the require message to 32 characters or fewer

https://github.com/code-423n4/2022-05-runes/blob/060b4f82b79c8308fe65674a39a07c44fa586cd3/contracts/ForgottenRunesWarriorsMinter.sol#L140-L143

https://github.com/code-423n4/2022-05-runes/blob/060b4f82b79c8308fe65674a39a07c44fa586cd3/contracts/ForgottenRunesWarriorsMinter.sol#L210-L213

        require(
            numWarriors > 0 && numWarriors <= 20,
            'You can summon no more than 20 Warriors at a time'
        );					

Change to:

       require(numWarriors != 0, 'Number of Warriors must exceed 0');
       require(numWarriors <= 20, 'Summon <= 20 Warriors at a time');
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 5, 2022
code423n4 added a commit that referenced this issue May 5, 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)
Projects
None yet
Development

No branches or pull requests

1 participant