-
Notifications
You must be signed in to change notification settings - Fork 470
[RFC] Add BOLT 12 payer proof primitives #4297
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
Open
vincenzopalazzo
wants to merge
16
commits into
lightningdevkit:main
Choose a base branch
from
vincenzopalazzo:macros/proof-of-payment-bolt12-spec
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f1eb03b
refactor(offers): extract payer key derivation helpers
vincenzopalazzo 8ed07f4
offers: add merkle selective-disclosure primitives
vincenzopalazzo 9398884
offers: add BOLT 12 payer proof primitives
vincenzopalazzo 011a1df
ln: persist the paid BOLT 12 invoice and build payer proofs
vincenzopalazzo 56ab271
fuzz: add a payer proof deserialization target
vincenzopalazzo 7d2749c
fixup! offers: add merkle selective-disclosure primitives
vincenzopalazzo 91e0be8
fixup! ln: persist the paid BOLT 12 invoice and build payer proofs
vincenzopalazzo b551b2b
fixup! offers: add BOLT 12 payer proof primitives
vincenzopalazzo 7025881
fixup! fuzz: add a payer proof deserialization target
vincenzopalazzo 15f658f
fixup! offers: add merkle selective-disclosure primitives
vincenzopalazzo f579ade
fixup! offers: add BOLT 12 payer proof primitives
vincenzopalazzo 564d463
fixup! offers: add merkle selective-disclosure primitives
vincenzopalazzo 679de69
fixup! ln: persist the paid BOLT 12 invoice and build payer proofs
vincenzopalazzo e06b2eb
fixup! offers: add merkle selective-disclosure primitives
vincenzopalazzo aced065
fixup! fixup! offers: add merkle selective-disclosure primitives
vincenzopalazzo 7c0b296
fixup! refactor(offers): extract payer key derivation helpers
vincenzopalazzo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
fuzz/fuzz-fake-hashes/src/bin/payer_proof_deser_target.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| // This file is auto-generated by gen_target.sh based on target_template.txt | ||
| // To modify it, modify target_template.txt and run gen_target.sh instead. | ||
|
|
||
| #![cfg_attr(feature = "libfuzzer_fuzz", no_main)] | ||
| #![cfg_attr(rustfmt, rustfmt_skip)] | ||
|
|
||
| #[cfg(not(fuzzing))] | ||
| compile_error!("Fuzz targets need cfg=fuzzing"); | ||
|
|
||
| #[cfg(not(hashes_fuzz))] | ||
| compile_error!("Fuzz target does not support cfg(not(hashes_fuzz))"); | ||
|
|
||
| #[cfg(not(secp256k1_fuzz))] | ||
| compile_error!("Fuzz targets need cfg=secp256k1_fuzz"); | ||
|
|
||
| extern crate lightning_fuzz; | ||
| use lightning_fuzz::payer_proof_deser::*; | ||
| use lightning_fuzz::utils::test_logger; | ||
|
|
||
| #[cfg(feature = "afl")] | ||
| #[macro_use] extern crate afl; | ||
| #[cfg(feature = "afl")] | ||
| fn main() { | ||
| fuzz!(|data| { | ||
| payer_proof_deser_test(&data, test_logger::DevNull {}); | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(feature = "honggfuzz")] | ||
| #[macro_use] extern crate honggfuzz; | ||
| #[cfg(feature = "honggfuzz")] | ||
| fn main() { | ||
| loop { | ||
| fuzz!(|data| { | ||
| payer_proof_deser_test(&data, test_logger::DevNull {}); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "libfuzzer_fuzz")] | ||
| #[macro_use] extern crate libfuzzer_sys; | ||
| #[cfg(feature = "libfuzzer_fuzz")] | ||
| fuzz_target!(|data: &[u8]| { | ||
| payer_proof_deser_test(data, test_logger::DevNull {}); | ||
| }); | ||
|
|
||
| #[cfg(feature = "stdin_fuzz")] | ||
| fn main() { | ||
| use std::io::Read; | ||
|
|
||
| // On macOS, panic=abort causes the process to send SIGABRT which can leave it | ||
| // stuck in an uninterruptible state due to the ReportCrash daemon. Using | ||
| // process::exit in a panic hook avoids this by terminating cleanly. | ||
| #[cfg(target_os = "macos")] | ||
| std::panic::set_hook(Box::new(|panic_info| { | ||
| use std::io::Write; | ||
| let _ = std::io::stdout().flush(); | ||
| eprintln!("{}\n{}", panic_info, std::backtrace::Backtrace::force_capture()); | ||
| let _ = std::io::stderr().flush(); | ||
| std::process::exit(1); | ||
| })); | ||
|
|
||
| let mut data = Vec::with_capacity(8192); | ||
| std::io::stdin().read_to_end(&mut data).unwrap(); | ||
| payer_proof_deser_test(&data, test_logger::Stdout {}); | ||
| } | ||
|
|
||
| #[test] | ||
| fn run_test_cases() { | ||
| use std::fs; | ||
| use std::io::Read; | ||
| use lightning_fuzz::utils::test_logger::StringBuffer; | ||
|
|
||
| use std::sync::{atomic, Arc}; | ||
| { | ||
| let data: Vec<u8> = vec![0]; | ||
| payer_proof_deser_test(&data, test_logger::DevNull {}); | ||
| } | ||
| let mut threads = Vec::new(); | ||
| let threads_running = Arc::new(atomic::AtomicUsize::new(0)); | ||
| if let Ok(tests) = fs::read_dir("../test_cases/payer_proof_deser") { | ||
| for test in tests { | ||
| let mut data: Vec<u8> = Vec::new(); | ||
| let path = test.unwrap().path(); | ||
| fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap(); | ||
| threads_running.fetch_add(1, atomic::Ordering::AcqRel); | ||
|
|
||
| let thread_count_ref = Arc::clone(&threads_running); | ||
| let main_thread_ref = std::thread::current(); | ||
| threads.push((path.file_name().unwrap().to_str().unwrap().to_string(), | ||
| std::thread::spawn(move || { | ||
| let string_logger = StringBuffer::new(); | ||
|
|
||
| let panic_logger = string_logger.clone(); | ||
| let res = if ::std::panic::catch_unwind(move || { | ||
| payer_proof_deser_test(&data, panic_logger); | ||
| }).is_err() { | ||
| Some(string_logger.into_string()) | ||
| } else { None }; | ||
| thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel); | ||
| main_thread_ref.unpark(); | ||
| res | ||
| }) | ||
| )); | ||
| while threads_running.load(atomic::Ordering::Acquire) > 32 { | ||
| std::thread::park(); | ||
| } | ||
| } | ||
| } | ||
| let mut failed_outputs = Vec::new(); | ||
| for (test, thread) in threads.drain(..) { | ||
| if let Some(output) = thread.join().unwrap() { | ||
| println!("\nOutput of {}:\n{}\n", test, output); | ||
| failed_outputs.push(test); | ||
| } | ||
| } | ||
| if !failed_outputs.is_empty() { | ||
| println!("Test cases which failed: "); | ||
| for case in failed_outputs { | ||
| println!("{}", case); | ||
| } | ||
| panic!(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // This file is Copyright its original authors, visible in version control | ||
| // history. | ||
| // | ||
| // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE | ||
| // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option. | ||
| // You may not use this file except in accordance with one or both of these | ||
| // licenses. | ||
|
|
||
| use crate::utils::test_logger; | ||
| use core::convert::TryFrom; | ||
| use lightning::offers::payer_proof::PayerProof; | ||
| use lightning::util::ser::Writeable; | ||
|
|
||
| #[inline] | ||
| pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) { | ||
| if let Ok(payer_proof) = PayerProof::try_from(data.to_vec()) { | ||
| let mut bytes = Vec::with_capacity(data.len()); | ||
| payer_proof.write(&mut bytes).unwrap(); | ||
| assert_eq!(data, bytes); | ||
| } | ||
| } | ||
|
|
||
| pub fn payer_proof_deser_test<Out: test_logger::Output>(data: &[u8], out: Out) { | ||
| do_test(data, out); | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub extern "C" fn payer_proof_deser_run(data: *const u8, datalen: usize) { | ||
| do_test(unsafe { std::slice::from_raw_parts(data, datalen) }, test_logger::DevNull {}); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also update the invoice fuzzer to build a payer proof, just like how the offer fuzzer builds an invoice request and how the invoice request fuzzer builds an invoice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preimage gate makes this a no-op if I put it in
invoice_deser. Building a proof requiresSHA256(preimage) == invoice.payment_hash(), andinvoice_deserparses arbitrary invoices, so we never hold a matching preimage.prove_payer()returnsPreimageMismatchbefore any of the interesting code runs (build_unsigned doesn't even re-check the invoice signature, the preimage is the only gate), so we'd just be exercising the early error return.Claude help me find the place where we actually control the payment hash is
invoice_request_deser, since it builds the invoice itself via respond_with(paths, payment_hash). If I set payment_hash = SHA256(known_preimage) there, I can chain a full payer proof build+sign right after the invoice is signed, which exercises the selective disclosure, merkle tree, and proof signing for real.Want me to add it in invoice_request_deser that way? Or do you still want the call in invoice_deser even though it only ever hits PreimageMismatch?