diff --git a/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp b/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp index e9a0720af..e86210ca3 100644 --- a/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp @@ -86,7 +86,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) stack.parserResult()->code, EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion()) ); - if (termReason == yulFuzzerUtil::TerminationReason::StepLimitReached) + if (yulFuzzerUtil::resourceLimitsExceeded(termReason)) return 0; stack.optimize(); @@ -97,6 +97,9 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size) (yul::test::yul_fuzzer::yulFuzzerUtil::maxSteps * 4) ); + if (yulFuzzerUtil::resourceLimitsExceeded(termReason)) + return 0; + bool isTraceEq = (os1.str() == os2.str()); yulAssert(isTraceEq, "Interpreted traces for optimized and unoptimized code differ."); return 0; diff --git a/test/tools/ossfuzz/yulFuzzerCommon.cpp b/test/tools/ossfuzz/yulFuzzerCommon.cpp index d977c7761..68c6ec5d6 100644 --- a/test/tools/ossfuzz/yulFuzzerCommon.cpp +++ b/test/tools/ossfuzz/yulFuzzerCommon.cpp @@ -73,3 +73,11 @@ yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret( state.dumpTraceAndState(_os); return reason; } + +bool yulFuzzerUtil::resourceLimitsExceeded(TerminationReason _reason) +{ + return + _reason == yulFuzzerUtil::TerminationReason::StepLimitReached || + _reason == yulFuzzerUtil::TerminationReason::TraceLimitReached || + _reason == yulFuzzerUtil::TerminationReason::ExpresionNestingLimitReached; +} diff --git a/test/tools/ossfuzz/yulFuzzerCommon.h b/test/tools/ossfuzz/yulFuzzerCommon.h index 489cc4532..462811c1c 100644 --- a/test/tools/ossfuzz/yulFuzzerCommon.h +++ b/test/tools/ossfuzz/yulFuzzerCommon.h @@ -40,6 +40,11 @@ struct yulFuzzerUtil size_t _maxTraceSize = maxTraceSize, size_t _maxExprNesting = maxExprNesting ); + + /// @returns true if @param _reason for Yul interpreter terminating is + /// resource exhaustion of some form e.g., exceeded maximum time-out + /// threshold, number of nested expressions etc. + static bool resourceLimitsExceeded(TerminationReason _reason); static size_t constexpr maxSteps = 100; static size_t constexpr maxTraceSize = 75; static size_t constexpr maxExprNesting = 64; diff --git a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp index d07c792f1..d405c2bc8 100644 --- a/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp +++ b/test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp @@ -100,11 +100,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) EVMDialect::strictAssemblyForEVMObjects(version) ); - if ( - termReason == yulFuzzerUtil::TerminationReason::StepLimitReached || - termReason == yulFuzzerUtil::TerminationReason::TraceLimitReached || - termReason == yulFuzzerUtil::TerminationReason::ExpresionNestingLimitReached - ) + if (yulFuzzerUtil::resourceLimitsExceeded(termReason)) return; YulOptimizerTestCommon optimizerTest( @@ -119,11 +115,7 @@ DEFINE_PROTO_FUZZER(Program const& _input) astBlock, EVMDialect::strictAssemblyForEVMObjects(version) ); - if ( - termReason == yulFuzzerUtil::TerminationReason::StepLimitReached || - termReason == yulFuzzerUtil::TerminationReason::TraceLimitReached || - termReason == yulFuzzerUtil::TerminationReason::ExpresionNestingLimitReached - ) + if (yulFuzzerUtil::resourceLimitsExceeded(termReason)) return; bool isTraceEq = (os1.str() == os2.str());