From f7a3a0130a2301a0fce20482df722e077702062f Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 26 Jun 2024 09:10:29 +0200 Subject: [PATCH 1/2] Clarify hardhat config and enable optimisation by default. --- hardhat.config.js | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/hardhat.config.js b/hardhat.config.js index ef90c2d3c0b..d39d3d07323 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -1,12 +1,12 @@ /// ENVVAR -// - COMPILE_VERSION: compiler version (default: 0.8.20) -// - SRC: contracts folder to compile (default: contracts) -// - COMPILE_MODE: production modes enables optimizations (default: development) -// - IR: enable IR compilation (default: false) -// - COVERAGE: enable coverage report -// - ENABLE_GAS_REPORT: enable gas report -// - COINMARKETCAP: coinmarkercat api key for USD value in gas report -// - CI: output gas report to file instead of stdout +// - COMPILER: compiler version (default: 0.8.24) +// - SRC: contracts folder to compile (default: contracts) +// - RUNS: number of optimization runs (default: 200) +// - IR: enable IR compilation (default: false) +// - COVERAGE: enable coverage report (default: false) +// - GAS: enable gas report (default: false) +// - COINMARKETCAP: coinmarketcap api key for USD value in gas report +// - CI: output gas report to file instead of stdout const fs = require('fs'); const path = require('path'); @@ -25,11 +25,10 @@ const { argv } = require('yargs/yargs')() type: 'string', default: 'contracts', }, - mode: { - alias: 'compileMode', - type: 'string', - choices: ['production', 'development'], - default: 'development', + runs: { + alias: 'optimizationRuns', + type: 'number', + default: 200, }, ir: { alias: 'enableIR', @@ -69,9 +68,6 @@ for (const f of fs.readdirSync(path.join(__dirname, 'hardhat'))) { require(path.join(__dirname, 'hardhat', f)); } -const withOptimizations = argv.gas || argv.coverage || argv.compileMode === 'production'; -const allowUnlimitedContractSize = argv.gas || argv.coverage || argv.compileMode === 'development'; - /** * @type import('hardhat/config').HardhatUserConfig */ @@ -80,11 +76,11 @@ module.exports = { version: argv.compiler, settings: { optimizer: { - enabled: withOptimizations, - runs: 200, + enabled: true, + runs: argv.runs, }, evmVersion: argv.evm, - viaIR: withOptimizations && argv.ir, + viaIR: argv.ir, outputSelection: { '*': { '*': ['storageLayout'] } }, }, }, @@ -94,7 +90,7 @@ module.exports = { 'initcode-size': 'off', }, '*': { - 'code-size': withOptimizations, + 'code-size': true, 'unused-param': !argv.coverage, // coverage causes unused-param warnings 'transient-storage': false, default: 'error', @@ -103,7 +99,9 @@ module.exports = { networks: { hardhat: { hardfork: argv.evm, - allowUnlimitedContractSize, + // Exposed contracts often exceed the maximum contract size. For normal contract, + // we rely on the `code-size` compiler warning, that will cause a compilation error. + allowUnlimitedContractSize: true, initialBaseFeePerGas: argv.coverage ? 0 : undefined, }, }, From 5096311fd195633f7550daedfc75b0c304f99b1a Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Thu, 27 Jun 2024 14:29:13 +0200 Subject: [PATCH 2/2] foundry config --- foundry.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/foundry.toml b/foundry.toml index 391c40e6f11..3f60b7cbbf1 100644 --- a/foundry.toml +++ b/foundry.toml @@ -1,6 +1,8 @@ [profile.default] solc_version = '0.8.24' evm_version = 'cancun' +optimizer = true +optimizer-runs = 200 src = 'contracts' out = 'out' libs = ['node_modules', 'lib']