From 7aaab9a7974126649042fa65d53dc782104ba333 Mon Sep 17 00:00:00 2001 From: Midhun07 Date: Mon, 1 Nov 2021 19:17:30 +0530 Subject: [PATCH] Disallowed --metadata-literal, --model-checker-show-unproved, --model-checker-div-mod-no-slacks ----metadata-hash=swarm outside of compiler mode --- Changelog.md | 1 + solc/CommandLineParser.cpp | 7 ++++++- test/solc/CommandLineParser.cpp | 25 ++++++++++++------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Changelog.md b/Changelog.md index b37938172..72185e268 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ Compiler Features: Bugfixes: * ABI Encoder: When encoding an empty string coming from storage do not add a superfluous empty slot for data. * Yul Optimizer: Do not remove ``returndatacopy`` in cases in which it might perform out-of-bounds reads that unconditionally revert as out-of-gas. Previously, any ``returndatacopy`` that wrote to memory that was never read from was removed without accounting for the out-of-bounds condition. + * Commandline Interface: Disallow the following options outside of the compiler mode: ``--via-ir``,``--metadata-literal``, ``--metadata-hash``, ``--model-checker-show-unproved``, ``--model-checker-div-mod-no-slacks``. ### 0.8.14 (2022-05-17) diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp index 1a3fbed0e..3983194aa 100644 --- a/solc/CommandLineParser.cpp +++ b/solc/CommandLineParser.cpp @@ -911,7 +911,12 @@ void CommandLineParser::processArgs() // TODO: This should eventually contain all options. {g_strErrorRecovery, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, {g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, - {g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}} + {g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, + {g_strMetadataLiteral, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, + {g_strMetadataHash, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, + {g_strModelCheckerShowUnproved, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, + {g_strModelCheckerDivModNoSlacks, {InputMode::Compiler, InputMode::CompilerWithASTImport}}, + {g_strModelCheckerEngine, {InputMode::Compiler, InputMode::CompilerWithASTImport}} }; vector invalidOptionsForCurrentInputMode; for (auto const& [optionName, inputModes]: validOptionInputModeCombinations) diff --git a/test/solc/CommandLineParser.cpp b/test/solc/CommandLineParser.cpp index 22b3bd835..bcda823f3 100644 --- a/test/solc/CommandLineParser.cpp +++ b/test/solc/CommandLineParser.cpp @@ -281,15 +281,10 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options) "--libraries=" "dir1/file1.sol:L=0x1234567890123456789012345678901234567890," "dir2/file2.sol:L=0x1111122222333334444455555666667777788888", - "--metadata-hash=swarm", // Ignored in assembly mode - "--metadata-literal", // Ignored in assembly mode "--model-checker-contracts=" // Ignored in assembly mode "contract1.yul:A," "contract2.yul:B", - "--model-checker-div-mod-no-slacks", // Ignored in assembly mode - "--model-checker-engine=bmc", // Ignored in assembly mode "--model-checker-invariants=contract,reentrancy", // Ignored in assembly mode - "--model-checker-show-unproved", // Ignored in assembly mode "--model-checker-solvers=z3,smtlib2", // Ignored in assembly mode "--model-checker-targets=" // Ignored in assembly mode "underflow," @@ -378,15 +373,10 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options) "dir2/file2.sol:L=0x1111122222333334444455555666667777788888", "--gas", // Accepted but has no effect in Standard JSON mode "--combined-json=abi,bin", // Accepted but has no effect in Standard JSON mode - "--metadata-hash=swarm", // Ignored in Standard JSON mode - "--metadata-literal", // Ignored in Standard JSON mode "--model-checker-contracts=" // Ignored in Standard JSON mode "contract1.yul:A," "contract2.yul:B", - "--model-checker-div-mod-no-slacks", // Ignored in Standard JSON mode - "--model-checker-engine=bmc", // Ignored in Standard JSON mode "--model-checker-invariants=contract,reentrancy", // Ignored in Standard JSON mode - "--model-checker-show-unproved", // Ignored in Standard JSON mode "--model-checker-solvers=z3,smtlib2", // Ignored in Standard JSON mode "--model-checker-targets=" // Ignored in Standard JSON mode "underflow," @@ -424,16 +414,25 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations) // TODO: This should eventually contain all options. {"--error-recovery", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, {"--experimental-via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, - {"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}} + {"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, + {"--metadata-literal", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, + {"--metadata-hash=swarm", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, + {"--model-checker-show-unproved", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, + {"--model-checker-div-mod-no-slacks", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}, + {"--model-checker-engine=bmc", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}} }; for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations) for (string const& inputMode: inputModes) { stringstream serr; - vector commandLine = {"solc", optionName, "file", inputMode}; + size_t separatorPosition = optionName.find("="); + string optionNameWithoutValue = optionName.substr(0, separatorPosition); + soltestAssert(!optionNameWithoutValue.empty()); - string expectedMessage = "The following options are not supported in the current input mode: " + optionName; + vector commandLine = {"solc", optionNameWithoutValue, "file", inputMode}; + + string expectedMessage = "The following options are not supported in the current input mode: " + optionNameWithoutValue; auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; }; BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);