-
Couldn't load subscription status.
- Fork 291
Use RawValue for RPC id #2455
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
base: master
Are you sure you want to change the base?
Use RawValue for RPC id #2455
Conversation
790f05d to
ca780a5
Compare
63abd4a to
35b4bd4
Compare
ca780a5 to
179e534
Compare
419e9d0 to
82cfbcc
Compare
179e534 to
5ca6192
Compare
82cfbcc to
622537c
Compare
5ca6192 to
c46a2d9
Compare
622537c to
6b41606
Compare
6b41606 to
6e63095
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.
Pull Request Overview
This PR optimizes JSONRPC request deserialization by using RawValue for the request id field instead of building a full serde_json::Value. This reduces the effectiveness of DOS attacks targeting large IDs by ~90% while maintaining acceptable performance for normal operations.
Key changes:
- Introduced
Request::from_raw_value()method that manually parses theidfield fromRawValue - Removed custom
Deserializeimplementation forRequestIdin favor of standard serde derivation - Updated all call sites to use the new
from_raw_value()method instead ofserde_json::from_str()
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| monad-rpc/src/jsonrpc.rs | Added from_raw_value() method to manually parse request ID, removed custom deserializers |
| monad-rpc/src/websocket/handler.rs | Updated to use new to_request() signature and from_raw_value() |
| monad-rpc/src/handlers/mod.rs | Replaced serde_json::from_str() calls with Request::from_raw_value() |
| monad-rpc/benches/deserialize.rs | Updated benchmark to use new deserialization method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
6e63095 to
a1e21a5
Compare
This change is a continuation of #2454 to prevent building a
serde_json::Valuewhen deserializing the JSONRPC requestid.Originally, this was solved more cleanly using
#[serde(untagged)]. Unfortunately, serde uses a custom deserializer for untagged enums which results in almost the same number of allocations when deserializing usingserde_jsonas before, leading to only a15-20%reduction in time for theidattacks. The current solution builds aRequestRawwhich internally has aRawValuewhich is manually parsed to reduce this attack's effectiveness by85%as shown below.The following benchmark change shows that the effectiveness of both of the remaining DOS vectors (
attack_large_id_arrayandattack_large_id_dict) are reduced by about85%while only slightly negatively impacting some of the other scenarios. Interestingly, theattack_large_payload_array_with_paramsandattack_large_payload_dict_with_paramsscenarios consistently performs better and by a similar margin to the regressions so these are all likely just noise, especially given that the payload attacks should perform similarly given the payload deserialization dominates the benchmark time and it did not change in this PR.