diff --git a/Changelog.md b/Changelog.md index c98d4992b..a42bf9cc6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,8 @@ Compiler Features: * Standard JSON: New option ``modelCheckerSettings.targets`` allows specifying which targets should be checked. The valid options are ``all``, ``constantCondition``, ``underflow``, ``overflow``, ``divByZero``, ``balance``, ``assert``, ``popEmptyArray``, where the default is ``all``. Multiple targets can be chosen at the same time, separated by a comma without spaces: ``underflow,overflow,assert``. + * Command Line Interface: Allow "=" as separator between library name and address in ``--libraries`` commandline option. + * Command Line Interface: Only accept the library address that is prefixed with "0x" in ``--libraries`` commandline option. Bugfixes: * Code Generator: Fix length check when decoding malformed error data in catch clause. diff --git a/docs/using-the-compiler.rst b/docs/using-the-compiler.rst index cfb3b4aa7..680681382 100644 --- a/docs/using-the-compiler.rst +++ b/docs/using-the-compiler.rst @@ -74,7 +74,10 @@ identify which libraries the placeholders represent. Note that the fully qualifi is the path of its source file and the library name separated by ``:``. You can use ``solc`` as a linker meaning that it will insert the library addresses for you at those points: -Either add ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890 file.sol:Heap:0xabCD567890123456789012345678901234567890"`` to your command to provide an address for each library (use commas or spaces as separators) or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``. +Either add ``--libraries "file.sol:Math=0x1234567890123456789012345678901234567890 file.sol:Heap=0xabCD567890123456789012345678901234567890"`` to your command to provide an address for each library (use commas or spaces as separators) or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``. + +.. note:: + Starting Solidity 0.8.1 accepts ``=`` as separator between library and address, and ``:`` as a separator is deprecated. It will be removed in the future. Currently ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890 file.sol:Heap:0xabCD567890123456789012345678901234567890"`` will work too. If ``solc`` is called with the option ``--standard-json``, it will expect a JSON input (as explained below) on the standard input, and return a JSON output on the standard output. This is the recommended interface for more complex and especially automated uses. The process will always terminate in a "success" state and report any errors via the JSON output. The option ``--base-path`` is also processed in standard-json mode. diff --git a/docs/yul.rst b/docs/yul.rst index 3f288cd04..aff5455e7 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -946,7 +946,7 @@ is equivalent to let a := 0x1234567890123456789012345678901234567890 -when the linker is invoked with ``--libraries "file.sol:Math:0x1234567890123456789012345678901234567890`` +when the linker is invoked with ``--libraries "file.sol:Math=0x1234567890123456789012345678901234567890`` option. See :ref:`Using the Commandline Compiler ` for details about the Solidity linker. diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8c447e6f0..306527281 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -666,16 +666,29 @@ bool CommandLineInterface::parseLibraryOption(string const& _input) for (string const& lib: libraries) if (!lib.empty()) { - //search for last colon in string as our binaries output placeholders in the form of file:Name - //so we need to search for the second `:` in the string - auto colon = lib.rfind(':'); - if (colon == string::npos) + //search for equal sign or last colon in string as our binaries output placeholders in the form of file=Name or file:Name + //so we need to search for `=` or `:` in the string + auto separator = lib.rfind('='); + bool isSeparatorEqualSign = true; + if (separator == string::npos) { - serr() << "Colon separator missing in library address specifier \"" << lib << "\"" << endl; - return false; + separator = lib.rfind(':'); + if (separator == string::npos) + { + serr() << "Equal sign separator missing in library address specifier \"" << lib << "\"" << endl; + return false; + } + else + isSeparatorEqualSign = false; // separator is colon } + else + if (lib.rfind('=') != lib.find('=')) + { + serr() << "Only one equal sign \"=\" is allowed in the address string \"" << lib << "\"." << endl; + return false; + } - string libName(lib.begin(), lib.begin() + static_cast(colon)); + string libName(lib.begin(), lib.begin() + static_cast(separator)); boost::trim(libName); if (m_libraries.count(libName)) { @@ -683,17 +696,25 @@ bool CommandLineInterface::parseLibraryOption(string const& _input) return false; } - string addrString(lib.begin() + static_cast(colon) + 1, lib.end()); + string addrString(lib.begin() + static_cast(separator) + 1, lib.end()); boost::trim(addrString); - if (addrString.substr(0, 2) == "0x") - addrString = addrString.substr(2); if (addrString.empty()) { - serr() << "Empty address provided for library \"" << libName << "\":" << endl; - serr() << "Note that there should not be any whitespace after the colon." << endl; + serr() << "Empty address provided for library \"" << libName << "\"." << endl; + serr() << "Note that there should not be any whitespace after the " << (isSeparatorEqualSign ? "equal sign" : "colon") << "." << endl; return false; } - else if (addrString.length() != 40) + + if (addrString.substr(0, 2) == "0x") + addrString = addrString.substr(2); + else + { + serr() << "The address " << addrString << " is not prefixed with \"0x\"." << endl; + serr() << "Note that the address must be prefixed with \"0x\"." << endl; + return false; + } + + if (addrString.length() != 40) { serr() << "Invalid length for address for library \"" << libName << "\": " << addrString.length() << " instead of 40 characters." << endl; return false; @@ -924,8 +945,8 @@ General Information)").c_str(), g_argLibraries.c_str(), po::value>()->value_name("libs"), "Direct string or file containing library addresses. Syntax: " - ":
[, or whitespace] ...\n" - "Address is interpreted as a hex string optionally prefixed by 0x." + "=
[, or whitespace] ...\n" + "Address is interpreted as a hex string prefixed by 0x." ) ; desc.add(linkerModeOptions); diff --git a/test/cmdlineTests.sh b/test/cmdlineTests.sh index 2c87de529..26b525c8a 100755 --- a/test/cmdlineTests.sh +++ b/test/cmdlineTests.sh @@ -376,11 +376,11 @@ rm -rf "$SOLTMPDIR" echo "Done." printTask "Testing library checksum..." -echo '' | "$SOLC" - --link --libraries a:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null -! echo '' | "$SOLC" - --link --libraries a:0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null +echo '' | "$SOLC" - --link --libraries a=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null +! echo '' | "$SOLC" - --link --libraries a=0x80f20564390eAe531E810af625A22f51385Cd222 &>/dev/null printTask "Testing long library names..." -echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname:0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null +echo '' | "$SOLC" - --link --libraries aveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerylonglibraryname=0x90f20564390eAe531E810af625A22f51385Cd222 >/dev/null printTask "Testing linking itself..." SOLTMPDIR=$(mktemp -d) @@ -394,7 +394,7 @@ SOLTMPDIR=$(mktemp -d) # But not in library file. grep -q -v '[/_]' L.bin # Now link - "$SOLC" --link --libraries x.sol:L:0x90f20564390eAe531E810af625A22f51385Cd222 C.bin + "$SOLC" --link --libraries x.sol:L=0x90f20564390eAe531E810af625A22f51385Cd222 C.bin # Now the placeholder and explanation should be gone. grep -q -v '[/_]' C.bin ) diff --git a/test/cmdlineTests/linking_solidity/args b/test/cmdlineTests/linking_solidity/args index 0b04ebd47..9a958527f 100644 --- a/test/cmdlineTests/linking_solidity/args +++ b/test/cmdlineTests/linking_solidity/args @@ -1 +1 @@ ---bin --bin-runtime --libraries linking_solidity/input.sol:L:0x1234567890123456789012345678901234567890 +--bin --bin-runtime --libraries linking_solidity/input.sol:L=0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_solidity_unresolved_references/args b/test/cmdlineTests/linking_solidity_unresolved_references/args index a08ce1cb4..8909b2779 100644 --- a/test/cmdlineTests/linking_solidity_unresolved_references/args +++ b/test/cmdlineTests/linking_solidity_unresolved_references/args @@ -1 +1 @@ ---bin --bin-runtime --libraries linking_solidity_unresolved_references/input.sol:L1:0x1234567890123456789012345678901234567890 +--bin --bin-runtime --libraries linking_solidity_unresolved_references/input.sol:L1=0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_strict_assembly/args b/test/cmdlineTests/linking_strict_assembly/args index 7a735d327..1388594ab 100644 --- a/test/cmdlineTests/linking_strict_assembly/args +++ b/test/cmdlineTests/linking_strict_assembly/args @@ -1 +1 @@ ---strict-assembly --libraries contract/test.sol:L:0x1234567890123456789012345678901234567890 +--strict-assembly --libraries contract/test.sol:L=0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/args b/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/args index 54be2478a..186eeedb3 100644 --- a/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/args +++ b/test/cmdlineTests/linking_strict_assembly_duplicate_library_name/args @@ -1 +1 @@ ---strict-assembly --libraries library.sol:L:0x1234567890123456789012345678901234567890,library.sol:L:0x0987654321098765432109876543210987654321 +--strict-assembly --libraries library.sol:L=0x1234567890123456789012345678901234567890,library.sol:L=0x0987654321098765432109876543210987654321 diff --git a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args index 57ee5078b..c7de26a69 100644 --- a/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args +++ b/test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/args @@ -1 +1 @@ ---strict-assembly --libraries L:0x1234567890123456789012345678901234567890 +--strict-assembly --libraries L=0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/args b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/args index a424a337a..304a7975b 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/args +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/args @@ -1 +1 @@ ---strict-assembly --libraries library1.sol:L:0x1111111111111111111111111111111111111111,library2.sol:L:0x2222222222222222222222222222222222222222 +--strict-assembly --libraries library1.sol:L=0x1111111111111111111111111111111111111111,library2.sol:L=0x2222222222222222222222222222222222222222 diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args index cce3dedbf..12e6cd123 100644 --- a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args @@ -1 +1 @@ ---strict-assembly --libraries library1.sol:L:0x1234567890123456789012345678901234567890 +--strict-assembly --libraries library1.sol:L=0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_strict_assembly_unresolved_references/args b/test/cmdlineTests/linking_strict_assembly_unresolved_references/args index 30b97f0a7..da00d1fd8 100644 --- a/test/cmdlineTests/linking_strict_assembly_unresolved_references/args +++ b/test/cmdlineTests/linking_strict_assembly_unresolved_references/args @@ -1 +1 @@ ---strict-assembly --libraries contract/test.sol:L1:0x1234567890123456789012345678901234567890 +--strict-assembly --libraries contract/test.sol:L1=0x1234567890123456789012345678901234567890