Skip to content

Commit ffaa7ff

Browse files
author
Mohammad Rezaei
committed
add unit tests for constant optimizer using solfuzzer
1 parent 31bdf9c commit ffaa7ff

File tree

6 files changed

+388
-12
lines changed

6 files changed

+388
-12
lines changed

test/cmdlineTests/~soljson_via_fuzzer/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ cd "$SOLTMPDIR"
1313
gnu_grep -L --include="*.sol" "^pragma experimental solidity;$" ./* | xargs -P 4 -n 50 "${SOLIDITY_BUILD_DIR}/test/tools/solfuzzer" --quiet --input-files
1414
gnu_grep -L --include="*.sol" "^pragma experimental solidity;$" ./* | xargs -P 4 -n 50 "${SOLIDITY_BUILD_DIR}/test/tools/solfuzzer" --without-optimizer --quiet --input-files
1515

16+
# constant optimizer tests
17+
grep -v "#" "$REPO_ROOT"/test/libevmasm/constants.txt | xargs -I {} sh -c "echo -n {} | "${SOLIDITY_BUILD_DIR}"/test/tools/solfuzzer --quiet --const-opt --hex"
18+
1619
rm -r "$SOLTMPDIR"

test/libevmasm/constants.txt

+358
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,358 @@
1+
# masks with 1 bits
2+
1
3+
2000000
4+
8000000000000
5+
10000000000000000000
6+
40000000000000000000000000
7+
80000000000000000000000000000000
8+
200000000000000000000000000000000000000
9+
400000000000000000000000000000000000000000000
10+
1000000000000000000000000000000000000000000000000000
11+
2000000000000000000000000000000000000000000000000000000000
12+
8000000000000000000000000000000000000000000000000000000000000000
13+
# masks with 2 bits
14+
3
15+
6000000
16+
c000000000000
17+
30000000000000000000
18+
60000000000000000000000000
19+
180000000000000000000000000000000
20+
300000000000000000000000000000000000000
21+
600000000000000000000000000000000000000000000
22+
1800000000000000000000000000000000000000000000000000
23+
3000000000000000000000000000000000000000000000000000000000
24+
c000000000000000000000000000000000000000000000000000000000000000
25+
# masks with 3 bits
26+
7
27+
e000000
28+
1c000000000000
29+
38000000000000000000
30+
e0000000000000000000000000
31+
1c0000000000000000000000000000000
32+
380000000000000000000000000000000000000
33+
e00000000000000000000000000000000000000000000
34+
1c00000000000000000000000000000000000000000000000000
35+
3800000000000000000000000000000000000000000000000000000000
36+
e000000000000000000000000000000000000000000000000000000000000000
37+
# masks with 4 bits
38+
f
39+
1e000000
40+
3c000000000000
41+
78000000000000000000
42+
f0000000000000000000000000
43+
3c0000000000000000000000000000000
44+
780000000000000000000000000000000000000
45+
f00000000000000000000000000000000000000000000
46+
1e00000000000000000000000000000000000000000000000000
47+
3c00000000000000000000000000000000000000000000000000000000
48+
f000000000000000000000000000000000000000000000000000000000000000
49+
# masks with 7 bits
50+
7f
51+
7f000000
52+
fe000000000000
53+
1fc000000000000000000
54+
3f8000000000000000000000000
55+
7f0000000000000000000000000000000
56+
fe0000000000000000000000000000000000000
57+
1fc0000000000000000000000000000000000000000000
58+
3f80000000000000000000000000000000000000000000000000
59+
7f00000000000000000000000000000000000000000000000000000000
60+
fe00000000000000000000000000000000000000000000000000000000000000
61+
# masks with 8 bits
62+
ff
63+
ff000000
64+
1fe000000000000
65+
3fc000000000000000000
66+
7f8000000000000000000000000
67+
ff0000000000000000000000000000000
68+
ff0000000000000000000000000000000000000
69+
1fe0000000000000000000000000000000000000000000
70+
3fc0000000000000000000000000000000000000000000000000
71+
7f80000000000000000000000000000000000000000000000000000000
72+
ff00000000000000000000000000000000000000000000000000000000000000
73+
# masks with 16 bits
74+
ffff
75+
ffff000000
76+
ffff000000000000
77+
ffff000000000000000000
78+
ffff000000000000000000000000
79+
ffff000000000000000000000000000000
80+
ffff000000000000000000000000000000000000
81+
ffff000000000000000000000000000000000000000000
82+
ffff000000000000000000000000000000000000000000000000
83+
ffff000000000000000000000000000000000000000000000000000000
84+
ffff000000000000000000000000000000000000000000000000000000000000
85+
# masks with 23 bits
86+
7fffff
87+
3fffff800000
88+
1fffffc00000000000
89+
fffffe00000000000000000
90+
fffffe00000000000000000000000
91+
7fffff00000000000000000000000000000
92+
3fffff80000000000000000000000000000000000
93+
3fffff80000000000000000000000000000000000000000
94+
1fffffc0000000000000000000000000000000000000000000000
95+
fffffe0000000000000000000000000000000000000000000000000000
96+
fffffe0000000000000000000000000000000000000000000000000000000000
97+
# masks with 32 bits
98+
ffffffff
99+
3fffffffc00000
100+
ffffffff00000000000
101+
7fffffff80000000000000000
102+
1fffffffe0000000000000000000000
103+
ffffffff0000000000000000000000000000
104+
3fffffffc000000000000000000000000000000000
105+
ffffffff000000000000000000000000000000000000000
106+
7fffffff800000000000000000000000000000000000000000000
107+
1fffffffe00000000000000000000000000000000000000000000000000
108+
ffffffff00000000000000000000000000000000000000000000000000000000
109+
# masks with 47 bits
110+
7fffffffffff
111+
7fffffffffff00000
112+
fffffffffffe0000000000
113+
1fffffffffffc000000000000000
114+
3fffffffffff800000000000000000000
115+
7fffffffffff00000000000000000000000000
116+
fffffffffffe0000000000000000000000000000000
117+
1fffffffffffc000000000000000000000000000000000000
118+
3fffffffffff800000000000000000000000000000000000000000
119+
7fffffffffff00000000000000000000000000000000000000000000000
120+
fffffffffffe0000000000000000000000000000000000000000000000000000
121+
# masks with 64 bits
122+
ffffffffffffffff
123+
7fffffffffffffff80000
124+
3fffffffffffffffc000000000
125+
1fffffffffffffffe00000000000000
126+
ffffffffffffffff0000000000000000000
127+
ffffffffffffffff000000000000000000000000
128+
7fffffffffffffff80000000000000000000000000000
129+
3fffffffffffffffc000000000000000000000000000000000
130+
1fffffffffffffffe00000000000000000000000000000000000000
131+
ffffffffffffffff0000000000000000000000000000000000000000000
132+
ffffffffffffffff000000000000000000000000000000000000000000000000
133+
# masks with 92 bits
134+
fffffffffffffffffffffff
135+
fffffffffffffffffffffff0000
136+
fffffffffffffffffffffff00000000
137+
1ffffffffffffffffffffffe000000000000
138+
1ffffffffffffffffffffffe0000000000000000
139+
3ffffffffffffffffffffffc00000000000000000000
140+
3ffffffffffffffffffffffc000000000000000000000000
141+
3ffffffffffffffffffffffc0000000000000000000000000000
142+
7ffffffffffffffffffffff800000000000000000000000000000000
143+
7ffffffffffffffffffffff8000000000000000000000000000000000000
144+
fffffffffffffffffffffff00000000000000000000000000000000000000000
145+
# masks with 103 bits
146+
7fffffffffffffffffffffffff
147+
3fffffffffffffffffffffffff8000
148+
1fffffffffffffffffffffffffc0000000
149+
fffffffffffffffffffffffffe00000000000
150+
fffffffffffffffffffffffffe000000000000000
151+
7fffffffffffffffffffffffff0000000000000000000
152+
3fffffffffffffffffffffffff80000000000000000000000
153+
3fffffffffffffffffffffffff800000000000000000000000000
154+
1fffffffffffffffffffffffffc000000000000000000000000000000
155+
fffffffffffffffffffffffffe0000000000000000000000000000000000
156+
fffffffffffffffffffffffffe00000000000000000000000000000000000000
157+
# masks with 128 bits
158+
ffffffffffffffffffffffffffffffff
159+
ffffffffffffffffffffffffffffffff000
160+
1fffffffffffffffffffffffffffffffe000000
161+
3fffffffffffffffffffffffffffffffc000000000
162+
7fffffffffffffffffffffffffffffff8000000000000
163+
ffffffffffffffffffffffffffffffff0000000000000000
164+
ffffffffffffffffffffffffffffffff0000000000000000000
165+
1fffffffffffffffffffffffffffffffe0000000000000000000000
166+
3fffffffffffffffffffffffffffffffc0000000000000000000000000
167+
7fffffffffffffffffffffffffffffff80000000000000000000000000000
168+
ffffffffffffffffffffffffffffffff00000000000000000000000000000000
169+
# masks with 133 bits
170+
1fffffffffffffffffffffffffffffffff
171+
1fffffffffffffffffffffffffffffffff000
172+
1fffffffffffffffffffffffffffffffff000000
173+
1fffffffffffffffffffffffffffffffff000000000
174+
3ffffffffffffffffffffffffffffffffe000000000000
175+
3ffffffffffffffffffffffffffffffffe000000000000000
176+
3ffffffffffffffffffffffffffffffffe000000000000000000
177+
7ffffffffffffffffffffffffffffffffc000000000000000000000
178+
7ffffffffffffffffffffffffffffffffc000000000000000000000000
179+
7ffffffffffffffffffffffffffffffffc000000000000000000000000000
180+
fffffffffffffffffffffffffffffffff8000000000000000000000000000000
181+
# masks with 160 bits
182+
ffffffffffffffffffffffffffffffffffffffff
183+
1fffffffffffffffffffffffffffffffffffffffe00
184+
7fffffffffffffffffffffffffffffffffffffff80000
185+
ffffffffffffffffffffffffffffffffffffffff0000000
186+
3fffffffffffffffffffffffffffffffffffffffc000000000
187+
ffffffffffffffffffffffffffffffffffffffff000000000000
188+
1fffffffffffffffffffffffffffffffffffffffe00000000000000
189+
7fffffffffffffffffffffffffffffffffffffff80000000000000000
190+
ffffffffffffffffffffffffffffffffffffffff0000000000000000000
191+
3fffffffffffffffffffffffffffffffffffffffc000000000000000000000
192+
ffffffffffffffffffffffffffffffffffffffff000000000000000000000000
193+
# masks with 175 bits
194+
7fffffffffffffffffffffffffffffffffffffffffff
195+
7fffffffffffffffffffffffffffffffffffffffffff00
196+
7fffffffffffffffffffffffffffffffffffffffffff0000
197+
7fffffffffffffffffffffffffffffffffffffffffff000000
198+
7fffffffffffffffffffffffffffffffffffffffffff00000000
199+
7fffffffffffffffffffffffffffffffffffffffffff0000000000
200+
7fffffffffffffffffffffffffffffffffffffffffff000000000000
201+
7fffffffffffffffffffffffffffffffffffffffffff00000000000000
202+
7fffffffffffffffffffffffffffffffffffffffffff0000000000000000
203+
7fffffffffffffffffffffffffffffffffffffffffff000000000000000000
204+
fffffffffffffffffffffffffffffffffffffffffffe00000000000000000000
205+
# masks with 200 bits
206+
ffffffffffffffffffffffffffffffffffffffffffffffffff
207+
1fffffffffffffffffffffffffffffffffffffffffffffffffe0
208+
7fffffffffffffffffffffffffffffffffffffffffffffffff800
209+
ffffffffffffffffffffffffffffffffffffffffffffffffff0000
210+
3fffffffffffffffffffffffffffffffffffffffffffffffffc00000
211+
ffffffffffffffffffffffffffffffffffffffffffffffffff0000000
212+
1fffffffffffffffffffffffffffffffffffffffffffffffffe00000000
213+
7fffffffffffffffffffffffffffffffffffffffffffffffff8000000000
214+
ffffffffffffffffffffffffffffffffffffffffffffffffff00000000000
215+
3fffffffffffffffffffffffffffffffffffffffffffffffffc000000000000
216+
ffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000
217+
# masks with 255 bits
218+
7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
219+
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
220+
# masks with 256 bits
221+
ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
222+
# powers of ten multiplied by 1
223+
a
224+
64
225+
3e8
226+
2710
227+
186a0
228+
f4240
229+
989680
230+
5f5e100
231+
3b9aca00
232+
2540be400
233+
174876e800
234+
e8d4a51000
235+
9184e72a000
236+
5af3107a4000
237+
38d7ea4c68000
238+
2386f26fc10000
239+
16345785d8a0000
240+
de0b6b3a7640000
241+
8ac7230489e80000
242+
56bc75e2d63100000
243+
3635c9adc5dea00000
244+
21e19e0c9bab2400000
245+
152d02c7e14af6800000
246+
d3c21bcecceda1000000
247+
84595161401484a000000
248+
52b7d2dcc80cd2e4000000
249+
33b2e3c9fd0803ce8000000
250+
204fce5e3e25026110000000
251+
1431e0fae6d7217caa0000000
252+
c9f2c9cd04674edea40000000
253+
7e37be2022c0914b2680000000
254+
4ee2d6d415b85acef8100000000
255+
314dc6448d9338c15b0a00000000
256+
1ed09bead87c0378d8e6400000000
257+
13426172c74d822b878fe800000000
258+
c097ce7bc90715b34b9f1000000000
259+
785ee10d5da46d900f436a000000000
260+
4b3b4ca85a86c47a098a224000000000
261+
2f050fe938943acc45f65568000000000
262+
1d6329f1c35ca4bfabb9f5610000000000
263+
125dfa371a19e6f7cb54395ca0000000000
264+
b7abc627050305adf14a3d9e40000000000
265+
72cb5bd86321e38cb6ce6682e80000000000
266+
47bf19673df52e37f2410011d100000000000
267+
2cd76fe086b93ce2f768a00b22a00000000000
268+
1c06a5ec5433c60ddaa16406f5a400000000000
269+
118427b3b4a05bc8a8a4de845986800000000000
270+
af298d050e4395d69670b12b7f41000000000000
271+
6d79f82328ea3da61e066ebb2f88a000000000000
272+
446c3b15f9926687d2c40534fdb564000000000000
273+
2ac3a4edbbfb8014e3ba83411e915e8000000000000
274+
1aba4714957d300d0e549208b31adb10000000000000
275+
10b46c6cdd6e3e0828f4db456ff0c8ea0000000000000
276+
a70c3c40a64e6c51999090b65f67d9240000000000000
277+
6867a5a867f103b2fffa5a71fba0e7b680000000000000
278+
4140c78940f6a24fdffc78873d4490d2100000000000000
279+
28c87cb5c89a2571ebfdcb54864ada834a00000000000000
280+
197d4df19d605767337e9f14d3eec8920e400000000000000
281+
fee50b7025c36a0802f236d04753d5b48e800000000000000
282+
9f4f2726179a224501d762422c946590d91000000000000000
283+
63917877cec0556b21269d695bdcbf7a87aa000000000000000
284+
3e3aeb4ae1383562f4b82261d969f7ac94ca4000000000000000
285+
26e4d30eccc3215dd8f3157d27e23acbdcfe68000000000000000
286+
184f03e93ff9f4daa797ed6e38ed64bf6a1f010000000000000000
287+
f316271c7fc3908a8bef464e3945ef7a25360a0000000000000000
288+
97edd871cfda3a5697758bf0e3cbb5ac5741c640000000000000000
289+
5ef4a74721e864761ea977768e5f518bb6891be80000000000000000
290+
3b58e88c75313ec9d329eaaa18fb92f75215b17100000000000000000
291+
25179157c93ec73e23fa32aa4f9d3bda934d8ee6a00000000000000000
292+
172ebad6ddc73c86d67c5faa71c245689c1079502400000000000000000
293+
e7d34c64a9c85d4460dbbca87196b61618a4bd216800000000000000000
294+
90e40fbeea1d3a4abc8955e946fe31cdcf66f634e1000000000000000000
295+
5a8e89d75252446eb5d5d5b1cc5edf20a1a059e10ca000000000000000000
296+
3899162693736ac531a5a58f1fbb4b746504382ca7e4000000000000000000
297+
235fadd81c2822bb3f07877973d50f28bf22a31be8ee8000000000000000000
298+
161bcca7119915b50764b4abe86529797775a5f1719510000000000000000000
299+
dd15fe86affad91249ef0eb713f39ebeaa987b6e6fd2a0000000000000000000
300+
# powers of ten multiplied by ffffffffffffffff
301+
9fffffffffffffff6
302+
63ffffffffffffff9c
303+
3e7fffffffffffffc18
304+
270fffffffffffffd8f0
305+
1869ffffffffffffe7960
306+
f423ffffffffffff0bdc0
307+
98967fffffffffff676980
308+
5f5e0fffffffffffa0a1f00
309+
3b9ac9ffffffffffc4653600
310+
2540be3fffffffffdabf41c00
311+
174876e7ffffffffe8b7891800
312+
e8d4a50fffffffff172b5af000
313+
9184e729ffffffff6e7b18d6000
314+
5af3107a3fffffffa50cef85c000
315+
38d7ea4c67ffffffc72815b398000
316+
2386f26fc0ffffffdc790d903f0000
317+
16345785d89fffffe9cba87a2760000
318+
de0b6b3a763fffff21f494c589c0000
319+
8ac7230489e7ffff7538dcfb76180000
320+
56bc75e2d630ffffa9438a1d29cf00000
321+
3635c9adc5de9fffc9ca36523a21600000
322+
21e19e0c9bab23ffde1e61f36454dc00000
323+
152d02c7e14af67fead2fd381eb509800000
324+
d3c21bcecceda0ff2c3de43133125f000000
325+
845951614014849f7ba6ae9ebfeb7b6000000
326+
52b7d2dcc80cd2e3ad482d2337f32d1c000000
327+
33b2e3c9fd0803ce4c4d1c3602f7fc318000000
328+
204fce5e3e250260efb031a1c1dafd9ef0000000
329+
1431e0fae6d7217c95ce1f051928de83560000000
330+
c9f2c9cd04674eddda0d3632fb98b1215c0000000
331+
7e37be2022c0914aa84841dfdd3f6eb4d980000000
332+
4ee2d6d415b85acea92d292bea47a53107f00000000
333+
314dc6448d9338c129bc39bb726cc73ea4f600000000
334+
1ed09bead87c0378ba15a4152783fc872719c00000000
335+
13426172c74d822b744d868d38b27dd478701800000000
336+
c097ce7bc90715b28b07418436f8ea4cb460f000000000
337+
785ee10d5da46d8f96e488f2a25b926ff0bc96000000000
338+
4b3b4ca85a86c479be4ed597a5793b85f675ddc000000000
339+
2f050fe938943acc16f1457ec76bc533ba09aa98000000000
340+
1d6329f1c35ca4bf8e56cb6f3ca35b4054460a9f0000000000
341+
125dfa371a19e6f7b8f63f2585e6190834abc6a360000000000
342+
b7abc627050305ad399e77773afcfa520eb5c261c0000000000
343+
72cb5bd86321e38c44030aaa84de1c734931997d180000000000
344+
47bf19673df52e37aa81e6aa930ad1c80dbeffee2f00000000000
345+
2cd76fe086b93ce2ca91302a9be6c31d08975ff4dd600000000000
346+
1c06a5ec5433c60dbe9abe1aa17039f2255e9bf90a5c00000000000
347+
118427b3b4a05bc89720b6d0a4e62437575b217ba679800000000000
348+
af298d050e4395d5e747242670fd6a29698f4ed480bf000000000000
349+
6d79f82328ea3da5b08c7698069e6259e1f99144d0776000000000000
350+
446c3b15f99266878e57ca1f0422fd782d3bfacb024a9c000000000000
351+
2ac3a4edbbfb8014b8f6de536295de6b1c457cbee16ea18000000000000
352+
1aba4714957d300cf39a4af41d9dab02f1ab6df74ce524f0000000000000
353+
10b46c6cdd6e3e0818406ed892828ae1d70b24ba900f37160000000000000
354+
a70c3c40a64e6c50f2845475b9196cd2666f6f49a09826dc0000000000000
355+
6867a5a867f103b29792b4c993afe4038005a58e045f184980000000000000
356+
4140c78940f6a24f9ebbb0fdfc4dee8230038778c2bb6f2df00000000000000
357+
28c87cb5c89a2571c3354e9ebdb0b5115e0234ab79b5257cb600000000000000
358+
# end of file -- no newline please

test/tools/afl_fuzzer.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ Allowed options)",
5555
(
5656
"const-opt",
5757
"Run the constant optimizer instead of compiling. "
58-
"Expects a binary string of up to 32 bytes on stdin."
58+
"Expects a binary string of up to 32 bytes on stdin or a single hex string with --hex."
59+
)
60+
(
61+
"hex",
62+
"Only usd with const-opt"
63+
"stdin must contain a single hex value, including 0x at the front"
5964
)
6065
(
6166
"input-file",
@@ -120,7 +125,7 @@ Allowed options)",
120125
try
121126
{
122127
if (arguments.count("const-opt"))
123-
FuzzerUtil::testConstantOptimizer(input, quiet);
128+
FuzzerUtil::testConstantOptimizer(input, quiet, arguments.count("hex"));
124129
else if (arguments.count("standard-json"))
125130
FuzzerUtil::testStandardCompiler(input, quiet);
126131
else

0 commit comments

Comments
 (0)