Skip to content

Commit feaf48a

Browse files
authored
Merge pull request #15700 from ipsilon/eof-reserved-names-fix
eof: Fix EOF builtin names unintentionally reserved outside of EOF
2 parents 4791d70 + 9032d58 commit feaf48a

9 files changed

+128
-38
lines changed

libyul/AsmAnalysis.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,28 @@ bool AsmAnalyzer::validateInstructions(std::string_view _instructionIdentifier,
695695
if (builtinHandle && defaultEVMDialect.builtin(*builtinHandle).instruction.has_value())
696696
return validateInstructions(*defaultEVMDialect.builtin(*builtinHandle).instruction, _location);
697697

698+
solAssert(!m_eofVersion.has_value() || (*m_eofVersion == 1 && m_evmVersion == langutil::EVMVersion::prague()));
698699
// TODO: Change `prague()` to `EVMVersion{}` once EOF gets deployed
699700
auto const& eofDialect = EVMDialect::strictAssemblyForEVM(EVMVersion::prague(), 1);
700701
auto const eofBuiltinHandle = eofDialect.findBuiltin(_instructionIdentifier);
701-
if (eofBuiltinHandle && eofDialect.builtin(*eofBuiltinHandle).instruction.has_value())
702-
return validateInstructions(*eofDialect.builtin(*eofBuiltinHandle).instruction, _location);
702+
if (eofBuiltinHandle)
703+
{
704+
auto const builtin = eofDialect.builtin(*eofBuiltinHandle);
705+
if (builtin.instruction.has_value())
706+
return validateInstructions(*builtin.instruction, _location);
707+
else if (!m_eofVersion.has_value())
708+
{
709+
m_errorReporter.declarationError(
710+
7223_error,
711+
_location,
712+
fmt::format(
713+
"Builtin function \"{}\" is only available in EOF.",
714+
fmt::arg("function", _instructionIdentifier)
715+
)
716+
);
717+
return true;
718+
}
719+
}
703720

704721
return false;
705722
}
@@ -716,8 +733,16 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
716733
yulAssert(
717734
_instr != evmasm::Instruction::JUMP &&
718735
_instr != evmasm::Instruction::JUMPI &&
719-
_instr != evmasm::Instruction::JUMPDEST,
720-
"");
736+
_instr != evmasm::Instruction::JUMPDEST &&
737+
_instr != evmasm::Instruction::DATALOADN &&
738+
_instr != evmasm::Instruction::EOFCREATE &&
739+
_instr != evmasm::Instruction::RETURNCONTRACT &&
740+
_instr != evmasm::Instruction::RJUMP &&
741+
_instr != evmasm::Instruction::RJUMPI &&
742+
_instr != evmasm::Instruction::CALLF &&
743+
_instr != evmasm::Instruction::JUMPF &&
744+
_instr != evmasm::Instruction::RETF
745+
);
721746

