mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Store compiler version in CBOR metadata
This commit is contained in:
parent
4037da9575
commit
e121c8f3c7
@ -8,6 +8,7 @@ Compiler Features:
|
|||||||
* SMTChecker: Support inherited state variables.
|
* SMTChecker: Support inherited state variables.
|
||||||
* SMTChecker: Support tuples and function calls with multiple return values.
|
* SMTChecker: Support tuples and function calls with multiple return values.
|
||||||
* SMTChecker: Support ``delete``.
|
* SMTChecker: Support ``delete``.
|
||||||
|
* Assembler: Encode the compiler version in the deployed bytecode.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
@ -37,6 +37,9 @@ function(create_build_info NAME)
|
|||||||
-DETH_BUILD_COMPILER="${ETH_BUILD_COMPILER}"
|
-DETH_BUILD_COMPILER="${ETH_BUILD_COMPILER}"
|
||||||
-DETH_BUILD_PLATFORM="${ETH_BUILD_PLATFORM}"
|
-DETH_BUILD_PLATFORM="${ETH_BUILD_PLATFORM}"
|
||||||
-DPROJECT_VERSION="${PROJECT_VERSION}"
|
-DPROJECT_VERSION="${PROJECT_VERSION}"
|
||||||
|
-DPROJECT_VERSION_MAJOR="${PROJECT_VERSION_MAJOR}"
|
||||||
|
-DPROJECT_VERSION_MINOR="${PROJECT_VERSION_MINOR}"
|
||||||
|
-DPROJECT_VERSION_PATCH="${PROJECT_VERSION_PATCH}"
|
||||||
-P "${ETH_SCRIPTS_DIR}/buildinfo.cmake"
|
-P "${ETH_SCRIPTS_DIR}/buildinfo.cmake"
|
||||||
)
|
)
|
||||||
include_directories("${PROJECT_BINARY_DIR}/include")
|
include_directories("${PROJECT_BINARY_DIR}/include")
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define ETH_PROJECT_VERSION "@PROJECT_VERSION@"
|
#define ETH_PROJECT_VERSION "@PROJECT_VERSION@"
|
||||||
|
#define ETH_PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||||
|
#define ETH_PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||||
|
#define ETH_PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||||
#define SOL_COMMIT_HASH "@SOL_COMMIT_HASH@"
|
#define SOL_COMMIT_HASH "@SOL_COMMIT_HASH@"
|
||||||
#define ETH_BUILD_TYPE "@ETH_BUILD_TYPE@"
|
#define ETH_BUILD_TYPE "@ETH_BUILD_TYPE@"
|
||||||
#define ETH_BUILD_OS "@ETH_BUILD_OS@"
|
#define ETH_BUILD_OS "@ETH_BUILD_OS@"
|
||||||
|
@ -1177,6 +1177,10 @@ bytes CompilerStack::createCBORMetadata(string const& _metadata, bool _experimen
|
|||||||
encoder.pushBytes("bzzr0", dev::swarmHash(_metadata).asBytes());
|
encoder.pushBytes("bzzr0", dev::swarmHash(_metadata).asBytes());
|
||||||
if (_experimentalMode)
|
if (_experimentalMode)
|
||||||
encoder.pushBool("experimental", true);
|
encoder.pushBool("experimental", true);
|
||||||
|
if (VersionIsRelease)
|
||||||
|
encoder.pushBytes("solc", VersionCompactBytes);
|
||||||
|
else
|
||||||
|
encoder.pushString("solc", VersionStringStrict);
|
||||||
return encoder.serialise();
|
return encoder.serialise();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,36 +44,10 @@ string const dev::solidity::VersionStringStrict =
|
|||||||
(string(SOL_VERSION_PRERELEASE).empty() ? "" : "-" + string(SOL_VERSION_PRERELEASE)) +
|
(string(SOL_VERSION_PRERELEASE).empty() ? "" : "-" + string(SOL_VERSION_PRERELEASE)) +
|
||||||
(string(SOL_VERSION_COMMIT).empty() ? "" : "+" + string(SOL_VERSION_COMMIT));
|
(string(SOL_VERSION_COMMIT).empty() ? "" : "+" + string(SOL_VERSION_COMMIT));
|
||||||
|
|
||||||
bytes dev::solidity::binaryVersion()
|
bytes const dev::solidity::VersionCompactBytes = {
|
||||||
{
|
ETH_PROJECT_VERSION_MAJOR,
|
||||||
bytes ret{0};
|
ETH_PROJECT_VERSION_MINOR,
|
||||||
size_t i = 0;
|
ETH_PROJECT_VERSION_PATCH
|
||||||
auto parseDecimal = [&]()
|
|
||||||
{
|
|
||||||
size_t ret = 0;
|
|
||||||
solAssert('0' <= VersionString[i] && VersionString[i] <= '9', "");
|
|
||||||
for (; i < VersionString.size() && '0' <= VersionString[i] && VersionString[i] <= '9'; ++i)
|
|
||||||
ret = ret * 10 + (VersionString[i] - '0');
|
|
||||||
return ret;
|
|
||||||
};
|
};
|
||||||
ret.push_back(uint8_t(parseDecimal()));
|
|
||||||
solAssert(i < VersionString.size() && VersionString[i] == '.', "");
|
|
||||||
++i;
|
|
||||||
ret.push_back(uint8_t(parseDecimal()));
|
|
||||||
solAssert(i < VersionString.size() && VersionString[i] == '.', "");
|
|
||||||
++i;
|
|
||||||
ret.push_back(uint8_t(parseDecimal()));
|
|
||||||
solAssert(i < VersionString.size() && (VersionString[i] == '-' || VersionString[i] == '+'), "");
|
|
||||||
++i;
|
|
||||||
size_t commitpos = VersionString.find("commit.");
|
|
||||||
solAssert(commitpos != string::npos, "");
|
|
||||||
i = commitpos + 7;
|
|
||||||
solAssert(i + 7 < VersionString.size(), "");
|
|
||||||
bytes commitHash = fromHex(VersionString.substr(i, 8));
|
|
||||||
solAssert(!commitHash.empty(), "");
|
|
||||||
ret += commitHash;
|
|
||||||
solAssert(ret.size() == 1 + 3 + 4, "");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
bool const dev::solidity::VersionIsRelease = string(SOL_VERSION_PRERELEASE).empty();
|
||||||
|
@ -33,11 +33,8 @@ namespace solidity
|
|||||||
extern char const* VersionNumber;
|
extern char const* VersionNumber;
|
||||||
extern std::string const VersionString;
|
extern std::string const VersionString;
|
||||||
extern std::string const VersionStringStrict;
|
extern std::string const VersionStringStrict;
|
||||||
|
extern bytes const VersionCompactBytes;
|
||||||
/// @returns a binary form of the version string, where A.B.C-HASH is encoded such that
|
extern bool const VersionIsRelease;
|
||||||
/// the first byte is zero, the following three bytes encode A B and C (interpreted as decimals)
|
|
||||||
/// and HASH is interpreted as 8 hex digits and encoded into the last four bytes.
|
|
||||||
bytes binaryVersion();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,9 @@ bytes onlyMetadata(bytes const& _bytecode)
|
|||||||
size_t metadataSize = (_bytecode[size - 2] << 8) + _bytecode[size - 1];
|
size_t metadataSize = (_bytecode[size - 2] << 8) + _bytecode[size - 1];
|
||||||
if (size < (metadataSize + 2))
|
if (size < (metadataSize + 2))
|
||||||
return bytes{};
|
return bytes{};
|
||||||
// Sanity check: assume the first byte is a fixed-size CBOR array with either 1 or 2 entries
|
// Sanity check: assume the first byte is a fixed-size CBOR array with either 2 or 3 entries
|
||||||
unsigned char firstByte = _bytecode[size - metadataSize - 2];
|
unsigned char firstByte = _bytecode[size - metadataSize - 2];
|
||||||
if (firstByte != 0xa1 && firstByte != 0xa2)
|
if (firstByte != 0xa2 && firstByte != 0xa3)
|
||||||
return bytes{};
|
return bytes{};
|
||||||
return bytes(_bytecode.end() - metadataSize - 2, _bytecode.end() - 2);
|
return bytes(_bytecode.end() - metadataSize - 2, _bytecode.end() - 2);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <test/Metadata.h>
|
#include <test/Metadata.h>
|
||||||
#include <test/Options.h>
|
#include <test/Options.h>
|
||||||
#include <libsolidity/interface/CompilerStack.h>
|
#include <libsolidity/interface/CompilerStack.h>
|
||||||
|
#include <libsolidity/interface/Version.h>
|
||||||
#include <libdevcore/SwarmHash.h>
|
#include <libdevcore/SwarmHash.h>
|
||||||
#include <libdevcore/JSON.h>
|
#include <libdevcore/JSON.h>
|
||||||
|
|
||||||
@ -69,7 +70,12 @@ BOOST_AUTO_TEST_CASE(metadata_stamp)
|
|||||||
bytes hash = dev::swarmHash(metadata).asBytes();
|
bytes hash = dev::swarmHash(metadata).asBytes();
|
||||||
BOOST_REQUIRE(hash.size() == 32);
|
BOOST_REQUIRE(hash.size() == 32);
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
||||||
BOOST_CHECK(cborMetadata.size() == 1);
|
BOOST_CHECK(cborMetadata.size() == 2);
|
||||||
|
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||||
|
if (VersionIsRelease)
|
||||||
|
BOOST_CHECK(cborMetadata.at("solc") == toHex(VersionCompactBytes));
|
||||||
|
else
|
||||||
|
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||||
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
||||||
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
||||||
}
|
}
|
||||||
@ -95,7 +101,12 @@ BOOST_AUTO_TEST_CASE(metadata_stamp_experimental)
|
|||||||
bytes hash = dev::swarmHash(metadata).asBytes();
|
bytes hash = dev::swarmHash(metadata).asBytes();
|
||||||
BOOST_REQUIRE(hash.size() == 32);
|
BOOST_REQUIRE(hash.size() == 32);
|
||||||
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
auto const cborMetadata = requireParsedCBORMetadata(bytecode);
|
||||||
BOOST_CHECK(cborMetadata.size() == 2);
|
BOOST_CHECK(cborMetadata.size() == 3);
|
||||||
|
BOOST_CHECK(cborMetadata.count("solc") == 1);
|
||||||
|
if (VersionIsRelease)
|
||||||
|
BOOST_CHECK(cborMetadata.at("solc") == toHex(VersionCompactBytes));
|
||||||
|
else
|
||||||
|
BOOST_CHECK(cborMetadata.at("solc") == VersionStringStrict);
|
||||||
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
BOOST_CHECK(cborMetadata.count("bzzr0") == 1);
|
||||||
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
BOOST_CHECK(cborMetadata.at("bzzr0") == toHex(hash));
|
||||||
BOOST_CHECK(cborMetadata.count("experimental") == 1);
|
BOOST_CHECK(cborMetadata.count("experimental") == 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user