Merge pull request #4764 from ethereum/cbor-version

Store compiler version in CBOR metadata
This commit is contained in:
chriseth
2019-05-09 10:10:50 +02:00
committed by GitHub
25 changed files with 188 additions and 221 deletions
+4
View File
@@ -1177,6 +1177,10 @@ bytes CompilerStack::createCBORMetadata(string const& _metadata, bool _experimen
encoder.pushBytes("bzzr0", dev::swarmHash(_metadata).asBytes());
if (_experimentalMode)
encoder.pushBool("experimental", true);
if (m_release)
encoder.pushBytes("solc", VersionCompactBytes);
else
encoder.pushString("solc", VersionStringStrict);
return encoder.serialise();
}
+5 -1
View File
@@ -25,6 +25,7 @@
#include <libsolidity/interface/ReadFile.h>
#include <libsolidity/interface/OptimiserSettings.h>
#include <libsolidity/interface/Version.h>
#include <liblangutil/ErrorReporter.h>
#include <liblangutil/EVMVersion.h>
@@ -261,6 +262,8 @@ public:
/// @returns a JSON representing the estimated gas usage for contract creation, internal and external functions
Json::Value gasEstimates(std::string const& _contractName) const;
/// Overwrites the release/prerelease flag. Should only be used for testing.
void overwriteReleaseFlag(bool release) { m_release = release; }
private:
/// The state per source unit. Filled gradually during parsing.
struct Source
@@ -333,7 +336,7 @@ private:
std::string createMetadata(Contract const& _contract) const;
/// @returns the metadata CBOR for the given serialised metadata JSON.
static bytes createCBORMetadata(std::string const& _metadata, bool _experimentalMode);
bytes createCBORMetadata(std::string const& _metadata, bool _experimentalMode);
/// @returns the computer source mapping string.
std::string computeSourceMapping(eth::AssemblyItems const& _items) const;
@@ -382,6 +385,7 @@ private:
langutil::ErrorReporter m_errorReporter;
bool m_metadataLiteralSources = false;
State m_stackState = Empty;
bool m_release = VersionIsRelease;
};
}
+6 -32
View File
@@ -44,36 +44,10 @@ string const dev::solidity::VersionStringStrict =
(string(SOL_VERSION_PRERELEASE).empty() ? "" : "-" + string(SOL_VERSION_PRERELEASE)) +
(string(SOL_VERSION_COMMIT).empty() ? "" : "+" + string(SOL_VERSION_COMMIT));
bytes dev::solidity::binaryVersion()
{
bytes ret{0};
size_t i = 0;
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;
}
bytes const dev::solidity::VersionCompactBytes = {
ETH_PROJECT_VERSION_MAJOR,
ETH_PROJECT_VERSION_MINOR,
ETH_PROJECT_VERSION_PATCH
};
bool const dev::solidity::VersionIsRelease = string(SOL_VERSION_PRERELEASE).empty();
+2 -5
View File
@@ -33,11 +33,8 @@ namespace solidity
extern char const* VersionNumber;
extern std::string const VersionString;
extern std::string const VersionStringStrict;
/// @returns a binary form of the version string, where A.B.C-HASH is encoded such that
/// 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();
extern bytes const VersionCompactBytes;
extern bool const VersionIsRelease;
}
}