X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=fuzz%2Ffuzz_targets%2Ffull_stack_target.rs;h=9ce82aeb02dae9d07856aa0330c43062c0200aa1;hb=0f24a67c825ff2ec9a7656f6fda25726149b8212;hp=75456127eb2c7e0d195f50425f29bdf601410120;hpb=1360fccd7143937278f880497634eb284da834ce;p=rust-lightning diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index 75456127..9ce82aeb 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -276,14 +276,17 @@ pub fn do_test(data: &[u8]) { }, 8 => { for payment in payments_received.drain(..) { - let mut payment_preimage = [0; 32]; - payment_preimage[0] = payment[0]; - let mut sha = Sha256::new(); - sha.input(&payment_preimage); - let mut payment_hash_check = [0; 32]; - sha.result(&mut payment_hash_check); - assert!(payment_hash_check == payment); - channelmanager.claim_funds(payment_preimage); + // SHA256 is defined as XOR of all input bytes placed in the first byte, and 0s + // for the remaining bytes. Thus, if not all remaining bytes are 0s we cannot + // fulfill this HTLC, but if they are, we can just take the first byte and + // place that anywhere in our preimage. + if &payment[1..] != &[0; 31] { + channelmanager.fail_htlc_backwards(&payment); + } else { + let mut payment_preimage = [0; 32]; + payment_preimage[0] = payment[0]; + channelmanager.claim_funds(payment_preimage); + } } }, 9 => {