Commit Graph

190 Commits

Author SHA1 Message Date
Chandra Pratap
df3043c4ef fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-11-10 15:14:31 +10:30
Chandra Pratap
c684e350f0 fuzz-tests: Add a test for the onion message handler
Changelog-None: `handle_onion_message()` in `connectd/onion_message.c`
is responsible for handling incoming onion messages from a peer.
Since it deals with external input, add a test for it.
2025-11-10 15:14:31 +10:30
Rusty Russell
42f9361375 ccan: update to get improved grab_file API, and adapt code.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Sangbida Chaudhuri
b4984fd94e hsm_encryption: delete hsm_encryption
Changelog-Removed: Remove hsm_encryption files as they have now been replaced by hsm_secret
2025-10-26 12:37:58 +10:30
Rusty Russell
631a8ccdc1 fuzz: translate fuzz-hsm_encryption to fuzz-hsm_secret.
Copy corpora, since it's the same code paths.

Thanks Claude!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-26 12:37:58 +10:30
Rusty Russell
365add06f7 fuzz/fuzz-hsm_encryption: don't run as unit test under valgrind.
Thanks to Argon hashing, this is intolerably slow under valgrind, and
times out under CI.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
2adfdfd0d9 Makefile: run fuzzing corpora as normal unit tests in non-fuzzing mode.
This means we can make sure the compile and run in normal builds.

Side note: various tests call common_setup(), which means we called it
twice in unit testing mode, so we conditionalize those.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
a6ea428294 fuzz: fix build undr FreeBSD.
They have a `struct splice` already:

