Change library placeholder to __$<hash>$__.

This commit is contained in:
chriseth 2018-10-08 15:08:12 +02:00
parent 4d6d224cf8
commit 26c693aa92
4 changed files with 12 additions and 9 deletions

View File

@ -160,8 +160,10 @@ Command Line and JSON Interfaces
* In unlinked binary hex files, library address placeholders are now
the first 36 hex characters of the keccak256 hash of the fully qualified
library name, instead of just the fully qualified library name.
Binary files now also contain a list of mappings from these hex placeholders
library name, surrounded by ``$...$``. Previously,
just the fully qualified library name was used.
This recudes the chances of collisions, especially when long paths are used.
Binary files now also contain a list of mappings from these placeholders
to the fully qualified names.
Constructors

View File

@ -41,15 +41,16 @@ If there are multiple matches due to remappings, the one with the longest common
For security reasons the compiler has restrictions what directories it can access. Paths (and their subdirectories) of source files specified on the commandline and paths defined by remappings are allowed for import statements, but everything else is rejected. Additional paths (and their subdirectories) can be allowed via the ``--allow-paths /sample/path,/another/sample/path`` switch.
If your contracts use :ref:`libraries <libraries>`, you will notice that the bytecode contains substrings of the form ``__53aea86b7d70b31448b230b20ae141a537e5__``. These are placeholders for the actual library addresses.
The placeholder is a 36 character prefix of the hex encoding of the keccak256 hash of the fully qualified library name.
The bytecode file will also contain lines of the form ``// <placeholder> -> <library name>`` at the end to help
identify which libraries the placeholders represent.
If your contracts use :ref:`libraries <libraries>`, you will notice that the bytecode contains substrings of the form ``__$53aea86b7d70b31448b230b20ae141a537$__``. These are placeholders for the actual library addresses.
The placeholder is a 34 character prefix of the hex encoding of the keccak256 hash of the fully qualified library name.
The bytecode file will also contain lines of the form ``// <placeholder> -> <fq library name>`` at the end to help
identify which libraries the placeholders represent. Note that the fully qualified library name
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 or store the string in a file (one library per line) and run ``solc`` using ``--libraries fileName``.
If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__53aea86b7d70b31448b230b20ae141a537e5__``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case.
If ``solc`` is called with the option ``--link``, all input files are interpreted to be unlinked binaries (hex-encoded) in the ``__$53aea86b7d70b31448b230b20ae141a537$__``-format given above and are linked in-place (if the input is read from stdin, it is written to stdout). All options except ``--libraries`` are ignored (including ``-o``) in this case.
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.

View File

@ -61,7 +61,7 @@ string LinkerObject::toHex() const
string LinkerObject::libraryPlaceholder(string const& _libraryName)
{
return "0x" + keccak256(_libraryName).hex().substr(0, 34);
return "$" + keccak256(_libraryName).hex().substr(0, 34) + "$";
}
h160 const*

View File

@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(all_assembly_items)
BOOST_CHECK_EQUAL(
_assembly.assemble().toHex(),
"5b6001600220606773__bf005014d9d0f534b8fcb268bd84c491a238__"
"5b6001600220606773__$bf005014d9d0f534b8fcb268bd84c491a2$__"
"6000567f556e75736564206665617475726520666f722070757368696e"
"6720737472696e605f6001605e73000000000000000000000000000000000000000000fe"
"fe010203044266eeaa"