Skip to content

Commit 1d21bb4

Browse files
authored
Merge pull request #15961 from ethereum/safeguard_builtin_handles
Better safeguard against incompatible builtin handles between dialects
2 parents 406bdfb + 55e29b6 commit 1d21bb4

File tree

12 files changed

+880
-426
lines changed

12 files changed

+880
-426
lines changed

liblangutil/EVMVersion.h

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323

2424
#include <libsolutil/Assertions.h>
2525

26+
#include <array>
2627
#include <cstdint>
2728
#include <optional>
2829
#include <string>
29-
#include <vector>
30-
31-
#include <boost/operators.hpp>
3230

3331

3432
namespace solidity::evmasm
@@ -44,30 +42,30 @@ namespace solidity::langutil
4442
* A version specifier of the EVM we want to compile to.
4543
* Defaults to the latest version deployed on Ethereum Mainnet at the time of compiler release.
4644
*/
47-
class EVMVersion:
48-
boost::less_than_comparable<EVMVersion>,
49-
boost::equality_comparable<EVMVersion>
45+
class EVMVersion
5046
{
5147
public:
5248
EVMVersion() = default;
5349

54-
static EVMVersion homestead() { return {Version::Homestead}; }
55-
static EVMVersion tangerineWhistle() { return {Version::TangerineWhistle}; }
56-
static EVMVersion spuriousDragon() { return {Version::SpuriousDragon}; }
57-
static EVMVersion byzantium() { return {Version::Byzantium}; }
58-
static EVMVersion constantinople() { return {Version::Constantinople}; }
59-
static EVMVersion petersburg() { return {Version::Petersburg}; }
60-
static EVMVersion istanbul() { return {Version::Istanbul}; }
61-
static EVMVersion berlin() { return {Version::Berlin}; }
62-
static EVMVersion london() { return {Version::London}; }
63-
static EVMVersion paris() { return {Version::Paris}; }
64-
static EVMVersion shanghai() { return {Version::Shanghai}; }
65-
static EVMVersion cancun() { return {Version::Cancun}; }
66-
static EVMVersion prague() { return {Version::Prague}; }
67-
static EVMVersion osaka() { return {Version::Osaka}; }
68-
69-
static std::vector<EVMVersion> allVersions() {
70-
return {
50+
static EVMVersion current() { return {currentVersion}; }
51+
52+
static EVMVersion constexpr homestead() { return {Version::Homestead}; }
53+
static EVMVersion constexpr tangerineWhistle() { return {Version::TangerineWhistle}; }
54+
static EVMVersion constexpr spuriousDragon() { return {Version::SpuriousDragon}; }
55+
static EVMVersion constexpr byzantium() { return {Version::Byzantium}; }
56+
static EVMVersion constexpr constantinople() { return {Version::Constantinople}; }
57+
static EVMVersion constexpr petersburg() { return {Version::Petersburg}; }
58+
static EVMVersion constexpr istanbul() { return {Version::Istanbul}; }
59+
static EVMVersion constexpr berlin() { return {Version::Berlin}; }
60+
static EVMVersion constexpr london() { return {Version::London}; }
61+
static EVMVersion constexpr paris() { return {Version::Paris}; }
62+
static EVMVersion constexpr shanghai() { return {Version::Shanghai}; }
63+
static EVMVersion constexpr cancun() { return {Version::Cancun}; }
64+
static EVMVersion constexpr prague() { return {Version::Prague}; }
65+
static EVMVersion constexpr osaka() { return {Version::Osaka}; }
66+
67+
static auto constexpr allVersions() {
68+
return std::array{
7169
homestead(),
7270
tangerineWhistle(),
7371
spuriousDragon(),
@@ -85,6 +83,14 @@ class EVMVersion:
8583
};
8684
}
8785

86+
static auto constexpr allEOFVersions()
87+
{
88+
return std::array{
89+
std::optional<uint8_t>(),
90+
std::make_optional<uint8_t>(1)
91+
};
92+
}
93+
8894
static std::optional<EVMVersion> fromString(std::string const& _version)
8995
{
9096
for (auto const& v: allVersions())
@@ -96,11 +102,10 @@ class EVMVersion:
96102
static EVMVersion firstWithEOF() { return {Version::Osaka}; }
97103

98104
bool isExperimental() const {
99-
return *this > EVMVersion{};
105+
return m_version > currentVersion;
100106
}
101107

102-
bool operator==(EVMVersion const& _other) const { return m_version == _other.m_version; }
103-
bool operator<(EVMVersion const& _other) const { return m_version < _other.m_version; }
108+
auto operator<=>(EVMVersion const&) const = default;
104109

105110
std::string name() const
106111
{
@@ -164,10 +169,11 @@ class EVMVersion:
164169
Prague,
165170
Osaka,
166171
};
172+
static auto constexpr currentVersion = Version::Prague;
167173

168-
EVMVersion(Version _version): m_version(_version) {}
174+
constexpr EVMVersion(Version _version): m_version(_version) {}
169175

170-
Version m_version = Version::Prague;
176+
Version m_version = currentVersion;
171177
};
172178

173179
}

libyul/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ add_library(yul
5858
backends/evm/ControlFlowGraphBuilder.h
5959
backends/evm/EthAssemblyAdapter.cpp
6060
backends/evm/EthAssemblyAdapter.h
61+
backends/evm/EVMBuiltins.cpp
62+
backends/evm/EVMBuiltins.h
6163
backends/evm/EVMCodeTransform.cpp
6264
backends/evm/EVMCodeTransform.h
6365
backends/evm/EVMDialect.cpp

0 commit comments

Comments
 (0)