Skip to content

fix(security): guard enrollment_weight and epoch_weight_to_units against non-finite weights (#8619) - #8621

Open
thinhnx128 wants to merge 1 commit into
Scottcjn:mainfrom
thinhnx128:fix/issue-8619-sybil-guard-nonfinite-weights
Open

thinhnx128 wants to merge 1 commit into
Scottcjn:mainfrom
thinhnx128:fix/issue-8619-sybil-guard-nonfinite-weights

Conversation

@thinhnx128

@thinhnx128 thinhnx128 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #8619

This PR hardens the sybil-guard enrollment and settlement weight conversion chain against non-finite (NaN, +inf, -inf), boolean, negative, and non-coercible (None, "N/A") weight inputs:

  1. node/sybil_guard.py (enrollment_weight):
    • Rejects bool values (isinstance(hw_weight, bool)), non-coercible inputs (TypeError, ValueError), negative numbers (weight < 0.0), and non-finite floats (not math.isfinite(weight)) by failing closed to 0.0 instead of returning the raw uncapped input or propagating NaN/inf into grandfathered/trusted branches.
  2. node/sybil_guard.py (hold_for_settlement):
    • Catches OverflowError (raised by int(float("inf"))) alongside TypeError and ValueError so settlement hold recording strictly honors its "Never raises" contract.
  3. node/rustchain_v2_integrated_v2.2.1_rip200.py (epoch_weight_to_units):
    • Rejects bool, None, and non-finite Decimal values (not value.is_finite()) before integer quantization, preventing unhandled decimal.InvalidOperation / OverflowError HTTP 500 crashes on the enrollment path, and clamps to MAX_EPOCH_WEIGHT_UNITS.
  4. Regression Tests (node/tests/test_sybil_guard_nonfinite_8619.py):
    • Covers None, "N/A", float("nan"), float("inf"), float("-inf"), negative weights, booleans, and hold_for_settlement escrow resilience across all probation states.

…nst non-finite and non-coercible weights (Scottcjn#8619)

- Enforce fail-closed 0.0 return in sybil_guard.enrollment_weight() for None, booleans, non-coercible strings, negative values, and non-finite floats (NaN, +inf, -inf).
- Catch OverflowError in sybil_guard.hold_for_settlement() when converting escrowed weights.
- Guard epoch_weight_to_units() against non-finite Decimal values and clamp to MAX_EPOCH_WEIGHT_UNITS.
- Add regression test suite node/tests/test_sybil_guard_nonfinite_8619.py.

Fixes Scottcjn#8619
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Welcome to RustChain! Thanks for your first pull request.

Before we review, please make sure:

  • Non-doc PRs have a BCOS-L1 or BCOS-L2 label
  • Doc-only PRs are exempt from BCOS tier labels when they only touch docs/**, *.md, or common image/PDF files
  • New code files include an SPDX license header
  • You've tested your changes against the live node

Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150)

A maintainer will review your PR soon. Thanks for contributing!

@github-actions github-actions Bot added BCOS-L1 Beacon Certified Open Source tier BCOS-L1 (required for non-doc PRs) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related tests Test suite changes size/M PR: 51-200 lines labels Nov 6, 2026
@github-actions github-actions Bot added the security Security-related change label Nov 30, 2026

This branch has not been deployed

No deployments
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) BCOS-L2 Beacon Certified Open Source tier BCOS-L2 (required for non-doc PRs) node Node server related security Security-related change size/M PR: 51-200 lines tests Test suite changes

Projects

None yet

1 participant