From 982476f99d085072d25b703a146a6d92cd280714 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 26 Feb 2018 19:53:38 +0100 Subject: [PATCH] Add TangerineWhistle. --- libsolidity/interface/EVMVersion.h | 39 ++++++++++++------- solc/CommandLineInterface.cpp | 2 +- test/RPCSession.cpp | 16 ++++---- .../SolidityNameAndTypeResolution.cpp | 2 +- test/libsolidity/StandardCompiler.cpp | 4 ++ test/libsolidity/ViewPureChecker.cpp | 2 +- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/libsolidity/interface/EVMVersion.h b/libsolidity/interface/EVMVersion.h index 1ddcd218b..954a9f8f1 100644 --- a/libsolidity/interface/EVMVersion.h +++ b/libsolidity/interface/EVMVersion.h @@ -23,6 +23,7 @@ #include #include +#include namespace dev { @@ -33,28 +34,40 @@ namespace solidity * A version specifier of the EVM we want to compile to. * Defaults to the latest version. */ -class EVMVersion +class EVMVersion: + boost::less_than_comparable, + boost::equality_comparable { public: EVMVersion() {} static EVMVersion homestead() { return {Version::Homestead}; } + static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; } + static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; } static EVMVersion byzantium() { return {Version::Byzantium}; } static boost::optional fromString(std::string const& _version) { - if (_version == "homestead") - return homestead(); - else if (_version == "byzantium") - return byzantium(); - else - return {}; + for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium()}) + if (_version == v.name()) + return v; + return {}; } bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; } - bool operator!=(EVMVersion const& _other) const { return !this->operator==(_other); } + bool operator<(EVMVersion const& _other) const { return m_version < _other.m_version; } - std::string name() const { return m_version == Version::Byzantium ? "byzantium" : "homestead"; } + std::string name() const + { + switch (m_version) + { + case Version::Byzantium: return "byzantium"; + case Version::TangerineWhistle: return "tangerineWhistle"; + case Version::SpuriousDragon: return "spuriousDragon"; + case Version::Homestead: return "homestead"; + } + return "INVALID"; + } /// Has the RETURNDATACOPY and RETURNDATASIZE opcodes. bool supportsReturndata() const { return *this >= byzantium(); } @@ -62,14 +75,10 @@ public: /// Whether we have to retain the costs for the call opcode itself (false), /// or whether we can just forward easily all remaining gas (true). - bool canOverchargeGasForCall() const - { - // @TODO when exactly was this introduced? Was together with the call stack fix. - return m_version == Version::Byzantium; - } + bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); } private: - enum class Version { Homestead, Byzantium }; + enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium }; EVMVersion(Version _version): m_version(_version) {} diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 8ccb04eee..caa564bc3 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -539,7 +539,7 @@ Allowed options)", ( g_strEVMVersion.c_str(), po::value()->value_name("version"), - "Select desired EVM version. Either homestead or byzantium (default)." + "Select desired EVM version. Either homestead, tangerineWhistle, spuriousDragon or byzantium (default)." ) (g_argOptimize.c_str(), "Enable bytecode optimizer.") ( diff --git a/test/RPCSession.cpp b/test/RPCSession.cpp index 79ddf754d..54871057f 100644 --- a/test/RPCSession.cpp +++ b/test/RPCSession.cpp @@ -219,9 +219,13 @@ string RPCSession::personal_newAccount(string const& _password) void RPCSession::test_setChainParams(vector const& _accounts) { - string enableByzantium; - if (test::Options::get().evmVersion() == solidity::EVMVersion::byzantium()) - enableByzantium = "\"byzantiumForkBlock\": \"0x00\","; + string forks; + if (test::Options::get().evmVersion() >= solidity::EVMVersion::tangerineWhistle()) + forks += "\"EIP150ForkBlock\": \"0x00\",\n"; + if (test::Options::get().evmVersion() >= solidity::EVMVersion::spuriousDragon()) + forks += "\"EIP158ForkBlock\": \"0x00\",\n"; + if (test::Options::get().evmVersion() >= solidity::EVMVersion::byzantium()) + forks += "\"byzantiumForkBlock\": \"0x00\",\n"; static string const c_configString = R"( { "sealEngine": "NoProof", @@ -230,10 +234,8 @@ void RPCSession::test_setChainParams(vector const& _accounts) "maximumExtraDataSize": "0x1000000", "blockReward": "0x", "allowFutureBlocks": true, - "homesteadForkBlock": "0x00", - )" + enableByzantium + R"( - "EIP150ForkBlock": "0x00", - "EIP158ForkBlock": "0x00" + )" + forks + R"( + "homesteadForkBlock": "0x00" }, "genesis": { "author": "0000000000000010000000000000000000000000", diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index e3cde5d65..7c2603353 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -7087,7 +7087,7 @@ BOOST_AUTO_TEST_CASE(returndatacopy_as_variable) {Error::Type::Warning, "Variable is shadowed in inline assembly by an instruction of the same name"}, {Error::Type::DeclarationError, "Unbalanced stack"} }); - if (dev::test::Options::get().evmVersion() == EVMVersion::homestead()) + if (!dev::test::Options::get().evmVersion().supportsReturndata()) expectations.emplace_back(make_pair(Error::Type::Warning, std::string("\"returndatasize\" instruction is only available for Byzantium-compatible"))); CHECK_ALLOW_MULTI(text, expectations); } diff --git a/test/libsolidity/StandardCompiler.cpp b/test/libsolidity/StandardCompiler.cpp index df3ece7c0..4c8918be8 100644 --- a/test/libsolidity/StandardCompiler.cpp +++ b/test/libsolidity/StandardCompiler.cpp @@ -746,6 +746,10 @@ BOOST_AUTO_TEST_CASE(evm_version) Json::Value result; result = compile(inputForVersion("\"evmVersion\": \"homestead\",")); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"homestead\"") != string::npos); + result = compile(inputForVersion("\"evmVersion\": \"tangerineWhistle\",")); + BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"tangerineWhistle\"") != string::npos); + result = compile(inputForVersion("\"evmVersion\": \"spuriousDragon\",")); + BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"spuriousDragon\"") != string::npos); result = compile(inputForVersion("\"evmVersion\": \"byzantium\",")); BOOST_CHECK(result["contracts"]["fileA"]["A"]["metadata"].asString().find("\"evmVersion\":\"byzantium\"") != string::npos); // test default diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index 35a0c7e5f..e6a5cfd06 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -425,7 +425,7 @@ BOOST_AUTO_TEST_CASE(assembly_staticcall) } } )"; - if (dev::test::Options::get().evmVersion() == EVMVersion::homestead()) + if (!dev::test::Options::get().evmVersion().hasStaticCall()) CHECK_WARNING(text, "\"staticcall\" instruction is only available for Byzantium-compatible"); else CHECK_SUCCESS_NO_WARNINGS(text);