Skip to content

Commit 692a99f

Browse files
committed
yulRun: Add recursion protection
1 parent d10d967 commit 692a99f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

test/tools/yulInterpreter/Interpreter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ void ExpressionEvaluator::runExternalCall(evmasm::Instruction _instruction)
461461
InterpreterState tmpState;
462462
tmpState.calldata = m_state.readMemory(memInOffset, memInSize);
463463
tmpState.callvalue = callvalue;
464+
tmpState.numInstance = m_state.numInstance + 1;
465+
466+
yulAssert(tmpState.numInstance < 1024, "Detected more than 1024 recursive calls, aborting...");
464467

465468
// Create new interpreter for the called contract
466469
unique_ptr<Interpreter> newInterpreter = makeInterpreterNew(tmpState, tmpScope);

test/tools/yulInterpreter/Interpreter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct InterpreterState
107107
size_t maxExprNesting = 0;
108108
ControlFlowState controlFlowState = ControlFlowState::Default;
109109

110+
/// Number of the current state instance, used for recursion protection
111+
size_t numInstance = 0;
112+
110113
/// Prints execution trace and non-zero storage to @param _out.
111114
/// Flag @param _disableMemoryTrace, if set, does not produce a memory dump. This
112115
/// avoids false positives reports by the fuzzer when certain optimizer steps are

0 commit comments

Comments
 (0)