2017-02-15 13:52:53 +00:00
|
|
|
/*
|
|
|
|
This file is part of solidity.
|
|
|
|
|
|
|
|
solidity is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
solidity is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Analyzer part of inline assembly.
|
|
|
|
*/
|
|
|
|
|
2018-11-23 10:18:57 +00:00
|
|
|
#include <libyul/AsmAnalysis.h>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
2018-11-23 10:18:57 +00:00
|
|
|
#include <libyul/AsmData.h>
|
|
|
|
#include <libyul/AsmScopeFiller.h>
|
|
|
|
#include <libyul/AsmScope.h>
|
|
|
|
#include <libyul/AsmAnalysisInfo.h>
|
2019-01-15 12:40:10 +00:00
|
|
|
#include <libyul/Utilities.h>
|
2019-03-04 14:38:05 +00:00
|
|
|
#include <libyul/Exceptions.h>
|
2019-07-09 15:23:14 +00:00
|
|
|
#include <libyul/Object.h>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
2018-11-14 13:59:30 +00:00
|
|
|
#include <liblangutil/ErrorReporter.h>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
|
|
|
#include <boost/range/adaptor/reversed.hpp>
|
2017-06-08 14:44:03 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <functional>
|
2019-03-04 14:38:05 +00:00
|
|
|
#include <utility>
|
2017-02-15 13:52:53 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace dev;
|
2018-11-14 16:11:55 +00:00
|
|
|
using namespace langutil;
|
2018-11-21 11:42:34 +00:00
|
|
|
using namespace yul;
|
|
|
|
using namespace dev;
|
2017-02-15 13:52:53 +00:00
|
|
|
|
2019-03-28 11:47:21 +00:00
|
|
|
namespace
|
|
|
|
{
|
2017-05-26 19:43:28 +00:00
|
|
|
|
|
|
|
set<string> const builtinTypes{"bool", "u8", "s8", "u32", "s32", "u64", "s64", "u128", "s128", "u256", "s256"};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-17 15:05:22 +00:00
|
|
|
bool AsmAnalyzer::analyze(Block const& _block)
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2019-04-25 09:34:56 +00:00
|
|
|
bool success = false;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!(ScopeFiller(m_info, m_errorReporter))(_block))
|
|
|
|
return false;
|
2017-03-22 12:21:58 +00:00
|
|
|
|
2019-04-25 09:34:56 +00:00
|
|
|
success = (*this)(_block);
|
|
|
|
if (!success)
|
|
|
|
solAssert(m_errorReporter.hasErrors(), "No success but no error.");
|
|
|
|
}
|
|
|
|
catch (FatalError const&)
|
|
|
|
{
|
|
|
|
// This FatalError con occur if the errorReporter has too many errors.
|
|
|
|
solAssert(!m_errorReporter.errors().empty(), "Fatal error detected, but no error is reported.");
|
|
|
|
}
|
2019-02-18 17:08:33 +00:00
|
|
|
return success && !m_errorReporter.hasErrors();
|
2017-02-15 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
2019-07-09 15:23:14 +00:00
|
|
|
AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect, Object const& _object)
|
2019-01-29 14:01:30 +00:00
|
|
|
{
|
|
|
|
ErrorList errorList;
|
|
|
|
langutil::ErrorReporter errors(errorList);
|
2019-07-09 15:23:14 +00:00
|
|
|
AsmAnalysisInfo analysisInfo;
|
2019-01-29 14:01:30 +00:00
|
|
|
bool success = yul::AsmAnalyzer(
|
|
|
|
analysisInfo,
|
|
|
|
errors,
|
2019-07-09 15:23:14 +00:00
|
|
|
_dialect,
|
|
|
|
{},
|
|
|
|
_object.dataNames()
|
|
|
|
).analyze(*_object.code);
|
2019-01-29 14:01:30 +00:00
|
|
|
solAssert(success && errorList.empty(), "Invalid assembly/yul code.");
|
|
|
|
return analysisInfo;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(yul::Instruction const& _instruction)
|
2017-03-22 12:21:58 +00:00
|
|
|
{
|
2019-09-10 10:11:43 +00:00
|
|
|
solAssert(false, "The use of non-functional instructions is disallowed. Please use functional notation instead.");
|
2017-03-22 12:21:58 +00:00
|
|
|
auto const& info = instructionInfo(_instruction.instruction);
|
|
|
|
m_stackHeight += info.ret - info.args;
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_instruction] = m_stackHeight;
|
2017-06-13 18:10:26 +00:00
|
|
|
warnOnInstructions(_instruction.instruction, _instruction.location);
|
2017-03-22 12:21:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(Literal const& _literal)
|
2017-02-16 22:44:22 +00:00
|
|
|
{
|
2018-10-29 14:12:02 +00:00
|
|
|
expectValidType(_literal.type.str(), _literal.location);
|
2017-03-22 12:21:58 +00:00
|
|
|
++m_stackHeight;
|
2018-11-21 11:42:34 +00:00
|
|
|
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_literal.location,
|
2018-10-29 14:12:02 +00:00
|
|
|
"String literal too long (" + to_string(_literal.value.str().size()) + " > 32)"
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-02-16 22:44:22 +00:00
|
|
|
return false;
|
2017-02-17 15:05:22 +00:00
|
|
|
}
|
2018-11-21 11:42:34 +00:00
|
|
|
else if (_literal.kind == LiteralKind::Number && bigint(_literal.value.str()) > u256(-1))
|
2018-01-04 23:25:41 +00:00
|
|
|
{
|
|
|
|
m_errorReporter.typeError(
|
|
|
|
_literal.location,
|
|
|
|
"Number literal too large (> 256 bits)"
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-21 11:42:34 +00:00
|
|
|
else if (_literal.kind == LiteralKind::Boolean)
|
2018-02-22 00:00:26 +00:00
|
|
|
{
|
2019-05-16 08:56:56 +00:00
|
|
|
solAssert(m_dialect.flavour == AsmFlavour::Yul, "");
|
2018-12-10 03:25:51 +00:00
|
|
|
solAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
|
2018-02-22 00:00:26 +00:00
|
|
|
}
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_literal] = m_stackHeight;
|
2017-02-16 22:44:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(Identifier const& _identifier)
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(!_identifier.name.empty(), "");
|
2017-05-11 13:26:35 +00:00
|
|
|
size_t numErrorsBefore = m_errorReporter.errors().size();
|
2017-02-17 15:05:22 +00:00
|
|
|
bool success = true;
|
|
|
|
if (m_currentScope->lookup(_identifier.name, Scope::Visitor(
|
|
|
|
[&](Scope::Variable const& _var)
|
2017-02-17 11:03:55 +00:00
|
|
|
{
|
2017-06-13 22:07:13 +00:00
|
|
|
if (!m_activeVariables.count(&_var))
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
|
|
|
_identifier.location,
|
2018-10-29 14:12:02 +00:00
|
|
|
"Variable " + _identifier.name.str() + " used before it was declared."
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-02-17 15:05:22 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2017-03-22 12:21:58 +00:00
|
|
|
++m_stackHeight;
|
|
|
|
},
|
|
|
|
[&](Scope::Label const&)
|
|
|
|
{
|
|
|
|
++m_stackHeight;
|
2017-02-17 15:05:22 +00:00
|
|
|
},
|
|
|
|
[&](Scope::Function const&)
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_identifier.location,
|
2018-10-29 14:12:02 +00:00
|
|
|
"Function " + _identifier.name.str() + " used without being called."
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-02-17 15:05:22 +00:00
|
|
|
success = false;
|
2017-02-17 11:03:55 +00:00
|
|
|
}
|
2017-02-17 15:05:22 +00:00
|
|
|
)))
|
|
|
|
{
|
2017-02-17 11:03:55 +00:00
|
|
|
}
|
2017-03-22 12:21:58 +00:00
|
|
|
else
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2017-03-22 12:21:58 +00:00
|
|
|
size_t stackSize(-1);
|
|
|
|
if (m_resolver)
|
2017-05-24 16:34:19 +00:00
|
|
|
{
|
|
|
|
bool insideFunction = m_currentScope->insideFunction();
|
2018-10-15 09:58:51 +00:00
|
|
|
stackSize = m_resolver(_identifier, yul::IdentifierContext::RValue, insideFunction);
|
2017-05-24 16:34:19 +00:00
|
|
|
}
|
2017-03-22 12:21:58 +00:00
|
|
|
if (stackSize == size_t(-1))
|
|
|
|
{
|
2017-04-25 11:15:42 +00:00
|
|
|
// Only add an error message if the callback did not do it.
|
2017-05-11 13:26:35 +00:00
|
|
|
if (numErrorsBefore == m_errorReporter.errors().size())
|
|
|
|
m_errorReporter.declarationError(_identifier.location, "Identifier not found.");
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
m_stackHeight += stackSize == size_t(-1) ? 1 : stackSize;
|
2017-02-15 13:52:53 +00:00
|
|
|
}
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_identifier] = m_stackHeight;
|
2017-02-17 15:05:22 +00:00
|
|
|
return success;
|
2017-02-15 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(ExpressionStatement const& _statement)
|
2017-12-08 13:01:22 +00:00
|
|
|
{
|
2018-02-15 14:18:09 +00:00
|
|
|
int initialStackHeight = m_stackHeight;
|
2019-11-19 15:42:49 +00:00
|
|
|
bool success = std::visit(*this, _statement.expression);
|
2019-09-18 10:35:53 +00:00
|
|
|
if (success && m_stackHeight != initialStackHeight)
|
2018-02-15 14:18:09 +00:00
|
|
|
{
|
|
|
|
string msg =
|
|
|
|
"Top-level expressions are not supposed to return values (this expression returns " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(m_stackHeight - initialStackHeight) +
|
2018-02-15 14:18:09 +00:00
|
|
|
" value" +
|
|
|
|
(m_stackHeight - initialStackHeight == 1 ? "" : "s") +
|
|
|
|
"). Use ``pop()`` or assign them.";
|
2019-09-10 09:58:20 +00:00
|
|
|
m_errorReporter.error(Error::Type::TypeError, _statement.location, msg);
|
|
|
|
success = false;
|
2018-02-15 14:18:09 +00:00
|
|
|
}
|
2017-12-08 13:01:22 +00:00
|
|
|
m_info.stackHeightInfo[&_statement] = m_stackHeight;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(Assignment const& _assignment)
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(_assignment.value, "");
|
2017-05-19 16:06:26 +00:00
|
|
|
int const expectedItems = _assignment.variableNames.size();
|
|
|
|
solAssert(expectedItems >= 1, "");
|
2017-03-22 12:21:58 +00:00
|
|
|
int const stackHeight = m_stackHeight;
|
2019-11-19 15:42:49 +00:00
|
|
|
bool success = std::visit(*this, *_assignment.value);
|
2017-05-19 16:06:26 +00:00
|
|
|
if ((m_stackHeight - stackHeight) != expectedItems)
|
|
|
|
{
|
|
|
|
m_errorReporter.declarationError(
|
|
|
|
_assignment.location,
|
|
|
|
"Variable count does not match number of values (" +
|
|
|
|
to_string(expectedItems) +
|
|
|
|
" vs. " +
|
|
|
|
to_string(m_stackHeight - stackHeight) +
|
|
|
|
")"
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (auto const& variableName: _assignment.variableNames)
|
|
|
|
if (!checkAssignment(variableName, 1))
|
|
|
|
success = false;
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_assignment] = m_stackHeight;
|
2017-02-17 15:05:22 +00:00
|
|
|
return success;
|
2017-02-15 13:52:53 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2017-05-05 15:46:26 +00:00
|
|
|
bool success = true;
|
2017-07-12 18:51:16 +00:00
|
|
|
int const numVariables = _varDecl.variables.size();
|
2019-11-06 17:06:36 +00:00
|
|
|
if (m_resolver)
|
|
|
|
for (auto const& variable: _varDecl.variables)
|
|
|
|
// Call the resolver for variable declarations to allow it to raise errors on shadowing.
|
|
|
|
m_resolver(
|
|
|
|
yul::Identifier{variable.location, variable.name},
|
|
|
|
yul::IdentifierContext::VariableDeclaration,
|
|
|
|
m_currentScope->insideFunction()
|
|
|
|
);
|
2017-05-05 15:46:26 +00:00
|
|
|
if (_varDecl.value)
|
2017-05-05 20:10:05 +00:00
|
|
|
{
|
2017-05-05 15:46:26 +00:00
|
|
|
int const stackHeight = m_stackHeight;
|
2019-11-19 15:42:49 +00:00
|
|
|
success = std::visit(*this, *_varDecl.value);
|
2018-12-04 10:22:49 +00:00
|
|
|
int numValues = m_stackHeight - stackHeight;
|
|
|
|
if (numValues != numVariables)
|
2017-05-05 15:46:26 +00:00
|
|
|
{
|
2018-12-04 10:22:49 +00:00
|
|
|
m_errorReporter.declarationError(_varDecl.location,
|
|
|
|
"Variable count mismatch: " +
|
|
|
|
to_string(numVariables) +
|
|
|
|
" variables and " +
|
|
|
|
to_string(numValues) +
|
|
|
|
" values."
|
|
|
|
);
|
|
|
|
// Adjust stack height to avoid misleading additional errors.
|
|
|
|
m_stackHeight += numVariables - numValues;
|
2017-05-05 15:46:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-05 20:10:05 +00:00
|
|
|
}
|
2017-05-05 15:46:26 +00:00
|
|
|
else
|
2017-07-12 18:51:16 +00:00
|
|
|
m_stackHeight += numVariables;
|
2017-05-05 17:35:40 +00:00
|
|
|
|
|
|
|
for (auto const& variable: _varDecl.variables)
|
2017-05-24 23:27:48 +00:00
|
|
|
{
|
2018-10-29 14:12:02 +00:00
|
|
|
expectValidType(variable.type.str(), variable.location);
|
2019-11-19 15:42:49 +00:00
|
|
|
m_activeVariables.insert(&std::get<Scope::Variable>(m_currentScope->identifiers.at(variable.name)));
|
2017-05-24 23:27:48 +00:00
|
|
|
}
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_varDecl] = m_stackHeight;
|
2017-05-05 17:56:29 +00:00
|
|
|
return success;
|
2017-02-17 11:03:55 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(!_funDef.name.empty(), "");
|
2017-05-26 19:46:02 +00:00
|
|
|
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
|
|
|
|
solAssert(virtualBlock, "");
|
|
|
|
Scope& varScope = scope(virtualBlock);
|
2017-12-01 13:10:49 +00:00
|
|
|
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
|
2017-05-24 23:27:48 +00:00
|
|
|
{
|
2018-10-29 14:12:02 +00:00
|
|
|
expectValidType(var.type.str(), var.location);
|
2019-11-19 15:42:49 +00:00
|
|
|
m_activeVariables.insert(&std::get<Scope::Variable>(varScope.identifiers.at(var.name)));
|
2017-05-24 23:27:48 +00:00
|
|
|
}
|
2017-02-17 15:05:22 +00:00
|
|
|
|
2017-03-22 12:21:58 +00:00
|
|
|
int const stackHeight = m_stackHeight;
|
2017-12-01 13:10:49 +00:00
|
|
|
m_stackHeight = _funDef.parameters.size() + _funDef.returnVariables.size();
|
2017-03-22 12:21:58 +00:00
|
|
|
|
|
|
|
bool success = (*this)(_funDef.body);
|
|
|
|
|
|
|
|
m_stackHeight = stackHeight;
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_funDef] = m_stackHeight;
|
2017-03-22 12:21:58 +00:00
|
|
|
return success;
|
2017-02-17 15:05:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
2017-02-17 11:03:55 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(!_funCall.functionName.name.empty(), "");
|
2017-02-17 11:03:55 +00:00
|
|
|
bool success = true;
|
2018-12-04 10:22:49 +00:00
|
|
|
size_t parameters = 0;
|
2017-02-17 15:05:22 +00:00
|
|
|
size_t returns = 0;
|
2018-12-20 16:22:17 +00:00
|
|
|
bool needsLiteralArguments = false;
|
2019-05-16 08:56:56 +00:00
|
|
|
if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name))
|
2018-12-04 10:23:28 +00:00
|
|
|
{
|
|
|
|
// TODO: compare types, too
|
|
|
|
parameters = f->parameters.size();
|
|
|
|
returns = f->returns.size();
|
2018-12-20 16:22:17 +00:00
|
|
|
if (f->literalArguments)
|
|
|
|
needsLiteralArguments = true;
|
2018-12-04 10:23:28 +00:00
|
|
|
}
|
|
|
|
else if (!m_currentScope->lookup(_funCall.functionName.name, Scope::Visitor(
|
2017-02-17 15:05:22 +00:00
|
|
|
[&](Scope::Variable const&)
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_funCall.functionName.location,
|
|
|
|
"Attempt to call variable instead of function."
|
|
|
|
);
|
2017-02-17 15:05:22 +00:00
|
|
|
success = false;
|
|
|
|
},
|
|
|
|
[&](Scope::Label const&)
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_funCall.functionName.location,
|
|
|
|
"Attempt to call label instead of function."
|
|
|
|
);
|
2017-02-17 15:05:22 +00:00
|
|
|
success = false;
|
|
|
|
},
|
|
|
|
[&](Scope::Function const& _fun)
|
|
|
|
{
|
2017-04-26 22:58:34 +00:00
|
|
|
/// TODO: compare types too
|
2018-12-04 10:22:49 +00:00
|
|
|
parameters = _fun.arguments.size();
|
2017-04-26 22:58:34 +00:00
|
|
|
returns = _fun.returns.size();
|
2017-02-17 15:05:22 +00:00
|
|
|
}
|
|
|
|
)))
|
2017-02-15 13:52:53 +00:00
|
|
|
{
|
2019-09-18 09:36:20 +00:00
|
|
|
if (!warnOnInstructions(_funCall.functionName.name.str(), _funCall.functionName.location))
|
|
|
|
m_errorReporter.declarationError(_funCall.functionName.location, "Function not found.");
|
2017-02-15 13:52:53 +00:00
|
|
|
success = false;
|
|
|
|
}
|
2017-02-17 15:05:22 +00:00
|
|
|
if (success)
|
2018-12-04 10:22:49 +00:00
|
|
|
if (_funCall.arguments.size() != parameters)
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_funCall.functionName.location,
|
2018-12-04 10:22:49 +00:00
|
|
|
"Function expects " +
|
|
|
|
to_string(parameters) +
|
|
|
|
" arguments but got " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(_funCall.arguments.size()) + "."
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-02-17 11:03:55 +00:00
|
|
|
success = false;
|
2017-02-17 15:05:22 +00:00
|
|
|
}
|
2018-12-04 10:22:49 +00:00
|
|
|
|
2017-02-17 11:03:55 +00:00
|
|
|
for (auto const& arg: _funCall.arguments | boost::adaptors::reversed)
|
2018-12-20 16:22:17 +00:00
|
|
|
{
|
2017-06-01 12:16:01 +00:00
|
|
|
if (!expectExpression(arg))
|
2017-02-17 11:03:55 +00:00
|
|
|
success = false;
|
2019-07-09 12:06:33 +00:00
|
|
|
else if (needsLiteralArguments)
|
|
|
|
{
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!holds_alternative<Literal>(arg))
|
2019-07-09 12:06:33 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_funCall.functionName.location,
|
|
|
|
"Function expects direct literals as arguments."
|
|
|
|
);
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (!m_dataNames.count(std::get<Literal>(arg).value))
|
2019-07-09 12:06:33 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_funCall.functionName.location,
|
2019-11-19 15:42:49 +00:00
|
|
|
"Unknown data object \"" + std::get<Literal>(arg).value.str() + "\"."
|
2019-07-09 12:06:33 +00:00
|
|
|
);
|
|
|
|
}
|
2018-12-20 16:22:17 +00:00
|
|
|
}
|
2018-12-04 10:22:49 +00:00
|
|
|
// Use argument size instead of parameter count to avoid misleading errors.
|
|
|
|
m_stackHeight += int(returns) - int(_funCall.arguments.size());
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_funCall] = m_stackHeight;
|
2017-02-17 11:03:55 +00:00
|
|
|
return success;
|
2017-02-16 22:44:22 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 12:36:41 +00:00
|
|
|
bool AsmAnalyzer::operator()(If const& _if)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
2019-05-22 14:08:49 +00:00
|
|
|
int const initialHeight = m_stackHeight;
|
2017-11-21 12:36:41 +00:00
|
|
|
if (!expectExpression(*_if.condition))
|
|
|
|
success = false;
|
2019-05-22 14:08:49 +00:00
|
|
|
|
|
|
|
m_stackHeight = initialHeight;
|
2017-11-21 12:36:41 +00:00
|
|
|
|
|
|
|
if (!(*this)(_if.body))
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
m_info.stackHeightInfo[&_if] = m_stackHeight;
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2017-04-28 13:27:56 +00:00
|
|
|
bool AsmAnalyzer::operator()(Switch const& _switch)
|
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(_switch.expression, "");
|
|
|
|
|
2017-05-19 17:33:25 +00:00
|
|
|
bool success = true;
|
|
|
|
|
2019-05-22 14:08:49 +00:00
|
|
|
int const initialHeight = m_stackHeight;
|
2017-06-01 12:16:01 +00:00
|
|
|
if (!expectExpression(*_switch.expression))
|
2017-05-19 17:33:25 +00:00
|
|
|
success = false;
|
2017-04-28 13:27:56 +00:00
|
|
|
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour == AsmFlavour::Yul)
|
2019-01-15 12:40:10 +00:00
|
|
|
{
|
|
|
|
YulString caseType;
|
|
|
|
bool mismatchingTypes = false;
|
|
|
|
for (auto const& _case: _switch.cases)
|
|
|
|
if (_case.value)
|
|
|
|
{
|
|
|
|
if (caseType.empty())
|
|
|
|
caseType = _case.value->type;
|
|
|
|
else if (caseType != _case.value->type)
|
|
|
|
{
|
|
|
|
mismatchingTypes = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mismatchingTypes)
|
|
|
|
m_errorReporter.typeError(
|
|
|
|
_switch.location,
|
|
|
|
"Switch cases have non-matching types."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-25 11:30:05 +00:00
|
|
|
set<u256> cases;
|
2017-04-28 13:27:56 +00:00
|
|
|
for (auto const& _case: _switch.cases)
|
|
|
|
{
|
2017-05-17 10:21:37 +00:00
|
|
|
if (_case.value)
|
2017-04-28 13:27:56 +00:00
|
|
|
{
|
2017-06-07 09:40:47 +00:00
|
|
|
int const initialStackHeight = m_stackHeight;
|
2019-04-17 13:05:44 +00:00
|
|
|
bool isCaseValueValid = true;
|
2017-06-07 09:40:47 +00:00
|
|
|
// We cannot use "expectExpression" here because *_case.value is not a
|
|
|
|
// Statement and would be converted to a Statement otherwise.
|
|
|
|
if (!(*this)(*_case.value))
|
2019-04-17 13:05:44 +00:00
|
|
|
{
|
|
|
|
isCaseValueValid = false;
|
2017-05-19 17:33:25 +00:00
|
|
|
success = false;
|
2019-04-17 13:05:44 +00:00
|
|
|
}
|
2017-06-07 09:40:47 +00:00
|
|
|
expectDeposit(1, initialStackHeight, _case.value->location);
|
2017-05-17 10:21:37 +00:00
|
|
|
m_stackHeight--;
|
|
|
|
|
2019-04-17 13:05:44 +00:00
|
|
|
// If the case value is not valid, we should not insert it into cases.
|
|
|
|
yulAssert(isCaseValueValid || m_errorReporter.hasErrors(), "Invalid case value.");
|
2017-05-17 10:21:37 +00:00
|
|
|
/// Note: the parser ensures there is only one default case
|
2019-04-17 13:05:44 +00:00
|
|
|
if (isCaseValueValid && !cases.insert(valueOfLiteral(*_case.value)).second)
|
2017-05-17 10:21:37 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
|
|
|
_case.location,
|
2019-01-15 12:40:10 +00:00
|
|
|
"Duplicate case defined."
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-05-19 17:33:25 +00:00
|
|
|
success = false;
|
2017-05-17 10:21:37 +00:00
|
|
|
}
|
2017-04-28 13:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(*this)(_case.body))
|
2017-05-19 17:33:25 +00:00
|
|
|
success = false;
|
2017-04-28 13:27:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-22 14:08:49 +00:00
|
|
|
m_stackHeight = initialHeight;
|
2017-05-24 16:34:19 +00:00
|
|
|
m_info.stackHeightInfo[&_switch] = m_stackHeight;
|
2017-04-28 13:27:56 +00:00
|
|
|
|
2017-05-19 17:33:25 +00:00
|
|
|
return success;
|
2017-04-28 13:27:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::operator()(ForLoop const& _for)
|
2017-04-28 13:33:52 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(_for.condition, "");
|
|
|
|
|
2019-03-04 14:38:05 +00:00
|
|
|
Scope* outerScope = m_currentScope;
|
2017-06-01 12:16:12 +00:00
|
|
|
|
2019-05-22 14:08:49 +00:00
|
|
|
int const initialHeight = m_stackHeight;
|
|
|
|
|
2017-06-01 12:16:12 +00:00
|
|
|
bool success = true;
|
|
|
|
if (!(*this)(_for.pre))
|
|
|
|
success = false;
|
|
|
|
// The block was closed already, but we re-open it again and stuff the
|
|
|
|
// condition, the body and the post part inside.
|
|
|
|
m_stackHeight += scope(&_for.pre).numberOfVariables();
|
|
|
|
m_currentScope = &scope(&_for.pre);
|
|
|
|
|
|
|
|
if (!expectExpression(*_for.condition))
|
|
|
|
success = false;
|
2019-05-22 14:08:49 +00:00
|
|
|
|
2017-06-01 12:16:12 +00:00
|
|
|
m_stackHeight--;
|
2019-03-04 14:38:05 +00:00
|
|
|
|
|
|
|
// backup outer for-loop & create new state
|
|
|
|
auto outerForLoop = m_currentForLoop;
|
|
|
|
m_currentForLoop = &_for;
|
|
|
|
|
2017-06-01 12:16:12 +00:00
|
|
|
if (!(*this)(_for.body))
|
|
|
|
success = false;
|
2019-03-04 14:38:05 +00:00
|
|
|
|
2017-06-01 12:16:12 +00:00
|
|
|
if (!(*this)(_for.post))
|
|
|
|
success = false;
|
|
|
|
|
2019-05-22 14:08:49 +00:00
|
|
|
m_stackHeight = initialHeight;
|
2017-06-01 12:16:12 +00:00
|
|
|
m_info.stackHeightInfo[&_for] = m_stackHeight;
|
2019-03-04 14:38:05 +00:00
|
|
|
m_currentScope = outerScope;
|
|
|
|
m_currentForLoop = outerForLoop;
|
2017-06-01 12:16:12 +00:00
|
|
|
|
|
|
|
return success;
|
2017-04-28 13:33:52 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 14:38:05 +00:00
|
|
|
bool AsmAnalyzer::operator()(Break const& _break)
|
|
|
|
{
|
|
|
|
m_info.stackHeightInfo[&_break] = m_stackHeight;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsmAnalyzer::operator()(Continue const& _continue)
|
|
|
|
{
|
|
|
|
m_info.stackHeightInfo[&_continue] = m_stackHeight;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-06 01:06:00 +00:00
|
|
|
bool AsmAnalyzer::operator()(Leave const& _leaveStatement)
|
2019-10-28 14:25:02 +00:00
|
|
|
{
|
2019-11-06 01:06:00 +00:00
|
|
|
m_info.stackHeightInfo[&_leaveStatement] = m_stackHeight;
|
2019-10-28 14:25:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-15 13:52:53 +00:00
|
|
|
bool AsmAnalyzer::operator()(Block const& _block)
|
|
|
|
{
|
|
|
|
bool success = true;
|
2017-05-26 19:46:02 +00:00
|
|
|
auto previousScope = m_currentScope;
|
2017-02-17 11:03:55 +00:00
|
|
|
m_currentScope = &scope(&_block);
|
2017-02-15 13:52:53 +00:00
|
|
|
|
2017-05-26 19:46:02 +00:00
|
|
|
int const initialStackHeight = m_stackHeight;
|
2017-03-22 12:21:58 +00:00
|
|
|
|
2017-02-15 13:52:53 +00:00
|
|
|
for (auto const& s: _block.statements)
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!std::visit(*this, s))
|
2017-02-15 13:52:53 +00:00
|
|
|
success = false;
|
|
|
|
|
2017-06-01 13:47:11 +00:00
|
|
|
m_stackHeight -= scope(&_block).numberOfVariables();
|
2017-03-22 12:21:58 +00:00
|
|
|
|
2017-03-22 18:02:27 +00:00
|
|
|
int const stackDiff = m_stackHeight - initialStackHeight;
|
2019-09-18 10:35:53 +00:00
|
|
|
if (success && stackDiff != 0)
|
2017-03-22 12:21:58 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
|
|
|
_block.location,
|
2017-03-22 12:21:58 +00:00
|
|
|
"Unbalanced stack at the end of a block: " +
|
|
|
|
(
|
|
|
|
stackDiff > 0 ?
|
|
|
|
to_string(stackDiff) + string(" surplus item(s).") :
|
|
|
|
to_string(-stackDiff) + string(" missing item(s).")
|
2017-05-11 13:26:35 +00:00
|
|
|
)
|
|
|
|
);
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
2017-04-26 13:41:08 +00:00
|
|
|
m_info.stackHeightInfo[&_block] = m_stackHeight;
|
2017-05-26 19:46:02 +00:00
|
|
|
m_currentScope = previousScope;
|
2017-02-15 13:52:53 +00:00
|
|
|
return success;
|
|
|
|
}
|
2017-02-17 11:03:55 +00:00
|
|
|
|
2017-12-08 13:01:22 +00:00
|
|
|
bool AsmAnalyzer::expectExpression(Expression const& _expr)
|
2017-06-01 12:16:01 +00:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
int const initialHeight = m_stackHeight;
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!std::visit(*this, _expr))
|
2017-06-01 12:16:01 +00:00
|
|
|
success = false;
|
2019-09-18 10:35:53 +00:00
|
|
|
if (success && !expectDeposit(1, initialHeight, locationOf(_expr)))
|
2017-06-07 09:40:47 +00:00
|
|
|
success = false;
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsmAnalyzer::expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location)
|
|
|
|
{
|
|
|
|
if (m_stackHeight - _oldHeight != _deposit)
|
2017-06-01 12:16:01 +00:00
|
|
|
{
|
|
|
|
m_errorReporter.typeError(
|
2017-06-07 09:40:47 +00:00
|
|
|
_location,
|
2017-06-01 13:56:49 +00:00
|
|
|
"Expected expression to return one item to the stack, but did return " +
|
2018-08-08 14:26:30 +00:00
|
|
|
to_string(m_stackHeight - _oldHeight) +
|
2017-06-01 12:16:01 +00:00
|
|
|
" items."
|
|
|
|
);
|
2017-06-07 09:40:47 +00:00
|
|
|
return false;
|
2017-06-01 12:16:01 +00:00
|
|
|
}
|
2017-06-07 09:40:47 +00:00
|
|
|
return true;
|
2017-06-01 12:16:01 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:42:34 +00:00
|
|
|
bool AsmAnalyzer::checkAssignment(Identifier const& _variable, size_t _valueSize)
|
2017-02-17 11:03:55 +00:00
|
|
|
{
|
2018-05-10 08:43:39 +00:00
|
|
|
solAssert(!_variable.name.empty(), "");
|
2017-03-22 12:21:58 +00:00
|
|
|
bool success = true;
|
2017-05-11 13:26:35 +00:00
|
|
|
size_t numErrorsBefore = m_errorReporter.errors().size();
|
2017-03-22 12:21:58 +00:00
|
|
|
size_t variableSize(-1);
|
2017-03-21 18:38:37 +00:00
|
|
|
if (Scope::Identifier const* var = m_currentScope->lookup(_variable.name))
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
|
|
|
// Check that it is a variable
|
2019-11-19 15:42:49 +00:00
|
|
|
if (!holds_alternative<Scope::Variable>(*var))
|
2017-02-17 15:05:22 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(_variable.location, "Assignment requires variable.");
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
2017-02-17 15:05:22 +00:00
|
|
|
}
|
2019-11-19 15:42:49 +00:00
|
|
|
else if (!m_activeVariables.count(&std::get<Scope::Variable>(*var)))
|
2017-03-22 12:21:58 +00:00
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.declarationError(
|
|
|
|
_variable.location,
|
2018-10-29 14:12:02 +00:00
|
|
|
"Variable " + _variable.name.str() + " used before it was declared."
|
2017-05-11 13:26:35 +00:00
|
|
|
);
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
variableSize = 1;
|
2017-02-17 11:03:55 +00:00
|
|
|
}
|
2017-03-22 12:21:58 +00:00
|
|
|
else if (m_resolver)
|
2017-05-24 16:34:19 +00:00
|
|
|
{
|
|
|
|
bool insideFunction = m_currentScope->insideFunction();
|
2018-10-15 09:58:51 +00:00
|
|
|
variableSize = m_resolver(_variable, yul::IdentifierContext::LValue, insideFunction);
|
2017-05-24 16:34:19 +00:00
|
|
|
}
|
2017-03-22 12:21:58 +00:00
|
|
|
if (variableSize == size_t(-1))
|
2017-03-21 18:38:37 +00:00
|
|
|
{
|
2017-04-25 11:15:42 +00:00
|
|
|
// Only add message if the callback did not.
|
2017-05-11 13:26:35 +00:00
|
|
|
if (numErrorsBefore == m_errorReporter.errors().size())
|
|
|
|
m_errorReporter.declarationError(_variable.location, "Variable not found or variable not lvalue.");
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
if (_valueSize == size_t(-1))
|
|
|
|
_valueSize = variableSize == size_t(-1) ? 1 : variableSize;
|
|
|
|
|
|
|
|
m_stackHeight -= _valueSize;
|
|
|
|
|
|
|
|
if (_valueSize != variableSize && variableSize != size_t(-1))
|
|
|
|
{
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_variable.location,
|
2017-03-22 12:21:58 +00:00
|
|
|
"Variable size (" +
|
|
|
|
to_string(variableSize) +
|
|
|
|
") and value size (" +
|
|
|
|
to_string(_valueSize) +
|
2017-05-11 13:26:35 +00:00
|
|
|
") do not match."
|
|
|
|
);
|
2017-03-22 12:21:58 +00:00
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2017-02-17 11:03:55 +00:00
|
|
|
Scope& AsmAnalyzer::scope(Block const* _block)
|
|
|
|
{
|
2017-05-23 21:58:37 +00:00
|
|
|
solAssert(m_info.scopes.count(_block) == 1, "Scope requested but not present.");
|
2017-04-26 13:41:08 +00:00
|
|
|
auto scopePtr = m_info.scopes.at(_block);
|
2017-02-17 15:05:22 +00:00
|
|
|
solAssert(scopePtr, "Scope requested but not present.");
|
|
|
|
return *scopePtr;
|
2017-02-17 11:03:55 +00:00
|
|
|
}
|
2017-05-24 23:27:48 +00:00
|
|
|
void AsmAnalyzer::expectValidType(string const& type, SourceLocation const& _location)
|
|
|
|
{
|
2019-05-16 08:56:56 +00:00
|
|
|
if (m_dialect.flavour != AsmFlavour::Yul)
|
2017-05-25 00:59:57 +00:00
|
|
|
return;
|
2017-05-24 23:27:48 +00:00
|
|
|
|
2017-05-26 19:43:28 +00:00
|
|
|
if (!builtinTypes.count(type))
|
2017-05-11 13:26:35 +00:00
|
|
|
m_errorReporter.typeError(
|
|
|
|
_location,
|
|
|
|
"\"" + type + "\" is not a valid type (user defined types are not yet supported)."
|
|
|
|
);
|
2017-05-24 23:27:48 +00:00
|
|
|
}
|
2017-05-24 20:51:54 +00:00
|
|
|
|
2019-09-18 09:36:20 +00:00
|
|
|
bool AsmAnalyzer::warnOnInstructions(std::string const& _instructionIdentifier, langutil::SourceLocation const& _location)
|
|
|
|
{
|
2019-10-25 13:00:11 +00:00
|
|
|
auto const builtin = EVMDialect::strictAssemblyForEVM(EVMVersion{}).builtin(YulString(_instructionIdentifier));
|
|
|
|
if (builtin)
|
2019-10-28 13:07:53 +00:00
|
|
|
return warnOnInstructions(builtin->instruction.value(), _location);
|
2019-09-18 09:36:20 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsmAnalyzer::warnOnInstructions(dev::eth::Instruction _instr, SourceLocation const& _location)
|
2017-05-24 20:51:54 +00:00
|
|
|
{
|
2018-02-23 10:42:53 +00:00
|
|
|
// We assume that returndatacopy, returndatasize and staticcall are either all available
|
|
|
|
// or all not available.
|
|
|
|
solAssert(m_evmVersion.supportsReturndata() == m_evmVersion.hasStaticCall(), "");
|
2018-09-18 22:42:33 +00:00
|
|
|
// Similarly we assume bitwise shifting and create2 go together.
|
|
|
|
solAssert(m_evmVersion.hasBitwiseShifting() == m_evmVersion.hasCreate2(), "");
|
2019-05-16 08:56:56 +00:00
|
|
|
solAssert(m_dialect.flavour != AsmFlavour::Yul, "");
|
2018-02-23 10:42:53 +00:00
|
|
|
|
2019-02-26 18:21:32 +00:00
|
|
|
auto errorForVM = [=](string const& vmKindMessage) {
|
|
|
|
m_errorReporter.typeError(
|
2019-02-25 18:04:55 +00:00
|
|
|
_location,
|
|
|
|
"The \"" +
|
|
|
|
boost::to_lower_copy(instructionInfo(_instr).name)
|
|
|
|
+ "\" instruction is " +
|
|
|
|
vmKindMessage +
|
2019-02-26 18:21:32 +00:00
|
|
|
" VMs " +
|
|
|
|
" (you are currently compiling for \"" +
|
2019-02-25 18:04:55 +00:00
|
|
|
m_evmVersion.name() +
|
2019-02-26 18:21:32 +00:00
|
|
|
"\")."
|
2019-02-25 18:04:55 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-02-25 14:59:09 +00:00
|
|
|
if ((
|
2019-03-28 11:47:21 +00:00
|
|
|
_instr == dev::eth::Instruction::RETURNDATACOPY ||
|
|
|
|
_instr == dev::eth::Instruction::RETURNDATASIZE
|
2018-02-23 10:42:53 +00:00
|
|
|
) && !m_evmVersion.supportsReturndata())
|
2019-02-25 18:04:55 +00:00
|
|
|
{
|
2019-02-26 18:21:32 +00:00
|
|
|
errorForVM("only available for Byzantium-compatible");
|
2019-02-25 18:04:55 +00:00
|
|
|
}
|
2019-03-28 11:47:21 +00:00
|
|
|
else if (_instr == dev::eth::Instruction::STATICCALL && !m_evmVersion.hasStaticCall())
|
2019-02-25 18:04:55 +00:00
|
|
|
{
|
2019-02-26 18:21:32 +00:00
|
|
|
errorForVM("only available for Byzantium-compatible");
|
2019-02-25 18:04:55 +00:00
|
|
|
}
|
2018-02-28 07:43:18 +00:00
|
|
|
else if ((
|
2019-03-28 11:47:21 +00:00
|
|
|
_instr == dev::eth::Instruction::SHL ||
|
|
|
|
_instr == dev::eth::Instruction::SHR ||
|
|
|
|
_instr == dev::eth::Instruction::SAR
|
2018-02-28 07:43:18 +00:00
|
|
|
) && !m_evmVersion.hasBitwiseShifting())
|
2019-02-25 18:04:55 +00:00
|
|
|
{
|
2019-02-26 18:21:32 +00:00
|
|
|
errorForVM("only available for Constantinople-compatible");
|
2019-02-25 18:04:55 +00:00
|
|
|
}
|
2019-03-28 11:47:21 +00:00
|
|
|
else if (_instr == dev::eth::Instruction::CREATE2 && !m_evmVersion.hasCreate2())
|
2019-02-25 18:04:55 +00:00
|
|
|
{
|
2019-02-26 18:21:32 +00:00
|
|
|
errorForVM("only available for Constantinople-compatible");
|
2019-02-25 18:04:55 +00:00
|
|
|
}
|
2019-03-28 11:47:21 +00:00
|
|
|
else if (_instr == dev::eth::Instruction::EXTCODEHASH && !m_evmVersion.hasExtCodeHash())
|
2019-02-25 14:59:09 +00:00
|
|
|
{
|
2019-02-26 18:21:32 +00:00
|
|
|
errorForVM("only available for Constantinople-compatible");
|
2019-02-25 14:59:09 +00:00
|
|
|
}
|
2019-09-02 13:23:45 +00:00
|
|
|
else if (_instr == dev::eth::Instruction::CHAINID && !m_evmVersion.hasChainID())
|
|
|
|
{
|
|
|
|
errorForVM("only available for Istanbul-compatible");
|
|
|
|
}
|
|
|
|
else if (_instr == dev::eth::Instruction::SELFBALANCE && !m_evmVersion.hasSelfBalance())
|
|
|
|
{
|
|
|
|
errorForVM("only available for Istanbul-compatible");
|
|
|
|
}
|
2019-03-28 11:47:21 +00:00
|
|
|
else if (
|
|
|
|
_instr == dev::eth::Instruction::JUMP ||
|
|
|
|
_instr == dev::eth::Instruction::JUMPI ||
|
|
|
|
_instr == dev::eth::Instruction::JUMPDEST
|
|
|
|
)
|
2018-02-15 14:18:09 +00:00
|
|
|
{
|
2019-09-10 09:58:20 +00:00
|
|
|
m_errorReporter.error(
|
|
|
|
Error::Type::SyntaxError,
|
|
|
|
_location,
|
|
|
|
"Jump instructions and labels are low-level EVM features that can lead to "
|
|
|
|
"incorrect stack access. Because of that they are disallowed in strict assembly. "
|
|
|
|
"Use functions, \"switch\", \"if\" or \"for\" statements instead."
|
|
|
|
);
|
2018-02-15 14:18:09 +00:00
|
|
|
}
|
2019-09-18 09:36:20 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2018-02-15 14:18:09 +00:00
|
|
|
}
|