QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-8hp7-jqjc-hrhf

    verify_math returns VERIFIED for wrong results at small magnitudes (6-decimal quantisation and absolute 1e-6 tolerance)

    mediumFixed in 9.0.0GHSA-8hp7-jqjc-hrhf · Published 6 November 2026

    Impact

    VerificationEngine.verify_math(expression, expected_value) returns VERIFIED with is_correct: true for wrong claims about small values and for wrong digits beyond the sixth decimal place. Both sides are compared after rounding the computed value to 6 decimal places, using an absolute tolerance of 1e-6. A caller's tolerance=0 does not restore an exact comparison.

    Call 8.0.0 Correct
    verify_math("1/1000000000", 0) VERIFIED, is_correct: true wrong (true value 1e-9)
    verify_math("1/1000000000", 0, tolerance=0) VERIFIED, is_correct: true wrong
    verify_math("9/10000000", 0) VERIFIED, is_correct: true wrong (true value 9e-7)
    verify_math("1/3", 0.3333329) VERIFIED, is_correct: true wrong 7th digit
    verify_math("1/3", 0.3333323) VERIFIED, is_correct: true off by 1.03e-6, more than the stated 1e-6 tolerance
    verify_math("1/1000000000", 0.005, tolerance=0.01) VERIFIED, is_correct: true the tolerance cap does not scale down for small values
    verify_math("1/3", 0.3333333333333333, tolerance=1e-7) DISPROVEN correct to 1.9e-17; only the computed side is rounded, so a precise claim is rejected
    verify_math("2+2", 5), verify_math("10000000000000001", 10000000000000000) (controls) DISPROVEN correct

    This is the small-magnitude counterpart of GHSA-j622-qffp-rc27, which fixed the same false VERIFIED for values above 15 significant digits.

    Wrong rates, probabilities, unit prices and per-unit fees (values below about 1e-3) can be certified as correct. On the natural-language path the wrong result is signed as a VERIFIED verdict; admission is withheld there because the translation is unverified, but the verdict itself is false.

    Affected

    qwed (PyPI) through 8.0.0. Reproduced on main @ 10f5627 (unchanged since 8.0.0).

    Reachable from:

    • the VerificationEngine.verify_math Python API;
    • POST /verify/natural_language, via ControlPlane.process_natural_language (control_plane.py:282);
    • consensus math checks, via ConsensusVerifier (consensus_verifier.py:774).

    Not affected:

    • POST /verify/math in a = b form, which uses symbolic_difference_status;
    • batch math items (core/batch.py, exact comparison);
    • the SDK's local _math_answers_match.

    Reproduction

    from qwed_new.core.verifier import VerificationEngine
    
    m = VerificationEngine()
    for expr, claim, kw in [("1/1000000000", 0, {}), ("1/1000000000", 0, {"tolerance": 0}),
                            ("1/3", 0.3333329, {}), ("2+2", 5, {})]:
        r = m.verify_math(expr, claim, **kw)
        print(expr, claim, kw, r["status"], r.get("is_correct"))
    

    Details

    src/qwed_new/core/verifier.py:

    • Line 719: _VERIFY_MATH_QUANTUM = Decimal("0.000001"). _calc_decimal (lines 730-751) quantises the computed value to 6 decimal places before comparison (line 791); the claim (expected_decimal) is not quantised.
    • Line 760: the default tolerance: float = 1e-6 is absolute, independent of magnitude.
    • Line 686: MIN_VERIFY_MATH_TOLERANCE_CAP = Decimal("0.01"), so a caller tolerance up to 0.01 is accepted even when the value is many orders of magnitude smaller.
    • Lines 806-807: diff = abs(calculated_value - expected_decimal), then is_correct = diff <= tolerance_decimal.

    Patches

    Fixed in 9.0.0 (d4a0b0b). Upgrade to 9.0.0 or later.

    • The comparison no longer rounds. An exact rational value is compared with the claim exactly; any other value is evaluated at a precision of at least 30 digits, more for large values and long claims.
    • With no tolerance, a claim matches when it lies within min(1e-6, max(1e-9 × |value|, 1e-12)) of the value, or when it has at least 6 significant digits and is the value correctly rounded to its last digit. So 1/3 = 0.333333 still matches, and 1/3 = 0.3333329 does not.
    • tolerance=0 is exact. A caller's tolerance stays absolute and is still capped at 1% of the value (at least 0.01), but never more than the value itself.
    • tolerance now defaults to None. The result has a new match field saying how a claim matched (exact, caller_tolerance, default_bound or rounded_claim) and the bound used.

    On 9.0.0 the first five wrong claims in the table are DISPROVEN, and verify_math("1/1000000000", 0.005, tolerance=0.01) is BLOCKED (Tolerance exceeds deterministic verification bound), since a tolerance may not exceed the value. The precise claim verify_math("1/3", 0.3333333333333333, tolerance=1e-7) is VERIFIED. The controls are unchanged.

    Workarounds

    Upgrade to 9.0.0. On older versions, use POST /verify/math with the a = b form, or batch math items, which compare exactly. Do not rely on verify_math or the natural-language verdict for values below about 1e-3, or for claims with more than 6 significant decimal places.

    Source

    Internal correctness audit (October 2026). Not previously disclosed.

    All advisories