Skip to content

Commit

Permalink
Allow basefee as Yul identifier for EVMVersion < london
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hrkrshnn committed Aug 11, 2021
1 parent 79733fc commit 7f1a2be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
14 changes: 11 additions & 3 deletions libyul/backends/evm/EVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,22 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
return {name, f};
}

set<YulString> createReservedIdentifiers()
set<YulString> createReservedIdentifiers(langutil::EVMVersion _evmVersion)
{
// TODO remove this in 0.9.0. We allow creating functions or identifiers in Yul with the name
// basefee for VMs before london.
auto baseFeeException = [&](evmasm::Instruction _instr) -> bool
{
return _instr == evmasm::Instruction::BASEFEE && _evmVersion < langutil::EVMVersion::london();
};

set<YulString> reserved;
for (auto const& instr: evmasm::c_instructions)
{
string name = instr.first;
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
reserved.emplace(name);
if (!baseFeeException(instr.second))
reserved.emplace(name);
}
reserved += vector<YulString>{
"linkersymbol"_yulstring,
Expand Down Expand Up @@ -300,7 +308,7 @@ EVMDialect::EVMDialect(langutil::EVMVersion _evmVersion, bool _objectAccess):
m_objectAccess(_objectAccess),
m_evmVersion(_evmVersion),
m_functions(createBuiltins(_evmVersion, _objectAccess)),
m_reserved(createReservedIdentifiers())
m_reserved(createReservedIdentifiers(_evmVersion))
{
}

Expand Down
3 changes: 2 additions & 1 deletion scripts/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def examine_id_coverage(top_dir, source_id_to_file_names, new_ids_only=False):
# The warning may or may not exist in a compiler build.
"4591", # "There are more than 256 warnings. Ignoring the rest."
# Due to 3805, the warning lists look different for different compiler builds.
"1834" # Unimplemented feature error, as we do not test it anymore via cmdLineTests
"1834", # Unimplemented feature error, as we do not test it anymore via cmdLineTests
"5430" # basefee being used in inline assembly for EVMVersion < london
}
assert len(test_ids & white_ids) == 0, "The sets are not supposed to intersect"
test_ids |= white_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ contract C {
function f() public view returns (uint) {
return block.basefee;
}
function g() public view returns (uint ret) {
assembly {
ret := basefee()
}
}
}
// ====
// EVMVersion: =berlin
// EVMVersion: <=berlin
// ----
// TypeError 5921: (74-87): "basefee" is not supported by the VM version.
// TypeError 5430: (183-190): The "basefee" instruction is only available for London-compatible VMs (you are currently compiling for "berlin").

0 comments on commit 7f1a2be

Please sign in to comment.