722747
auto errorForVM = [&](ErrorId _errorId, std::string const& vmKindMessage) {
723748
m_errorReporter.typeError(
@@ -783,7 +808,7 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
783808
4328_error,
784809
_location,
785810
fmt::format(
786-
"The \"{}\" instruction is only available on EOF.",
811+
"The \"{}\" instruction is only available in EOF.",
787812
fmt::arg("instruction", boost::to_lower_copy(instructionInfo(_instr, m_evmVersion).name))
788813
)
789814
);

libyul/backends/evm/EVMDialect.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,13 @@ std::set<std::string, std::less<>> createReservedIdentifiers(langutil::EVMVersio
155155

156156
auto eofIdentifiersException = [&](evmasm::Instruction _instr) -> bool
157157
{
158-
solAssert(!_eofVersion.has_value() || _evmVersion >= langutil::EVMVersion::prague());
159-
return
160-
!_eofVersion.has_value() &&
161-
(
162-
_instr == evmasm::Instruction::EXTCALL ||
163-
_instr == evmasm::Instruction::EXTSTATICCALL ||
164-
_instr == evmasm::Instruction::EXTDELEGATECALL
165-
);
158+
solAssert(!_eofVersion.has_value() || (*_eofVersion == 1 && _evmVersion == langutil::EVMVersion::prague()));
159+
if (_eofVersion.has_value())
160+
// For EOF every instruction is reserved identifier.
161+
return false;
162+
else
163+
return langutil::EVMVersion::prague().hasOpcode(_instr, 1) &&
164+
!langutil::EVMVersion::prague().hasOpcode(_instr, std::nullopt);
166165
};
167166

168167
std::set<std::string, std::less<>> reserved;

test/libyul/yulSyntaxTests/eof/auxdataloadn_in_legacy.yul

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ object "a" {
1111
// EVMVersion: >=prague
1212
// bytecodeFormat: legacy
1313
// ----
14-
// DeclarationError 4619: (42-54): Function "auxdataloadn" not found.
15-
// TypeError 3950: (42-57): Expected expression to evaluate to one value, but got 0 values instead.
14+
// DeclarationError 7223: (42-54): Builtin function "auxdataloadn" is only available in EOF.
15+
// TypeError 3950: (42-57): Expected expression to evaluate to one value, but got 0 values instead.

test/libyul/yulSyntaxTests/eof/eof_identifiers_in_legacy.yul

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
auxdataloadn(0)
3+
dataloadn(0)
4+
eofcreate("name", 0, 0, 0, 0)
5+
returncontract("name", 0, 0)
6+
rjump()
7+
rjumpi()
8+
callf(0)
9+
jumpf(0)
10+
retf()
11+
extcall(0, 1, 2, 3)
12+
extstaticcall(0, 1, 2)
13+
extdelegatecall(0, 1, 2)
14+
}
15+
// ====
16+
// bytecodeFormat: legacy
17+
// ----
18+
// DeclarationError 7223: (6-18): Builtin function "auxdataloadn" is only available in EOF.
19+
// DeclarationError 4619: (26-35): Function "dataloadn" not found.
20+
// DeclarationError 7223: (43-52): Builtin function "eofcreate" is only available in EOF.
21+
// DeclarationError 4619: (77-91): Function "returncontract" not found.
22+
// DeclarationError 4619: (110-115): Function "rjump" not found.
23+
// DeclarationError 4619: (122-128): Function "rjumpi" not found.
24+
// DeclarationError 4619: (135-140): Function "callf" not found.
25+
// DeclarationError 4619: (148-153): Function "jumpf" not found.
26+
// DeclarationError 4619: (161-165): Function "retf" not found.
27+
// TypeError 4328: (172-179): The "extcall" instruction is only available in EOF.
28+
// TypeError 4328: (196-209): The "extstaticcall" instruction is only available in EOF.
29+
// TypeError 4328: (223-238): The "extdelegatecall" instruction is only available in EOF.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
function auxdataloadn() {}
3+
function dataloadn() {}
4+
function eofcreate() {}
5+
function returncontract() {}
6+
function rjump() {}
7+
function rjumpi() {}
8+
function callf() {}
9+
function jumpf() {}
10+
function retf() {}
11+
function extcall() {}
12+
function extstaticcall() {}
13+
function extdelegatecall() {}
14+
}
15+
// ====
16+
// bytecodeFormat: legacy
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
function auxdataloadn() {}
3+
function eofcreate() {}
4+
function returncontract() {}
5+
function extcall() {}
6+
function extdelegatecall() {}
7+
function extstaticcall() {}
8+
}
9+
// ====
10+
// bytecodeFormat: >=EOFv1
11+
// ----
12+
// ParserError 5568: (15-27): Cannot use builtin function name "auxdataloadn" as identifier name.
13+
// ParserError 5568: (46-55): Cannot use builtin function name "eofcreate" as identifier name.
14+
// ParserError 5568: (74-88): Cannot use builtin function name "returncontract" as identifier name.
15+
// ParserError 5568: (107-114): Cannot use builtin function name "extcall" as identifier name.
16+
// ParserError 5568: (133-148): Cannot use builtin function name "extdelegatecall" as identifier name.
17+
// ParserError 5568: (167-180): Cannot use builtin function name "extstaticcall" as identifier name.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
function dataloadn() {}
3+
function rjump() {}
4+
function rjumpi() {}
5+
function callf() {}
6+
function jumpf() {}
7+
function retf() {}
8+
}
9+
// ====
10+
// bytecodeFormat: >=EOFv1
11+
// ----
12+
// DeclarationError 5017: (6-29): The identifier "dataloadn" is reserved and can not be used.
13+
// DeclarationError 5017: (34-53): The identifier "rjump" is reserved and can not be used.
14+
// DeclarationError 5017: (58-78): The identifier "rjumpi" is reserved and can not be used.
15+
// DeclarationError 5017: (83-102): The identifier "callf" is reserved and can not be used.
16+
// DeclarationError 5017: (107-126): The identifier "jumpf" is reserved and can not be used.
17+
// DeclarationError 5017: (131-149): The identifier "retf" is reserved and can not be used.
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
object "a" {
2-
code {
3-
pop(extcall(address(), 0, 0, 0))
4-
pop(extdelegatecall(address(), 0, 0))
5-
pop(extstaticcall(address(), 0, 0))
6-
}
1+
{
2+
pop(extcall(address(), 0, 0, 0))
3+
pop(extdelegatecall(address(), 0, 0))
4+
pop(extstaticcall(address(), 0, 0))
75
}
8-
96
// ====
107
// bytecodeFormat: legacy
118
// ----
12-
// TypeError 4328: (36-43): The "extcall" instruction is only available on EOF.
13-
// TypeError 3950: (36-63): Expected expression to evaluate to one value, but got 0 values instead.
14-
// TypeError 4328: (77-92): The "extdelegatecall" instruction is only available on EOF.
15-
// TypeError 3950: (77-109): Expected expression to evaluate to one value, but got 0 values instead.
16-
// TypeError 4328: (123-136): The "extstaticcall" instruction is only available on EOF.
17-
// TypeError 3950: (123-153): Expected expression to evaluate to one value, but got 0 values instead.
9+
// TypeError 4328: (10-17): The "extcall" instruction is only available in EOF.
10+
// TypeError 3950: (10-37): Expected expression to evaluate to one value, but got 0 values instead.
11+
// TypeError 4328: (47-62): The "extdelegatecall" instruction is only available in EOF.
12+
// TypeError 3950: (47-79): Expected expression to evaluate to one value, but got 0 values instead.
13+
// TypeError 4328: (89-102): The "extstaticcall" instruction is only available in EOF.
14+
// TypeError 3950: (89-119): Expected expression to evaluate to one value, but got 0 values instead.

0 commit comments

Comments
 (0)