Skip to content

Commit e28d00a

Browse files
authored
Merge pull request #11763 from ethereum/basefee-hasOpcode
Allow basefee as Yul identifier for EVMVersion < london
2 parents 98a259a + 892700d commit e28d00a

File tree

7 files changed

+53
-13
lines changed

7 files changed

+53
-13
lines changed

liblangutil/EVMVersion.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ bool EVMVersion::hasOpcode(Instruction _opcode) const
4646
return hasChainID();
4747
case Instruction::SELFBALANCE:
4848
return hasSelfBalance();
49+
case Instruction::BASEFEE:
50+
return hasBaseFee();
4951
default:
5052
return true;
5153
}
5254
}
53-

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

scripts/test_antlr_grammar.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ done < <(
118118
grep -v -E 'literals/.*_direction_override.*.sol' |
119119
# Skipping a test with "revert E;" because ANTLR cannot distinguish it from
120120
# a variable declaration.
121-
grep -v -E 'revertStatement/non_called.sol'
121+
grep -v -E 'revertStatement/non_called.sol' |
122+
# Skipping a test with "let basefee := ..."
123+
grep -v -E 'inlineAssembly/basefee_berlin_function.sol'
122124
)
123125

124126
YUL_FILES=()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
contract C {
2+
function f() public view returns (uint ret) {
3+
assembly {
4+
let basefee := sload(0)
5+
ret := basefee
6+
}
7+
}
8+
function g() public pure returns (uint ret) {
9+
assembly {
10+
function basefee() -> r {
11+
r := 1000
12+
}
13+
ret := basefee()
14+
}
15+
}
16+
}
17+
// ====
18+
// compileViaYul: also
19+
// EVMVersion: <=berlin
20+
// ----
21+
// f() -> 0
22+
// g() -> 1000
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
contract C {
2+
function f() public view returns (uint ret) {
3+
assembly {
4+
let basefee := sload(0)
5+
ret := basefee
6+
}
7+
}
8+
}
9+
// ====
10+
// EVMVersion: =london
11+
// ----
12+
// ParserError 5568: (98-105): Cannot use builtin function name "basefee" as identifier name.

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)