fix: reject non-finite withdrawal amounts#5719
Conversation
TJCurnutte
left a comment
There was a problem hiding this comment.
Approved. The withdrawal amount validation now rejects non-finite floats at the endpoint boundary, before nonce/database/signature handling, while preserving the existing invalid-JSON, non-numeric, negative, and minimum-withdrawal behavior.
Validation run on detached PR worktree at 04ba47dd5a3c9455d2c9d810f125bc3e61e54a4d:
git diff --check origin/main...HEAD -- node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py
python3 -B -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py
RC_ADMIN_KEY=0123456789abcdef0123456789abcdef PYTHONPATH=node python3 -B -m pytest -q node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py --tb=short -p no:cacheproviderResult: 13 passed, 1 warning in 0.53s.
I also ran a temp-DB Flask probe against /withdraw/request. On this PR, "NaN" and "inf" both returned HTTP 400 with amount must be a finite positive number, and a top-level array body returned HTTP 400 with Invalid JSON body. The same probe on origin/main let non-finite values pass the amount gate and fail later (NaN reached signature validation; inf reached the balance check), so this patch closes the right pre-DB validation gap.
minyanyi
left a comment
There was a problem hiding this comment.
I re-ran the PR's updated withdrawal validation tests on current head 04ba47d and found a Windows-specific blocker in the new fixture setup.
Reproduction:
python -B -m pytest -q node/tests/test_withdrawal_validation.py --tb=short
Observed result:
- the assertions themselves run, but teardown fails for every case with
PermissionError: [WinError 32] ... withdrawal-validation.db - the failure happens in the new
tempfile.TemporaryDirectory()fixture path added by this PR, while the imported integrated module is still holding the SQLite file open when cleanup tries to unlink it
Representative failure:
E PermissionError: [WinError 32] ... '...\\withdrawal-validation.db'
node/tests/test_withdrawal_validation.py:29: in app
with tempfile.TemporaryDirectory() as tmpdir:
So the PR moves the file past the old syntax/import problem, but the updated regression harness is still not green on Windows because the temp DB is not released before directory cleanup. I would fix that fixture lifecycle before merge.
jaxint
left a comment
There was a problem hiding this comment.
LGTM! Great work on this PR. 🚀
Review: changes requestedI reviewed PR #5719 ( Validation run:
Finding:
raw_amount = data.get('amount', 0)
amount = float(raw_amount)In Python, Manual Flask client repro after initializing a temp DB: This shows Suggested fix: if isinstance(raw_amount, bool):
return jsonify({"error": "amount must be a number", "received": "bool"}), 400Add a regression test for |
|
Reviewed the non-finite withdrawal amount change. Functional behavior looks directionally correct: However, I hit a test-suite blocker on Windows when running the added/related withdrawal tests: The module imported in Other checks run: |
Summary
Closes #4420
Tests
uv run --with pytest --with flask --with requests python -B -m pytest -q node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py --tb=short -p no:cacheproviderpython3 -B -m py_compile node/rustchain_v2_integrated_v2.2.1_rip200.py node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py