Repository navigation
sv1 api hardening - #2498
sv1 api hardening#2498bit-aloo wants to merge 9 commits into
Conversation
|
Pinning the wire forms first is great, but |
Covers the envelope forms, every request and notification parser, client-side results, and the JSON emitted for replies and notifications, so the redesign that follows shows each behaviour change as a fixture diff.
Replaces the four-variant message enum, the Method layer and the direction enums with a two-variant envelope, where a notification is a request without an ID. Typed messages are grouped by operation: ClientToServer and ServerToClient carry them in Request and Response envelopes, and a reply is typed by the method of the request it answers. IsServer and IsClient, each with an Async variant, become routers with one entry point and required handlers. They keep no session state and check none: a handler acts on its message and sends the reply, and callers match replies to their requests. Also accepts string IDs, an omitted authorize password and opaque subscribe resume IDs, rejects ntime and nonce above 32 bits, reads short min-bit-count strings as decimal, and sends mining.set_version_mask under its BIP 310 name. stratum-translation, the example and the fuzz targets move to the new API.
…culty A zero target gives an infinite difficulty, which SetDifficulty cannot encode. Return InvalidSv1Difficulty instead.
Checks hex lengths before decoding, limits notify merkle branches to 32 entries, extranonce2 sizes to what a submit can carry and string IDs to 64 bytes, keeps decode errors bounded whatever the message size, escapes peer strings in Display, and redacts the configure connection URL from raw requests.
Clamps the mask in configure results to VERSION_ROLLING_MASK when decoding and when encoding, so neither side acts on reserved bits whatever the peer or the implementor provides.
Encoding panics on a difficulty that is not finite and positive, so decoding now rejects such values too and any decoded notification can be sent again. The fuzz target asserts that round trip.
serde_json's default float parser can be off by one ulp, so a message re-encoded from an exact float failed the equality assertion. Enable float_roundtrip for the fuzz build only.
sv1_api 8.0.0 breaks its public API, and stratum_translation and stratum-core expose its types.
46445c8 to
49e2010
Compare
The sv1 wire target builds messages with arbitrary string IDs and asserted that every serialized message decodes. Decoding now rejects a string ID longer than 64 bytes, so the target asserts that rejection and keeps the round trip for every other message.
|
I am opening this for review. This changes I am also working on |
closes: #2462
closes: #2464
closes: #2469
closes: #2472
closes: #2473
closes: #2474
closes: #2475
closes: #2476
closes: #2477
closes: #2478
closes: #2479
closes: #2480
closes: #2481
closes: #2482
closes: #2487
closes: #2488
closes: #2489
closes: #2490
closes: #2491
closes: #2492
closes: #2493
closes: #2494
ref: #2412
closes: project-loupe/audit-stratum#6
closes: project-loupe/audit-stratum#43
closes: project-loupe/audit-stratum#85
closes: project-loupe/audit-stratum#102
closes: project-loupe/audit-stratum#103
closes: project-loupe/audit-stratum#104
closes: project-loupe/audit-stratum#105
closes: project-loupe/audit-stratum#106
closes: project-loupe/audit-stratum#107
closes: project-loupe/audit-stratum#161
closes: project-loupe/audit-stratum#163
closes: project-loupe/audit-stratum#205
closes: project-loupe/audit-stratum#206
closes: project-loupe/audit-stratum#207
closes: project-loupe/audit-stratum#209
closes: project-loupe/audit-stratum#210
closes: project-loupe/audit-stratum#236
closes: project-loupe/audit-stratum#261
closes: project-loupe/audit-stratum#262
closes: project-loupe/audit-stratum#269
closes: project-loupe/audit-stratum#275
closes: project-loupe/audit-stratum#280
companion stratum-mining/sv2-apps#996