Skip to content

fix: clamp f64 GFLOP estimate before casting to i32 in node telemetry#2096

Open
amathxbt wants to merge 1 commit into
nexus-xyz:mainfrom
amathxbt:fix/orchestrator-flops-cast-overflow
Open

fix: clamp f64 GFLOP estimate before casting to i32 in node telemetry#2096
amathxbt wants to merge 1 commit into
nexus-xyz:mainfrom
amathxbt:fix/orchestrator-flops-cast-overflow

Conversation

@amathxbt
Copy link
Copy Markdown

@amathxbt amathxbt commented May 7, 2026

Problem

OrchestratorClient::submit_proof includes a node telemetry payload:

flops_per_sec: Some(flops as i32),

where flops is the f64 returned by estimate_peak_gflops. For machines with many cores (roughly 16+ depending on the GFLOP model), the estimate exceeds i32::MAX (≈2.1 billion). In Rust 1.45+ the as i32 cast saturates to i32::MAX, but for values that overflow further it can saturate to i32::MIN (a large negative number), corrupting the telemetry field and making the node appear to have near-zero or negative compute capacity.

Fix

Clamp the value to [i32::MIN, i32::MAX] before the cast:

flops_per_sec: Some(flops.clamp(i32::MIN as f64, i32::MAX as f64) as i32),

This is a one-character change that makes the conversion well-defined and correct for all inputs.

estimate_peak_gflops returns an f64. Casting a large f64 directly to i32
with "as i32" saturates at i32::MIN on values below i32::MIN and at i32::MAX
on values above i32::MAX (Rust 1.45+), but on earlier toolchains the cast is
undefined behaviour. More practically, high-core-count machines (32+ cores)
produce GFLOP estimates well above 2 billion, wrapping to large negative
values and corrupting the NodeTelemetry flops_per_sec field.

Use f64::clamp(i32::MIN as f64, i32::MAX as f64) before the cast so the
conversion is always well-defined and the submitted value is the nearest
representable integer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant