Skip to content

Commit bbaf8a4

Browse files
authored
Merge pull request #13283 from ethereum/yulDebugger
Yul Debugger
2 parents add6a6b + 692a99f commit bbaf8a4

18 files changed

+692
-36
lines changed

libevmasm/Instruction.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ enum class Instruction: uint8_t
188188
SELFDESTRUCT = 0xff ///< halt execution and register account for later deletion
189189
};
190190

191+
/// @returns true if the instruction is of the CALL opcode family
192+
constexpr bool isCallInstruction(Instruction _inst) noexcept
193+
{
194+
switch (_inst)
195+
{
196+
case Instruction::CALL:
197+
case Instruction::CALLCODE:
198+
case Instruction::DELEGATECALL:
199+
case Instruction::STATICCALL:
200+
return true;
201+
default:
202+
return false;
203+
}
204+
}
205+
191206
/// @returns true if the instruction is a PUSH
192207
inline bool isPushInstruction(Instruction _inst)
193208
{

test/libyul/EwasmTranslationTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ string EwasmTranslationTest::interpret()
112112
state,
113113
WasmDialect{},
114114
*m_object->code,
115+
/*disableExternalCalls=*/true,
115116
/*disableMemoryTracing=*/false
116117
);
117118
}

test/libyul/YulInterpreterTest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ YulInterpreterTest::YulInterpreterTest(string const& _filename):
5151
{
5252
m_source = m_reader.source();
5353
m_expectation = m_reader.simpleExpectations();
54+
m_simulateExternalCallsToSelf = m_reader.boolSetting("simulateExternalCall", false);
5455
}
5556

5657
TestCase::TestResult YulInterpreterTest::run(ostream& _stream, string const& _linePrefix, bool const _formatted)
@@ -98,7 +99,8 @@ string YulInterpreterTest::interpret()
9899
state,
99100
EVMDialect::strictAssemblyForEVMObjects(langutil::EVMVersion{}),
100101
*m_ast,
101-
/*disableMemoryTracing=*/false
102+
/*disableExternalCalls=*/ !m_simulateExternalCallsToSelf,
103+
/*disableMemoryTracing=*/ false
102104
);
103105
}
104106
catch (InterpreterTerminatedGeneric const&)

test/libyul/YulInterpreterTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class YulInterpreterTest: public solidity::frontend::test::EVMVersionRestrictedT
4747

4848
std::shared_ptr<Block> m_ast;
4949
std::shared_ptr<AsmAnalysisInfo> m_analysisInfo;
50+
bool m_simulateExternalCallsToSelf = false;
5051
};
5152

5253
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
mstore(0x40, 0x42)
3+
4+
if iszero(calldatasize()) {
5+
let x := call(gas(), address(), 0, 0x40, 0x20, 0x100, 0x20)
6+
sstore(0x64, calldataload(0))
7+
sstore(0x100, x)
8+
return(0x0, 0)
9+
}
10+
return(0x40, 0x20)
11+
}
12+
// ====
13+
// simulateExternalCall: true
14+
// ----
15+
// Trace:
16+
// CALL(153, 0x11111111, 0, 64, 32, 256, 32)
17+
// RETURN(0, 0)
18+
// Memory dump:
19+
// 40: 0000000000000000000000000000000000000000000000000000000000000042
20+
// 100: 0000000000000000000000000000000000000000000000000000000000000042
21+
// Storage dump:
22+
// 0000000000000000000000000000000000000000000000000000000000000100: 0000000000000000000000000000000000000000000000000000000000000001

test/libyul/yulInterpreterTests/external_call.yul renamed to test/libyul/yulInterpreterTests/external_call_unexecuted.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
let x := call(gas(), 0x45, 0x5, 0, 0x20, 0x30, 0x20)
3-
sstore(100, x)
3+
sstore(0x64, x)
44
}
55
// ----
66
// Trace:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
let x := callcode(gas(), 0x45, 0x5, 0, 0x20, 0x30, 0x20)
3+
sstore(100, x)
4+
}
5+
// ----
6+
// Trace:
7+
// CALLCODE(153, 69, 5, 0, 32, 48, 32)
8+
// Memory dump:
9+
// Storage dump:
10+
// 0000000000000000000000000000000000000000000000000000000000000064: 0000000000000000000000000000000000000000000000000000000000000001
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
let x := delegatecall(gas(), 0x45, 0, 0x20, 0x30, 0x20)
3+
sstore(100, x)
4+
}
5+
// ----
6+
// Trace:
7+
// DELEGATECALL(153, 69, 0, 32, 48, 32)
8+
// Memory dump:
9+
// Storage dump:
10+
// 0000000000000000000000000000000000000000000000000000000000000064: 0000000000000000000000000000000000000000000000000000000000000001
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
let x := staticcall(gas(), 0x45, 0, 0x20, 0x30, 0x20)
3+
sstore(0x64, x)
4+
}
5+
// ====
6+
// EVMVersion: >=byzantium
7+
// ----
8+
// Trace:
9+
// STATICCALL(153, 69, 0, 32, 48, 32)
10+
// Memory dump:
11+
// Storage dump:
12+
// 0000000000000000000000000000000000000000000000000000000000000064: 0000000000000000000000000000000000000000000000000000000000000001

test/tools/ossfuzz/yulFuzzerCommon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret(
5353
TerminationReason reason = TerminationReason::None;
5454
try
5555
{
56-
Interpreter::run(state, _dialect, *_ast, _disableMemoryTracing);
56+
Interpreter::run(state, _dialect, *_ast, true, _disableMemoryTracing);
5757
}
5858
catch (StepLimitReached const&)
5959
{

0 commit comments

Comments
 (0)