Skip to content

Commit 44ddeb9

Browse files
committed
Logging every sent and receive onion message
1 parent d2242f6 commit 44ddeb9

File tree

126 files changed

+7918
-3669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+7918
-3669
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ be covered by functional tests.
8888
When refactoring, structure your PR to make it easy to review and don't
8989
hesitate to split it into multiple small, focused PRs.
9090

91-
The Minimum Supported Rust Version (MSRV) currently is 1.41.1 (enforced by
92-
our GitHub Actions). Also, the compatibility for LDK object serialization is
93-
currently ensured back to and including crate version 0.0.99 (see the
94-
[changelog](CHANGELOG.md)).
91+
The Minimum Supported Rust Version (MSRV) currently is 1.48.0 (enforced by
92+
our GitHub Actions). We support reading serialized LDK objects written by any
93+
version of LDK 0.0.99 and above. We support LDK versions 0.0.113 and above
94+
reading serialized LDK objects written by modern LDK. Any expected issues with
95+
upgrades or downgrades should be mentioned in the [changelog](CHANGELOG.md).
9596

9697
Commits should cover both the issue fixed and the solution's rationale. These
9798
[guidelines](https://chris.beams.io/posts/git-commit/) should be kept in mind.

ci/ci-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
6868
cargo check --verbose --color always --features esplora-async
6969
cargo test --verbose --color always --features esplora-async-https
7070
cargo check --verbose --color always --features esplora-async-https
71+
cargo test --verbose --color always --features electrum
72+
cargo check --verbose --color always --features electrum
7173
popd
7274
fi
7375

fuzz/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ stdin_fuzz = []
2020
[dependencies]
2121
lightning = { path = "../lightning", features = ["regex", "hashbrown", "_test_utils"] }
2222
lightning-rapid-gossip-sync = { path = "../lightning-rapid-gossip-sync" }
23-
bitcoin = { version = "0.29.0", features = ["secp-lowmemory"] }
24-
hex = "0.3"
23+
bitcoin = { version = "0.30.2", features = ["secp-lowmemory"] }
24+
hex = { package = "hex-conservative", version = "0.1.1", default-features = false }
2525
hashbrown = "0.8"
2626

2727
afl = { version = "0.12", optional = true }

fuzz/README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# Fuzzing
22

3-
Fuzz tests generate a ton of random parameter arguments to the program and then validate that none cause it to crash.
3+
Fuzz tests generate a ton of random parameter arguments to the program and then validate that none
4+
cause it to crash.
45

56
## How does it work?
67

7-
Typically, Travis CI will run `travis-fuzz.sh` on one of the environments the automated tests are configured for.
8-
This is the most time-consuming component of the continuous integration workflow, so it is recommended that you detect
9-
issues locally, and Travis merely acts as a sanity check. Fuzzing is further only effective with
10-
a lot of CPU time, indicating that if crash scenarios are discovered on Travis with its low
11-
runtime constraints, the crash is caused relatively easily.
8+
Typically, CI will run `ci-fuzz.sh` on one of the environments the automated tests are
9+
configured for. Fuzzing is further only effective with a lot of CPU time, indicating that if crash
10+
scenarios are discovered on CI with its low runtime constraints, the crash is caused relatively
11+
easily.
1212

1313
## How do I run fuzz tests locally?
1414

15-
You typically won't need to run the entire combination of different fuzzing tools. For local execution, `honggfuzz`
16-
should be more than sufficient.
15+
We support multiple fuzzing engines such as `honggfuzz`, `libFuzzer` and `AFL`. You typically won't
16+
need to run the entire suite of different fuzzing tools. For local execution, `honggfuzz`should be
17+
more than sufficient.
1718

1819
### Setup
19-
20+
#### Honggfuzz
2021
To install `honggfuzz`, simply run
2122

2223
```shell
@@ -31,9 +32,18 @@ cargo update -p honggfuzz --precise "0.5.52"
3132
cargo install --force honggfuzz --version "0.5.52"
3233
```
3334

35+
#### cargo-fuzz / libFuzzer
36+
To install `cargo-fuzz`, simply run
37+
38+
```shell
39+
cargo update
40+
cargo install --force cargo-fuzz
41+
```
42+
3443
### Execution
3544

36-
To run the Hongg fuzzer, do
45+
#### Honggfuzz
46+
To run fuzzing using `honggfuzz`, do
3747

3848
```shell
3949
export CPU_COUNT=1 # replace as needed
@@ -46,33 +56,53 @@ cargo hfuzz run $TARGET
4656

4757
(Or, for a prettier output, replace the last line with `cargo --color always hfuzz run $TARGET`.)
4858

59+
#### cargo-fuzz / libFuzzer
60+
To run fuzzing using `cargo-fuzz / libFuzzer`, run
61+
62+
```shell
63+
rustup install nightly # Note: libFuzzer requires a nightly version of rust.
64+
cargo +nightly fuzz run --features "libfuzzer_fuzz" msg_ping_target
65+
```
66+
Note: If you encounter a `SIGKILL` during run/build check for OOM in kernel logs and consider
67+
increasing RAM size for VM.
68+
69+
If you wish to just generate fuzzing binary executables for `libFuzzer` and not run them:
70+
```shell
71+
cargo +nightly fuzz build --features "libfuzzer_fuzz" msg_ping_target
72+
# Generates binary artifact in path ./target/aarch64-unknown-linux-gnu/release/msg_ping_target
73+
# Exact path depends on your system architecture.
74+
```
75+
You can upload the build artifact generated above to `ClusterFuzz` for distributed fuzzing.
76+
77+
### List Fuzzing Targets
4978
To see a list of available fuzzing targets, run:
5079

5180
```shell
5281
ls ./src/bin/
5382
```
5483

55-
## A fuzz test failed on Travis, what do I do?
84+
## A fuzz test failed, what do I do?
5685

57-
You're trying to create a PR, but need to find the underlying cause of that pesky fuzz failure blocking the merge?
86+
You're trying to create a PR, but need to find the underlying cause of that pesky fuzz failure
87+
blocking the merge?
5888

5989
Worry not, for this is easily traced.
6090

61-
If your Travis output log looks like this:
91+
If your output log looks like this:
6292

6393
```
6494
Size:639 (i,b,hw,ed,ip,cmp): 0/0/0/0/0/1, Tot:0/0/0/2036/5/28604
6595
Seen a crash. Terminating all fuzzing threads
6696
6797
… # a lot of lines in between
6898
69-
<0x0000555555565559> [func:UNKNOWN file: line:0 module:/home/travis/build/rust-bitcoin/rust-lightning/fuzz/hfuzz_target/x86_64-unknown-linux-gnu/release/full_stack_target]
99+
<0x0000555555565559> [func:UNKNOWN file: line:0 module:./rust-lightning/fuzz/hfuzz_target/x86_64-unknown-linux-gnu/release/full_stack_target]
70100
<0x0000000000000000> [func:UNKNOWN file: line:0 module:UNKNOWN]
71101
=====================================================================
72102
2d3136383734090101010101010101010101010101010101010101010101
73103
010101010100040101010101010101010101010103010101010100010101
74104
0069d07c319a4961
75-
The command "if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./travis-fuzz.sh; fi" exited with 1.
105+
The command "if [ "$(rustup show | grep default | grep stable)" != "" ]; then cd fuzz && cargo test --verbose && ./ci-fuzz.sh; fi" exited with 1.
76106
```
77107

78108
Note that the penultimate stack trace line ends in `release/full_stack_target]`. That indicates that

fuzz/src/bin/gen_target.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,9 @@ GEN_TEST msg_tx_signatures msg_targets::
7070
GEN_TEST msg_tx_init_rbf msg_targets::
7171
GEN_TEST msg_tx_ack_rbf msg_targets::
7272
GEN_TEST msg_tx_abort msg_targets::
73+
74+
GEN_TEST msg_stfu msg_targets::
75+
76+
GEN_TEST msg_splice msg_targets::
77+
GEN_TEST msg_splice_ack msg_targets::
78+
GEN_TEST msg_splice_locked msg_targets::

fuzz/src/bin/msg_splice_ack_target.rs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
#[cfg(not(fuzzing))]
16+
compile_error!("Fuzz targets need cfg=fuzzing");
17+
18+
extern crate lightning_fuzz;
19+
use lightning_fuzz::msg_targets::msg_splice_ack::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
msg_splice_ack_run(data.as_ptr(), data.len());
27+
});
28+
}
29+
30+
#[cfg(feature = "honggfuzz")]
31+
#[macro_use] extern crate honggfuzz;
32+
#[cfg(feature = "honggfuzz")]
33+
fn main() {
34+
loop {
35+
fuzz!(|data| {
36+
msg_splice_ack_run(data.as_ptr(), data.len());
37+
});
38+
}
39+
}
40+
41+
#[cfg(feature = "libfuzzer_fuzz")]
42+
#[macro_use] extern crate libfuzzer_sys;
43+
#[cfg(feature = "libfuzzer_fuzz")]
44+
fuzz_target!(|data: &[u8]| {
45+
msg_splice_ack_run(data.as_ptr(), data.len());
46+
});
47+
48+
#[cfg(feature = "stdin_fuzz")]
49+
fn main() {
50+
use std::io::Read;
51+
52+
let mut data = Vec::with_capacity(8192);
53+
std::io::stdin().read_to_end(&mut data).unwrap();
54+
msg_splice_ack_run(data.as_ptr(), data.len());
55+
}
56+
57+
#[test]
58+
fn run_test_cases() {
59+
use std::fs;
60+
use std::io::Read;
61+
use lightning_fuzz::utils::test_logger::StringBuffer;
62+
63+
use std::sync::{atomic, Arc};
64+
{
65+
let data: Vec<u8> = vec![0];
66+
msg_splice_ack_run(data.as_ptr(), data.len());
67+
}
68+
let mut threads = Vec::new();
69+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
70+
if let Ok(tests) = fs::read_dir("test_cases/msg_splice_ack") {
71+
for test in tests {
72+
let mut data: Vec<u8> = Vec::new();
73+
let path = test.unwrap().path();
74+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
75+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
76+
77+
let thread_count_ref = Arc::clone(&threads_running);
78+
let main_thread_ref = std::thread::current();
79+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
80+
std::thread::spawn(move || {
81+
let string_logger = StringBuffer::new();
82+
83+
let panic_logger = string_logger.clone();
84+
let res = if ::std::panic::catch_unwind(move || {
85+
msg_splice_ack_test(&data, panic_logger);
86+
}).is_err() {
87+
Some(string_logger.into_string())
88+
} else { None };
89+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
90+
main_thread_ref.unpark();
91+
res
92+
})
93+
));
94+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
95+
std::thread::park();
96+
}
97+
}
98+
}
99+
let mut failed_outputs = Vec::new();
100+
for (test, thread) in threads.drain(..) {
101+
if let Some(output) = thread.join().unwrap() {
102+
println!("\nOutput of {}:\n{}\n", test, output);
103+
failed_outputs.push(test);
104+
}
105+
}
106+
if !failed_outputs.is_empty() {
107+
println!("Test cases which failed: ");
108+
for case in failed_outputs {
109+
println!("{}", case);
110+
}
111+
panic!();
112+
}
113+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// This file is Copyright its original authors, visible in version control
2+
// history.
3+
//
4+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7+
// You may not use this file except in accordance with one or both of these
8+
// licenses.
9+
10+
// This file is auto-generated by gen_target.sh based on target_template.txt
11+
// To modify it, modify target_template.txt and run gen_target.sh instead.
12+
13+
#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
14+
15+
#[cfg(not(fuzzing))]
16+
compile_error!("Fuzz targets need cfg=fuzzing");
17+
18+
extern crate lightning_fuzz;
19+
use lightning_fuzz::msg_targets::msg_splice_locked::*;
20+
21+
#[cfg(feature = "afl")]
22+
#[macro_use] extern crate afl;
23+
#[cfg(feature = "afl")]
24+
fn main() {
25+
fuzz!(|data| {
26+
msg_splice_locked_run(data.as_ptr(), data.len());
27+
});
28+
}
29+
30+
#[cfg(feature = "honggfuzz")]
31+
#[macro_use] extern crate honggfuzz;
32+
#[cfg(feature = "honggfuzz")]
33+
fn main() {
34+
loop {
35+
fuzz!(|data| {
36+
msg_splice_locked_run(data.as_ptr(), data.len());
37+
});
38+
}
39+
}
40+
41+
#[cfg(feature = "libfuzzer_fuzz")]
42+
#[macro_use] extern crate libfuzzer_sys;
43+
#[cfg(feature = "libfuzzer_fuzz")]
44+
fuzz_target!(|data: &[u8]| {
45+
msg_splice_locked_run(data.as_ptr(), data.len());
46+
});
47+
48+
#[cfg(feature = "stdin_fuzz")]
49+
fn main() {
50+
use std::io::Read;
51+
52+
let mut data = Vec::with_capacity(8192);
53+
std::io::stdin().read_to_end(&mut data).unwrap();
54+
msg_splice_locked_run(data.as_ptr(), data.len());
55+
}
56+
57+
#[test]
58+
fn run_test_cases() {
59+
use std::fs;
60+
use std::io::Read;
61+
use lightning_fuzz::utils::test_logger::StringBuffer;
62+
63+
use std::sync::{atomic, Arc};
64+
{
65+
let data: Vec<u8> = vec![0];
66+
msg_splice_locked_run(data.as_ptr(), data.len());
67+
}
68+
let mut threads = Vec::new();
69+
let threads_running = Arc::new(atomic::AtomicUsize::new(0));
70+
if let Ok(tests) = fs::read_dir("test_cases/msg_splice_locked") {
71+
for test in tests {
72+
let mut data: Vec<u8> = Vec::new();
73+
let path = test.unwrap().path();
74+
fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
75+
threads_running.fetch_add(1, atomic::Ordering::AcqRel);
76+
77+
let thread_count_ref = Arc::clone(&threads_running);
78+
let main_thread_ref = std::thread::current();
79+
threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
80+
std::thread::spawn(move || {
81+
let string_logger = StringBuffer::new();
82+
83+
let panic_logger = string_logger.clone();
84+
let res = if ::std::panic::catch_unwind(move || {
85+
msg_splice_locked_test(&data, panic_logger);
86+
}).is_err() {
87+
Some(string_logger.into_string())
88+
} else { None };
89+
thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
90+
main_thread_ref.unpark();
91+
res
92+
})
93+
));
94+
while threads_running.load(atomic::Ordering::Acquire) > 32 {
95+
std::thread::park();
96+
}
97+
}
98+
}
99+
let mut failed_outputs = Vec::new();
100+
for (test, thread) in threads.drain(..) {
101+
if let Some(output) = thread.join().unwrap() {
102+
println!("\nOutput of {}:\n{}\n", test, output);
103+
failed_outputs.push(test);
104+
}
105+
}
106+
if !failed_outputs.is_empty() {
107+
println!("Test cases which failed: ");
108+
for case in failed_outputs {
109+
println!("{}", case);
110+
}
111+
panic!();
112+
}
113+
}

0 commit comments

Comments
 (0)