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

Follow-ups to #3139 #3202

Merged

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Jul 23, 2024

Addresses remaining comments and oversights from #3139

  • More thoroughly test Bolt12Invoice::is_for_refund_without_paths
  • Use a Result for Bolt12Invoice::verify_using_payer_data
  • Use different IV bytes for metadata in blinded paths
  • Add OffersContext::InboundPayment and remove OffersContext::Unknown

@jkczyz jkczyz force-pushed the 2024-07-blinded-path-auth-follow-up branch from 457047b to 9f4ae79 Compare July 23, 2024 23:49
@jkczyz jkczyz added this to the 0.0.124 milestone Jul 23, 2024
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

Attention: Patch coverage is 95.59748% with 7 lines in your changes missing coverage. Please review.

Project coverage is 89.74%. Comparing base (50d21b7) to head (8834336).

Files Patch % Lines
lightning/src/ln/channelmanager.rs 88.88% 1 Missing and 2 partials ⚠️
lightning/src/events/mod.rs 0.00% 2 Missing ⚠️
lightning/src/ln/peer_handler.rs 0.00% 1 Missing ⚠️
lightning/src/onion_message/functional_tests.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3202      +/-   ##
==========================================
- Coverage   89.75%   89.74%   -0.02%     
==========================================
  Files         122      122              
  Lines      101791   101862      +71     
  Branches   101791   101862      +71     
==========================================
+ Hits        91366    91413      +47     
- Misses       7744     7758      +14     
- Partials     2681     2691      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkczyz jkczyz force-pushed the 2024-07-blinded-path-auth-follow-up branch from 9f4ae79 to 9b18b7e Compare July 24, 2024 15:26
Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

LGTM, feel free to squash IMO.

@jkczyz jkczyz force-pushed the 2024-07-blinded-path-auth-follow-up branch from 9b18b7e to 4248827 Compare July 24, 2024 18:57
Use a Result return type instead of a bool when verifying a
Bolt12Invoice. This way ignoring the result will produce a compiler
warning.
In an upcoming commit, the iv_bytes used in MetadataMaterial will vary
depending on when whether a blinded path is included in the
corresponding message. Delay adding into MetadataMaterial::hmac as
otherwise the HmacEngine would need to be re-initialized using an
ExpandedKey, which won't be readily available.
Best practice is to use different IV bytes for different contexts.
Update Offer and Refund metadata computation to use different IV bytes
when the metadata is included in a blinded path. For invoice requests,
the metatdata will always be in the blinded path, so it remains the
same.
When creating a Bolt12Invoice in fuzz tests, use
BlindedPath::new_for_payment instead of BlindedPath::new_for_message.
This way PaymentContext is used instead of MessageContext, as is more
realistic though should not affect the test. This allows us to remove
OffersContext::Unknown.
By including the payment hash from the invoice in an onion message's
reply path, it can be used when logging errors as additional context.
Instead of using OffersContext::Unknown for the Bolt12Invoice reply path
use OffersContext::InboundPayment to include the payment hash.
OffersContext::Unknown will be removed in another commit.
Now that ChannelManager uses a known OffersContext when creating blinded
paths, OffersContext::Unknown is no longer needed. Remove it and update
OffersMessageHandler to us an Option, which is more idiomatic for
signifying whether a message was delivered with or without an
OffersContext.
@jkczyz jkczyz force-pushed the 2024-07-blinded-path-auth-follow-up branch from 4248827 to 8834336 Compare July 30, 2024 21:23
@jkczyz
Copy link
Contributor Author

jkczyz commented Jul 30, 2024

Rebased since the follow-on PR needs some changes from main.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

LGTM, only diff sinec @valentinewallace's LGTM is a squash, looks like:

