mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Yul interpreter: Limit nesting level
This commit is contained in:
@@ -27,12 +27,14 @@ yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret(
|
||||
shared_ptr<yul::Block> _ast,
|
||||
Dialect const& _dialect,
|
||||
size_t _maxSteps,
|
||||
size_t _maxTraceSize
|
||||
size_t _maxTraceSize,
|
||||
size_t _maxExprNesting
|
||||
)
|
||||
{
|
||||
InterpreterState state;
|
||||
state.maxTraceSize = _maxTraceSize;
|
||||
state.maxSteps = _maxSteps;
|
||||
state.maxExprNesting = _maxExprNesting;
|
||||
// Add 64 bytes of pseudo-randomly generated calldata so that
|
||||
// calldata opcodes perform non trivial work.
|
||||
state.calldata = {
|
||||
@@ -59,6 +61,10 @@ yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret(
|
||||
{
|
||||
reason = TerminationReason::TraceLimitReached;
|
||||
}
|
||||
catch (ExpressionNestingLimitReached const&)
|
||||
{
|
||||
reason = TerminationReason::ExpresionNestingLimitReached;
|
||||
}
|
||||
catch (ExplicitlyTerminated const&)
|
||||
{
|
||||
reason = TerminationReason::ExplicitlyTerminated;
|
||||
|
||||
@@ -28,6 +28,7 @@ struct yulFuzzerUtil
|
||||
ExplicitlyTerminated,
|
||||
StepLimitReached,
|
||||
TraceLimitReached,
|
||||
ExpresionNestingLimitReached,
|
||||
None
|
||||
};
|
||||
|
||||
@@ -36,10 +37,12 @@ struct yulFuzzerUtil
|
||||
std::shared_ptr<yul::Block> _ast,
|
||||
Dialect const& _dialect,
|
||||
size_t _maxSteps = maxSteps,
|
||||
size_t _maxTraceSize = maxTraceSize
|
||||
size_t _maxTraceSize = maxTraceSize,
|
||||
size_t _maxExprNesting = maxExprNesting
|
||||
);
|
||||
static size_t constexpr maxSteps = 100;
|
||||
static size_t constexpr maxTraceSize = 75;
|
||||
static size_t constexpr maxExprNesting = 60;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -91,19 +91,25 @@ DEFINE_PROTO_FUZZER(Program const& _input)
|
||||
|
||||
ostringstream os1;
|
||||
ostringstream os2;
|
||||
yulFuzzerUtil::interpret(
|
||||
yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret(
|
||||
os1,
|
||||
stack.parserResult()->code,
|
||||
EVMDialect::strictAssemblyForEVMObjects(version)
|
||||
);
|
||||
|
||||
if (
|
||||
termReason == yulFuzzerUtil::TerminationReason::StepLimitReached ||
|
||||
termReason == yulFuzzerUtil::TerminationReason::TraceLimitReached ||
|
||||
termReason == yulFuzzerUtil::TerminationReason::ExpresionNestingLimitReached
|
||||
)
|
||||
return;
|
||||
|
||||
stack.optimize();
|
||||
yulFuzzerUtil::TerminationReason termReason = yulFuzzerUtil::interpret(
|
||||
termReason = yulFuzzerUtil::interpret(
|
||||
os2,
|
||||
stack.parserResult()->code,
|
||||
EVMDialect::strictAssemblyForEVMObjects(version)
|
||||
);
|
||||
|
||||
if (termReason == yulFuzzerUtil::TerminationReason::StepLimitReached)
|
||||
return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user