Skip to content

Commit

Permalink
eof: Addressing review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Jan 16, 2025
1 parent ff1a2af commit 577e2cc
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 126 deletions.
32 changes: 23 additions & 9 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,25 @@ size_t AsmAnalyzer::operator()(FunctionCall const& _funCall)
else
{
if (!validateInstructions(_funCall))
m_errorReporter.declarationError(
4619_error,
nativeLocationOf(_funCall.functionName),
fmt::format("Function \"{}\" not found.", resolveFunctionName(_funCall.functionName, m_dialect))
);
{
auto const functionName = resolveFunctionName(_funCall.functionName, m_dialect);

if (functionName == "auxdataloadn" || functionName == "eofcreate" || functionName == "returncontract")
m_errorReporter.declarationError(
4328_error,
nativeLocationOf(_funCall.functionName),
fmt::format(
"The \"{}\" instruction is only available in EOF.",
fmt::arg("instruction", functionName)
)
);
else
m_errorReporter.declarationError(
4619_error,
nativeLocationOf(_funCall.functionName),
fmt::format("Function \"{}\" not found.", functionName)
);
}
yulAssert(!watcher.ok(), "Expected a reported error.");
}

Expand Down Expand Up @@ -724,8 +738,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
_instr != evmasm::Instruction::RJUMPI &&
_instr != evmasm::Instruction::CALLF &&
_instr != evmasm::Instruction::JUMPF &&
_instr != evmasm::Instruction::RETF,
"");
_instr != evmasm::Instruction::RETF
);

