yulInterpreter: More fine-grained exception handling

This commit is contained in:
Bhargava Shastry
2019-04-04 13:02:55 +02:00
parent 44fc658aa0
commit f15cedad7a
8 changed files with 65 additions and 24 deletions
+19 -2
View File
@@ -76,9 +76,26 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
ostringstream os1;
ostringstream os2;
yulFuzzerUtil::interpret(os1, stack.parserResult()->code);
try
{
yulFuzzerUtil::interpret(os1, stack.parserResult()->code);
}
catch (yul::test::StepLimitReached const&)
{
return 0;
}
catch (yul::test::InterpreterTerminatedGeneric const&)
{
}
stack.optimize();
yulFuzzerUtil::interpret(os2, stack.parserResult()->code);
try
{
yulFuzzerUtil::interpret(os2, stack.parserResult()->code);
}
catch (yul::test::InterpreterTerminatedGeneric const&)
{
}
bool isTraceEq = (os1.str() == os2.str());
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");
+3 -10
View File
@@ -24,17 +24,10 @@ void yulFuzzerUtil::interpret(ostream& _os, shared_ptr<yul::Block> _ast)
{
InterpreterState state;
state.maxTraceSize = 75;
state.maxSteps = 10000;
state.maxSteps = 100;
Interpreter interpreter(state);
try
{
interpreter(*_ast);
}
catch (InterpreterTerminated const&)
{
}
interpreter(*_ast);
_os << "Trace:" << endl;
for (auto const& line: interpreter.trace())
_os << " " << line << endl;
}
}
+19 -2
View File
@@ -72,9 +72,26 @@ DEFINE_PROTO_FUZZER(Function const& _input)
ostringstream os1;
ostringstream os2;
yulFuzzerUtil::interpret(os1, stack.parserResult()->code);
try
{
yulFuzzerUtil::interpret(os1, stack.parserResult()->code);
}
catch (yul::test::StepLimitReached const&)
{
return;
}
catch (yul::test::InterpreterTerminatedGeneric const&)
{
}
stack.optimize();
yulFuzzerUtil::interpret(os2, stack.parserResult()->code);
try
{
yulFuzzerUtil::interpret(os2, stack.parserResult()->code);
}
catch (yul::test::InterpreterTerminatedGeneric const&)
{
}
bool isTraceEq = (os1.str() == os2.str());
yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ.");