-
Notifications
You must be signed in to change notification settings - Fork 402
Calculate Trampoline onion packet sizes dynamically. #3333
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
Calculate Trampoline onion packet sizes dynamically. #3333
Conversation
f780f8e
to
85c7d76
Compare
lightning/src/ln/onion_utils.rs
Outdated
let packet_length: usize = payloads | ||
.iter() | ||
.map(|p| { | ||
let mut payload_len = LengthCalculatingWriter(0); | ||
p.write(&mut payload_len).expect("Failed to calculate length"); | ||
payload_len.0 + 32 | ||
}) | ||
.sum(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it harmful for privacy to not use a fixed length?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But we can always pad after the fact, right? Or we can make this an option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the recipient has to read the entire onion anyway, and therefore its potential size is limited by how many outer onion hops came before, and that there are not usually many Trampoline hops, there is a potential limitation of privacy even so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the code be more confusing if we padded after the fact? I'd kinda prefer to review this commit amidst some more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I do think padding after the fact would be more complicated. The context is mostly integration tests against ACINQ, where the current version does not appear to be padding the onion to a fixed size, which we should actually bring up to Bastien. It didn't occur to me yesterday.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3333 +/- ##
==========================================
- Coverage 89.66% 89.60% -0.06%
==========================================
Files 126 126
Lines 102676 102766 +90
Branches 102676 102766 +90
==========================================
+ Hits 92062 92088 +26
- Misses 7894 7943 +49
- Partials 2720 2735 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
7f89095
to
b4da6fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to squash when you next push.
lightning/src/ln/onion_utils.rs
Outdated
payload_len.0.checked_add(32).expect("Excessive payload size") | ||
}) | ||
.try_fold(0usize, |a, b| a.checked_add(b)) | ||
.expect("Excessive onion length"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check + expect rather than just adding? I don't think we're at any real risk of a u64
overflowing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frankly, I've been thinking the same thing. Currently it's in a bit of a limbo state, because even with the checked addition, it's still expecting. So either I should surface it to an Error struct, or allow it to throw immediately. Though you're also right, it's unlikely to happen outside of a fuzz scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure its possible anyway? We'd have to have a huge custom TLV and we should reject that long before we get to this point (or just blame the user for trying to stuff 4GB of garbage down an onion).
b4da6fb
to
f12051f
Compare
f12051f
to
bcfab4b
Compare
bcfab4b
to
2056f92
Compare
2056f92
to
bc899ce
Compare
03ce3c0
to
4077d64
Compare
lightning/src/ln/onion_utils.rs
Outdated
"Trampoline onion packet must be smaller than outer onion" | ||
); | ||
|
||
let packet_length = length.unwrap_or(minimum_packet_length as u16) as usize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let packet_length = length.unwrap_or(minimum_packet_length as u16) as usize; | |
let packet_length = length.map(|l| usize::from(l)).unwrap_or(minimum_packet_length); |
usize::from
guarantees no information loss, as usize
does not.
lightning/src/ln/onion_utils.rs
Outdated
) -> Result<msgs::TrampolineOnionPacket, ()> { | ||
let mut packet_data = vec![0u8; length as usize]; | ||
let minimum_packet_length: usize = payloads.iter().map(|p| p.serialized_length() + 32).sum(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: doesn't seem like : usize
is needed, but I let you make the decision on style - from my point of view, we are talking about lengths here, so not surprising that the type is usize
.
lightning/src/ln/onion_utils.rs
Outdated
|
||
assert!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please no hard assertions unless its gonna result in us losing money. debug assert and handle the err.
4077d64
to
b679944
Compare
LGTM after squash! |
b679944
to
06aea45
Compare
For outbound Trampoline payments, we will need to generate onion packets whose size matches their content. This allows them to be included in individual hops at arbitrary positions. A future spec change may involve defining a static size to improve privacy from Trampoline nodes.
06aea45
to
7c6f220
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I ACK'd already but guess not
b1fc7d8
into
lightningdevkit:main
Given that Trampoline onion sizes will be variable, this obviates the need to pass the onion size a priori.
Builds on top of #3446.