Skip to content
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

invoice: reproduce parsing mismatch #3703

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lightning-invoice/.DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions lightning-invoice/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,4 +1416,32 @@ mod test {
assert!(parse_is_code_length_err(&too_long));
assert!(!parse_is_code_length_err(&too_long[..too_long.len() - 1]));
}

#[test]
fn test_raw_data_base32_roundtrip() {
use crate::ser::Base32Iterable;
use crate::RawDataPart;
use bech32::Fe32;

// These are the expected Fe32 values that should round-trip correctly
// The critical difference is in the handling of tag 5 (Features) with empty payload
let expected_values: Vec<u8> = vec![
0, 0, 4, 8, 23, 5, 0, 1, 1, 20, 16, 0, 24, 0, 1, 18, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 24, 0, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0,
0, 16, 0, 0, 0, 0, 0, 5, 0, 1, 0, 13, 0, 0,
];

// Convert to Fe32 for processing
let values_input: Vec<Fe32> = expected_values
.iter()
.map(|&v| <Fe32 as TryFrom<u8>>::try_from(v).expect("Value out of range"))
.collect();

// Round-trip through the parser
let raw_data = RawDataPart::from_base32(&values_input).unwrap();
let actual_output = raw_data.fe_iter().collect::<Vec<_>>();

// The test fails because the parser doesn't correctly handle empty Features field
assert_eq!(values_input, actual_output, "Failed to correctly round-trip BOLT11 data");
}
}
4 changes: 2 additions & 2 deletions lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ mod prelude {
use crate::prelude::*;

/// Re-export serialization traits
#[cfg(fuzzing)]
#[cfg(any(fuzzing, test))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proably this is no longer required

pub use crate::de::FromBase32;
#[cfg(not(fuzzing))]
#[cfg(not(any(fuzzing, test)))]
use crate::de::FromBase32;
#[cfg(fuzzing)]
pub use crate::ser::Base32Iterable;
Expand Down
Loading