Skip to content

Commit

Permalink
eof: Fix errors for instructions deplacated by EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Dec 19, 2024
1 parent 0370606 commit 290a6bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
60 changes: 30 additions & 30 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,36 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
// The errors below are meant to be issued when processing an undeclared identifier matching a builtin name
// present on the default EVM version but not on the currently selected one,
// since the other `validateInstructions()` overload uses the default EVM version.
if (_instr == evmasm::Instruction::RETURNDATACOPY && !m_evmVersion.supportsReturndata())
if (m_eofVersion.has_value() && (
_instr == evmasm::Instruction::CALL ||
_instr == evmasm::Instruction::CALLCODE ||
_instr == evmasm::Instruction::DELEGATECALL ||
_instr == evmasm::Instruction::STATICCALL ||
_instr == evmasm::Instruction::SELFDESTRUCT ||
_instr == evmasm::Instruction::JUMP ||
_instr == evmasm::Instruction::JUMPI ||
_instr == evmasm::Instruction::PC ||
_instr == evmasm::Instruction::CREATE ||
_instr == evmasm::Instruction::CREATE2 ||
_instr == evmasm::Instruction::CODESIZE ||
_instr == evmasm::Instruction::CODECOPY ||
_instr == evmasm::Instruction::EXTCODESIZE ||
_instr == evmasm::Instruction::EXTCODECOPY ||
_instr == evmasm::Instruction::EXTCODEHASH ||
_instr == evmasm::Instruction::GAS
))
{
m_errorReporter.typeError(
9132_error,
_location,
fmt::format(
"The \"{instruction}\" instruction is {kind} VMs (you are currently compiling to EOF).",
fmt::arg("instruction", boost::to_lower_copy(instructionInfo(_instr, m_evmVersion).name)),
fmt::arg("kind", "only available in legacy bytecode")
)
);
}
else if (_instr == evmasm::Instruction::RETURNDATACOPY && !m_evmVersion.supportsReturndata())
errorForVM(7756_error, "only available for Byzantium-compatible");
else if (_instr == evmasm::Instruction::RETURNDATASIZE && !m_evmVersion.supportsReturndata())
errorForVM(4778_error, "only available for Byzantium-compatible");
Expand Down Expand Up @@ -788,35 +817,6 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
)
);
}
else if (m_eofVersion.has_value() && (
_instr == evmasm::Instruction::CALL ||
_instr == evmasm::Instruction::CALLCODE ||
_instr == evmasm::Instruction::DELEGATECALL ||
_instr == evmasm::Instruction::STATICCALL ||
_instr == evmasm::Instruction::SELFDESTRUCT ||
_instr == evmasm::Instruction::JUMP ||
_instr == evmasm::Instruction::JUMPI ||
_instr == evmasm::Instruction::PC ||
_instr == evmasm::Instruction::CREATE ||
_instr == evmasm::Instruction::CREATE2 ||
_instr == evmasm::Instruction::CODESIZE ||
_instr == evmasm::Instruction::CODECOPY ||
_instr == evmasm::Instruction::EXTCODESIZE ||
_instr == evmasm::Instruction::EXTCODECOPY ||
_instr == evmasm::Instruction::EXTCODEHASH ||
_instr == evmasm::Instruction::GAS
))
{
m_errorReporter.typeError(
9132_error,
_location,
fmt::format(
"The \"{instruction}\" instruction is {kind} VMs (you are currently compiling to EOF).",
fmt::arg("instruction", boost::to_lower_copy(instructionInfo(_instr, m_evmVersion).name)),
fmt::arg("kind", "only available in legacy bytecode")
)
);
}
else
{
// Sanity check
Expand Down
8 changes: 8 additions & 0 deletions test/libyul/yulSyntaxTests/invalid/eof/pc_disallowed.yul
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
pop(pc())
}
// ====
// bytecodeFormat: >=EOFv1
// ----
// TypeError 9132: (10-12): The "pc" instruction is only available in legacy bytecode VMs (you are currently compiling to EOF).
// TypeError 3950: (10-14): Expected expression to evaluate to one value, but got 0 values instead.

0 comments on commit 290a6bd

Please sign in to comment.