Skip to content

Commit

Permalink
Merge pull request lightningdevkit#3270 from optout21/bech32-iterser
Browse files Browse the repository at this point in the history
Upgrade bech32 dependency (iterative)
  • Loading branch information
TheBlueMatt authored Oct 3, 2024
2 parents d49a08a + aa2f6b4 commit bc1931b
Show file tree
Hide file tree
Showing 13 changed files with 683 additions and 520 deletions.
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ stdin_fuzz = []
lightning = { path = "../lightning", features = ["regex", "_test_utils"] }
lightning-invoice = { path = "../lightning-invoice" }
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
bech32 = "0.9.1"
bech32 = "0.11.0"
bitcoin = { version = "0.32.2", features = ["secp-lowmemory"] }

afl = { version = "0.12", optional = true }
Expand Down
13 changes: 7 additions & 6 deletions fuzz/src/bolt11_deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
// licenses.

use crate::utils::test_logger;
use bech32::{u5, FromBase32, ToBase32};
use bech32::Fe32;
use bitcoin::secp256k1::{Secp256k1, SecretKey};
use lightning_invoice::{
Bolt11Invoice, RawBolt11Invoice, RawDataPart, RawHrp, RawTaggedField, TaggedField,
Base32Iterable, Bolt11Invoice, FromBase32, RawBolt11Invoice, RawDataPart, RawHrp,
RawTaggedField, TaggedField,
};
use std::str::FromStr;

Expand All @@ -25,19 +26,19 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
Err(_) => return,
};
let bech32 =
data.iter().skip(hrp_len).map(|x| u5::try_from_u8(x % 32).unwrap()).collect::<Vec<_>>();
data.iter().skip(hrp_len).map(|x| Fe32::try_from(x % 32).unwrap()).collect::<Vec<_>>();
let invoice_data = match RawDataPart::from_base32(&bech32) {
Ok(invoice) => invoice,
Err(_) => return,
};

let invoice_data_base32 = invoice_data.fe_iter().collect::<Vec<_>>();
// Our data encoding is not worse than the input
assert!(invoice_data.to_base32().len() <= bech32.len());
assert!(invoice_data_base32.len() <= bech32.len());

// Our data serialization is loss-less
assert_eq!(
RawDataPart::from_base32(&invoice_data.to_base32())
.expect("faild parsing out own encoding"),
RawDataPart::from_base32(&invoice_data_base32).expect("faild parsing out own encoding"),
invoice_data
);

Expand Down
2 changes: 1 addition & 1 deletion lightning-invoice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
std = []

[dependencies]
bech32 = { version = "0.9.1", default-features = false }
bech32 = { version = "0.11.0", default-features = false }
lightning-types = { version = "0.1.0", path = "../lightning-types", default-features = false }
serde = { version = "1.0.118", optional = true }
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }
Expand Down
Loading

0 comments on commit bc1931b

Please sign in to comment.