fix: use bounded incoming message buffers for all protocols#2268
fix: use bounded incoming message buffers for all protocols#2268
Conversation
b5605db to
362dfd8
Compare
Code ReviewSolid fix for the OOM DoS vector (issue #2247). The approach of bounding per-protocol incoming message buffers with protocol-specific constants is well-designed. The formula derivation for triple generation is clearly documented, and the test coverage across all protocol variants is thorough. One observation worth noting (not blocking):
No critical issues found. ✅ Approved |
e8ce1ed to
0b9e5d5
Compare
|
@claude review |
|
PR title type suggestion: This PR introduces bounded message buffers as a new defensive feature/systematic improvement across all protocols, rather than fixing an existing bug. The type should probably be Suggested title: |
Code ReviewThis is a well-designed fix for the OOM DoS vector. The bounded buffer approach with protocol-specific constants is sound, and the test coverage is thorough. A few observations:
No other critical issues found. Safe arithmetic is used in the formula computation, the ✅ Approved |
kevindeforth
left a comment
There was a problem hiding this comment.
Thank you!
Only nits.
| pub(crate) const REDJUBJUB_SIGN_MAX_INCOMING_COORDINATOR_ENTRIES: usize = 1; | ||
| /// Maximum incoming buffer entries for non-coordinator participants in the `RedJubjub` sign protocol. | ||
| #[cfg(test)] | ||
| pub(crate) const REDJUBJUB_SIGN_MAX_INCOMING_PARTICIPANT_ENTRIES: usize = 1; |
There was a problem hiding this comment.
do we need this somewhere else, or could we define it inside the test module?
There was a problem hiding this comment.
left it there just to keep some uniformity. atm it could be just in the test module as you mention
SimonRastikian
left a comment
There was a problem hiding this comment.
I reviewed most of the PR.
As explained in the meeting, we all know this is not the cleanest solution. I hope you could open an Issue describing a cleaner way to solve it. (This is independent of my approval)
The changes I hope to see is more helper functions that cleanup the code. Otherwise thanks for takling this.
crates/threshold-signatures/src/confidential_key_derivation/protocol.rs
Outdated
Show resolved
Hide resolved
|
|
||
| for &p in &participants { | ||
| let comms = Comms::with_buffer_capacity(usize::MAX); | ||
| let comms_ref = comms.clone(); |
There was a problem hiding this comment.
Nit: Please add a comment as discussed in our meeting about cloning Arc.
There was a problem hiding this comment.
I believe this is not something you normally find in code, but I can add it in one place if that would help the future reader. Maybe I can refactor a bit to make it more clear
crates/threshold-signatures/src/ecdsa/ot_based_ecdsa/triples/batch_random_ot.rs
Show resolved
Hide resolved
Opened #2285 |
0b9e5d5 to
3cf34a6
Compare
Closes #2247
Added per-protocol incoming messages buffer capacity constants throughout threshold-signatures.
Comms::with_buffer_capacity(max)rejects messages for new headers once the capis reached; messages for existing entries still flow. Honest participants always use the same buffer capacity for each protocol.
Now each protocol now declares its own maximum:
Majority of the code is the added tests to guarantee that the new buffer capacity bounds do not break existing implementations.
This solves the issue because the buffer is always bounded. A malicious can still stall the protocol, but can no longer cause an OOM, which seems a strict improvement. A better solution might be possible, but would certainly require breaking changes, so this one seems the best we can get for now.
As a byproduct, the computed numbers make it extremely clear how many rounds each protocol has, which is something that we did not know previously (for the triples for example)