Skip to content

fix: reject non-finite withdrawal amounts#5728

Closed
iamdinhthuan wants to merge 1 commit into
Scottcjn:mainfrom
iamdinhthuan:codex/live-bounty-triage-20260519
Closed

fix: reject non-finite withdrawal amounts#5728
iamdinhthuan wants to merge 1 commit into
Scottcjn:mainfrom
iamdinhthuan:codex/live-bounty-triage-20260519

Conversation

@iamdinhthuan
Copy link
Copy Markdown
Contributor

Summary

  • reject NaN and infinity withdrawal amounts before nonce/database work
  • keep malformed JSON and invalid amount validation covered by Flask client tests
  • make the withdrawal validation tests import the dotted integrated-node filename through importlib and share the module to avoid duplicate Prometheus metric registration

Fixes #4420

Verification

  • python3 -B -m pytest -q node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py --tb=short -p no:cacheprovider
  • 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
  • git diff --check

@iamdinhthuan iamdinhthuan requested a review from Scottcjn as a code owner May 19, 2026 15:52
@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related tests Test suite changes size/M PR: 51-200 lines labels May 19, 2026
Copy link
Copy Markdown
Contributor

@jaxint jaxint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Great work on this PR. 🚀

Copy link
Copy Markdown

@TJCurnutte TJCurnutte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. The non-finite withdrawal amount guard is in the right place: immediately after float(raw_amount) and before nonce/database work.

What I checked:

  • math.isfinite(amount) rejects NaN, inf, and -inf before balance, nonce, or signature logic can operate on non-finite floats.
  • Existing malformed JSON, nonnumeric amount, negative amount, and minimum-withdrawal behavior remains covered by the focused tests.
  • The shared import name in the tests avoids duplicate module/Prometheus registration during the combined test run.

Validation performed on head 9b3dc1a5ef2ab87eb3371cc423408220f879e67f:

  • 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 passed.
  • /Users/curnutte/.hermes/hermes-agent/venv/bin/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 passed.
  • /Users/curnutte/.hermes/hermes-agent/venv/bin/python3 -B -m pytest -q node/tests/test_withdraw_amount_validation.py node/tests/test_withdrawal_validation.py --tb=short -p no:cacheprovider returned 12 passed in 0.24s.
  • Temp-DB Flask probe compared origin/main with this PR for /withdraw/request: origin/main let NaN/inf reach database work and returned 500 in the stripped temp DB path, while this PR returned HTTP 400 with Amount must be a finite positive number for NaN, inf, and -inf before DB access.

I do not see a blocking issue in this diff.

@Scottcjn
Copy link
Copy Markdown
Owner

Closing as duplicate of #5719 (william08190, first-poster — filed 4 hours earlier at 11:07 UTC vs 15:52 UTC here, both reference issue #4420 'reject non-finite withdrawal amounts'). #5719 was merged with credit. Thanks for the parallel work; per the first-poster-per-issue rule, credit goes to whoever lands first.

@Scottcjn Scottcjn closed this May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) node Node server related size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Withdraw request route returns 500 for malformed JSON and invalid amounts

4 participants