Merge pull request #11763 from ethereum/basefee-hasOpcode

Allow basefee as Yul identifier for EVMVersion < london
This commit is contained in:
Daniel Kirchner 2021-08-11 14:14:21 +02:00 committed by GitHub
commit e28d00a76d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 53 additions and 13 deletions

View File

@ -46,8 +46,9 @@ bool EVMVersion::hasOpcode(Instruction _opcode) const
return hasChainID(); return hasChainID();
case Instruction::SELFBALANCE: case Instruction::SELFBALANCE:
return hasSelfBalance(); return hasSelfBalance();
case Instruction::BASEFEE:
return hasBaseFee();
default: default:
return true; return true;
} }
} }

View File

@ -112,14 +112,22 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
return {name, f}; 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; set<YulString> reserved;
for (auto const& instr: evmasm::c_instructions) for (auto const& instr: evmasm::c_instructions)
{ {
string name = instr.first; string name = instr.first;
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); }); 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>{ reserved += vector<YulString>{
"linkersymbol"_yulstring, "linkersymbol"_yulstring,
@ -300,7 +308,7 @@ EVMDialect::EVMDialect(langutil::EVMVersion _evmVersion, bool _objectAccess):
m_objectAccess(_objectAccess), m_objectAccess(_objectAccess),
m_evmVersion(_evmVersion), m_evmVersion(_evmVersion),
m_functions(createBuiltins(_evmVersion, _objectAccess)), m_functions(createBuiltins(_evmVersion, _objectAccess)),
m_reserved(createReservedIdentifiers()) m_reserved(createReservedIdentifiers(_evmVersion))
{ {
} }

View File

@ -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. # The warning may or may not exist in a compiler build.
"4591", # "There are more than 256 warnings. Ignoring the rest." "4591", # "There are more than 256 warnings. Ignoring the rest."
# Due to 3805, the warning lists look different for different compiler builds. # 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" assert len(test_ids & white_ids) == 0, "The sets are not supposed to intersect"
test_ids |= white_ids test_ids |= white_ids

View File

@ -118,7 +118,9 @@ done < <(
grep -v -E 'literals/.*_direction_override.*.sol' | grep -v -E 'literals/.*_direction_override.*.sol' |
# Skipping a test with "revert E;" because ANTLR cannot distinguish it from # Skipping a test with "revert E;" because ANTLR cannot distinguish it from
# a variable declaration. # a variable declaration.
grep -v -E 'revertStatement/non_called.sol' grep -v -E 'revertStatement/non_called.sol' |
# Skipping a test with "let basefee := ..."
grep -v -E 'inlineAssembly/basefee_berlin_function.sol'
) )
YUL_FILES=() YUL_FILES=()

View File

@ -0,0 +1,22 @@
contract C {
function f() public view returns (uint ret) {
assembly {
let basefee := sload(0)
ret := basefee
}
}
function g() public pure returns (uint ret) {
assembly {
function basefee() -> r {
r := 1000
}
ret := basefee()
}
}
}
// ====
// compileViaYul: also
// EVMVersion: <=berlin
// ----
// f() -> 0
// g() -> 1000

View File

@ -0,0 +1,12 @@
contract C {
function f() public view returns (uint ret) {
assembly {
let basefee := sload(0)
ret := basefee
}
}
}
// ====
// EVMVersion: =london
// ----
// ParserError 5568: (98-105): Cannot use builtin function name "basefee" as identifier name.

View File

@ -2,14 +2,8 @@ contract C {
function f() public view returns (uint) { function f() public view returns (uint) {
return block.basefee; 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 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").