fix(proof): reject non-string keys in proof metadata#275
Conversation
Bounty ramimbo#228 _clean_proof_metadata now validates that all dict keys are strings before processing. Non-string keys (integers, booleans, etc.) are rejected with a clear error message. Adds tests for integer keys, boolean keys, and shows that string keys still pass through. Refs ramimbo#228
SihyeonJeon
left a comment
There was a problem hiding this comment.
Requesting changes: the implementation idea is reasonable, but the current PR fails the quality gate because the new test block is not formatted and includes unused imports.
Evidence checked:
- Inspected
app/ledger/service.pyandtests/test_security.pyon head72ea021. - The service change adds the intended non-string key guard in
_clean_proof_metadata()before control-character validation. - The regression does exercise
_clean_proof_metadata({1: ...}),_clean_proof_metadata({True: ...}), and thepay_bounty(... verifier_result={123: ...})path, and the focused test itself passes. - However,
tests/test_security.pyadds a long inline import inside the test and importsadd_ledger_entryandTREASURY_ACCOUNTwithout using them. - The new block also has trailing whitespace on multiple blank lines.
Validation run on current head 72ea021:
./.venv/bin/python -m pytest tests/test_security.py::test_clean_proof_metadata_rejects_non_string_keys -q-> 1 passed./.venv/bin/python -m ruff check app/ledger/service.py tests/test_security.py-> fails with I001 import formatting, E501 line too long, and unused imports foradd_ledger_entryandTREASURY_ACCOUNT./.venv/bin/python -m ruff format --check app/ledger/service.py tests/test_security.py-> would reformattests/test_security.pygit diff --check origin/main...HEAD-> fails with trailing whitespace intests/test_security.py- Hosted
Quality, readiness, docs, and image checksis failing.
Suggested fix: move the needed imports to the module import section or split the local import into a formatted block, remove add_ledger_entry and TREASURY_ACCOUNT, remove trailing whitespace, then rerun Ruff, format-check, and git diff --check.
No secrets, wallet material, payout details, private deployment values, private vulnerability details, or MRWK price claims were reviewed or disclosed.
g8rr5dg2p7-svg
left a comment
There was a problem hiding this comment.
Thanks for the pass. I think this needs changes before merge.
Blocking:
- This scope is already covered by #252 (Reject non-string proof metadata keys), which changes the same proof metadata key path for bounty #228. Please coordinate with or close in favor of that PR to avoid duplicate acceptance work.
- The branch currently fails the hosted quality check. I reproduced locally:
.venv/bin/ruff format --check tests/test_security.pysaystests/test_security.pywould be reformatted, and.venv/bin/ruff check app/ledger/service.py tests/test_security.pyreports an unsorted import, E501, and two unused imports on the new test import line.
Evidence: the targeted regression itself passes: .venv/bin/python -m pytest tests/test_security.py::test_clean_proof_metadata_rejects_non_string_keys -q -> 1 passed.
Once this is deduped and formatted, the underlying guard/test direction looks reasonable, but I would not merge this PR as-is.
|
Quick review: the core change makes sense to me, and the full pytest run in CI got through the test suite. The red CI is coming from formatting/lint on the new test file. I checked the patch and reproduced the local checks:
So I think the fix is just to run |
Bounty #228
Summary
_clean_proof_metadatanow validates that all dict keys are strings before processing. Non-string keys (integers, booleans, etc.) are rejected with a clear error message.Changes
isinstance(key, str)check at the start of the loop in_clean_proof_metadatatest_clean_proof_metadata_rejects_non_string_keyscovering integer keys, boolean keys, and the string-keys-still-pass pathEvidence
Without this check,
pay_bountyacceptsverifier_result={1: "value"}which Python automatically stringifies duringjson.dumps, creating a discrepancy between the validated dict and the serialized JSON. This is a type-safety hardening for the proof metadata pipeline.Refs #228