Skip to content

Commit 406e031

Browse files
committed
Fuzz fetching InvoiceRequestFields from VerifiedInvoiceRequests
This should allow us to reach the panic from two commits ago from the fuzzer.
1 parent cf684fa commit 406e031

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

fuzz/src/invoice_request_deser.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,26 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
8585
let expanded_key = ExpandedKey::new([42; 32]);
8686
let entropy_source = Randomness {};
8787
let nonce = Nonce::from_entropy_source(&entropy_source);
88+
89+
let invoice_request_fields =
90+
if let Ok(ver) = invoice_request.clone().verify_using_metadata(&expanded_key, secp_ctx) {
91+
// Previously we had a panic where we'd truncate the payer note possibly cutting a
92+
// Unicode character in two here, so try to fetch fields if we can validate.
93+
ver.fields()
94+
} else {
95+
InvoiceRequestFields {
96+
payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
97+
quantity: invoice_request.quantity(),
98+
payer_note_truncated: invoice_request
99+
.payer_note()
100+
.map(|s| UntrustedString(s.to_string())),
101+
human_readable_name: None,
102+
}
103+
};
104+
88105
let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
89106
offer_id: OfferId([42; 32]),
90-
invoice_request: InvoiceRequestFields {
91-
payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
92-
quantity: invoice_request.quantity(),
93-
payer_note_truncated: invoice_request
94-
.payer_note()
95-
.map(|s| UntrustedString(s.to_string())),
96-
human_readable_name: None,
97-
},
107+
invoice_request: invoice_request_fields,
98108
});
99109
let payee_tlvs = UnauthenticatedReceiveTlvs {
100110
payment_secret: PaymentSecret([42; 32]),

lightning/src/offers/invoice_request.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,14 @@ impl VerifiedInvoiceRequest {
933933
#[cfg(c_bindings)]
934934
invoice_request_respond_with_derived_signing_pubkey_methods!(self, self.inner, InvoiceWithDerivedSigningPubkeyBuilder);
935935

936-
pub(crate) fn fields(&self) -> InvoiceRequestFields {
936+
/// Fetch the [`InvoiceRequestFields`] for this verified invoice.
937+
///
938+
/// These are fields which we expect to be useful when receiving a payment for this invoice
939+
/// request, and include the returned [`InvoiceRequestFields`] in the
940+
/// [`PaymentContext::Bolt12Offer`].
941+
///
942+
/// [`PaymentContext::Bolt12Offer`]: crate::blinded_path::payment::PaymentContext::Bolt12Offer
943+
pub fn fields(&self) -> InvoiceRequestFields {
937944
let InvoiceRequestContents {
938945
payer_signing_pubkey,
939946
inner: InvoiceRequestContentsWithoutPayerSigningPubkey {
@@ -1316,8 +1323,13 @@ pub struct InvoiceRequestFields {
13161323
}
13171324

13181325
/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1326+
#[cfg(not(fuzzing))]
13191327
pub const PAYER_NOTE_LIMIT: usize = 512;
13201328

1329+
/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1330+
#[cfg(fuzzing)]
1331+
pub const PAYER_NOTE_LIMIT: usize = 8;
1332+
13211333
impl Writeable for InvoiceRequestFields {
13221334
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
13231335
write_tlv_fields!(writer, {

0 commit comments

Comments
 (0)