2018-02-21 22:43:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2018-02-21 22:43:40 +00:00
|
|
|
/**
|
|
|
|
* EVM versioning.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-02-01 19:00:20 +00:00
|
|
|
#include <cstdint>
|
2019-10-28 10:39:30 +00:00
|
|
|
#include <optional>
|
2018-02-21 22:43:40 +00:00
|
|
|
#include <string>
|
|
|
|
|
2018-02-26 18:53:38 +00:00
|
|
|
#include <boost/operators.hpp>
|
2018-02-21 22:43:40 +00:00
|
|
|
|
2019-05-16 09:43:33 +00:00
|
|
|
|
2022-09-29 11:41:58 +00:00
|
|
|
namespace solidity::evmasm
|
|
|
|
{
|
|
|
|
/// Virtual machine bytecode instruction. Forward declared from libevmasm/Instruction.h
|
|
|
|
enum class Instruction: uint8_t;
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2018-02-21 22:43:40 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A version specifier of the EVM we want to compile to.
|
2022-06-27 23:11:50 +00:00
|
|
|
* Defaults to the latest version deployed on Ethereum Mainnet at the time of compiler release.
|
2018-02-21 22:43:40 +00:00
|
|
|
*/
|
2018-02-26 18:53:38 +00:00
|
|
|
class EVMVersion:
|
|
|
|
boost::less_than_comparable<EVMVersion>,
|
|
|
|
boost::equality_comparable<EVMVersion>
|
2018-02-21 22:43:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-12-12 13:51:22 +00:00
|
|
|
EVMVersion() = default;
|
2018-02-21 22:43:40 +00:00
|
|
|
|
|
|
|
static EVMVersion homestead() { return {Version::Homestead}; }
|
2018-02-26 18:53:38 +00:00
|
|
|
static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; }
|
|
|
|
static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; }
|
2018-02-21 22:43:40 +00:00
|
|
|
static EVMVersion byzantium() { return {Version::Byzantium}; }
|
2018-02-27 17:51:12 +00:00
|
|
|
static EVMVersion constantinople() { return {Version::Constantinople}; }
|
2019-02-25 14:51:26 +00:00
|
|
|
static EVMVersion petersburg() { return {Version::Petersburg}; }
|
2019-08-26 12:09:55 +00:00
|
|
|
static EVMVersion istanbul() { return {Version::Istanbul}; }
|
|
|
|
static EVMVersion berlin() { return {Version::Berlin}; }
|
2021-07-12 14:50:16 +00:00
|
|
|
static EVMVersion london() { return {Version::London}; }
|
2022-11-09 11:12:18 +00:00
|
|
|
static EVMVersion paris() { return {Version::Paris}; }
|
2018-02-21 22:43:40 +00:00
|
|
|
|
2019-10-28 10:39:30 +00:00
|
|
|
static std::optional<EVMVersion> fromString(std::string const& _version)
|
2018-02-21 22:43:40 +00:00
|
|
|
{
|
2022-11-09 11:12:18 +00:00
|
|
|
for (auto const& v: {homestead(), tangerineWhistle(), spuriousDragon(), byzantium(), constantinople(), petersburg(), istanbul(), berlin(), london(), paris()})
|
2018-02-26 18:53:38 +00:00
|
|
|
if (_version == v.name())
|
|
|
|
return v;
|
2019-10-28 10:39:30 +00:00
|
|
|
return std::nullopt;
|
2018-02-21 22:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }
|
2018-02-26 18:53:38 +00:00
|
|
|
bool operator<(EVMVersion const& _other) const { return m_version < _other.m_version; }
|
2018-02-21 22:43:40 +00:00
|
|
|
|
2018-02-26 18:53:38 +00:00
|
|
|
std::string name() const
|
|
|
|
{
|
|
|
|
switch (m_version)
|
|
|
|
{
|
2018-02-27 17:51:12 +00:00
|
|
|
case Version::Homestead: return "homestead";
|
2018-02-26 18:53:38 +00:00
|
|
|
case Version::TangerineWhistle: return "tangerineWhistle";
|
|
|
|
case Version::SpuriousDragon: return "spuriousDragon";
|
2018-02-27 17:51:12 +00:00
|
|
|
case Version::Byzantium: return "byzantium";
|
|
|
|
case Version::Constantinople: return "constantinople";
|
2019-02-25 14:51:26 +00:00
|
|
|
case Version::Petersburg: return "petersburg";
|
2019-08-26 12:09:55 +00:00
|
|
|
case Version::Istanbul: return "istanbul";
|
|
|
|
case Version::Berlin: return "berlin";
|
2021-07-12 14:50:16 +00:00
|
|
|
case Version::London: return "london";
|
2022-11-09 11:12:18 +00:00
|
|
|
case Version::Paris: return "paris";
|
2018-02-26 18:53:38 +00:00
|
|
|
}
|
|
|
|
return "INVALID";
|
|
|
|
}
|
2018-02-21 22:43:40 +00:00
|
|
|
|
|
|
|
/// Has the RETURNDATACOPY and RETURNDATASIZE opcodes.
|
|
|
|
bool supportsReturndata() const { return *this >= byzantium(); }
|
|
|
|
bool hasStaticCall() const { return *this >= byzantium(); }
|
2018-02-28 07:43:18 +00:00
|
|
|
bool hasBitwiseShifting() const { return *this >= constantinople(); }
|
2018-09-18 22:42:33 +00:00
|
|
|
bool hasCreate2() const { return *this >= constantinople(); }
|
2019-02-25 14:59:09 +00:00
|
|
|
bool hasExtCodeHash() const { return *this >= constantinople(); }
|
2019-09-02 13:23:45 +00:00
|
|
|
bool hasChainID() const { return *this >= istanbul(); }
|
|
|
|
bool hasSelfBalance() const { return *this >= istanbul(); }
|
2021-07-12 14:50:16 +00:00
|
|
|
bool hasBaseFee() const { return *this >= london(); }
|
2022-11-23 10:51:34 +00:00
|
|
|
bool hasPrevRandao() const { return *this >= paris(); }
|
2018-02-21 22:43:40 +00:00
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
bool hasOpcode(evmasm::Instruction _opcode) const;
|
2019-05-16 09:43:33 +00:00
|
|
|
|
2018-02-21 22:43:40 +00:00
|
|
|
/// Whether we have to retain the costs for the call opcode itself (false),
|
|
|
|
/// or whether we can just forward easily all remaining gas (true).
|
2018-02-26 18:53:38 +00:00
|
|
|
bool canOverchargeGasForCall() const { return *this >= tangerineWhistle(); }
|
2018-02-21 22:43:40 +00:00
|
|
|
|
|
|
|
private:
|
2022-11-09 11:12:18 +00:00
|
|
|
enum class Version { Homestead, TangerineWhistle, SpuriousDragon, Byzantium, Constantinople, Petersburg, Istanbul, Berlin, London, Paris };
|
2018-02-21 22:43:40 +00:00
|
|
|
|
|
|
|
EVMVersion(Version _version): m_version(_version) {}
|
|
|
|
|
2023-01-18 16:34:48 +00:00
|
|
|
Version m_version = Version::Paris;
|
2018-02-21 22:43:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|