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

npx hardhat compile never runs the optimizer. #4944

Closed
vessenes opened this issue Feb 28, 2024 · 1 comment
Closed

npx hardhat compile never runs the optimizer. #4944

vessenes opened this issue Feb 28, 2024 · 1 comment
Assignees

Comments

@vessenes
Copy link

Version of Hardhat

2.20.1

What happened?

solc run with optimizer turned on from the command line compiles my contract to 9k. Without the optimizer, solc compiles to 25k. Regardless of settings, hardhat compiles to 26k.

I can ignore warnings during the development cycle, but this makes testing and deployment impossible.

Minimal reproduction steps

$ npx hardhat compile

Warning: Contract code size is 26036 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
  --> contracts/Rewards.sol:12:1:
   |
12 | contract Rewards {
   | ^ (Relevant source part starts here and spans across multiple lines).
$  solc --optimize --combined-json bin Rewards.sol | jq '.contracts["Rewards.sol:Rewards"].bin' | wc -c | awk '{print ($1 - 3) / 2}'

--> Rewards.sol

9210

$ solc --combined-json bin Rewards.sol | jq '.contracts["Rewards.sol:Rewards"].bin' | wc -c | awk '{print ($1 - 3) / 2}' 

--> Rewards.sol

Warning: Contract code size is 25299 bytes and exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on Mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
  --> Rewards.sol:12:1:
   |
12 | contract Rewards {
   | ^ (Relevant source part starts here and spans across multiple lines).

25393

my config:

$ cat hardhat.config.ts 
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
  solidity: "0.8.23",
   optimizer: {
        enabled: true,
        runs: 10,
      },
  solidity: "0.8.24",
   optimizer: {
        enabled: true,
        runs: 10,
      },
};

export default config;

Search terms

compile optimizer size solidity

@vessenes
Copy link
Author

... And is if by magic, github was my rubber duck.

For reference, hardhat will not complain about malformed solidity settings. Here is a proper, working config:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
    solidity: {
        version: "0.8.23",
        settings: {
            optimizer: {
                enabled: true,
                runs: 10,
            },
        },
    },
};

export default config;

note the solidity object, and the settings object inlined, both different from my original.

@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Feb 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants