fuzz: fix ChaCha20 encrypt_single_block to preserve data
What changed, and why it matters
This commit fixes a bug in a fuzzing-only (test-only) fake version of the ChaCha20 encryption code. The fake encryptor accidentally left the output as all zeros instead of copying the input, which caused simulated Lightning payments to fail during testing. The fix makes the test fake copy input to output unchanged. This is not a real cryptographic vulnerability and does not affect production code.
No production action required. Ensure fuzz tests are re-run to confirm payment flows now pass. Consider adding a regression test that verifies encrypt_single_block preserves input data in fuzz builds.
Security signals we found
Test-only fuzz stub bug, not production crypto
Incorrect output buffer handling in encryption helper
Payment flow failure in fuzz tests due to metadata corruption
No real confidentiality/integrity bypass
Evidence from the diff
In lightning/src/crypto/chacha20.rs, the fuzzing stub fuzzy_chacha::ChaCha20::encrypt_single_block omitted copying src to dest, leaving dest as zeroes. This caused payment_secret metadata encryption/decryption round-trips in fuzz tests to produce zeros, leading to payment method mismatches (LdkPaymentHash vs UserPaymentHash) and ‘mismatching preimage’ failures. The patch adds dest.copy_from_slice(src), making the stub an identity transform consistent with the existing process() method. The change is confined to a test/fuzz-only module and has no effect on the real ChaCha20 implementation or production builds.
Changed components
lightning/src/crypto/chacha20.rsfuzzy_chacha fuzzing stubencrypt_single_blockInspect captured patch +1 / −0
diff --git a/lightning/src/crypto/chacha20.rs b/lightning/src/crypto/chacha20.rs
index 5b0c16c..67f9e93 100644
--- a/lightning/src/crypto/chacha20.rs
+++ b/lightning/src/crypto/chacha20.rs
@@ -321,6 +321,7 @@ mod fuzzy_chacha {
) {
debug_assert_eq!(dest.len(), src.len());
debug_assert!(dest.len() <= 32);
+ dest.copy_from_slice(src);
}
pub fn encrypt_single_block_in_place(
Why this scored 27/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.