/src/solidity/test/tools/ossfuzz/yulFuzzerCommon.cpp
Line | Count | Source |
1 | | /* |
2 | | This file is part of solidity. |
3 | | |
4 | | solidity is free software: you can redistribute it and/or modify |
5 | | it under the terms of the GNU General Public License as published by |
6 | | the Free Software Foundation, either version 3 of the License, or |
7 | | (at your option) any later version. |
8 | | |
9 | | solidity is distributed in the hope that it will be useful, |
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | | GNU General Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU General Public License |
15 | | along with solidity. If not, see <http://www.gnu.org/licenses/>. |
16 | | */ |
17 | | // SPDX-License-Identifier: GPL-3.0 |
18 | | #include <test/tools/ossfuzz/yulFuzzerCommon.h> |
19 | | |
20 | | using namespace solidity; |
21 | | using namespace solidity::yul; |
22 | | using namespace solidity::yul::test::yul_fuzzer; |
23 | | |
24 | | yulFuzzerUtil::TerminationReason yulFuzzerUtil::interpret( |
25 | | std::ostream& _os, |
26 | | AST const& _ast, |
27 | | bool _disableMemoryTracing, |
28 | | bool _outputStorageOnly, |
29 | | size_t _maxSteps, |
30 | | size_t _maxTraceSize, |
31 | | size_t _maxExprNesting |
32 | | ) |
33 | 99.5k | { |
34 | 99.5k | InterpreterState state; |
35 | 99.5k | state.maxTraceSize = _maxTraceSize; |
36 | 99.5k | state.maxSteps = _maxSteps; |
37 | 99.5k | state.maxExprNesting = _maxExprNesting; |
38 | | // Add 64 bytes of pseudo-randomly generated calldata so that |
39 | | // calldata opcodes perform non trivial work. |
40 | 99.5k | state.calldata = { |
41 | 99.5k | 0xe9, 0x96, 0x40, 0x7d, 0xa5, 0xda, 0xb0, 0x2d, |
42 | 99.5k | 0x97, 0xf5, 0xc3, 0x44, 0xd7, 0x65, 0x0a, 0xd8, |
43 | 99.5k | 0x2c, 0x14, 0x3a, 0xf3, 0xe7, 0x40, 0x0f, 0x1e, |
44 | 99.5k | 0x67, 0xce, 0x90, 0x44, 0x2e, 0x92, 0xdb, 0x88, |
45 | 99.5k | 0xb8, 0x43, 0x9c, 0x41, 0x42, 0x08, 0xf1, 0xd7, |
46 | 99.5k | 0x65, 0xe9, 0x7f, 0xeb, 0x7b, 0xb9, 0x56, 0x9f, |
47 | 99.5k | 0xc7, 0x60, 0x5f, 0x7c, 0xcd, 0xfb, 0x92, 0xcd, |
48 | 99.5k | 0x8e, 0xf3, 0x9b, 0xe4, 0x4f, 0x6c, 0x14, 0xde |
49 | 99.5k | }; |
50 | | |
51 | 99.5k | TerminationReason reason = TerminationReason::None; |
52 | 99.5k | try |
53 | 99.5k | { |
54 | 99.5k | Interpreter::run(state, _ast, true, _disableMemoryTracing); |
55 | 99.5k | } |
56 | 99.5k | catch (StepLimitReached const&) |
57 | 99.5k | { |
58 | 3.80k | reason = TerminationReason::StepLimitReached; |
59 | 3.80k | } |
60 | 99.5k | catch (TraceLimitReached const&) |
61 | 99.5k | { |
62 | 201 | reason = TerminationReason::TraceLimitReached; |
63 | 201 | } |
64 | 99.5k | catch (ExpressionNestingLimitReached const&) |
65 | 99.5k | { |
66 | 358 | reason = TerminationReason::ExpressionNestingLimitReached; |
67 | 358 | } |
68 | 99.5k | catch (ExplicitlyTerminated const&) |
69 | 99.5k | { |
70 | 7.12k | reason = TerminationReason::ExplicitlyTerminated; |
71 | 7.12k | } |
72 | | |
73 | 99.5k | if (_outputStorageOnly) |
74 | 0 | state.dumpStorage(_os); |
75 | 99.5k | else |
76 | 99.5k | state.dumpTraceAndState(_os, _disableMemoryTracing); |
77 | 99.5k | return reason; |
78 | 99.5k | } |
79 | | |
80 | | bool yulFuzzerUtil::resourceLimitsExceeded(TerminationReason _reason) |
81 | 99.5k | { |
82 | 99.5k | return |
83 | 99.5k | _reason == yulFuzzerUtil::TerminationReason::StepLimitReached || |
84 | 95.7k | _reason == yulFuzzerUtil::TerminationReason::TraceLimitReached || |
85 | 95.5k | _reason == yulFuzzerUtil::TerminationReason::ExpressionNestingLimitReached; |
86 | 99.5k | } |