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

Validate the number of optimizer runs #3488

Closed
fvictorio opened this issue Dec 29, 2022 · 4 comments · Fixed by #3512
Closed

Validate the number of optimizer runs #3488

fvictorio opened this issue Dec 29, 2022 · 4 comments · Fixed by #3512
Labels
good-first-issue Good for newcomers. Guidance available if needed status:ready This issue is ready to be worked on type:improvement

Comments

@fvictorio
Copy link
Member

Continuation of #1589.

The max number of optimizer runs is $2^{32}-1$. If you use a bigger number, the error is:

The "runs" setting must be an unsigned number.
Error HH600: Compilation failed

While this comes from solc, we should add some validation here and show a better error message.

@konarshankar07
Copy link
Contributor

Hello @fvictorio

Sorry, I'm new to this framework and probably a dumb question but do you know how we can reproduce this issue?

@fvictorio
Copy link
Member Author

Yes, just create a new project with some contracts and use this as your config:

module.exports = {
  solidity: {
    version: "0.8.17",
    settings: {
      optimizer: {
        enabled: true,
        runs: 2 ** 32,
      },
    },
  },
};

Then if you run npx hardhat compile you'll see this error:

The "runs" setting must be an unsigned number.
Error HH600: Compilation failed

That error comes from the compiler, but Hardhat should throw a validation error before even trying to compile.

I'm not super sure what's the best place to do this though. Maybe this needs a "post config resolution" phase, that we don't have yet (but we want to add, for example for #3323). But that's a bigger change. If you feel like tackling that, I can give you some hints.

@fvictorio
Copy link
Member Author

@konarshankar07 I opened #3500, if you want to give it a try. I think that what we need is:

  • Add a new function validateResolvedConfig(config: HardhatConfig) function in src/internal/core/config/config-validation.ts and validate the number of runs in the solidity configuration. We should validate both the list of compilers and any overrides.
  • Add a new INVALID_RESOLVED_CONFIG error (under the GENERAL category) in src/internal/core/errors-list.ts.
  • Add proper tests in test/internal/core/config/config-validation.ts

I know this might be a lot if it's your first contribution, so if you'd prefer to help with something easier, let me know!

@konarshankar07
Copy link
Contributor

Thanks @fvictorio I will first work on 3500 ticket and then come back on this

@github-project-automation github-project-automation bot moved this to Done in Hardhat Jan 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good-first-issue Good for newcomers. Guidance available if needed status:ready This issue is ready to be worked on type:improvement
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants