|
12 | 12 | FUZZ_TARGET(muhash)
|
13 | 13 | {
|
14 | 14 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
15 |
| - std::vector<uint8_t> data = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
16 |
| - std::vector<uint8_t> data2 = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
17 |
| - if (data.empty()) { |
18 |
| - data.resize(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096), fuzzed_data_provider.ConsumeIntegral<uint8_t>()); |
19 |
| - } |
20 |
| - if (data2.empty()) { |
21 |
| - data2.resize(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096), fuzzed_data_provider.ConsumeIntegral<uint8_t>()); |
22 |
| - } |
23 |
| - |
24 |
| - data = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
25 |
| - data2 = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 15 | + std::vector<uint8_t> data{ConsumeRandomLengthByteVector(fuzzed_data_provider)}; |
| 16 | + std::vector<uint8_t> data2{ConsumeRandomLengthByteVector(fuzzed_data_provider)}; |
26 | 17 |
|
27 | 18 | MuHash3072 muhash;
|
28 | 19 |
|
29 |
| - // Test that MuHash result is consistent independent of order of operations |
30 | 20 | muhash.Insert(data);
|
31 | 21 | muhash.Insert(data2);
|
32 | 22 |
|
| 23 | + const std::string initial_state_hash{"dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8"}; |
33 | 24 | uint256 out;
|
34 |
| - muhash.Finalize(out); |
35 |
| - |
36 |
| - muhash = MuHash3072(); |
37 |
| - muhash.Insert(data2); |
38 |
| - muhash.Insert(data); |
39 |
| - |
40 | 25 | uint256 out2;
|
41 |
| - muhash.Finalize(out2); |
42 |
| - |
| 26 | + CallOneOf( |
| 27 | + fuzzed_data_provider, |
| 28 | + [&] { |
| 29 | + // Test that MuHash result is consistent independent of order of operations |
| 30 | + muhash.Finalize(out); |
| 31 | + |
| 32 | + muhash = MuHash3072(); |
| 33 | + muhash.Insert(data2); |
| 34 | + muhash.Insert(data); |
| 35 | + muhash.Finalize(out2); |
| 36 | + }, |
| 37 | + [&] { |
| 38 | + // Test that multiplication with the initial state never changes the finalized result |
| 39 | + muhash.Finalize(out); |
| 40 | + MuHash3072 muhash3; |
| 41 | + muhash3 *= muhash; |
| 42 | + muhash3.Finalize(out2); |
| 43 | + }, |
| 44 | + [&] { |
| 45 | + // Test that dividing a MuHash by itself brings it back to it's initial state |
| 46 | + muhash /= muhash; |
| 47 | + muhash.Finalize(out); |
| 48 | + out2 = uint256S(initial_state_hash); |
| 49 | + }, |
| 50 | + [&] { |
| 51 | + // Test that removing all added elements brings the object back to it's initial state |
| 52 | + muhash.Remove(data); |
| 53 | + muhash.Remove(data2); |
| 54 | + muhash.Finalize(out); |
| 55 | + out2 = uint256S(initial_state_hash); |
| 56 | + }); |
43 | 57 | assert(out == out2);
|
44 |
| - MuHash3072 muhash3; |
45 |
| - muhash3 *= muhash; |
46 |
| - uint256 out3; |
47 |
| - muhash3.Finalize(out3); |
48 |
| - assert(out == out3); |
49 |
| - |
50 |
| - // Test that removing all added elements brings the object back to it's initial state |
51 |
| - muhash /= muhash; |
52 |
| - muhash.Finalize(out); |
53 |
| - |
54 |
| - MuHash3072 muhash2; |
55 |
| - muhash2.Finalize(out2); |
56 |
| - |
57 |
| - assert(out == out2); |
58 |
| - |
59 |
| - muhash3.Remove(data); |
60 |
| - muhash3.Remove(data2); |
61 |
| - muhash3.Finalize(out3); |
62 |
| - assert(out == out3); |
63 | 58 | }
|
0 commit comments