Skip to content

Commit 697821b

Browse files
Midhun07nishant-sachdeva
authored andcommitted
Disallowed --metadata-literal, --model-checker-show-unproved, --model-checker-div-mod-no-slacks ----metadata-hash=swarm outside of compiler mode
1 parent f904bb0 commit 697821b

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Compiler Features:
77

88

99
Bugfixes:
10+
* 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``, ``--model-checker-engine``, ``--model-checker-invariants``, ``--model-checker-solvers``, ``--model-checker-timeout``, ``--model-checker-contracts``, ``--model-checker-targets``.
1011

1112

1213
### 0.8.15 (2022-06-15)

solc/CommandLineParser.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -911,12 +911,26 @@ void CommandLineParser::processArgs()
911911
// TODO: This should eventually contain all options.
912912
{g_strErrorRecovery, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
913913
{g_strExperimentalViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
914-
{g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}}
914+
{g_strViaIR, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
915+
{g_strMetadataLiteral, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
916+
{g_strMetadataHash, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
917+
{g_strModelCheckerShowUnproved, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
918+
{g_strModelCheckerDivModNoSlacks, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
919+
{g_strModelCheckerEngine, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
920+
{g_strModelCheckerInvariants, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
921+
{g_strModelCheckerSolvers, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
922+
{g_strModelCheckerTimeout, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
923+
{g_strModelCheckerContracts, {InputMode::Compiler, InputMode::CompilerWithASTImport}},
924+
{g_strModelCheckerTargets, {InputMode::Compiler, InputMode::CompilerWithASTImport}}
915925
};
916926
vector<string> invalidOptionsForCurrentInputMode;
917927
for (auto const& [optionName, inputModes]: validOptionInputModeCombinations)
918928
{
919-
if (m_args.count(optionName) > 0 && inputModes.count(m_options.input.mode) == 0)
929+
if (
930+
m_args.count(optionName) > 0 &&
931+
inputModes.count(m_options.input.mode) == 0 &&
932+
!m_args[optionName].defaulted()
933+
)
920934
invalidOptionsForCurrentInputMode.push_back(optionName);
921935
}
922936

test/solc/CommandLineParser.cpp

+16-30
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,6 @@ BOOST_AUTO_TEST_CASE(assembly_mode_options)
281281
"--libraries="
282282
"dir1/file1.sol:L=0x1234567890123456789012345678901234567890,"
283283
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
284-
"--metadata-hash=swarm", // Ignored in assembly mode
285-
"--metadata-literal", // Ignored in assembly mode
286-
"--model-checker-contracts=" // Ignored in assembly mode
287-
"contract1.yul:A,"
288-
"contract2.yul:B",
289-
"--model-checker-div-mod-no-slacks", // Ignored in assembly mode
290-
"--model-checker-engine=bmc", // Ignored in assembly mode
291-
"--model-checker-invariants=contract,reentrancy", // Ignored in assembly mode
292-
"--model-checker-show-unproved", // Ignored in assembly mode
293-
"--model-checker-solvers=z3,smtlib2", // Ignored in assembly mode
294-
"--model-checker-targets=" // Ignored in assembly mode
295-
"underflow,"
296-
"divByZero",
297-
"--model-checker-timeout=5", // Ignored in assembly mode
298284
"--asm",
299285
"--bin",
300286
"--ir-optimized",
@@ -378,20 +364,6 @@ BOOST_AUTO_TEST_CASE(standard_json_mode_options)
378364
"dir2/file2.sol:L=0x1111122222333334444455555666667777788888",
379365
"--gas", // Accepted but has no effect in Standard JSON mode
380366
"--combined-json=abi,bin", // Accepted but has no effect in Standard JSON mode
381-
"--metadata-hash=swarm", // Ignored in Standard JSON mode
382-
"--metadata-literal", // Ignored in Standard JSON mode
383-
"--model-checker-contracts=" // Ignored in Standard JSON mode
384-
"contract1.yul:A,"
385-
"contract2.yul:B",
386-
"--model-checker-div-mod-no-slacks", // Ignored in Standard JSON mode
387-
"--model-checker-engine=bmc", // Ignored in Standard JSON mode
388-
"--model-checker-invariants=contract,reentrancy", // Ignored in Standard JSON mode
389-
"--model-checker-show-unproved", // Ignored in Standard JSON mode
390-
"--model-checker-solvers=z3,smtlib2", // Ignored in Standard JSON mode
391-
"--model-checker-targets=" // Ignored in Standard JSON mode
392-
"underflow,"
393-
"divByZero",
394-
"--model-checker-timeout=5", // Ignored in Standard JSON mode
395367
};
396368

397369
CommandLineOptions expectedOptions;
@@ -424,16 +396,30 @@ BOOST_AUTO_TEST_CASE(invalid_options_input_modes_combinations)
424396
// TODO: This should eventually contain all options.
425397
{"--error-recovery", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
426398
{"--experimental-via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
427-
{"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}
399+
{"--via-ir", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
400+
{"--metadata-literal", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
401+
{"--metadata-hash=swarm", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
402+
{"--model-checker-show-unproved", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
403+
{"--model-checker-div-mod-no-slacks", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
404+
{"--model-checker-engine=bmc", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
405+
{"--model-checker-invariants=contract,reentrancy", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
406+
{"--model-checker-solvers=z3,smtlib2", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
407+
{"--model-checker-timeout=5", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
408+
{"--model-checker-contracts=contract1.yul:A,contract2.yul:B", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}},
409+
{"--model-checker-targets=underflow,divByZero", {"--assemble", "--yul", "--strict-assembly", "--standard-json", "--link"}}
428410
};
429411

430412
for (auto const& [optionName, inputModes]: invalidOptionInputModeCombinations)
431413
for (string const& inputMode: inputModes)
432414
{
433415
stringstream serr;
416+
size_t separatorPosition = optionName.find("=");
417+
string optionNameWithoutValue = optionName.substr(0, separatorPosition);
418+
soltestAssert(!optionNameWithoutValue.empty());
419+
434420
vector<string> commandLine = {"solc", optionName, "file", inputMode};
435421

436-
string expectedMessage = "The following options are not supported in the current input mode: " + optionName;
422+
string expectedMessage = "The following options are not supported in the current input mode: " + optionNameWithoutValue;
437423
auto hasCorrectMessage = [&](CommandLineValidationError const& _exception) { return _exception.what() == expectedMessage; };
438424

439425
BOOST_CHECK_EXCEPTION(parseCommandLine(commandLine), CommandLineValidationError, hasCorrectMessage);

0 commit comments

Comments
 (0)