From 9f0283df5cf04572d6974743702c8d626c9c2aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 13 Nov 2020 23:19:56 +0100 Subject: [PATCH 1/2] Fix command-line tests using wrong file names for libraries --- test/cmdlineTests/linking_standard_solidity/input.json | 2 +- .../linking_standard_solidity_quote_in_file_name/input.json | 4 ++-- .../linking_standard_solidity_quote_in_file_name/output.json | 2 +- .../input.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/cmdlineTests/linking_standard_solidity/input.json b/test/cmdlineTests/linking_standard_solidity/input.json index b70481304..921aa5018 100644 --- a/test/cmdlineTests/linking_standard_solidity/input.json +++ b/test/cmdlineTests/linking_standard_solidity/input.json @@ -20,7 +20,7 @@ }, "settings": { "libraries": { - "contract/test.sol": { + "A": { "L": "0x1234567890123456789012345678901234567890" } }, diff --git a/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/input.json b/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/input.json index fc54cdabc..d96e65c5f 100644 --- a/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/input.json +++ b/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/input.json @@ -1,7 +1,7 @@ { "language": "Solidity", "sources": { - "A": { + "A\"B": { "content": " // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.0; @@ -20,7 +20,7 @@ }, "settings": { "libraries": { - "contract/test\"test.sol": { + "A\"B": { "L": "0x1234567890123456789012345678901234567890" } }, diff --git a/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/output.json b/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/output.json index 1cfa37405..f04e00b12 100644 --- a/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/output.json +++ b/test/cmdlineTests/linking_standard_solidity_quote_in_file_name/output.json @@ -1 +1 @@ -{"contracts":{"A":{"C":{"evm":{"bytecode":{"generatedSources":[],"linkReferences":{},"object":"","opcodes":"","sourceMap":""}}}}},"sources":{"A":{"id":0}}} +{"contracts":{"A\"B":{"C":{"evm":{"bytecode":{"generatedSources":[],"linkReferences":{},"object":"","opcodes":"","sourceMap":""}}}}},"sources":{"A\"B":{"id":0}}} diff --git a/test/cmdlineTests/linking_standard_solidity_unresolved_references/input.json b/test/cmdlineTests/linking_standard_solidity_unresolved_references/input.json index 597e7f96e..9a6ce25a7 100644 --- a/test/cmdlineTests/linking_standard_solidity_unresolved_references/input.json +++ b/test/cmdlineTests/linking_standard_solidity_unresolved_references/input.json @@ -28,7 +28,7 @@ }, "settings": { "libraries": { - "contract/test.sol": { + "A": { "L1": "0x1234567890123456789012345678901234567890" } }, From 4174f38b02fde0c30f9b0e04d3f34238f59a63ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 13 Nov 2020 22:30:50 +0100 Subject: [PATCH 2/2] StandardCompiler: Include file names in link references --- Changelog.md | 1 + libsolidity/interface/StandardCompiler.cpp | 3 +- .../args | 1 + .../err | 1 + .../input.yul | 6 ++ .../output | 22 ++++++ test/libsolidity/StandardCompiler.cpp | 68 ++++++++++++++++++- 7 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args create mode 100644 test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/err create mode 100644 test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul create mode 100644 test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output diff --git a/Changelog.md b/Changelog.md index 7dcf3313a..5c5d9d205 100644 --- a/Changelog.md +++ b/Changelog.md @@ -32,6 +32,7 @@ Bugfixes: * SMTChecker: Fix CHC false positives when branches are used inside modifiers. * Code generator: Fix missing creation dependency tracking for abstract contracts. * NatSpec: Fix internal error when inheriting return parameter documentation but the parameter names differ between base and inherited. + * Standard JSON: Fix library addresses specified in ``libraries`` being used for linking even if the file names do not match. ### 0.7.4 (2020-10-19) diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index 86587839d..f3ba7db35 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -839,8 +839,7 @@ std::variant StandardCompiler: try { - // @TODO use libraries only for the given source - ret.libraries[library] = util::h160(address); + ret.libraries[sourceName + ":" + library] = util::h160(address); } catch (util::BadHexCharacter const&) { 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 new file mode 100644 index 000000000..cce3dedbf --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/args @@ -0,0 +1 @@ +--strict-assembly --libraries library1.sol:L:0x1234567890123456789012345678901234567890 diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/err b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/err new file mode 100644 index 000000000..014a1178f --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/err @@ -0,0 +1 @@ +Warning: Yul is still experimental. Please use the output with care. diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul new file mode 100644 index 000000000..acb612857 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul @@ -0,0 +1,6 @@ +object "a" { + code { + let addr1 := linkersymbol("library1.sol:L") + let addr2 := linkersymbol("library2.sol:L") + } +} diff --git a/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output new file mode 100644 index 000000000..150355ba1 --- /dev/null +++ b/test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output @@ -0,0 +1,22 @@ + +======= linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul (EVM) ======= + +Pretty printed source: +object "a" { + code { + let addr1 := linkersymbol("library1.sol:L") + let addr2 := linkersymbol("library2.sol:L") + } +} + + +Binary representation: +73123456789012345678901234567890123456789073__$c3523432985587641d17c68161d2f700c5$__5050 + +Text representation: + linkerSymbol("f3ffc10c396a7cc41ae954b050792839d20947bf73497d30c49a9fda1ea477ec") + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":32:75 */ + linkerSymbol("c3523432985587641d17c68161d2f700c57aaf4ed21cda4f25d76193c831f97f") + /* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":22:133 */ + pop + pop diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index 270295c3c..887e0ac32 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -903,6 +903,38 @@ BOOST_AUTO_TEST_CASE(library_linking) expectLinkReferences(contractResult, {{"library2.sol", {"L2"}}}); } +BOOST_AUTO_TEST_CASE(linking_yul) +{ + char const* input = R"( + { + "language": "Yul", + "settings": { + "libraries": { + "fileB": { + "L": "0x4200000000000000000000000000000000000001" + } + }, + "outputSelection": { + "fileA": { + "*": [ + "evm.bytecode.linkReferences" + ] + } + } + }, + "sources": { + "fileA": { + "content": "object \"a\" { code { let addr := linkersymbol(\"fileB:L\") } }" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_TEST(containsAtMostWarnings(result)); + Json::Value contractResult = getContractResult(result, "fileA", "a"); + expectLinkReferences(contractResult, {}); +} + BOOST_AUTO_TEST_CASE(linking_yul_empty_link_reference) { char const* input = R"( @@ -932,7 +964,7 @@ BOOST_AUTO_TEST_CASE(linking_yul_empty_link_reference) Json::Value result = compile(input); BOOST_TEST(containsAtMostWarnings(result)); Json::Value contractResult = getContractResult(result, "fileA", "a"); - expectLinkReferences(contractResult, {}); + expectLinkReferences(contractResult, {{"", {""}}}); } BOOST_AUTO_TEST_CASE(linking_yul_no_filename_in_link_reference) @@ -964,7 +996,39 @@ BOOST_AUTO_TEST_CASE(linking_yul_no_filename_in_link_reference) Json::Value result = compile(input); BOOST_TEST(containsAtMostWarnings(result)); Json::Value contractResult = getContractResult(result, "fileA", "a"); - expectLinkReferences(contractResult, {}); + expectLinkReferences(contractResult, {{"", {"L"}}}); +} + +BOOST_AUTO_TEST_CASE(linking_yul_same_library_name_different_files) +{ + char const* input = R"( + { + "language": "Yul", + "settings": { + "libraries": { + "fileB": { + "L": "0x4200000000000000000000000000000000000001" + } + }, + "outputSelection": { + "fileA": { + "*": [ + "evm.bytecode.linkReferences" + ] + } + } + }, + "sources": { + "fileA": { + "content": "object \"a\" { code { let addr := linkersymbol(\"fileC:L\") } }" + } + } + } + )"; + Json::Value result = compile(input); + BOOST_TEST(containsAtMostWarnings(result)); + Json::Value contractResult = getContractResult(result, "fileA", "a"); + expectLinkReferences(contractResult, {{"fileC", {"L"}}}); } BOOST_AUTO_TEST_CASE(evm_version)