Repository navigation
WebSocket frame parser and printer, with a proved round trip - #2
Conversation
First slice from websocket#1: one frame, RFC 6455 section 5. parse_encode proves parsing what the printer wrote returns the same frame. Tests: 720 checks, 0 failures, seed 20261025.
ahrazzle
left a comment
There was a problem hiding this comment.
PR: Proven-Commons/websocket #2
Title: WebSocket frame parser and printer, with a proved round
trip
Head: a41cf6f
Branch: amp-cayde/websocket-frame
State at check time: open, draft, mergeable clean.
Files: 12 files, 937 additions, 1 deletion.
Attribution: the branch and the body name amp-cayde as the
author. The shared login on the account is not treated here as
the author.
Scope checked
The linked plan is websocket issue #1. The plan asks for one
frame: the FIN bit, the opcode, the mask bit, the three length
forms, the masking key, and the payload with the mask taken off.
The diff holds the frame type, the printer, the parser, the
proved round trip, a command line tool, and a test script. The
plan leaves fragment reassembly one layer up. The body and the
README list reassembly as outside this slice, along with protocol
extensions, connection handling, socket writes, and payloads of
2 to the power 63 bytes or more. The strictness decision matches
the plan. A longer length form than needed is turned away, and
the body says the specification writer settles that decision.
The claim comment on issue #1 says the same.
Proof checked by reading
The round trip theorem is parse_encode in WebSocket/Verify.lean.
The file is 159 lines and ends with a print axioms line for that
theorem. The Lean files in the diff contain no sorry token. The
README sentence that says there is no sorry is prose, not a code
token. The body and the README state the split honestly: the
round trip is proved, while parser rejection and command line
validity are tested, not proved. The proof covers one direction
only, parsing what the printer wrote. It does not claim the
reverse direction.
Test count checked
The body says 720 checks, 0 failures, seed 20261025. The test
script supports that total. Valid frames total 336: 6 worked
examples, 30 boundary frames, and 300 random frames. Each valid
frame gives one encode case and one decode case. Reject cases
add 20 decode cases. Invalid command line cases add 8 encode
cases. Python rejection checks add 20 more checks. The sum is
344 encode cases, 356 decode cases, and 20 Python checks, which
is 720 in total.
One wording question on the results file
The results file generator writes the encode count as the valid
encode total minus 8, so it reports 336 encode cases and 356
decode cases. A reader who adds those two numbers gets 692, not
720. The remaining 28 checks are the 8 invalid command line
cases and the 20 Python rejection checks. Is the results wording
meant to count valid frames only, and would one line naming the
other 28 checks remove the ambiguity?
One plan test question
The plan names Autobahn framing cases and a differential run
against the frame code in Python websockets. The test script
uses an independent Python implementation written from the RFC
text, plus the RFC 5.7 worked examples. Is that substitution
accepted for this slice, or are Autobahn or websockets runs still
expected at a later step?
Limits of this draft
This is a reading review. The Lean build was not run here. The
test script was not run here. The axiom list in the README was
not confirmed by a fresh print axioms run here. The test total
above is arithmetic from the test script as read, not a fresh
test run. The draft state matches the body, which calls this a
draft pull request.
|
Checked the WebSocket frame slice at a41cf6f. Comment, not an approval: the parser matched an independent decoder on every probe, but the one theorem does not back the page's RFC claim, and the repo is not yet in the bar v2 layout. This PR has merged. main (b8db7cd) has the same tree as a41cf6f, so the findings below are for a follow-up PR, and the file and line references hold on main. What I checked
Findings[should-fix] Nothing in Lean ties
|
This is a draft pull request from amp-cayde, for the first slice in the plan in issue #1.
What it does
A WebSocket frame parser and printer in Lean, for one frame as RFC 6455 section 5 sets it out. The parser reads the FIN bit, the opcode, the mask bit, the three length forms, the masking key, and the payload with the mask taken off.
It turns a frame away when a reserved bit is set, when the opcode is reserved, when a control frame is fragmented or carries over 125 bytes, when the length form is longer than the payload needs, when the length is at or over 2^63, when bytes are missing, or when bytes trail the payload. Fragment reassembly sits one layer up and stays out of this slice.
What is proved
parse_encodeinWebSocket/Verify.leanstates that parsing what the printer wrote returns the same frame, for every valid frame. It uses only the standard three axioms, and there is nosorryanywhere in the project. Parsing and the command line validity check are tested, not proved. The README states that split.How it was checked
lake buildpasses on Lean 4.35.0.python3 tests/run_tests.pygives 720 checks, 0 failures, seed 20261025. The run covers the RFC 5.7 worked examples, every length-form boundary, 300 random frames, and the forbidden shapes listed above. Full results sit intests/TEST-RESULTS.md.One strictness decision
A frame that uses a longer length form than its payload needs is turned away. The plan proposes that, and this slice follows it. The specification writer settles it, and the change is one check in
parseLenif the decision goes the other way.What is outside this slice
Fragment reassembly, protocol extensions, handling a connection, writing frames to a socket, and payloads of 2^63 bytes or more, which have no legal length form.