Skip to content

Commit 50cbac6

Browse files
committed
fixup! sphinx_test: add test for blinded route processing
1 parent 050f04e commit 50cbac6

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

path_test.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ func TestOnionMessageRouteBlinding(t *testing.T) {
403403
require.NoError(t, err)
404404

405405
// Once we have the raw file, we'll unpack it into our
406-
// onionMessageJsonTestCase struct defined above.
406+
// onionMessageJsonTestCase struct defined below.
407407
testCase := &onionMessageJsonTestCase{}
408408
require.NoError(t, json.Unmarshal(jsonBytes, testCase))
409409

@@ -426,6 +426,10 @@ func TestOnionMessageRouteBlinding(t *testing.T) {
426426
require.NoError(t, r.Start())
427427
defer r.Stop()
428428

429+
// Onion messages don't use associated data, so we pass in nil
430+
// here. Also, we set a random value for incomingCLTV as it's
431+
// only used as an accompanying purposefully general type in the
432+
// ReplayLog.
429433
res, err := r.ProcessOnionPacket(
430434
onionPacket, nil, 10,
431435
WithBlindingPoint(blindingPoint),
@@ -437,26 +441,30 @@ func TestOnionMessageRouteBlinding(t *testing.T) {
437441

438442
hops := testCase.Generate.Hops
439443

440-
// There are some things that the processor of the onion packet will
441-
// only be able to determine from the actual contents of the encrypted
442-
// data it receives. These things include the next_blinding_point for
443-
// the introduction point and the next_blinding_override. The decryption
444-
// of this data is dependent on the encoding chosen by higher layers.
445-
// The test uses TLVs. Since the extraction of this data is dependent
446-
// on layers outside the scope of this library, we provide handle these
447-
// cases manually for the sake of the test.
444+
// There are some things that the processor of the onion will only be
445+
// able to determine from the actual contents of the onion_message and
446+
// the encrypted_recipient_date it receives. These things include the
447+
// first_path_key for the introduction point and the
448+
// next_path_key_override. This test doesn't decode the onion_message
449+
// and the decryption of the encrypted_recipient_data so it doesn't
450+
// extract these values. Instead we provide them manually. It also needs
451+
// to know where the next_path_key_override is located in the route,
452+
// hence it needs the concatIndex, where the part of the blinded route
453+
// constructed by Dave starts.
448454
var (
449-
firstBlinding = pubKeyFromString(testCase.Route.FirstPathKey)
450-
concatIndex = 1
451-
blindingOverride = pubKeyFromString(
455+
firstPathKey = pubKeyFromString(
456+
testCase.Route.FirstPathKey,
457+
)
458+
concatIndex = 1
459+
nextPathKeyOverride = pubKeyFromString(
452460
hops[0].EncodedOnionMessageTLVs.NextPathKeyOverride,
453461
)
454462
)
455463

456-
// Onion message routes are always entirely blinded, so
457-
// the first hop will always use the first blinding
458-
// point.
459-
blindingPoint := firstBlinding
464+
// Onion message routes are always entirely blinded, so the first hop
465+
// will always use the first path key.
466+
pathKey := firstPathKey
467+
460468
currentOnionPacket := onionPacket
461469
for i, hop := range testCase.Decrypt.Hops {
462470
// We encode the onion message packet to a buffer at each hop to
@@ -480,23 +488,23 @@ func TestOnionMessageRouteBlinding(t *testing.T) {
480488
priv := privKeyFromString(hop.PrivKey)
481489

482490
if i == concatIndex {
483-
blindingPoint = blindingOverride
491+
pathKey = nextPathKeyOverride
484492
}
485493

486494
// With peelOnion we call into ProcessOnionPacket (with the
487495
// functional option WithBlindingPoint) and we expect that the
488496
// onion message packet for this hop is processed without error,
489497
// otherwise peelOnion fails the test.
490498
processedPkt := peelOnion(
491-
priv, blindingPoint, currentOnionPacket,
499+
priv, pathKey, currentOnionPacket,
492500
)
493501

494-
// We derive the next blinding point from the current blinding
495-
// point and the private key of the current hop. The new
496-
// blindingPoint will be used to peel the next hop's onion
497-
// unless it is overridden by a blinding override.
498-
blindingPoint, err = NextEphemeral(
499-
&PrivKeyECDH{priv}, blindingPoint,
502+
// We derive the next path key from the current path key and the
503+
// private key of the current hop. The new path key will be used
504+
// to peel the next hop's onion unless it is overridden by a
505+
// path key override.
506+
pathKey, err = NextEphemeral(
507+
&PrivKeyECDH{priv}, pathKey,
500508
)
501509
require.NoError(t, err)
502510

@@ -568,6 +576,7 @@ type routeOnionMessageData struct {
568576
Hops []blindedOnionMessageHop `json:"hops"`
569577
}
570578

579+
//nolint:tagliatelle
571580
type onionMessageData struct {
572581
OnionMessagePacket string `json:"onion_message_packet"`
573582
}

0 commit comments

Comments
 (0)