From ea724071b1535ae54f12e24cdcf5f1225c26d136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Mon, 19 Jun 2023 11:29:00 +0200 Subject: [PATCH] prepare_report: Add viaIR presets --- scripts/bytecodecompare/prepare_report.js | 8 ++++++-- scripts/bytecodecompare/prepare_report.py | 13 +++++++++++-- test/scripts/test_bytecodecompare_prepare_report.py | 7 ++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/scripts/bytecodecompare/prepare_report.js b/scripts/bytecodecompare/prepare_report.js index 8c714679b..451a67bb1 100755 --- a/scripts/bytecodecompare/prepare_report.js +++ b/scripts/bytecodecompare/prepare_report.js @@ -5,8 +5,10 @@ const fs = require('fs') const compiler = require('solc') SETTINGS_PRESETS = { - 'legacy-optimize': {optimize: true}, - 'legacy-no-optimize': {optimize: false}, + 'legacy-optimize': {optimize: true, viaIR: false}, + 'legacy-no-optimize': {optimize: false, viaIR: false}, + 'via-ir-optimize': {optimize: true, viaIR: true}, + 'via-ir-no-optimize': {optimize: false, viaIR: true}, } function loadSource(sourceFileName, stripSMTPragmas) @@ -67,6 +69,8 @@ for (const preset of presets) }, settings: { optimizer: {enabled: settings.optimize}, + // NOTE: We omit viaIR rather than set it to false to handle older versions that don't have it. + viaIR: settings.viaIR ? true : undefined, outputSelection: {'*': {'*': ['evm.bytecode.object', 'metadata']}} } } diff --git a/scripts/bytecodecompare/prepare_report.py b/scripts/bytecodecompare/prepare_report.py index 6ec80e753..b99e06b7d 100755 --- a/scripts/bytecodecompare/prepare_report.py +++ b/scripts/bytecodecompare/prepare_report.py @@ -29,6 +29,8 @@ class CompilerInterface(Enum): class SettingsPreset(Enum): LEGACY_OPTIMIZE = 'legacy-optimize' LEGACY_NO_OPTIMIZE = 'legacy-no-optimize' + VIA_IR_OPTIMIZE = 'via-ir-optimize' + VIA_IR_NO_OPTIMIZE = 'via-ir-no-optimize' class SMTUse(Enum): @@ -40,12 +42,15 @@ class SMTUse(Enum): @dataclass(frozen=True) class CompilerSettings: optimize: bool + via_ir: bool @staticmethod def from_preset(preset: SettingsPreset): return { - SettingsPreset.LEGACY_OPTIMIZE: CompilerSettings(optimize=True), - SettingsPreset.LEGACY_NO_OPTIMIZE: CompilerSettings(optimize=False), + SettingsPreset.LEGACY_OPTIMIZE: CompilerSettings(optimize=True, via_ir=False), + SettingsPreset.LEGACY_NO_OPTIMIZE: CompilerSettings(optimize=False, via_ir=False), + SettingsPreset.VIA_IR_OPTIMIZE: CompilerSettings(optimize=True, via_ir=True), + SettingsPreset.VIA_IR_NO_OPTIMIZE: CompilerSettings(optimize=False, via_ir=True), }[preset] @@ -224,6 +229,8 @@ def prepare_compiler_input( }, 'settings': { 'optimizer': {'enabled': settings.optimize}, + # NOTE: We omit viaIR rather than set it to false to handle older versions that don't have it. + **({'viaIR': True} if settings.via_ir else {}), 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, } } @@ -243,6 +250,8 @@ def prepare_compiler_input( compiler_options.append('--optimize') elif force_no_optimize_yul: compiler_options.append('--no-optimize-yul') + if settings.via_ir: + compiler_options.append('--via-ir') if smt_use == SMTUse.DISABLE: compiler_options += ['--model-checker-engine', 'none'] diff --git a/test/scripts/test_bytecodecompare_prepare_report.py b/test/scripts/test_bytecodecompare_prepare_report.py index 16d73ee39..b8a1791d6 100644 --- a/test/scripts/test_bytecodecompare_prepare_report.py +++ b/test/scripts/test_bytecodecompare_prepare_report.py @@ -265,6 +265,7 @@ class TestPrepareCompilerInput(PrepareReportTestBase): }, 'settings': { 'optimizer': {'enabled': True}, + 'viaIR': True, 'outputSelection': {'*': {'*': ['evm.bytecode.object', 'metadata']}}, 'modelChecker': {'engine': 'none'}, } @@ -273,7 +274,7 @@ class TestPrepareCompilerInput(PrepareReportTestBase): (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_CONTRACT_WITH_MIXED_NEWLINES_SOL_PATH, - preset=SettingsPreset.LEGACY_OPTIMIZE, + preset=SettingsPreset.VIA_IR_OPTIMIZE, force_no_optimize_yul=False, interface=CompilerInterface.STANDARD_JSON, smt_use=SMTUse.DISABLE, @@ -317,7 +318,7 @@ class TestPrepareCompilerInput(PrepareReportTestBase): (command_line, compiler_input) = prepare_compiler_input( Path('solc'), SMT_SMOKE_TEST_SOL_PATH, - preset=SettingsPreset.LEGACY_OPTIMIZE, + preset=SettingsPreset.VIA_IR_OPTIMIZE, force_no_optimize_yul=False, interface=CompilerInterface.CLI, smt_use=SMTUse.PRESERVE, @@ -326,7 +327,7 @@ class TestPrepareCompilerInput(PrepareReportTestBase): self.assertEqual( command_line, - ['solc', str(SMT_SMOKE_TEST_SOL_PATH), '--bin', '--optimize'], + ['solc', str(SMT_SMOKE_TEST_SOL_PATH), '--bin', '--optimize', '--via-ir'], ) self.assertEqual(compiler_input, SMT_SMOKE_TEST_SOL_CODE)