From 91312e657bcc378e8a6b96b34b17d7c471a68c26 Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 21 May 2019 11:46:37 +0200 Subject: [PATCH] Skip empty entries in memory and storage dump. --- libdevcore/vector_ref.h | 2 + test/libyul/YulInterpreterTest.cpp | 10 +- test/libyul/yulInterpreterTests/datacopy.yul | 94 ------------------- .../yulInterpreterTests/external_call.yul | 3 - test/libyul/yulInterpreterTests/loop.yul | 2 - .../recursive_function_for_loop.yul | 4 - .../yulInterpreterTests/simple_mstore.yul | 1 - .../yulInterpreterTests/switch_statement.yul | 1 - test/tools/ossfuzz/yulFuzzerCommon.cpp | 4 +- test/tools/yulInterpreter/Interpreter.cpp | 21 +++++ test/tools/yulInterpreter/Interpreter.h | 2 + test/tools/yulrun.cpp | 10 +- 12 files changed, 28 insertions(+), 126 deletions(-) diff --git a/libdevcore/vector_ref.h b/libdevcore/vector_ref.h index b4dcff651..a866f6628 100644 --- a/libdevcore/vector_ref.h +++ b/libdevcore/vector_ref.h @@ -25,6 +25,8 @@ public: using mutable_value_type = typename std::conditional::value, typename std::remove_const<_T>::type, _T>::type; using string_type = typename std::conditional::value, std::string const, std::string>::type; using vector_type = typename std::conditional::value, std::vector::type> const, std::vector<_T>>::type; + using iterator = _T*; + using const_iterator = _T const*; static_assert(std::is_pod::value, "vector_ref can only be used with PODs due to its low-level treatment of data."); diff --git a/test/libyul/YulInterpreterTest.cpp b/test/libyul/YulInterpreterTest.cpp index 606f1c989..b918fd8ee 100644 --- a/test/libyul/YulInterpreterTest.cpp +++ b/test/libyul/YulInterpreterTest.cpp @@ -142,15 +142,7 @@ string YulInterpreterTest::interpret() } stringstream result; - result << "Trace:" << endl;; - for (auto const& line: interpreter.trace()) - result << " " << line << endl; - result << "Memory dump:\n"; - for (size_t i = 0; i < state.memory.size(); i += 0x20) - result << " " << std::hex << std::setw(4) << i << ": " << toHex(bytesConstRef(state.memory.data() + i, 0x20).toBytes()) << endl; - result << "Storage dump:" << endl; - for (auto const& slot: state.storage) - result << " " << slot.first.hex() << ": " << slot.second.hex() << endl; + state.dumpTraceAndState(result); return result.str(); } diff --git a/test/libyul/yulInterpreterTests/datacopy.yul b/test/libyul/yulInterpreterTests/datacopy.yul index b083b1fe2..cccfdea07 100644 --- a/test/libyul/yulInterpreterTests/datacopy.yul +++ b/test/libyul/yulInterpreterTests/datacopy.yul @@ -17,98 +17,4 @@ object "main" // MLOAD_FROM_SIZE(32, 32) // SSTORE(1, 0) // Memory dump: -// 0: 0000000000000000000000000000000000000000000000000000000000000000 -// 20: 0000000000000000000000000000000000000000000000000000000000000000 -// 40: 0000000000000000000000000000000000000000000000000000000000000000 -// 60: 0000000000000000000000000000000000000000000000000000000000000000 -// 80: 0000000000000000000000000000000000000000000000000000000000000000 -// a0: 0000000000000000000000000000000000000000000000000000000000000000 -// c0: 0000000000000000000000000000000000000000000000000000000000000000 -// e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 100: 0000000000000000000000000000000000000000000000000000000000000000 -// 120: 0000000000000000000000000000000000000000000000000000000000000000 -// 140: 0000000000000000000000000000000000000000000000000000000000000000 -// 160: 0000000000000000000000000000000000000000000000000000000000000000 -// 180: 0000000000000000000000000000000000000000000000000000000000000000 -// 1a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 1c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 1e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 200: 0000000000000000000000000000000000000000000000000000000000000000 -// 220: 0000000000000000000000000000000000000000000000000000000000000000 -// 240: 0000000000000000000000000000000000000000000000000000000000000000 -// 260: 0000000000000000000000000000000000000000000000000000000000000000 -// 280: 0000000000000000000000000000000000000000000000000000000000000000 -// 2a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 2c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 2e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 300: 0000000000000000000000000000000000000000000000000000000000000000 -// 320: 0000000000000000000000000000000000000000000000000000000000000000 -// 340: 0000000000000000000000000000000000000000000000000000000000000000 -// 360: 0000000000000000000000000000000000000000000000000000000000000000 -// 380: 0000000000000000000000000000000000000000000000000000000000000000 -// 3a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 3c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 3e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 400: 0000000000000000000000000000000000000000000000000000000000000000 -// 420: 0000000000000000000000000000000000000000000000000000000000000000 -// 440: 0000000000000000000000000000000000000000000000000000000000000000 -// 460: 0000000000000000000000000000000000000000000000000000000000000000 -// 480: 0000000000000000000000000000000000000000000000000000000000000000 -// 4a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 4c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 4e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 500: 0000000000000000000000000000000000000000000000000000000000000000 -// 520: 0000000000000000000000000000000000000000000000000000000000000000 -// 540: 0000000000000000000000000000000000000000000000000000000000000000 -// 560: 0000000000000000000000000000000000000000000000000000000000000000 -// 580: 0000000000000000000000000000000000000000000000000000000000000000 -// 5a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 5c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 5e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 600: 0000000000000000000000000000000000000000000000000000000000000000 -// 620: 0000000000000000000000000000000000000000000000000000000000000000 -// 640: 0000000000000000000000000000000000000000000000000000000000000000 -// 660: 0000000000000000000000000000000000000000000000000000000000000000 -// 680: 0000000000000000000000000000000000000000000000000000000000000000 -// 6a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 6c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 6e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 700: 0000000000000000000000000000000000000000000000000000000000000000 -// 720: 0000000000000000000000000000000000000000000000000000000000000000 -// 740: 0000000000000000000000000000000000000000000000000000000000000000 -// 760: 0000000000000000000000000000000000000000000000000000000000000000 -// 780: 0000000000000000000000000000000000000000000000000000000000000000 -// 7a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 7c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 7e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 800: 0000000000000000000000000000000000000000000000000000000000000000 -// 820: 0000000000000000000000000000000000000000000000000000000000000000 -// 840: 0000000000000000000000000000000000000000000000000000000000000000 -// 860: 0000000000000000000000000000000000000000000000000000000000000000 -// 880: 0000000000000000000000000000000000000000000000000000000000000000 -// 8a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 8c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 8e0: 0000000000000000000000000000000000000000000000000000000000000000 -// 900: 0000000000000000000000000000000000000000000000000000000000000000 -// 920: 0000000000000000000000000000000000000000000000000000000000000000 -// 940: 0000000000000000000000000000000000000000000000000000000000000000 -// 960: 0000000000000000000000000000000000000000000000000000000000000000 -// 980: 0000000000000000000000000000000000000000000000000000000000000000 -// 9a0: 0000000000000000000000000000000000000000000000000000000000000000 -// 9c0: 0000000000000000000000000000000000000000000000000000000000000000 -// 9e0: 0000000000000000000000000000000000000000000000000000000000000000 -// a00: 0000000000000000000000000000000000000000000000000000000000000000 -// a20: 0000000000000000000000000000000000000000000000000000000000000000 -// a40: 0000000000000000000000000000000000000000000000000000000000000000 -// a60: 0000000000000000000000000000000000000000000000000000000000000000 -// a80: 0000000000000000000000000000000000000000000000000000000000000000 -// aa0: 0000000000000000000000000000000000000000000000000000000000000000 -// ac0: 0000000000000000000000000000000000000000000000000000000000000000 -// ae0: 0000000000000000000000000000000000000000000000000000000000000000 -// b00: 0000000000000000000000000000000000000000000000000000000000000000 -// b20: 0000000000000000000000000000000000000000000000000000000000000000 -// b40: 0000000000000000000000000000000000000000000000000000000000000000 -// b60: 0000000000000000000000000000000000000000000000000000000000000000 // Storage dump: -// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000000 -// 0000000000000000000000000000000000000000000000000000000000000001: 0000000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libyul/yulInterpreterTests/external_call.yul b/test/libyul/yulInterpreterTests/external_call.yul index a7e0c6bae..6bfb44cd4 100644 --- a/test/libyul/yulInterpreterTests/external_call.yul +++ b/test/libyul/yulInterpreterTests/external_call.yul @@ -10,8 +10,5 @@ // CALL(153, 69, 5, 0, 32, 48, 32) // SSTORE(100, 1) // Memory dump: -// 0: 0000000000000000000000000000000000000000000000000000000000000000 -// 20: 0000000000000000000000000000000000000000000000000000000000000000 -// 40: 0000000000000000000000000000000000000000000000000000000000000000 // Storage dump: // 0000000000000000000000000000000000000000000000000000000000000064: 0000000000000000000000000000000000000000000000000000000000000001 diff --git a/test/libyul/yulInterpreterTests/loop.yul b/test/libyul/yulInterpreterTests/loop.yul index 45f584ab0..03d4ae3f3 100644 --- a/test/libyul/yulInterpreterTests/loop.yul +++ b/test/libyul/yulInterpreterTests/loop.yul @@ -14,7 +14,5 @@ // MSTORE_AT_SIZE(40, 32) [0000000000000000000000000000000000000000000000000000000000008000] // MSTORE_AT_SIZE(45, 32) [0000000000000000000000000000000000000000000000000000000000009000] // Memory dump: -// 0: 0000000000000000000000000000000000000000000000000000000000000000 -// 20: 0000000000000000000000000000000000000000000000000000000000000000 // 40: 0000000000000000000000900000000000000000000000000000000000000000 // Storage dump: diff --git a/test/libyul/yulInterpreterTests/recursive_function_for_loop.yul b/test/libyul/yulInterpreterTests/recursive_function_for_loop.yul index 003c71ee6..87e540cf5 100644 --- a/test/libyul/yulInterpreterTests/recursive_function_for_loop.yul +++ b/test/libyul/yulInterpreterTests/recursive_function_for_loop.yul @@ -30,8 +30,4 @@ // SSTORE(0, 0) // Memory dump: // 0: 0001000000000000000000000000000000000000000000000000000000000000 -// 20: 0000000000000000000000000000000000000000000000000000000000000000 -// 40: 0000000000000000000000000000000000000000000000000000000000000000 -// 60: 0000000000000000000000000000000000000000000000000000000000000000 // Storage dump: -// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000000 diff --git a/test/libyul/yulInterpreterTests/simple_mstore.yul b/test/libyul/yulInterpreterTests/simple_mstore.yul index 879b03801..f1e90b95e 100644 --- a/test/libyul/yulInterpreterTests/simple_mstore.yul +++ b/test/libyul/yulInterpreterTests/simple_mstore.yul @@ -5,6 +5,5 @@ // Trace: // MSTORE_AT_SIZE(10, 32) [000000000000000000000000000000000000000000000000000000000000000b] // Memory dump: -// 0: 0000000000000000000000000000000000000000000000000000000000000000 // 20: 0000000000000000000b00000000000000000000000000000000000000000000 // Storage dump: diff --git a/test/libyul/yulInterpreterTests/switch_statement.yul b/test/libyul/yulInterpreterTests/switch_statement.yul index 06ac3703a..2d429093d 100644 --- a/test/libyul/yulInterpreterTests/switch_statement.yul +++ b/test/libyul/yulInterpreterTests/switch_statement.yul @@ -8,6 +8,5 @@ // Trace: // MSTORE_AT_SIZE(1, 32) [0000000000000000000000000000000000000000000000000000000000000002] // Memory dump: -// 0: 0000000000000000000000000000000000000000000000000000000000000000 // 20: 0200000000000000000000000000000000000000000000000000000000000000 // Storage dump: diff --git a/test/tools/ossfuzz/yulFuzzerCommon.cpp b/test/tools/ossfuzz/yulFuzzerCommon.cpp index 4d28554a2..0931b8e41 100644 --- a/test/tools/ossfuzz/yulFuzzerCommon.cpp +++ b/test/tools/ossfuzz/yulFuzzerCommon.cpp @@ -35,7 +35,5 @@ void yulFuzzerUtil::interpret( state.maxMemSize = _maxMemory; Interpreter interpreter(state, _dialect); interpreter(*_ast); - _os << "Trace:" << endl; - for (auto const& line: interpreter.trace()) - _os << " " << line << endl; + state.dumpTraceAndState(_os); } diff --git a/test/tools/yulInterpreter/Interpreter.cpp b/test/tools/yulInterpreter/Interpreter.cpp index ff6a0cc99..7bcd4771e 100644 --- a/test/tools/yulInterpreter/Interpreter.cpp +++ b/test/tools/yulInterpreter/Interpreter.cpp @@ -32,12 +32,33 @@ #include #include +#include + +#include using namespace std; using namespace dev; using namespace yul; using namespace yul::test; +void InterpreterState::dumpTraceAndState(ostream& _out) const +{ + _out << "Trace:" << endl; + for (auto const& line: trace) + _out << " " << line << endl; + _out << "Memory dump:\n"; + for (size_t i = 0; i < memory.size(); i += 0x20) + { + bytesConstRef data(memory.data() + i, 0x20); + if (boost::algorithm::all_of_equal(data, 0)) + continue; + _out << " " << std::hex << std::setw(4) << i << ": " << toHex(data.toBytes()) << endl; + } + _out << "Storage dump:" << endl; + for (auto const& slot: storage) + if (slot.second != h256(0)) + _out << " " << slot.first.hex() << ": " << slot.second.hex() << endl; +} void Interpreter::operator()(ExpressionStatement const& _expressionStatement) { diff --git a/test/tools/yulInterpreter/Interpreter.h b/test/tools/yulInterpreter/Interpreter.h index cf449a017..6fc20280a 100644 --- a/test/tools/yulInterpreter/Interpreter.h +++ b/test/tools/yulInterpreter/Interpreter.h @@ -92,6 +92,8 @@ struct InterpreterState size_t maxSteps = 0; size_t numSteps = 0; LoopState loopState = LoopState::Default; + + void dumpTraceAndState(std::ostream& _out) const; }; /** diff --git a/test/tools/yulrun.cpp b/test/tools/yulrun.cpp index 9a559d220..fb544231f 100644 --- a/test/tools/yulrun.cpp +++ b/test/tools/yulrun.cpp @@ -98,15 +98,7 @@ void interpret(string const& _source) { } - cout << "Trace:" << endl; - for (auto const& line: interpreter.trace()) - cout << " " << line << endl; - cout << "Memory dump:" << endl; - for (size_t i = 0; i < state.memory.size(); i += 0x20) - cout << " " << std::hex << std::setw(4) << i << ": " << toHex(bytesConstRef(state.memory.data() + i, 0x20).toBytes()) << endl; - cout << "Storage dump:" << endl; - for (auto const& slot: state.storage) - cout << " " << slot.first.hex() << ": " << slot.second.hex() << endl; + state.dumpTraceAndState(cout); } }