-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: some miniscripts are being pointed as invalid, but are valid #633
Comments
Thanks for raising the issue. If this was a bug in #[test]
#[allow(unsafe_code)]
fn foo() {
use core::ffi::{CStr, c_char};
extern "C" fn rust_miniscript_from_str(input: *const c_char) -> bool {
if let Ok(data) = unsafe { CStr::from_ptr(input) }.to_str() {
if let Ok(_pol) = Miniscript::<String, Segwitv0>::from_str_insane(data) {
return true
} else if let Ok(_pol) = Miniscript::<String, Tap>::from_str_insane(data) {
return true
}
}
false
}
let tcs = vec!["nnnnnnnnnnnnnnnln:1", "dv:0", "lll:0", "l:1"];
for tc in tcs {
let _ = rust_miniscript_from_str(tc.as_ptr() as *const i8);
println!("Did not crash for input: {}", tc);
}
} Is the function ever returning |
FTR I wrote and ran that as a unit test in
|
Thanks for checking it, @tcharding. I modified your example to: for tc in tcs {
let result_parse = rust_miniscript_from_str(tc.as_ptr() as *const i8);
println!("{}", result_parse);
println!("Did not crash for input: {}", tc);
} and it's printing:
I suppose it should print |
No sweat, happy to help.
There is no reason parsing those input strings must return
I'm not awesome at fuzzing but between us we might get there :) |
Hi @brunoerg. Sorry for not checking on this after you reported it on IRC. Thanks for filing the issue. @tcharding all these Miniscripts are valid, accepted by Bitcoin Core, and should be accepted by us too. And indeed, they are.
This code is not correct. |
Ha! Thats a bug in my code not the original, does this uncovered a similar bug in the fuzz suite @brunoerg? |
Thanks, @tcharding. Basically, I only need to know if the miniscript is valid or not, I'm using it to compare with the result provided by Core.
I'm investigating, but I think so. |
It looks valid to me. Possibly it violates length constraints or something but |
I fixed some things from use crate::{Miniscript, Segwitv0, Tap};
#[test]
#[allow(unsafe_code)]
fn foo() {
fn test(input: &str) -> bool {
if let Ok(_pol) = Miniscript::<String, Segwitv0>::from_str_insane(input) {
return true
} else if let Ok(_pol) = Miniscript::<String, Tap>::from_str_insane(input) {
return true
}
false
}
let tcs = vec!["lll:0", "ulllll:0"];
for tc in tcs {
let result_parse = test(tc);
println!("{} - {}", tc, result_parse);
}
} |
@brunoerg thanksI!! So, we have an error Probably we should just drop this error variant. There are many other inefficiencies that we don't attempt to prevent. But OTOH, this is very easy and cheap to detect, and this inefficiency is almost certainly just a mistake.. cc @sipa do you have any thoughts on this? Should Core or the Miniscript definition reject |
Meanwhile, I'll make |
I don't think we should be making a backward incompatible change to Miniscript / Bitcoin Core just for ruling out an inefficiency. Even without considering backward compatibility i don't think it's necessary to special case them. They are semantically valid and it doesn't cost more to not rule them out. Sure, compilers shouldn't output such inefficient constructs in the first place, but once they are in use we might as well parse them.
nit: how so? They are literally the same expression: |
Hmm. Yeah, you're right. The expression |
Thanks, I'll update bitcoinfuzz |
Hi, recently I started developing bitcoinfuzz - differential fuzzing of Bitcoin implementations and libraries. One of the targets gets a string and checks whether it's a valid miniscript. The code I'm using to check it with
rust-miniscript
is:and
bitcoinfuzz
is crashing (rust-miniscript returning invalid) with the following miniscripts (and other ones):Could I be missing something in my code or is it a bug?
The text was updated successfully, but these errors were encountered: