Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routing: Add Validation for Decoding Blinded Paths #8142

Merged
merged 12 commits into from
Jan 3, 2024

Conversation

carlaKC
Copy link
Collaborator

@carlaKC carlaKC commented Nov 1, 2023

Fixes #8137 and expands validation of blinded routes.

As outlined in the original issue, the fuzzer ran into the following problems:

  • We allow creation of blinded route payloads in PackHopPayload.
  • We do not allow deserialization of the payloads in NewPayloadFromReader because LND doesn't support forwarding blinded routes.

This PR updates validation to be consistent across all validation functions.

A few of the commits in the beginning of the PR are just fixing up test data to be more accurate before stricter validation is implemented. They're included separately to make sure that they pass with the new and old code.

@carlaKC
Copy link
Collaborator Author

carlaKC commented Nov 1, 2023

@morehouse opening this up early for a first look, specifically want to make sure that I'm grasping the fuzz test properly:

  • With the introduction of blinded routes, we use external context (ie the sphinx packet) to determine whether a hop belongs to the final node (previously we used the nextChanID context that is provided within the payload).
  • We need to tell the fuzzer this external context so that is can create and test valid payloads for that specific context (previously we were just inferring from whatever value the fuzzer gave us for nextChanID)

To do this, I've split fuzzing up into final and non-final tests, but I'm not sure that it's the best-practice way of doing things? I could also pull a byte off the fuzzing data to decide this context?

@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from 5585186 to a85d723 Compare November 2, 2023 19:06
htlcswitch/hop/iterator_test.go Show resolved Hide resolved
routing/route/route.go Outdated Show resolved Hide resolved
routing/route/route.go Outdated Show resolved Hide resolved
routing/route/route.go Outdated Show resolved Hide resolved
htlcswitch/hop/payload.go Show resolved Hide resolved
@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch 3 times, most recently from 9405c80 to df88cc2 Compare November 3, 2023 18:33
@saubyk saubyk added the routing label Nov 5, 2023
@saubyk saubyk added this to the v0.18.0 milestone Nov 5, 2023
@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from df88cc2 to 3f01dba Compare November 6, 2023 15:37
htlcswitch/hop/payload.go Outdated Show resolved Hide resolved
htlcswitch/hop/payload.go Outdated Show resolved Hide resolved
htlcswitch/hop/payload_test.go Show resolved Hide resolved
htlcswitch/hop/fuzz_test.go Outdated Show resolved Hide resolved
htlcswitch/hop/payload.go Show resolved Hide resolved
@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from 3f01dba to 8b55b2d Compare November 6, 2023 20:13
@morehouse
Copy link
Collaborator

Code looks good and the fuzz test seems happy again (mostly). There's another small change that needs to be made to the fuzz tests to accommodate the route blinding stuff, but it doesn't belong in this PR. I'll send a separate PR once this one is merged.

I'll run the fuzz tests overnight to check for any other problems, and do a final review tomorrow if everything passes.

There' a couple small unresolved comments, but nothing blocking.

@saubyk
Copy link
Collaborator

saubyk commented Nov 30, 2023

cc: @ziggie1984 for review

Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition of validation logic when creating/parsing the payload data.

PR looks really good 👏, just had some minor nits

For me personally I found the commit splitting a bit too fine granular because all these small testcase commits in the beginning were clear to me after I reviewed the commit where the validation logic was added.

routing/route/route_test.go Show resolved Hide resolved
htlcswitch/hop/iterator_test.go Outdated Show resolved Hide resolved
htlcswitch/hop/payload_test.go Show resolved Hide resolved
routing/route/route.go Outdated Show resolved Hide resolved
routing/route/route.go Outdated Show resolved Hide resolved
routing/route/route_test.go Outdated Show resolved Hide resolved
routing/route/route_test.go Outdated Show resolved Hide resolved
htlcswitch/hop/fuzz_test.go Show resolved Hide resolved
@lightninglabs-deploy
Copy link

@carlaKC, remember to re-request review from reviewers when ready

@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from 8b55b2d to e1db579 Compare December 12, 2023 14:47
Add the missing channel field to the final hop in our clear text
route test case. Note that this is the channel of the hop. With the
addition of stricter validation, we'll need this so that the
penultimate hop has a non-zero next channel ID.
Blinding points will always be accompanied by encrypted data, so
update the test to more accurately represent reality.
@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from e1db579 to eec6795 Compare December 12, 2023 15:02
@carlaKC carlaKC requested a review from ziggie1984 December 12, 2023 15:03
Copy link
Collaborator

@ziggie1984 ziggie1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean and great PR: LGTM ⚡️

htlcswitch/hop/iterator_test.go Outdated Show resolved Hide resolved
routing/route/route_test.go Show resolved Hide resolved
htlcswitch/hop/payload_test.go Show resolved Hide resolved
Update test to include the sphinx action to more closely represent
reality. This will be required when we add more validation to the
presence of a nextChanID field. A MoreHops action is chose because
we're testing the case with a payload that contains forwarding info.
Provide valid hop payloads for tests cases that use TLV onion format.
Previously, we were using nextChanID to determine whether a hop
payload is for the final recipient. This is no longer suitable in a
route-blinding world where intermediate hops are allowed to have zero
nextChanID TLVs (as this information is provided to forwarding nodes
in their encrypted data). This commit updates payload reading to use
the signal provided by sphinx that we are on the last packet, rather
than implying it from the contents of a hop.
Previously, we'd use the value of nextChanID to infer whether a payload
was for the final hop in a route. This commit updates our packing logic
to explicitly signal to account for blinded routes, which allow zero
value nextChanID in intermediate hops. This is a preparatory commit
that allows us to more thoroughly validate payloads.
Fix our existing test to have a valid intermediate hop that will pass
stricter validation. Previously, we did not specify a next channel for
an intermediate hop (which violates bolt4).
@carlaKC carlaKC force-pushed the 8137-validateblindedpayload branch from eec6795 to 31d4242 Compare December 18, 2023 16:28
@carlaKC
Copy link
Collaborator Author

carlaKC commented Dec 18, 2023

Pushed comment change + additional test case for validation.

@Roasbeef Roasbeef merged commit cedbdd8 into lightningnetwork:master Jan 3, 2024
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[bug]: blinded forwarding: hop encoding / payload decoding inconsistency
6 participants