From 62e9ad11395e44f15f95c0faa571ca00dd213f41 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Tue, 21 Jan 2020 17:36:14 +0100 Subject: [PATCH] sphinx: Fix the broken legacy payload loading from test-vectors We were for some reason encoding all payloads as raw payloads instead of loading legacy payloads into a padded array. --- devtools/onion.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/devtools/onion.c b/devtools/onion.c index 5ebca0578..5a8d53eaf 100644 --- a/devtools/onion.c +++ b/devtools/onion.c @@ -220,15 +220,16 @@ static void runtest(const char *filename) json_to_pubkey(buffer, pubkeytok, &pubkey); if (!typetok || json_tok_streq(buffer, typetok, "legacy")) { /* Legacy has a single 0 prepended as "realm" byte */ - full = tal_arrz(ctx, u8, 1); + full = tal_arrz(ctx, u8, 33); + memcpy(full + 1, payload, tal_bytelen(payload)); } else { /* TLV has length prepended */ full = tal_arr(ctx, u8, 0); towire_bigsize(&full, tal_bytelen(payload)); + prepended = tal_bytelen(full); + tal_resize(&full, prepended + tal_bytelen(payload)); + memcpy(full + prepended, payload, tal_bytelen(payload)); } - prepended = tal_bytelen(full); - tal_resize(&full, prepended + tal_bytelen(payload)); - memcpy(full + prepended, payload, tal_bytelen(payload)); sphinx_add_hop(path, &pubkey, full); } res = create_onionpacket(ctx, path, &shared_secrets);