Skip to content

Commit 23c3ffb

Browse files
committed
Merge #287: Fix fuzz
463779e fix: clippy (Christian Lewe) 67f932f fix: Update generate-files.sh (Christian Lewe) Pull request description: Fix some tiny things that I found in simplicity-fuzz. ACKs for top commit: apoelstra: ACK 463779e; successfully ran local tests; thanks!! Tree-SHA512: 1d6e1d7bdda43b2db7467c5235d058888354d6bc880e43ffdf6fb8ee5384c64a634de82559cb76a59ccf2f6ce85a61b04bb9dbce6d3178702cad77b1da72bd4c
2 parents 2f52e22 + 463779e commit 23c3ffb

File tree

2 files changed

+4
-86
lines changed

2 files changed

+4
-86
lines changed

Diff for: fuzz/fuzz_targets/regression_value.rs

+2-84
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,6 @@
22

33
#![cfg_attr(fuzzing, no_main)]
44

5-
#[cfg(any(fuzzing, test))]
6-
use std::sync::Arc;
7-
8-
#[cfg(any(fuzzing, test))]
9-
use old_simplicity::{types::Final as OldFinal, Value as OldValue};
10-
#[cfg(any(fuzzing, test))]
11-
use simplicity::types::Final;
12-
13-
#[cfg(any(fuzzing, test))]
14-
fn convert_ty(new: &Final) -> Option<Arc<OldFinal>> {
15-
/// Our stack of tasks describing “what we need to do next.”
16-
enum Task<'a> {
17-
/// Convert this `Final` into an `OldFinal`.
18-
NeedType(&'a Final),
19-
Binary {
20-
is_sum: bool,
21-
dupe: bool,
22-
},
23-
}
24-
25-
// We'll push tasks onto this stack until everything is converted.
26-
let mut task_stack = vec![Task::NeedType(new)];
27-
// As we finish conversion of subtrees, we store them here along with
28-
// a count of units. Because the released version of 0.3.0 does not
29-
// have any typeskip optimization we need to bail out if there are
30-
// too many units, since otherwise we will OOM in from_compact_bits.
31-
let mut result_stack: Vec<(usize, Arc<OldFinal>)> = vec![];
32-
const MAX_UNITS: usize = 1024 * 1024;
33-
34-
// Process tasks in LIFO order
35-
while let Some(task) = task_stack.pop() {
36-
match task {
37-
Task::NeedType(final_ty) => {
38-
if final_ty.is_unit() {
39-
result_stack.push((1, OldFinal::unit()));
40-
} else if let Some((left, right)) = final_ty.as_sum() {
41-
let dupe = Arc::ptr_eq(left, right);
42-
task_stack.push(Task::Binary { is_sum: true, dupe });
43-
if !dupe {
44-
task_stack.push(Task::NeedType(right));
45-
}
46-
task_stack.push(Task::NeedType(left));
47-
} else if let Some((left, right)) = final_ty.as_product() {
48-
let dupe = Arc::ptr_eq(left, right);
49-
task_stack.push(Task::Binary {
50-
is_sum: false,
51-
dupe,
52-
});
53-
if !dupe {
54-
task_stack.push(Task::NeedType(right));
55-
}
56-
task_stack.push(Task::NeedType(left));
57-
} else {
58-
unreachable!();
59-
}
60-
}
61-
Task::Binary { is_sum, dupe } => {
62-
let right = result_stack.pop().expect("right type missing");
63-
let left = if dupe {
64-
(right.0, Arc::clone(&right.1))
65-
} else {
66-
result_stack.pop().expect("left type missing")
67-
};
68-
let new_total = left.0 + right.0;
69-
if new_total > MAX_UNITS {
70-
return None;
71-
}
72-
if is_sum {
73-
result_stack.push((new_total, OldFinal::sum(left.1, right.1)));
74-
} else {
75-
result_stack.push((new_total, OldFinal::product(left.1, right.1)));
76-
}
77-
}
78-
}
79-
}
80-
81-
// At the end, we should have exactly one final type.
82-
assert_eq!(result_stack.len(), 1, "Internal conversion error");
83-
let (_, res) = result_stack.pop().unwrap();
84-
Some(res)
85-
}
86-
875
#[cfg(any(fuzzing, test))]
886
fn do_test(data: &[u8]) {
897
let mut extractor_1 = simplicity_fuzz::Extractor::new(data);
@@ -95,8 +13,8 @@ fn do_test(data: &[u8]) {
9513
) {
9614
(Some(val), Some(old_val)) => (val, old_val),
9715
(None, None) => return,
98-
(Some(val), None) => panic!("Could extract new value but not old."),
99-
(None, Some(val)) => panic!("Could extract old value but not new."),
16+
(Some(_), None) => panic!("Could extract new value but not old."),
17+
(None, Some(_)) => panic!("Could extract old value but not new."),
10018
};
10119

10220
assert!(val.iter_compact().eq(old_val.iter_compact()));

Diff for: fuzz/generate-files.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ path = "fuzz_lib/lib.rs"
2727
libfuzzer-sys = "0.4"
2828
# We shouldn't need an explicit version on the next line, but Andrew's tools
2929
# choke on it otherwise. See https://github.com/nix-community/crate2nix/issues/373
30-
simplicity-lang = { path = "..", features = ["test-utils"], version = "0.3.0" }
31-
old_simplicity = { package = "simplicity-lang", version = "0.3.0", default-features = false }
30+
simplicity-lang = { path = "..", features = ["test-utils"], version = "0.4.0" }
31+
old_simplicity = { package = "simplicity-lang", version = "0.3.1", default-features = false }
3232
3333
[dev-dependencies]
3434
base64 = "0.22.1"

0 commit comments

Comments
 (0)