auto errorForVM = [&](ErrorId _errorId, std::string const& vmKindMessage) {
m_errorReporter.typeError(
Expand Down Expand Up @@ -783,8 +797,8 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
);
else if (!m_eofVersion.has_value() && (
_instr == evmasm::Instruction::EXTCALL ||
_instr == evmasm::Instruction::EXTSTATICCALL ||
_instr == evmasm::Instruction::EXTDELEGATECALL
_instr == evmasm::Instruction::EXTDELEGATECALL ||
_instr == evmasm::Instruction::EXTSTATICCALL
))
{
m_errorReporter.typeError(
Expand Down
4 changes: 2 additions & 2 deletions test/libyul/yulSyntaxTests/eof/auxdataloadn_in_legacy.yul
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ object "a" {
// EVMVersion: >=prague
// bytecodeFormat: legacy
// ----
// DeclarationError 4619: (42-54): Function "auxdataloadn" not found.
// TypeError 3950: (42-57): Expected expression to evaluate to one value, but got 0 values instead.
// DeclarationError 4328: (42-54): The "auxdataloadn" instruction is only available in EOF.
// TypeError 3950: (42-57): Expected expression to evaluate to one value, but got 0 values instead.
10 changes: 3 additions & 7 deletions test/libyul/yulSyntaxTests/eof/auxdataloadn_reserved_in_eof.yul
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function auxdataloadn() {}
}
{
function auxdataloadn() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-53): Cannot use builtin function name "auxdataloadn" as identifier name.
// ParserError 8143: (41-53): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-27): Cannot use builtin function name "auxdataloadn" as identifier name.
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
object "a" {
code {
auxdataloadn(0)
dataloadn(0)
eofcreate("name", 0, 0, 0, 0)
returncontract("name", 0, 0)
rjump()
rjumpi()
callf(0)
jumpf(0)
retf()
extcall(0, 1, 2, 3)
extstaticcall(0, 1, 2)
extdelegatecall(0, 1, 2)
}
{
auxdataloadn(0)
dataloadn(0)
eofcreate("name", 0, 0, 0, 0)
returncontract("name", 0, 0)
rjump()
rjumpi()
callf(0)
jumpf(0)
retf()
extcall(0, 1, 2, 3)
extstaticcall(0, 1, 2)
extdelegatecall(0, 1, 2)
}

// ====
// bytecodeFormat: legacy
// ----
// DeclarationError 4619: (32-44): Function "auxdataloadn" not found.
// DeclarationError 4619: (56-65): Function "dataloadn" not found.
// DeclarationError 4619: (77-86): Function "eofcreate" not found.
// DeclarationError 4619: (115-129): Function "returncontract" not found.
// DeclarationError 4619: (152-157): Function "rjump" not found.
// DeclarationError 4619: (168-174): Function "rjumpi" not found.
// DeclarationError 4619: (185-190): Function "callf" not found.
// DeclarationError 4619: (202-207): Function "jumpf" not found.
// DeclarationError 4619: (219-223): Function "retf" not found.
// TypeError 4328: (234-241): The "extcall" instruction is only available in EOF.
// TypeError 4328: (262-275): The "extstaticcall" instruction is only available in EOF.
// TypeError 4328: (293-308): The "extdelegatecall" instruction is only available in EOF.
// DeclarationError 4328: (6-18): The "auxdataloadn" instruction is only available in EOF.
// DeclarationError 4619: (26-35): Function "dataloadn" not found.
// DeclarationError 4328: (43-52): The "eofcreate" instruction is only available in EOF.
// DeclarationError 4328: (77-91): The "returncontract" instruction is only available in EOF.
// DeclarationError 4619: (110-115): Function "rjump" not found.
// DeclarationError 4619: (122-128): Function "rjumpi" not found.
// DeclarationError 4619: (135-140): Function "callf" not found.
// DeclarationError 4619: (148-153): Function "jumpf" not found.
// DeclarationError 4619: (161-165): Function "retf" not found.
// TypeError 4328: (172-179): The "extcall" instruction is only available in EOF.
// TypeError 4328: (196-209): The "extstaticcall" instruction is only available in EOF.
// TypeError 4328: (223-238): The "extdelegatecall" instruction is only available in EOF.
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
object "a" {
code {
function auxdataloadn() {}
function dataloadn() {}
function eofcreate() {}
function returncontract() {}
function rjump() {}
function rjumpi() {}
function callf() {}
function jumpf() {}
function retf() {}
function extcall() {}
function extstaticcall() {}
function extdelegatecall() {}
}
{
function auxdataloadn() {}
function dataloadn() {}
function eofcreate() {}
function returncontract() {}
function rjump() {}
function rjumpi() {}
function callf() {}
function jumpf() {}
function retf() {}
function extcall() {}
function extstaticcall() {}
function extdelegatecall() {}
}

// ====
// bytecodeFormat: legacy
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
object "a" {
code {
function dataloadn() {}
function rjump() {}
function rjumpi() {}
function callf() {}
function jumpf() {}
function retf() {}
}
{
function dataloadn() {}
function rjump() {}
function rjumpi() {}
function callf() {}
function jumpf() {}
function retf() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// DeclarationError 5017: (32-55): The identifier "dataloadn" is reserved and can not be used.
// DeclarationError 5017: (64-83): The identifier "rjump" is reserved and can not be used.
// DeclarationError 5017: (92-112): The identifier "rjumpi" is reserved and can not be used.
// DeclarationError 5017: (121-140): The identifier "callf" is reserved and can not be used.
// DeclarationError 5017: (149-168): The identifier "jumpf" is reserved and can not be used.
// DeclarationError 5017: (177-195): The identifier "retf" is reserved and can not be used.
// DeclarationError 5017: (6-29): The identifier "dataloadn" is reserved and can not be used.
// DeclarationError 5017: (34-53): The identifier "rjump" is reserved and can not be used.
// DeclarationError 5017: (58-78): The identifier "rjumpi" is reserved and can not be used.
// DeclarationError 5017: (83-102): The identifier "callf" is reserved and can not be used.
// DeclarationError 5017: (107-126): The identifier "jumpf" is reserved and can not be used.
// DeclarationError 5017: (131-149): The identifier "retf" is reserved and can not be used.
10 changes: 3 additions & 7 deletions test/libyul/yulSyntaxTests/eof/eofcreate_reserved_in_eof.yul
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function eofcreate() {}
}
{
function eofcreate() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-50): Cannot use builtin function name "eofcreate" as identifier name.
// ParserError 8143: (41-50): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-24): Cannot use builtin function name "eofcreate" as identifier name.
10 changes: 3 additions & 7 deletions test/libyul/yulSyntaxTests/eof/extcall_reserved_in_eof.yul
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function extcall() {}
}
{
function extcall() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-48): Cannot use builtin function name "extcall" as identifier name.
// ParserError 8143: (41-48): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-22): Cannot use builtin function name "extcall" as identifier name.
23 changes: 10 additions & 13 deletions test/libyul/yulSyntaxTests/eof/extcalls_invalid_in_legacy.yul
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
object "a" {
code {
pop(extcall(address(), 0, 0, 0))
pop(extdelegatecall(address(), 0, 0))
pop(extstaticcall(address(), 0, 0))
}
{
pop(extcall(address(), 0, 0, 0))
pop(extdelegatecall(address(), 0, 0))
pop(extstaticcall(address(), 0, 0))
}

// ====
// bytecodeFormat: legacy
// ----
// TypeError 4328: (36-43): The "extcall" instruction is only available in EOF.
// TypeError 3950: (36-63): Expected expression to evaluate to one value, but got 0 values instead.
// TypeError 4328: (77-92): The "extdelegatecall" instruction is only available in EOF.
// TypeError 3950: (77-109): Expected expression to evaluate to one value, but got 0 values instead.
// TypeError 4328: (123-136): The "extstaticcall" instruction is only available in EOF.
// TypeError 3950: (123-153): Expected expression to evaluate to one value, but got 0 values instead.
// TypeError 4328: (10-17): The "extcall" instruction is only available in EOF.
// TypeError 3950: (10-37): Expected expression to evaluate to one value, but got 0 values instead.
// TypeError 4328: (47-62): The "extdelegatecall" instruction is only available in EOF.
// TypeError 3950: (47-79): Expected expression to evaluate to one value, but got 0 values instead.
// TypeError 4328: (89-102): The "extstaticcall" instruction is only available in EOF.
// TypeError 3950: (89-119): Expected expression to evaluate to one value, but got 0 values instead.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function extdelegatecall() {}
}
{
function extdelegatecall() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-56): Cannot use builtin function name "extdelegatecall" as identifier name.
// ParserError 8143: (41-56): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-30): Cannot use builtin function name "extdelegatecall" as identifier name.
10 changes: 3 additions & 7 deletions test/libyul/yulSyntaxTests/eof/extstaticcall_reserved_in_eof.yul
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function extstaticcall() {}
}
{
function extstaticcall() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-54): Cannot use builtin function name "extstaticcall" as identifier name.
// ParserError 8143: (41-54): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-28): Cannot use builtin function name "extstaticcall" as identifier name.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
object "a" {
code {
function returncontract() {}
}
{
function returncontract() {}
}

// ====
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-55): Cannot use builtin function name "returncontract" as identifier name.
// ParserError 8143: (41-55): Expected keyword "data" or "object" or "}".
// ParserError 5568: (15-29): Cannot use builtin function name "returncontract" as identifier name.

0 comments on commit 577e2cc

Please sign in to comment.