Skip to content

Commit

Permalink
Fix false positive caused by early termination due to nested expressi…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
bshastry committed Mar 26, 2021
1 parent d75a132 commit f3f1ccc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
5 changes: 4 additions & 1 deletion test/tools/ossfuzz/strictasm_diff_ossfuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/tools/ossfuzz/yulFuzzerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions test/tools/ossfuzz/yulFuzzerCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 2 additions & 10 deletions test/tools/ossfuzz/yulProto_diff_ossfuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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());
Expand Down

0 comments on commit f3f1ccc

Please sign in to comment.