```
2025-10-22T08:33:39.2432203Z tests/fuzz/fuzz-wire-splice.c:6:8: error: redefinition of 'splice'
2025-10-22T08:33:39.2434453Z     6 | struct splice {
2025-10-22T08:33:39.2435520Z       |        ^
2025-10-22T08:33:39.2436087Z /usr/include/sys/socket.h:683:8: note: previous definition is here
2025-10-22T08:33:39.2436709Z   683 | struct splice {
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
d8ee3a5eb9 tests/fuzz: fix include order.
Nobody ever runs `make check-includes` with fuzzing enabled.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
abe09ec03e common/node_id: runtime assertion override, not separate compile time for fuzzing.
This makes it trivial to run the fuzz tests as unit tests in non-fuzzing mode.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
f6a4e79420 global: remove unnecessary includes from headers.
Each header should only include the other headers it needs to compile;
`devtools/reduce-includes.sh */*.h` does this.  The C files then need
additional includes if they don't compile.

And remove the entirely useless wire/onion_wire.h, which only serves to include wire/onion_wiregen.h.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-10-23 06:44:04 +10:30
Rusty Russell
e120f87083 Makefile: create a library containing common, wire and bitcoin objects.
This means we don't have to manually choose what to link against,
which is much of the complexity of our Makefiles: the compiler will
automatically use any object files it needs to link.

We already do this for ccan as libccan.a, now we have libcommon.a.

We don't link against it for *everything*, as some tests require their own
versions.

Notes:
1. I get rid of the weird plugins/test/Makefile2 (accidental commit?)
2. Many tests change due to update-mocks.
3. In some places I added the missing dependency on the Makefile itself, though most are in the next
   patch.

Before:
	Total program size:     221366528
	Total tests size:       364243856

After:
	Total program size:     190733656
	Total tests size:       337880888

Build time from make clean (RUST=0) (includes building external libs):

Before:
	real    0m38.227000-44.245000(41.8222+/-1.6)s
	user    3m2.105000-33.696000(23.1442+/-8.4)s
	sys     0m35.054000-42.269000(39.7231+/-2)s
After:
	real    0m38.944000-40.416000(40.1131+/-0.4)s
	user    3m6.790000-17.159000(15.0571+/-2.8)s
	sys     0m35.304000-37.336000(36.8942+/-0.57)s

Build time after touch config.vars (RUST=0):

Before:
	real    0m18.928000-22.776000(21.5084+/-1.1)s
	user    2m8.613000-36.567000(27.7281+/-7.7)s
	sys     0m20.458000-23.436000(22.3963+/-0.77)s

After:
	real    0m19.831000-21.862000(21.5528+/-0.58)s
	user    2m15.361000-30.731000(28.4798+/-4.4)s
	sys     0m21.056000-22.339000(22.0346+/-0.35)s

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

rusty@rusty-Framework:~/devel/cvs/lightni
2025-10-23 06:44:04 +10:30
Sangbida Chaudhuri
8578d6cd1b makefile: enable fuzzing support on macOS
Enable fuzzing support on macOS by configuring the build system to use Homebrew LLVM toolchain and handle macOS-specific linking requirements.

The `make check-fuzz` command was failing on macOS because:
- System clang lacks fuzzer runtime library support
- Linking issues with fuzzer targets
- Test script attempts to execute debug symbol files

This PR adds macOS-specific configuration to:
- Use Homebrew LLVM toolchain for fuzzer support
- Explicitly link fuzzer libraries
- Exclude `.dSYM` directories from test discovery

All 76 fuzzer targets now build and pass on macOS.
2025-10-20 14:34:20 +10:30
Rusty Russell
8895ca2982 Revert "update makefile to remove hsm_encryption"
This reverts commit 084b03375c.
2025-10-02 11:08:35 +09:30
Sangbida Chaudhuri
084b03375c update makefile to remove hsm_encryption 2025-10-01 22:59:55 +09:30
Rusty Russell
54444e4337 BOLT12: Update recurrence to latest spec draft.
Changes:
* Fields renumbered to their draft values + billion.
* offer_recurrence now comes in compulsory or optional (backwards compat) flavors.
* `proportional_amount` is now inside `offer_recurrence_base` not `offer_recurrence_paywindow`.
* New field `invreq_recurrence_cancel`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-EXPERIMENTAL: Draft specification for recurring offers changed: old recurring offers will no longer work.
2025-10-01 15:31:30 +09:30
Rusty Russell
9fe8f3ab2e build: suppress amount checking in fuzzing tests.
```
tests/fuzz/fuzz-funder-policy.c:32:	amt.satoshis %= (MAX_SATS + 1);
tests/fuzz/fuzz-funder-policy.c:132:				total.satoshis, tcase->max_channel_size.satoshis);
tests/fuzz/fuzz-funder-policy.c:140:				our_funds.satoshis, tcase->policy.per_channel_min.satoshis);
tests/fuzz/fuzz-funder-policy.c:145:				our_funds.satoshis, tcase->policy.per_channel_max.satoshis);
tests/fuzz/fuzz-funder-policy.c:155:				our_funds.satoshis, tcase->available_funds.satoshis,
tests/fuzz/fuzz-funder-policy.c:156:				tcase->policy.reserve_tank.satoshis);
tests/fuzz/fuzz-funder-policy.c:161:			tcase->policy.reserve_tank.satoshis, tcase->available_funds.satoshis,
tests/fuzz/fuzz-funder-policy.c:162:			our_funds.satoshis);
make: *** [Makefile:577: check-amount-access] Error 1
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2025-09-22 12:43:35 +09:30
Chandra Pratap
cedf2f9d47 fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-09-22 11:03:54 +09:30
Chandra Pratap
d6a7c29af0 fuzz-tests: Add a test for codex32 operations
Changelog-None: Add a test for `codex32_encode()` and
`codex32_secret_decode()` defined in `common/codex32.{c, h}`.
2025-09-22 11:03:54 +09:30
Chandra Pratap
6e16f94443 fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzzing scheme of fuzz-bech32 led to the
discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
2025-09-22 10:23:24 +09:30
Chandra Pratap
b6a1c97c41 fuzz-tests: test 8-to-5 bit conversion
Currently, the test only verifies the 5-to-8 bit conversion. Replace
it with a roundtrip check that verifies 8-to-5 bit conversion as well.
2025-09-22 10:23:24 +09:30
Chandra Pratap
f4fdb1962a fuzz-tests: Test over all possible witness version values
According to `common/bech32.h`, the valid values of witness
program version are between 0 and 16 (inclusive). Update the
test to iterate over all of these values.
2025-09-22 10:23:24 +09:30
Chandra Pratap
83894faa21 fuzz-tests: Replace manual allocations with tal_arr()
Changelog-None: Use the common library utilities for temporary
allocations instead of manually calling `malloc` and `free`.

This makes the code conformant with rest of the codebase and
reduces the chances of leaks.
2025-09-22 10:23:24 +09:30
Chandra Pratap
5cc8d0ad78 fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-09-22 10:21:27 +09:30
Chandra Pratap
48ced70f9a fuzz-tests: Add a test for calculate_our_funding()
Changelog-None: `calculate_our_funding()` in `plugins/funder_policy.c`
is responsible for calculating our funding policy. Add a test for it.
2025-09-22 10:21:27 +09:30
Chandra Pratap
6f4cfedeea fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzzing scheme of `fuzz-close_tx` led to the
discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
2025-09-15 13:43:40 +09:30
Chandra Pratap
20e252b548 fuzz-tests: fix overflow of u32 in fuzz-close-tx
Changelog-None: The value WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX
is equal to 2.1e15, which is much higher than the maximum capacity
of a u32, which is 4.29e9.

Hence, use a u64 to store this value instead.
2025-09-15 13:43:40 +09:30
Chandra Pratap
17cf63aec3 fuzz-tests: Add coverage increasing inputs to seed corpora
Improvements in the fuzz-testing scheme of `fuzz-channel_id led
to the discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
2025-09-15 13:42:38 +09:30
Chandra Pratap
9e341453d5 fuzz-tests: Get rid of magic numbers
Replace instances of 36 with sizeof(outpoint) and 32 with
sizeof(chan_id) since that's what they represent. This makes
the test more future-proof.
2025-09-15 13:42:38 +09:30
Chandra Pratap
bc57dc9b90 fuzz-tests: Make the channel_id wire test roundtrip
Changelog-None: `memcmp()` the output of `towire_channel_id()`
and the input to `fromwire_channel_id()` to ensure that wire
encoding-decoding is correctly performed.
2025-09-15 13:42:38 +09:30
Chandra Pratap
271356f695 fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzzing scheme of `fuzz-bolt11` led to the
discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
2025-09-15 13:39:18 +09:30
Chandra Pratap
2a877633a4 fuzz-tests: Remove unnecessary #includes in the BOLT #11 test
The fuzz target for BOLT #11 has some unnecessary #includes.
Get rid of them.
2025-09-15 13:39:18 +09:30
Chandra Pratap
974af91cc6 fuzz-tests: add a check for bolt11_encode()
Changelog-None: Since `bolt11_decode()` defined in `common/bolt11.c`
is untested by the current BOLT #11 fuzz test, add a test for it.
2025-09-15 13:39:18 +09:30
Chandra Pratap
fc549b3bc8 fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-09-15 11:31:00 +09:30
Chandra Pratap
69a604fca5 fuzz-tests: add a test for handle_peer_error_or_warning()
Changelog-None: `handle_peer_error_or_warning()` in
`common/read_peer_message.{c, h}` is responsible for parsing any
incoming `error` or `warning` messages as defined in BOLT #1.

Add a test for it.
2025-09-15 11:31:00 +09:30
Chandra Pratap
7b4e182fbe fuzz-tests: order FUZZ_COMMON_OBJS lexicographic
The FUZZ_COMMON_OBJS list roughly follows lexicographic
order. Make it adhere strictly to the order. This makes adding
and reviewing changes to the file easier.
2025-09-15 11:31:00 +09:30
Chandra Pratap
3e96f07635 fuzz-tests: Add coverage-increasing inputs to seed corpora
Improvements in the fuzz-testing scheme of fuzz-bigsize led
to the discovery of test inputs that result in greater in
code-coverage. Add these inputs to the test's seed corpus.
2025-09-15 11:30:08 +09:30
Chandra Pratap
66e0d9c285 fuzz-tests: Add a roundtrip check for bigsize_put()
Add a roundtrip check for `bigsize_put()` using `bigsize_get()`.
This enforces a stricter check for the former and adds a test
for the latter, which is currently untested.
2025-09-15 11:30:08 +09:30
Chandra Pratap
8ab0a01e82 fuzz-tests: Replace hardcoded chunk size with iteration over sizes
Changelog-None: The exisiting fuzz test only extracts chunks of
a fixed size (8) from the fuzzer's input. Replace this with an
iteration over a set of chunk sizes (1 to BIGSIZE_MAX_LEN) for
better coverage.

While at it, get rid of the check `if (bs != 0)` because 0 is a
valid value for bigsize_t as well.
2025-09-15 11:30:08 +09:30
Chandra Pratap
a23dcf67f2 fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzz-testing scheme of fuzz-addr led to the
discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
2025-09-15 11:28:20 +09:30
Chandra Pratap
763be38e6d fuzz-tests: verify round‑trip scriptpubkey <-> addr conversion
Changelog-None: Currently, fuzz-addr only tests encoding via
encode_scriptpubkey_to_addr(), without checking decoding. Add a
round‑trip assertion: if encoding produces an address, decode
it back with decode_scriptpubkey_from_addr() and confirm the
result matches the original scriptpubkey.
2025-09-15 11:28:20 +09:30
Chandra Pratap
c7052b7d27 fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-09-15 11:28:07 +09:30
Chandra Pratap
871ae75b5e fuzz-tests: Add fuzz target for closing_sig
Changelog-None: 'closing_signed' and 'closing_sig' are
channel closing negotiation messages defined in BOLT #2.

While 'closing_signed' has a wire fuzz test, 'closing_sig'
does not. Add a test to perform a round-trip encoding check
(towire -> fromwire) similar to the other wire fuzzers.
2025-09-15 11:28:07 +09:30
Chandra Pratap
59ccced19d fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-09-15 11:21:25 +09:30
Chandra Pratap
0b401a92f2 fuzz-tests: Add fuzz target for closing_complete
Changelog-None: 'closing_signed' and 'closing_complete'
are channel closing negotiation messages defined in BOLT #2.

While 'closing_signed' has a wire fuzz test, 'closing_complete'
does not. Add a test to perform a round-trip encoding check
(towire -> fromwire) similar to the other wire fuzzers.
2025-09-15 11:21:25 +09:30
Chandra Pratap
a1c554fd76 fuzz-tests: Add coverage increasing inputs to seed corpora
Improvements in the fuzz-testing scheme of
`fuzz-bolt12-invrequest-decode` led to the discovery of test inputs
that result in greater in code coverage.

Add these inputs to the test's seed corpus.
2025-08-06 13:53:49 +09:30
Chandra Pratap
d9685a6c63 fuzz-tests: Make fuzz-bolt12-invrequest-decode roundrip
Changelog-None: Currently, the `BOLT #12` invrequest parsing test
only tests the invrequest decode function. Add a test for the
encoding function as well by making the test roundtrip.
2025-08-06 13:53:49 +09:30
Chandra Pratap
de5e4fe9ca fuzz-tests: Add a seed corpus for the new test
Add a minimal input set as a seed corpus for the newly introduced
test. This leads to discovery of interesting code paths faster.
2025-07-08 14:47:36 +09:30
Chandra Pratap
61bf4ffc35 fuzz-tests: Add differential test for HMAC-SHA256
Changelog-None: Add a differential fuzz test for
HMAC-SHA256, similar to those for SHA256 and RIPEMD160,
to verify CCAN’s implementation against OpenSSL’s.
2025-07-08 14:47:36 +09:30
Chandra Pratap
0651b37ae4 fuzz-tests: Add coverage-increasing inputs to seed corpora
Change in the fuzz-testing scheme of fuzz-base32-64 led to
the discovery of test inputs that result in greater in
code-coverage. Add these inputs to the test's seed corpus.
2025-07-08 12:54:56 +09:30