$ git range-diff 825bda03c9354d79e1095501e22c24f13be4c7c6...9b18b7e26b902d67716f2904f3245c7b91e8c08f 50d21b7c08bb600127223d86d391943dbafdacf9...88343366ca04085904ee0ac41d5a10a86d933a35
 1:  c1f62e598 =  1:  353b45f70 Bolt12Invoice::is_for_refund_without_paths tests
 2:  c2ca3ba61 =  2:  4a69f58ff Result from Bolt12Invoice::verify_using_payer_data
 3:  6eee053c6 =  3:  8849efe0d Delay adding iv_bytes to MetadataMaterial::hmac
 4:  1cb22c38a =  4:  293543b7c Use different iv_bytes for blinded path metadata
 5:  535fa4741 !  5:  3e832cbb7 Use BlindedPath::new_for_payment in fuzz tests
    @@ fuzz/src/invoice_request_deser.rs
      use bitcoin::secp256k1::{self, Keypair, Parity, PublicKey, Secp256k1, SecretKey};
      use core::convert::TryFrom;
     -use lightning::blinded_path::message::{ForwardNode, MessageContext, OffersContext};
    -+use lightning::blinded_path::payment::{Bolt12OfferContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
    ++use lightning::blinded_path::payment::{
    ++  Bolt12OfferContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay,
    ++  ReceiveTlvs,
    ++};
      use lightning::blinded_path::BlindedPath;
     +use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
      use lightning::ln::features::BlindedHopFeatures;
    @@ fuzz/src/invoice_request_deser.rs: fn build_response<T: secp256k1::Signing + sec
     +          invoice_request: InvoiceRequestFields {
     +                  payer_id: invoice_request.payer_id(),
     +                  quantity: invoice_request.quantity(),
    -+                  payer_note_truncated: invoice_request.payer_note().map(|s| UntrustedString(s.to_string())),
    ++                  payer_note_truncated: invoice_request
    ++                          .payer_note()
    ++                          .map(|s| UntrustedString(s.to_string())),
     +          },
     +  });
     +  let payee_tlvs = ReceiveTlvs {
    @@ fuzz/src/invoice_request_deser.rs: fn build_response<T: secp256k1::Signing + sec
     -                  fee_proportional_millionths: 1_000,
     -                  cltv_expiry_delta: 42,
     -                  htlc_minimum_msat: 100,
    +-                  htlc_maximum_msat: 1_000_000_000_000,
     +          payment_context,
     +  };
    -+  let intermediate_nodes = [
    -+          ForwardNode {
    -+                  tlvs: ForwardTlvs {
    -+                          short_channel_id: 43,
    -+                          payment_relay: PaymentRelay {
    -+                                  cltv_expiry_delta: 40,
    -+                                  fee_proportional_millionths: 1_000,
    -+                                  fee_base_msat: 1,
    -+                          },
    -+                          payment_constraints: PaymentConstraints {
    -+                                  max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
    -+                                  htlc_minimum_msat: 100,
    -+                          },
    -+                          features: BlindedHopFeatures::empty(),
    ++  let intermediate_nodes = [ForwardNode {
    ++          tlvs: ForwardTlvs {
    ++                  short_channel_id: 43,
    ++                  payment_relay: PaymentRelay {
    ++                          cltv_expiry_delta: 40,
    ++                          fee_proportional_millionths: 1_000,
    ++                          fee_base_msat: 1,
     +                  },
    -+                  node_id: pubkey(43),
    -                   htlc_maximum_msat: 1_000_000_000_000,
    --                  features: BlindedHopFeatures::empty(),
    ++                  payment_constraints: PaymentConstraints {
    ++                          max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
    ++                          htlc_minimum_msat: 100,
    ++                  },
    +                   features: BlindedHopFeatures::empty(),
                },
    -   ];
    +-  ];
    ++          node_id: pubkey(43),
    ++          htlc_maximum_msat: 1_000_000_000_000,
    ++  }];
     +  let payment_path = BlindedPath::new_for_payment(
    -+          &intermediate_nodes, pubkey(42), payee_tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
    -+          &entropy_source, secp_ctx,
    -+  ).unwrap();
    ++          &intermediate_nodes,
    ++          pubkey(42),
    ++          payee_tlvs,
    ++          u64::MAX,
    ++          MIN_FINAL_CLTV_EXPIRY_DELTA,
    ++          &entropy_source,
    ++          secp_ctx,
    ++  )
    ++  .unwrap();

     -  let payment_paths = payinfo.into_iter().zip(paths.into_iter()).collect();
        let payment_hash = PaymentHash([42; 32]);
    @@ fuzz/src/refund_deser.rs
      use bitcoin::secp256k1::{self, Keypair, PublicKey, Secp256k1, SecretKey};
      use core::convert::TryFrom;
     -use lightning::blinded_path::message::{ForwardNode, MessageContext, OffersContext};
    -+use lightning::blinded_path::payment::{Bolt12RefundContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext, PaymentRelay, ReceiveTlvs};
    ++use lightning::blinded_path::payment::{
    ++  Bolt12RefundContext, ForwardNode, ForwardTlvs, PaymentConstraints, PaymentContext,
    ++  PaymentRelay, ReceiveTlvs,
    ++};
      use lightning::blinded_path::BlindedPath;
     +use lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA;
      use lightning::ln::features::BlindedHopFeatures;
    @@ fuzz/src/refund_deser.rs: fn build_response<T: secp256k1::Signing + secp256k1::V
     -                  fee_proportional_millionths: 1_000,
     -                  cltv_expiry_delta: 42,
     -                  htlc_minimum_msat: 100,
    +-                  htlc_maximum_msat: 1_000_000_000_000,
     +          payment_context,
     +  };
    -+  let intermediate_nodes = [
    -+          ForwardNode {
    -+                  tlvs: ForwardTlvs {
    -+                          short_channel_id: 43,
    -+                          payment_relay: PaymentRelay {
    -+                                  cltv_expiry_delta: 40,
    -+                                  fee_proportional_millionths: 1_000,
    -+                                  fee_base_msat: 1,
    -+                          },
    -+                          payment_constraints: PaymentConstraints {
    -+                                  max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
    -+                                  htlc_minimum_msat: 100,
    -+                          },
    -+                          features: BlindedHopFeatures::empty(),
    ++  let intermediate_nodes = [ForwardNode {
    ++          tlvs: ForwardTlvs {
    ++                  short_channel_id: 43,
    ++                  payment_relay: PaymentRelay {
    ++                          cltv_expiry_delta: 40,
    ++                          fee_proportional_millionths: 1_000,
    ++                          fee_base_msat: 1,
     +                  },
    -+                  node_id: pubkey(43),
    -                   htlc_maximum_msat: 1_000_000_000_000,
    --                  features: BlindedHopFeatures::empty(),
    ++                  payment_constraints: PaymentConstraints {
    ++                          max_cltv_expiry: payee_tlvs.payment_constraints.max_cltv_expiry + 40,
    ++                          htlc_minimum_msat: 100,
    ++                  },
    +                   features: BlindedHopFeatures::empty(),
                },
    -   ];
    +-  ];
    ++          node_id: pubkey(43),
    ++          htlc_maximum_msat: 1_000_000_000_000,
    ++  }];
     +  let payment_path = BlindedPath::new_for_payment(
    -+          &intermediate_nodes, pubkey(42), payee_tlvs, u64::MAX, MIN_FINAL_CLTV_EXPIRY_DELTA,
    -+          &entropy_source, secp_ctx,
    -+  ).unwrap();
    ++          &intermediate_nodes,
    ++          pubkey(42),
    ++          payee_tlvs,
    ++          u64::MAX,
    ++          MIN_FINAL_CLTV_EXPIRY_DELTA,
    ++          &entropy_source,
    ++          secp_ctx,
    ++  )
    ++  .unwrap();

     -  let payment_paths = payinfo.into_iter().zip(paths.into_iter()).collect();
        let payment_hash = PaymentHash([42; 32]);
 6:  fd060fbd6 <  -:  --------- f - rustfmt
 7:  4b30d1420 =  6:  2fc0c1b85 Include payment hash when logging InvoiceError
 8:  8fc2aceff =  7:  a5382ddcd Include payment hash when logging invoice handling
 9:  34b2be75b =  8:  d2c22d58c Include payment hash in Bolt12Invoice reply path
10:  9b18b7e26 =  9:  88343366c Replace use of OffersContext::Unknown with None

@TheBlueMatt TheBlueMatt merged commit 85e5e6a into lightningdevkit:main Aug 5, 2024
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants