Skip to content

Fix Sophia governor malformed transfer amount handling - #6679

Merged
Scottcjn merged 1 commit into
Scottcjn:mainfrom
keon0711:codex/sophia-governor-amount-validation
May 31, 2026
Merged

Scottcjn merged 1 commit into
Scottcjn:mainfrom
keon0711:codex/sophia-governor-amount-validation

Conversation

@keon0711

Copy link
Copy Markdown
Contributor

Summary

  • add safe scalar parsing for pending_transfer amount fields in the Sophia governor
  • reject booleans, arrays, objects, negative values, and non-finite values as malformed transfer amounts
  • preserve review flow by emitting invalid_transfer_amount instead of raising HTTP 500
  • align existing recent-endpoint tests with the current admin gate

Fixes #6678.
Claiming under bug bounty #305.
Payout miner_id: github:darlina-bounty-codex

Tests

  • uv run --no-project --with pytest --with flask python -m pytest -q node/tests/test_sophia_governor.py --tb=short
  • python3 -m py_compile node/sophia_governor.py node/tests/test_sophia_governor.py
  • git diff --check -- node/sophia_governor.py node/tests/test_sophia_governor.py

Manual verification

Malformed pending transfer amount payloads now return HTTP 200 with a medium-risk local_then_phone_home review and the invalid_transfer_amount signal instead of crashing.

@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 31, 2026
@keon0711

Copy link
Copy Markdown
Contributor Author

CI note: the full repository test job is currently red with the same broad repo-wide failures seen on other open RustChain PRs. I did not see failures in the Sophia governor tests touched by this PR; the related governor auth tests passed in the CI log.

Local targeted verification for this change passes:

uv run --no-project --with pytest --with flask python -m pytest -q node/tests/test_sophia_governor.py --tb=short
python3 -m py_compile node/sophia_governor.py node/tests/test_sophia_governor.py
git diff --check -- node/sophia_governor.py node/tests/test_sophia_governor.py

Manual malformed payload checks also returned HTTP 200 with invalid_transfer_amount instead of the pre-fix HTTP 500.

@JONASXZB JONASXZB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I found one amount-precedence edge case in the malformed-transfer parser. The crash fix is useful, but the fallback condition currently treats a valid zero RTC amount as absent and then lets amount_i64 change the interpreted amount or malformed flag.

Comment thread node/sophia_governor.py
def _pending_transfer_amount_rtc(payload: dict[str, Any]) -> tuple[float, bool]:
"""Return best-effort pending transfer RTC amount and whether it was malformed."""
amount_rtc, invalid = _safe_nonnegative_float(payload.get("amount_rtc"))
if amount_rtc:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using truthiness here means a valid explicit amount_rtc of 0 or "0" does not win over the legacy amount_i64 field. For example, {"amount_rtc": 0, "amount_i64": 999999999} is interpreted as 999.999999 RTC, and {"amount_rtc": 0, "amount_i64": ["bad"]} is marked malformed even though the primary amount field is valid. Since the function accepts 0 as a non-negative value, the fallback should probably key off presence/is not None rather than truthiness: if amount_rtc is supplied and valid, return it even when it is zero; only fall back to amount_i64 when amount_rtc is missing/empty or invalid by policy.

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] Sophia governor crashes on malformed pending transfer amount

3 participants