Skip to content

Commit f4a9aea

Browse files
committed
Re-add one-hop onion message fuzzing test
Revert fuzz test removal in 6dc4223. The test originally checked that OnionMessenger would fail for one-hop blinded paths. The commit added support for such paths, but changing the checks was not sufficient since the node was not connected to the introduction node of the reply path. This is required in order to work with the trivial TestMessageRouter. Fix this by explicitly connecting the nodes.
1 parent e793efe commit f4a9aea

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

fuzz/src/onion_message.rs

+59-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bitcoin::secp256k1::ecdsa::RecoverableSignature;
77
use bitcoin::secp256k1::schnorr;
88

99
use lightning::sign::{Recipient, KeyMaterial, EntropySource, NodeSigner, SignerProvider};
10+
use lightning::ln::features::InitFeatures;
1011
use lightning::ln::msgs::{self, DecodeError, OnionMessageHandler};
1112
use lightning::ln::script::ShutdownScript;
1213
use lightning::offers::invoice::UnsignedBolt12Invoice;
@@ -39,9 +40,20 @@ pub fn do_test<L: Logger>(data: &[u8], logger: &L) {
3940
&keys_manager, &keys_manager, logger, &message_router, &offers_msg_handler,
4041
&custom_msg_handler
4142
);
42-
let mut pk = [2; 33]; pk[1] = 0xff;
43-
let peer_node_id_not_used = PublicKey::from_slice(&pk).unwrap();
44-
onion_messenger.handle_onion_message(&peer_node_id_not_used, &msg);
43+
44+
let peer_node_id = {
45+
let mut secret_bytes = [0; 32];
46+
secret_bytes[31] = 2;
47+
let secret = SecretKey::from_slice(&secret_bytes).unwrap();
48+
PublicKey::from_secret_key(&Secp256k1::signing_only(), &secret)
49+
};
50+
51+
let mut features = InitFeatures::empty();
52+
features.set_onion_messages_optional();
53+
let init = msgs::Init { features, networks: None, remote_network_address: None };
54+
55+
onion_messenger.peer_connected(&peer_node_id, &init, false).unwrap();
56+
onion_messenger.handle_onion_message(&peer_node_id, &msg);
4557
}
4658
}
4759

@@ -211,6 +223,50 @@ mod tests {
211223

212224
#[test]
213225
fn test_no_onion_message_breakage() {
226+
let one_hop_om = "\
227+
020000000000000000000000000000000000000000000000000000000000000e01055600020000000000000\
228+
000000000000000000000000000000000000000000000000e01ae0276020000000000000000000000000000\
229+
000000000000000000000000000000000002020000000000000000000000000000000000000000000000000\
230+
000000000000e0101022a0000000000000000000000000000014551231950b75fc4402da1732fc9bebf0010\
231+
9500000000000000000000000000000004106d000000000000000000000000000000fd1092202a2a2a2a2a2\
232+
a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a0000000000000000000000000000000000\
233+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
234+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
235+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
236+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
237+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
238+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
239+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
240+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
241+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
242+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
243+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
244+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
245+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
246+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
247+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
248+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
249+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
250+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
251+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
252+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
253+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
254+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
255+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
256+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
257+
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\
258+
000000000000000000000000000000000000000005600000000000000000000000000000000000000000000\
259+
000000000000000000";
260+
let logger = TrackingLogger { lines: Mutex::new(HashMap::new()) };
261+
super::do_test(&::hex::decode(one_hop_om).unwrap(), &logger);
262+
{
263+
let log_entries = logger.lines.lock().unwrap();
264+
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
265+
"Received an onion message with path_id None and a reply_path".to_string())), Some(&1));
266+
assert_eq!(log_entries.get(&("lightning::onion_message::messenger".to_string(),
267+
"Sending onion message when responding to Custom onion message with path_id None".to_string())), Some(&1));
268+
}
269+
214270
let two_unblinded_hops_om = "\
215271
020000000000000000000000000000000000000000000000000000000000000e01055600020000000000000\
216272
000000000000000000000000000000000000000000000000e01350433042102020202020202020202020202\

0 commit comments

Comments
 (0)