Skip to content

Commit

Permalink
fix(config): disable optimizer by default (#9657)
Browse files Browse the repository at this point in the history
* fix: disable optimizer by default

* Set default optimizer runs to 200
  • Loading branch information
grandizzy authored Jan 9, 2025
1 parent 6cbf390 commit 39f13df
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 38 deletions.
10 changes: 5 additions & 5 deletions crates/cast/tests/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ Nothing to compile
.stdout_eq(str![[r#"
Executing previous transactions from the block.
Traces:
[13520] → new <unknown>@0x5FbDB2315678afecb367f032d93F642f64180aa3
[..] → new <unknown>@0x5FbDB2315678afecb367f032d93F642f64180aa3
├─ emit topic 0: 0xa7263295d3a687d750d1fd377b5df47de69d7db8decc745aaa4bbee44dc1688d
│ data: 0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266
└─ ← [Return] 62 bytes of code
Expand All @@ -1852,7 +1852,7 @@ Executing previous transactions from the block.
Compiling project to generate artifacts
No files changed, compilation skipped
Traces:
[13520] → new LocalProjectContract@0x5FbDB2315678afecb367f032d93F642f64180aa3
[..] → new LocalProjectContract@0x5FbDB2315678afecb367f032d93F642f64180aa3
├─ emit LocalProjectContractCreated(owner: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266)
└─ ← [Return] 62 bytes of code
Expand Down Expand Up @@ -1914,7 +1914,7 @@ forgetest_async!(show_state_changes_in_traces, |prj, cmd| {
.stdout_eq(str![[r#"
Executing previous transactions from the block.
Traces:
[22287] 0x5FbDB2315678afecb367f032d93F642f64180aa3::setNumber(111)
[..] 0x5FbDB2315678afecb367f032d93F642f64180aa3::setNumber(111)
├─ storage changes:
│ @ 0: 0 → 111
└─ ← [Stop]
Expand Down Expand Up @@ -2005,8 +2005,8 @@ contract CounterInExternalLibScript is Script {
.stdout_eq(str![[r#"
...
Traces:
[37739] → new <unknown>@0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
├─ [22411] 0xfAb06527117d29EA121998AC4fAB9Fc88bF5f979::updateCounterInExternalLib(0, 100) [delegatecall]
[..] → new <unknown>@0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
├─ [..] 0x52F3e85EC3F0f9D0a2200D646482fcD134D5adc9::updateCounterInExternalLib(0, 100) [delegatecall]
│ └─ ← [Stop]
└─ ← [Return] 62 bytes of code
Expand Down
2 changes: 1 addition & 1 deletion crates/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ gas_reports_ignore = []
# solc = '0.8.10'
auto_detect_solc = true
offline = false
optimizer = true
optimizer = false
optimizer_runs = 200
model_checker = { contracts = { 'a.sol' = [
'A1',
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,7 +2298,7 @@ impl Default for Config {
vyper: Default::default(),
auto_detect_solc: true,
offline: false,
optimizer: true,
optimizer: false,
optimizer_runs: 200,
optimizer_details: None,
model_checker: None,
Expand Down
3 changes: 3 additions & 0 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ contract Dummy {
});

forgetest!(initcode_size_exceeds_limit, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_source("LargeContract", generate_large_contract(5450).as_str()).unwrap();
cmd.args(["build", "--sizes"]).assert_failure().stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
Expand Down Expand Up @@ -103,6 +104,7 @@ Compiler run successful!
});

forgetest!(initcode_size_limit_can_be_ignored, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_source("LargeContract", generate_large_contract(5450).as_str()).unwrap();
cmd.args(["build", "--sizes", "--ignore-eip-3860"]).assert_success().stdout_eq(str![[r#"
[COMPILING_FILES] with [SOLC_VERSION]
Expand Down Expand Up @@ -149,6 +151,7 @@ Compiler run successful!
// tests build output is as expected
forgetest_init!(build_sizes_no_forge_std, |prj, cmd| {
prj.write_config(Config {
optimizer: true,
solc: Some(foundry_config::SolcReq::Version(semver::Version::new(0, 8, 27))),
..Default::default()
});
Expand Down
31 changes: 27 additions & 4 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ forgetest!(gas_report_all_contracts, |prj, cmd| {

// report for all
prj.write_config(Config {
optimizer: true,
gas_reports: (vec!["*".to_string()]),
gas_reports_ignore: (vec![]),
..Default::default()
Expand Down Expand Up @@ -1682,7 +1683,7 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
.is_json(),
);

prj.write_config(Config { gas_reports: (vec![]), ..Default::default() });
prj.write_config(Config { optimizer: true, gas_reports: (vec![]), ..Default::default() });
cmd.forge_fuse().arg("test").arg("--gas-report").assert_success().stdout_eq(str![[r#"
...
╭----------------------------------------+-----------------+-------+--------+-------+---------╮
Expand Down Expand Up @@ -1787,7 +1788,11 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
.is_json(),
);

prj.write_config(Config { gas_reports: (vec!["*".to_string()]), ..Default::default() });
prj.write_config(Config {
optimizer: true,
gas_reports: (vec!["*".to_string()]),
..Default::default()
});
cmd.forge_fuse().arg("test").arg("--gas-report").assert_success().stdout_eq(str![[r#"
...
╭----------------------------------------+-----------------+-------+--------+-------+---------╮
Expand Down Expand Up @@ -1893,6 +1898,7 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
);

prj.write_config(Config {
optimizer: true,
gas_reports: (vec![
"ContractOne".to_string(),
"ContractTwo".to_string(),
Expand Down Expand Up @@ -2010,7 +2016,11 @@ forgetest!(gas_report_some_contracts, |prj, cmd| {
prj.add_source("Contracts.sol", GAS_REPORT_CONTRACTS).unwrap();

// report for One
prj.write_config(Config { gas_reports: vec!["ContractOne".to_string()], ..Default::default() });
prj.write_config(Config {
optimizer: true,
gas_reports: vec!["ContractOne".to_string()],
..Default::default()
});
cmd.forge_fuse();
cmd.arg("test").arg("--gas-report").assert_success().stdout_eq(str![[r#"
...
Expand Down Expand Up @@ -2057,7 +2067,11 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
);

// report for Two
prj.write_config(Config { gas_reports: vec!["ContractTwo".to_string()], ..Default::default() });
prj.write_config(Config {
optimizer: true,
gas_reports: vec!["ContractTwo".to_string()],
..Default::default()
});
cmd.forge_fuse();
cmd.arg("test").arg("--gas-report").assert_success().stdout_eq(str![[r#"
...
Expand Down Expand Up @@ -2105,6 +2119,7 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)

// report for Three
prj.write_config(Config {
optimizer: true,
gas_reports: vec!["ContractThree".to_string()],
..Default::default()
});
Expand Down Expand Up @@ -2160,6 +2175,7 @@ forgetest!(gas_report_ignore_some_contracts, |prj, cmd| {

// ignore ContractOne
prj.write_config(Config {
optimizer: true,
gas_reports: (vec!["*".to_string()]),
gas_reports_ignore: (vec!["ContractOne".to_string()]),
..Default::default()
Expand Down Expand Up @@ -2242,6 +2258,7 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
// ignore ContractTwo
cmd.forge_fuse();
prj.write_config(Config {
optimizer: true,
gas_reports: (vec![]),
gas_reports_ignore: (vec!["ContractTwo".to_string()]),
..Default::default()
Expand Down Expand Up @@ -2328,6 +2345,7 @@ Ran 3 test suites [ELAPSED]: 3 tests passed, 0 failed, 0 skipped (3 total tests)
// indicating the "double listing".
cmd.forge_fuse();
prj.write_config(Config {
optimizer: true,
gas_reports: (vec![
"ContractOne".to_string(),
"ContractTwo".to_string(),
Expand Down Expand Up @@ -2461,6 +2479,7 @@ Warning: ContractThree is listed in both 'gas_reports' and 'gas_reports_ignore'.
});

forgetest!(gas_report_flatten_multiple_selectors, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.insert_ds_test();
prj.add_source(
"Counter.sol",
Expand Down Expand Up @@ -2579,6 +2598,7 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)

// <https://github.com/foundry-rs/foundry/issues/9115>
forgetest_init!(gas_report_with_fallback, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_test(
"DelegateProxyTest.sol",
r#"
Expand Down Expand Up @@ -2722,6 +2742,7 @@ Ran 1 test suite [ELAPSED]: 1 tests passed, 0 failed, 0 skipped (1 total tests)

// <https://github.com/foundry-rs/foundry/issues/9300>
forgetest_init!(gas_report_size_for_nested_create, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_test(
"NestedDeployTest.sol",
r#"
Expand Down Expand Up @@ -3160,6 +3181,7 @@ Error: No source files found in specified build paths.

// checks that build --sizes includes all contracts even if unchanged
forgetest_init!(can_build_sizes_repeatedly, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.clear_cache();

cmd.args(["build", "--sizes"]).assert_success().stdout_eq(str![[r#"
Expand Down Expand Up @@ -3226,6 +3248,7 @@ interface Counter {
// checks that `clean` also works with the "out" value set in Config
forgetest_init!(gas_report_include_tests, |prj, cmd| {
prj.write_config(Config {
optimizer: true,
gas_reports_include_tests: true,
fuzz: FuzzConfig { runs: 1, ..Default::default() },
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/forge/tests/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ Compiler run successful!

// test to ensure yul optimizer can be set as intended
forgetest!(can_set_yul_optimizer, |prj, cmd| {
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_source(
"foo.sol",
r"
Expand Down
4 changes: 2 additions & 2 deletions crates/forge/tests/cli/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Transaction: {
"to": null,
"maxFeePerGas": "0x77359401",
"maxPriorityFeePerGas": "0x1",
"gas": "0x17575",
"gas": "0x241e7",
"input": "[..]",
"nonce": "0x0",
"chainId": "0x7a69"
Expand Down Expand Up @@ -222,7 +222,7 @@ ABI: [
"to": null,
"maxFeePerGas": "0x77359401",
"maxPriorityFeePerGas": "0x1",
"gas": "0x17575",
"gas": "0x241e7",
"input": "[..]",
"nonce": "0x0",
"chainId": "0x7a69"
Expand Down
32 changes: 17 additions & 15 deletions crates/forge/tests/cli/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::constants::TEMPLATE_CONTRACT;
use alloy_primitives::{address, hex, Address, Bytes};
use anvil::{spawn, NodeConfig};
use forge_script_sequence::ScriptSequence;
use foundry_config::Config;
use foundry_test_utils::{
rpc,
snapbox::IntoData,
Expand Down Expand Up @@ -230,7 +231,7 @@ Traces:
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [..] → new GasWaster@[..]
│ └─ ← [Return] 221 bytes of code
│ └─ ← [Return] 415 bytes of code
├─ [..] GasWaster::wasteGas(200000 [2e5])
│ └─ ← [Stop]
└─ ← [Stop]
Expand All @@ -242,10 +243,10 @@ Script ran successfully.
==========================
Simulated On-chain Traces:
[44291] → new GasWaster@[..]
└─ ← [Return] 221 bytes of code
[..] → new GasWaster@[..]
└─ ← [Return] 415 bytes of code
[224] GasWaster::wasteGas(200000 [2e5])
[..] GasWaster::wasteGas(200000 [2e5])
└─ ← [Stop]
Expand Down Expand Up @@ -336,7 +337,7 @@ Traces:
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [..] → new GasWaster@[..]
│ └─ ← [Return] 221 bytes of code
│ └─ ← [Return] 415 bytes of code
├─ [..] GasWaster::wasteGas(200000 [2e5])
│ └─ ← [Stop]
└─ ← [Stop]
Expand All @@ -348,10 +349,10 @@ Script ran successfully.
==========================
Simulated On-chain Traces:
[44291] → new GasWaster@[..]
└─ ← [Return] 221 bytes of code
[..] → new GasWaster@[..]
└─ ← [Return] 415 bytes of code
[224] GasWaster::wasteGas(200000 [2e5])
[..] GasWaster::wasteGas(200000 [2e5])
└─ ← [Stop]
Expand Down Expand Up @@ -520,7 +521,7 @@ Traces:
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [..] → new HashChecker@[..]
│ └─ ← [Return] 368 bytes of code
│ └─ ← [Return] 718 bytes of code
└─ ← [Stop]
Expand Down Expand Up @@ -1925,6 +1926,7 @@ forgetest_async!(adheres_to_json_flag, |prj, cmd| {
}

foundry_test_utils::util::initialize(prj.root());
prj.write_config(Config { optimizer: true, ..Default::default() });
prj.add_script(
"Foo",
r#"
Expand Down Expand Up @@ -2372,9 +2374,9 @@ Traces:
├─ [0] VM::startBroadcast()
│ └─ ← [Return]
├─ [..] → new A@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
│ └─ ← [Return] 116 bytes of code
│ └─ ← [Return] 175 bytes of code
├─ [..] → new B@0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
│ ├─ [145] A::getValue() [staticcall]
│ ├─ [..] A::getValue() [staticcall]
│ │ └─ ← [Return] 100
│ └─ ← [Return] 62 bytes of code
└─ ← [Stop]
Expand All @@ -2386,11 +2388,11 @@ Script ran successfully.
==========================
Simulated On-chain Traces:
[23273] → new A@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
└─ ← [Return] 116 bytes of code
[..] → new A@0x5b73C5498c1E3b4dbA84de0F1833c4a029d90519
└─ ← [Return] 175 bytes of code
[15662] → new B@0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
├─ [145] A::getValue() [staticcall]
[..] → new B@0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
├─ [..] A::getValue() [staticcall]
│ └─ ← [Return] 100
└─ ← [Return] 62 bytes of code
...
Expand Down
Loading

0 comments on commit 39f13df

Please sign in to comment.