Repository navigation
fix(protocol): bound ProbeResponse.rate_per_mb at the wire boundary (#378) - #396
Conversation
…378) ProbeResponse.rate_per_mb is peer-controlled and feeds the client selection score `rate × rtt × scale / reputation²` (#322). With no upper bound, a malicious node could advertise u64::MAX and overflow the multiplication, silently winning the selection — the inverse of what an honestly-priced rate would do. - Add MAX_RATE_PER_MB = 10^12 (1 trillion base units) in the protocol crate. Comfortably above any realistic CDN rate; ~7 orders of magnitude of headroom from u64::MAX for downstream arithmetic. - Implement Deserialize manually for ProbeResponse so the wire boundary rejects oversize rates as MessageValidationError, mapped by the framing layer to FrameError::Decode → APP_ERR_MALFORMED_MESSAGE on the server side and a decode error on the client side. - Pin the wire layout with a fixed-byte assertion so the manual impl cannot silently diverge from the derived Serialize. - Tighten resolve_payment to enforce the same ceiling at startup and on hot reload, so an operator misconfiguring the rate fails fast instead of publishing ProbeResponses every honest client rejects. Selection-formula callers should still use saturating arithmetic as defense-in-depth — the bound is the protocol-boundary check, not a substitute for safe math.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a protocol-level maximum limit for the rate_per_mb field in ProbeResponse to prevent potential overflows in client selection calculations. Validation is enforced both at the protocol boundary through a manual Deserialize implementation and within the node's configuration layer. New unit tests verify these boundary constraints and ensure the stability of the wire format. I have no feedback to provide.
There was a problem hiding this comment.
Code Review
This pull request introduces a protocol-level ceiling on rate_per_mb to prevent potential overflows in client selection scores. The changes include adding a MAX_RATE_PER_MB constant, implementing validation logic in the node's configuration layer, and adding a manual Deserialize implementation for ProbeResponse to enforce the limit at the wire boundary. A review comment suggests using Serde's deserialize_with attribute instead of a manual Deserialize implementation with a mirror struct to reduce maintenance risk and ensure field synchronization.
…_with Address Gemini review feedback on #396: replace the hand-written `impl Deserialize for ProbeResponse` + mirror struct with `#[serde(deserialize_with = "deserialize_rate_per_mb")]` on the field. The field-level hook keeps the struct's `Deserialize` derived, so field order and codec stay in lockstep with the public type — there is no mirror struct that can drift out of sync with the wire format. Validation logic is unchanged; the wire bytes are byte-identical (the existing `probe_response_wire_format_is_stable` test still passes), and all 33 protocol tests remain green.
|
Addressed in 5d12c35: replaced the manual /gemini review |
The cargo doc job rejects intra-doc links from public items to private ones (`-D rustdoc::private-intra-doc-links`). Reference the hook by name in backticks rather than as a clickable link.
There was a problem hiding this comment.
Code Review
This pull request introduces a protocol-level limit on the rate_per_mb field within ProbeResponse to mitigate potential overflow issues in client selection algorithms, addressing issue #378. The implementation includes a new MAX_RATE_PER_MB constant, a custom Serde deserialization hook for wire-boundary validation, and corresponding checks in the node's payment resolution logic to ensure configuration consistency. Additionally, the PR includes unit tests for validation logic and wire-format stability. I have no feedback to provide.
Summary
Fixes #378 —
ProbeResponse.rate_per_mbwas a peer-controlledu64with no upper bound at the wire boundary. A malicious node could advertiseu64::MAX, overflowing the client selection scorerate × rtt × scale / reputation²(#322) and silently winning selection — the inverse of what an honestly-priced rate would do.Changes
crates/protocol/src/message.rs): AddMAX_RATE_PER_MB = 10^12(1 trillion base units, ~7 orders of magnitude of headroom fromu64::MAX). ImplementDeserializemanually forProbeResponseso the wire boundary rejects oversize rates asMessageValidationError. Postcard wraps this asSerdeDeCustom, which the framing layer maps toFrameError::Decode→APP_ERR_MALFORMED_MESSAGE(ADR 013) on the server side and a decode error on the client side.ProbeResponseis unchanged — manualDeserializecannot silently diverge from the derivedSerialize.crates/node/src/config/mod.rs): Tightenresolve_paymentto enforce the same ceiling at startup and on hot reload (viaPaymentSection::resolve), so an operator misconfiguring the rate fails fast rather than publishingProbeResponses that every honest client decoder rejects.Bound rationale
MAX_RATE_PER_MB = 1_000_000_000_000(1 trillion base units):u64::MAXforrate_per_mb × rtt_msmath.ADR alignment
rate_per_mbas a planned signed field ofProbeResponse. The validatingDeserializeimpl is documented to move with the futureProbeResponseBodyso the bound continues to apply after the signed-body refactor.Deserializeproduced. No ALPN bump required.Test plan
cargo build— passescargo clippy --all-targets --workspace -- -D warnings— passescargo test -p decdn-protocol— 33/33 pass (8 new: roundtrip-at-max, decode-rejects-above-max, decode-rejects-u64-max, message-decode-propagates, validate-consistency, wire-format-stability)cargo test -p decdn-node— 215+ pass (2 new inconfig::tests: rejects-rate-above-protocol-max, accepts-rate-at-protocol-max)cargo fmt -- --check— cleanNote:
probe_rate_limit_returns_rate_limited_close_codeexhibits pre-existing flakiness under workspace-wide concurrent test pressure (passes 3/3 in isolation, both with and without these changes).