1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
use crate::{corpus_from_strategy, fuzz_data_to_value, FuzzTargetImpl};
use accumulator::test_helpers::{
arb_hash_batch, arb_list_of_hash_batches, arb_three_hash_batches, arb_two_hash_batches,
test_append_empty_impl, test_append_many_impl, test_consistency_proof_impl,
test_get_frozen_subtree_hashes_impl, test_proof_impl, test_range_proof_impl,
};
use diem_jellyfish_merkle::test_helper::{
arb_existent_kvs_and_nonexistent_keys, arb_kv_pair_with_distinct_last_nibble,
arb_tree_with_index, test_get_range_proof, test_get_with_proof,
test_get_with_proof_with_distinct_last_nibble,
};
use diem_proptest_helpers::ValueGenerator;
use diem_scratchpad::test_utils::proptest_helpers::{
arb_smt_correctness_case, test_smt_correctness_impl,
};
use diem_types::account_state_blob::AccountStateBlob;
use diemdb::{
schema::fuzzing::fuzz_decode, test_helper::arb_blocks_to_commit, test_save_blocks_impl,
};
use proptest::{collection::vec, prelude::*};
#[derive(Clone, Debug, Default)]
pub struct StorageSaveBlocks;
impl FuzzTargetImpl for StorageSaveBlocks {
fn description(&self) -> &'static str {
"Storage save blocks"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_blocks_to_commit()))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_blocks_to_commit());
test_save_blocks_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct StorageSchemaDecode;
impl FuzzTargetImpl for StorageSchemaDecode {
fn description(&self) -> &'static str {
"Storage schemas do not panic on corrupted bytes."
}
fn generate(&self, _idx: usize, gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(gen.generate(prop_oneof![
100 => vec(any::<u8>(), 0..1024),
1 => vec(any::<u8>(), 1024..1024 * 10),
]))
}
fn fuzz(&self, data: &[u8]) {
fuzz_decode(data)
}
}
#[derive(Clone, Debug, Default)]
pub struct JellyfishGetWithProof;
impl FuzzTargetImpl for JellyfishGetWithProof {
fn description(&self) -> &'static str {
"JellyfishMerkleTree get with proof"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(
arb_existent_kvs_and_nonexistent_keys::<AccountStateBlob>(1000, 100),
))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(
data,
arb_existent_kvs_and_nonexistent_keys::<AccountStateBlob>(1000, 100),
);
test_get_with_proof(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct JellyfishGetWithProofWithDistinctLastNibble;
impl FuzzTargetImpl for JellyfishGetWithProofWithDistinctLastNibble {
fn description(&self) -> &'static str {
"JellyfishMerkleTree get with proof with distinct last nibble"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(
arb_kv_pair_with_distinct_last_nibble::<AccountStateBlob>(),
))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(
data,
arb_kv_pair_with_distinct_last_nibble::<AccountStateBlob>(),
);
test_get_with_proof_with_distinct_last_nibble(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct JellyfishGetRangeProof;
impl FuzzTargetImpl for JellyfishGetRangeProof {
fn description(&self) -> &'static str {
"JellyfishMerkleTree get range proof"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(
arb_tree_with_index::<AccountStateBlob>(100),
))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_tree_with_index::<AccountStateBlob>(100));
test_get_range_proof(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorFrozenSubtreeHashes;
impl FuzzTargetImpl for AccumulatorFrozenSubtreeHashes {
fn description(&self) -> &'static str {
"Accumulator frozen subtree hashes"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_hash_batch(1000)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_hash_batch(1000));
test_get_frozen_subtree_hashes_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct SparseMerkleCorrectness;
impl FuzzTargetImpl for SparseMerkleCorrectness {
fn description(&self) -> &'static str {
"Scratchpad SMT correctness."
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_smt_correctness_case()))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_smt_correctness_case());
test_smt_correctness_impl(input)
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorProof;
impl FuzzTargetImpl for AccumulatorProof {
fn description(&self) -> &'static str {
"Accumulator proof"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_two_hash_batches(100)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_two_hash_batches(100));
test_proof_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorConsistencyProof;
impl FuzzTargetImpl for AccumulatorConsistencyProof {
fn description(&self) -> &'static str {
"Accumulator consistency proof"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_two_hash_batches(100)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_two_hash_batches(100));
test_consistency_proof_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorRangeProof;
impl FuzzTargetImpl for AccumulatorRangeProof {
fn description(&self) -> &'static str {
"Accumulator range proof"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_three_hash_batches(100)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_three_hash_batches(100));
test_range_proof_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorAppendMany;
impl FuzzTargetImpl for AccumulatorAppendMany {
fn description(&self) -> &'static str {
"Accumulator amend many leaves"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_list_of_hash_batches(10, 10)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_list_of_hash_batches(10, 10));
test_append_many_impl(input);
}
}
#[derive(Clone, Debug, Default)]
pub struct AccumulatorAppendEmpty;
impl FuzzTargetImpl for AccumulatorAppendEmpty {
fn description(&self) -> &'static str {
"Accumulator amend empty leave"
}
fn generate(&self, _idx: usize, _gen: &mut ValueGenerator) -> Option<Vec<u8>> {
Some(corpus_from_strategy(arb_hash_batch(100)))
}
fn fuzz(&self, data: &[u8]) {
let input = fuzz_data_to_value(data, arb_hash_batch(100));
test_append_empty_impl(input);
}
}