Skip to content

Commit 7f1a2be

Browse files
committed
Allow basefee as Yul identifier for EVMVersion < london
This was done to prevent basefee from being a breaking change. This change will be removed in 0.9.0. TODO revert this commit in breaking.
1 parent 79733fc commit 7f1a2be

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

libyul/backends/evm/EVMDialect.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,22 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
112112
return {name, f};
113113
}
114114

115-
set<YulString> createReservedIdentifiers()
115+
set<YulString> createReservedIdentifiers(langutil::EVMVersion _evmVersion)
116116
{
117+
// TODO remove this in 0.9.0. We allow creating functions or identifiers in Yul with the name
118+
// basefee for VMs before london.
119+
auto baseFeeException = [&](evmasm::Instruction _instr) -> bool
120+
{
121+
return _instr == evmasm::Instruction::BASEFEE && _evmVersion < langutil::EVMVersion::london();
122+
};
123+
117124
set<YulString> reserved;
118125
for (auto const& instr: evmasm::c_instructions)
119126
{
120127
string name = instr.first;
121128
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
122-
reserved.emplace(name);
129+
if (!baseFeeException(instr.second))
130+
reserved.emplace(name);
123131
}
124132
reserved += vector<YulString>{
125133
"linkersymbol"_yulstring,
@@ -300,7 +308,7 @@ EVMDialect::EVMDialect(langutil::EVMVersion _evmVersion, bool _objectAccess):
300308
m_objectAccess(_objectAccess),
301309
m_evmVersion(_evmVersion),
302310
m_functions(createBuiltins(_evmVersion, _objectAccess)),
303-
m_reserved(createReservedIdentifiers())
311+
m_reserved(createReservedIdentifiers(_evmVersion))
304312
{
305313
}
306314

scripts/error_codes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ def examine_id_coverage(top_dir, source_id_to_file_names, new_ids_only=False):
198198
# The warning may or may not exist in a compiler build.
199199
"4591", # "There are more than 256 warnings. Ignoring the rest."
200200
# Due to 3805, the warning lists look different for different compiler builds.
201-
"1834" # Unimplemented feature error, as we do not test it anymore via cmdLineTests
201+
"1834", # Unimplemented feature error, as we do not test it anymore via cmdLineTests
202+
"5430" # basefee being used in inline assembly for EVMVersion < london
202203
}
203204
assert len(test_ids & white_ids) == 0, "The sets are not supposed to intersect"
204205
test_ids |= white_ids

test/libsolidity/syntaxTests/types/magic_block_basefee_error.sol

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,8 @@ contract C {
22
function f() public view returns (uint) {
33
return block.basefee;
44
}
5-
function g() public view returns (uint ret) {
6-
assembly {
7-
ret := basefee()
8-
}
9-
}
105
}
116
// ====
12-
// EVMVersion: =berlin
7+
// EVMVersion: <=berlin
138
// ----
149
// TypeError 5921: (74-87): "basefee" is not supported by the VM version.
15-
// TypeError 5430: (183-190): The "basefee" instruction is only available for London-compatible VMs (you are currently compiling for "berlin").

0 commit comments

Comments
 (0)