← Back to Pull requests

fix SmallFp mul overflow on u32 #1126

Open
benbencik opened this pull request with 15 lines diff across 2 files
View on GitHub
benbencik benbencik commented on Jul 21, 2026 10:13 UTC
Author

Motivation

SmallFp multiplication can overflow on u32 prime fields. This can be replicated on native tests for TeddyBear prime.

Description

Edited case for primes 2^16 < p < 2^32 to handle the overflow. Copied the approach that is used for u64 primes. Added TeddyBear definition and tests for this field.

Diff: 15 lines (+13 / -2) across 2 files Reviewer: z-tech Review duration: 123746m
All Vouch review confidence checks passed
Residual risk 0.04 = Change Risk (0.28) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.28 · 15 lines diff across 2 files
0.28
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 3 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
87%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.166
Real PR Conversation Timeline
5 items
z-tech z-tech commented on Jul 21, 2026 20:45 UTC
Contributor

Heyy 👋

I imagine you found a concrete op / test case that fails for this ? Curious what is.

Reason I'm curious is we have (a somewhat diverged) version of this code in the "z" repo. We were surprised when we were able to formalize the z repo against mathlib that there were seemingly no bugs. One theory is that the bugs were silently fixed when porting over the arithmetic (or during the process of formalizing itself).

Your finding would rule out the possibility that there were genuinely no bugs to begin with by counterexample

benbencik benbencik commented on Jul 22, 2026 15:15 UTC
Author

Interesting, perhaps the port somehow took care of this. I would be curious to know more. One simple example that fails is (p-1)*(p-1).

z-tech z-tech commented on Jul 24, 2026 21:14 UTC
Contributor

Interesting, perhaps the port somehow took care of this. I would be curious to know more. One simple example that fails is (p-1)*(p-1).

Ah it also fails because we formally verify instances like BabyBear, KoalaBear, M31... not the generic implementation over all inputs, which makes sense.

Cool!

z-tech z-tech approved these changes on Jul 24, 2026 21:15 UTC
Approved Reviewer

Adding that example might be helpful for regression tests.

Reviewers
Assignees
benbencik benbencik
Labels
risk: low confidence: 87.4% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 28% (LOW) · Higher = larger blast radius
28%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 87.4% · Lower = rushed or shallow review
87.4%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.5% · Safe to merge
3.5%