From e1b44500ddb01ad0a0c26fb541c94eea60860873 Mon Sep 17 00:00:00 2001 From: Bhargava Shastry Date: Wed, 22 Jul 2020 22:59:15 +0200 Subject: [PATCH] Yul interpreter: Smaller execution timeout for tests and additional test cases --- test/libyul/YulInterpreterTest.cpp | 4 +- .../yulInterpreterTests/bounded_recursion.yul | 16 +++++++ .../infinite_recursion.yul | 11 +++++ .../infinite_recursion_tracelimit.yul | 44 +++++++++++++++++++ test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp | 8 +++- 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 test/libyul/yulInterpreterTests/bounded_recursion.yul create mode 100644 test/libyul/yulInterpreterTests/infinite_recursion.yul create mode 100644 test/libyul/yulInterpreterTests/infinite_recursion_tracelimit.yul diff --git a/test/libyul/YulInterpreterTest.cpp b/test/libyul/YulInterpreterTest.cpp index 78e815785..ec1fa53f1 100644 --- a/test/libyul/YulInterpreterTest.cpp +++ b/test/libyul/YulInterpreterTest.cpp @@ -87,8 +87,8 @@ bool YulInterpreterTest::parse(ostream& _stream, string const& _linePrefix, bool string YulInterpreterTest::interpret() { InterpreterState state; - state.maxTraceSize = 10000; - state.maxSteps = 10000; + state.maxTraceSize = 32; + state.maxSteps = 512; try { Interpreter::run(state, EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}), *m_ast); diff --git a/test/libyul/yulInterpreterTests/bounded_recursion.yul b/test/libyul/yulInterpreterTests/bounded_recursion.yul new file mode 100644 index 000000000..ce22638ca --- /dev/null +++ b/test/libyul/yulInterpreterTests/bounded_recursion.yul @@ -0,0 +1,16 @@ +{ + function f(x) -> y { + if lt(x, 150) { + y := f(add(x, 1)) + } + if eq(x, 150) { + y := x + } + } + mstore(0, f(0)) +} +// ---- +// Trace: +// Memory dump: +// 0: 0000000000000000000000000000000000000000000000000000000000000096 +// Storage dump: diff --git a/test/libyul/yulInterpreterTests/infinite_recursion.yul b/test/libyul/yulInterpreterTests/infinite_recursion.yul new file mode 100644 index 000000000..0e3109ab5 --- /dev/null +++ b/test/libyul/yulInterpreterTests/infinite_recursion.yul @@ -0,0 +1,11 @@ +{ + function f() { + f() + } + f() +} +// ---- +// Trace: +// Interpreter execution step limit reached. +// Memory dump: +// Storage dump: diff --git a/test/libyul/yulInterpreterTests/infinite_recursion_tracelimit.yul b/test/libyul/yulInterpreterTests/infinite_recursion_tracelimit.yul new file mode 100644 index 000000000..45d3cc781 --- /dev/null +++ b/test/libyul/yulInterpreterTests/infinite_recursion_tracelimit.yul @@ -0,0 +1,44 @@ +{ + function f() { + log0(0x0, 0x0) + f() + } + f() +} +// ---- +// Trace: +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// LOG0(0, 0) +// Trace size limit reached. +// Memory dump: +// Storage dump: diff --git a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp index c95b4db7f..de9bfe9c7 100644 --- a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp @@ -104,12 +104,18 @@ DEFINE_PROTO_FUZZER(Program const& _input) return; stack.optimize(); - yulFuzzerUtil::interpret( + termReason = yulFuzzerUtil::interpret( os2, stack.parserResult()->code, EVMDialect::strictAssemblyForEVMObjects(version) ); + if ( + termReason == yulFuzzerUtil::TerminationReason::StepLimitReached || + termReason == yulFuzzerUtil::TerminationReason::TraceLimitReached + ) + return; + bool isTraceEq = (os1.str() == os2.str()); yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ."); return;