Fuzzer: Count step by number of interpreted statements

Co-authored-by: chriseth <chris@ethereum.org>
This commit is contained in:
Bhargava Shastry
2020-07-21 15:38:02 +02:00
co-authored by chriseth
parent f4b912fffa
commit 18fbbfa5ca
4 changed files with 27 additions and 11 deletions
+16 -6
View File
@@ -145,6 +145,11 @@ void Interpreter::operator()(ForLoop const& _forLoop)
}
while (evaluate(*_forLoop.condition) != 0)
{
// Increment step for each loop iteration for loops with
// an empty body and post blocks to prevent a deadlock.
if (_forLoop.body.statements.size() == 0 && _forLoop.post.statements.size() == 0)
incrementStep();
m_state.controlFlowState = ControlFlowState::Default;
(*this)(_forLoop.body);
if (m_state.controlFlowState == ControlFlowState::Break || m_state.controlFlowState == ControlFlowState::Leave)
@@ -176,12 +181,6 @@ void Interpreter::operator()(Leave const&)
void Interpreter::operator()(Block const& _block)
{
m_state.numSteps++;
if (m_state.maxSteps > 0 && m_state.numSteps >= m_state.maxSteps)
{
m_state.trace.emplace_back("Interpreter execution step limit reached.");
throw StepLimitReached();
}
enterScope(_block);
// Register functions.
for (auto const& statement: _block.statements)
@@ -193,6 +192,7 @@ void Interpreter::operator()(Block const& _block)
for (auto const& statement: _block.statements)
{
incrementStep();
visit(statement);
if (m_state.controlFlowState != ControlFlowState::Default)
break;
@@ -235,6 +235,16 @@ void Interpreter::leaveScope()
yulAssert(m_scope, "");
}
void Interpreter::incrementStep()
{
m_state.numSteps++;
if (m_state.maxSteps > 0 && m_state.numSteps >= m_state.maxSteps)
{
m_state.trace.emplace_back("Interpreter execution step limit reached.");
throw StepLimitReached();
}
}
void ExpressionEvaluator::operator()(Literal const& _literal)
{
static YulString const trueString("true");