Repository navigation
fix(rpc)!: answer an id-less object with unstructured params - #5446
Conversation
JSON-RPC 2.0 defines a notification as a Request object without an id,
and section 4.2 asks that the parameters, when present, be an array or
an object. isNotification read the version, the method and the missing
id, but not the parameters. So an object such as
{"jsonrpc":"2.0","method":"eth_chainId","params":"bar"} got no
response, alone or in a batch, where section 5 asks for one.
isNotification now also requires that the parameters be absent, an
array or an object. Any other id-less object goes to the reader of
requests, which answers -32600 with the identifier null.
answerJson_isSome_of_params states that such an object gets a response.
BREAKING CHANGE: execution.rpc answers an id-less JSON-RPC object whose
params is neither an array nor an object with the error -32600, where
it gave no response.
tcoratger
left a comment
There was a problem hiding this comment.
Reviewed with a spec, statement, architecture and docs panel. The rule matches JSON-RPC 2.0, sections 4, 4.1, 4.2 and 5: an object whose params is not structured is no Request object, so it is no notification and gets -32600. The fork does not accept maintainer pushes, so the follow-up (a theorem that states the -32600 response itself, plus doc alignment) lands in a separate PR right after this one.
I will check if I can change this rule in our fork |
Apparently it is a GitHub limitation. "Allow edits by maintainers" isn't available in organization forks. |
An object without an
idwhoseparamsis neither an array nor an object gets the error-32600, where it got no response.The problem
JSON-RPC 2.0 defines a notification in section 4.1 as "a Request object without an "id" member", and the server must not reply to one.
Section 4.2 says: "If present, parameters for the rpc call MUST be provided as a Structured value", that is, an array or an object.
So an object with
"params": "bar"is no Request object, and no notification either.Section 5 says that "the Server MUST reply with a Response, except for in the case of Notifications".
isNotification(Execution/Rpc/Methods.lean) read the version, the method and the missingid, but notparams.So
answerJsongave no response to such an object, alone or in a batch.The idea
A value is a notification only if it is a Request object.
So
isNotificationalso requires thatparamsbe absent, an array or an object.Every other object without an
idgoes to the reader of requests.That reader rejects it with
-32600and the identifiernull, as it already does for an object without anidwhose method is no string.answerJson_isSome_of_params(Execution/Proofs/Rpc/Methods.lean) states that such an object gets a response.Example
Section 7 has the example "rpc call with invalid Request object":
{"jsonrpc": "2.0", "method": 1, "params": "bar"}gets-32600and the identifiernull.The last line above is that request with a string method, which only the parameters keep from being a notification.
For reviewers
The reader of requests rejects parameters by name, but a notification gets no response either way.
"params": nullis no structured value, so such an object gets-32600.The reader of requests already rejects
nullparameters in an object with anid.id:request: no field id.serveanswers each item withanswerJson, so the batch gets the error for that item.Checks
lake build --wfail(whole library, proofs and exports), after a rebase on4309336: passed.lake exe gen-bindings --check: passed.lake exe check-decls: 0 findings.lake exe check-accessors,lake exe check-theoremsandcheck_theorems_baseline.py --base upstream/master: passed, nothing new.lake exe proof-coverage --checkandlake exe rule-history --check: passed.soundness_facts.py --check,check_layers.py,check_lean_layout.py --base upstream/master,check_comment_code.py,check_lean_commands.py,check_fork_cap.pyandcheck_fixture_pins.py: passed.uv run --no-sync pytest -n auto: 78094 passed, 680 skipped, 13 xfailed, before the rebase.After it,
pytest bindings/python/tests/rpc: 915 passed.check_vectors.py: 2328 pinned vectors match.ruff check,ruff format --check,ty check,check_raises.py,check_docstrings.py,check_python_boundary.pyandcheck_python_comments.py --all: passed.codespellran on the changed test file only.ty check --python-version 3.10of the package and the unit tests ofscripts/, which this change does not touch, and the build oftests/downstream.check_writing.py --base upstream/master: S1 suggestions only.BREAKING CHANGE:
execution.rpcanswers an object without anidwhoseparamsis neither an array nor an object with the error-32600, where it gave no response.