aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-10-04 20:55:02 +0800
committerchriseth <chris@ethereum.org>2018-10-12 21:15:01 +0800
commit6daeb39ecc7ffd0e834e63f6495442c4211c5c1c (patch)
tree670349dc15db2f9be5210f4ad2c99a386c079168 /libevmasm
parent5f5dc8956d39ab19c5408aa4c39a3cd10d3a2dec (diff)
downloaddexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.tar.gz
dexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.tar.zst
dexon-solidity-6daeb39ecc7ffd0e834e63f6495442c4211c5c1c.zip
Use hash for library placeholders.
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/LinkerObject.cpp10
-rw-r--r--libevmasm/LinkerObject.h5
2 files changed, 13 insertions, 2 deletions
diff --git a/libevmasm/LinkerObject.cpp b/libevmasm/LinkerObject.cpp
index 1d5efecb..0ac69966 100644
--- a/libevmasm/LinkerObject.cpp
+++ b/libevmasm/LinkerObject.cpp
@@ -21,6 +21,7 @@
#include <libevmasm/LinkerObject.h>
#include <libdevcore/CommonData.h>
+#include <libdevcore/SHA3.h>
using namespace dev;
using namespace dev::eth;
@@ -50,14 +51,19 @@ string LinkerObject::toHex() const
for (auto const& ref: linkReferences)
{
size_t pos = ref.first * 2;
- string const& name = ref.second;
+ string hash = libraryPlaceholder(ref.second);
hex[pos] = hex[pos + 1] = hex[pos + 38] = hex[pos + 39] = '_';
for (size_t i = 0; i < 36; ++i)
- hex[pos + 2 + i] = i < name.size() ? name[i] : '_';
+ hex[pos + 2 + i] = hash.at(i);
}
return hex;
}
+string LinkerObject::libraryPlaceholder(string const& _libraryName)
+{
+ return keccak256(_libraryName).hex().substr(0, 36);
+}
+
h160 const*
LinkerObject::matchLibrary(
string const& _linkRefName,
diff --git a/libevmasm/LinkerObject.h b/libevmasm/LinkerObject.h
index 152487b4..92890803 100644
--- a/libevmasm/LinkerObject.h
+++ b/libevmasm/LinkerObject.h
@@ -50,6 +50,11 @@ struct LinkerObject
/// addresses by placeholders.
std::string toHex() const;
+ /// @returns a 36 character string that is used as a placeholder for the library
+ /// address (enclosed by `__` on both sides). The placeholder is the hex representation
+ /// of the first 18 bytes of the keccak-256 hash of @a _libraryName.
+ static std::string libraryPlaceholder(std::string const& _libraryName);
+
private:
static h160 const* matchLibrary(
std::string const& _linkRefName,