{"record":{"id":"5d23b455e2088636","repo":"nautechsystems/nautilus_trader","slug":"deadline-computation-overflowed","errorCode":null,"errorMessage":"deadline computation overflowed","messagePattern":"deadline computation overflowed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/signing/auth_token.rs","lineNumber":127,"sourceCode":"///\n/// # Errors\n///\n/// Returns the underlying [`crate::common::credential::Credential::private_key`]\n/// failure if the secret cannot be decoded, or any [`build_auth_token`]\n/// failure (clock-before-epoch or, hypothetically, a breach caused by its own\n/// deadline validation).\npub fn build_auth_token_for(\n    credential: &crate::common::credential::Credential,\n) -> anyhow::Result<SecretString> {\n    let now = SystemTime::now()\n        .duration_since(UNIX_EPOCH)\n        .map_err(|_| anyhow::anyhow!(\"system clock is before UNIX epoch\"))?\n        .as_secs();\n    let now_i64 = i64::try_from(now)\n        .map_err(|_| anyhow::anyhow!(\"system clock overflowed when converting to i64\"))?;\n    let deadline = now_i64\n        .checked_add(DEFAULT_AUTH_TOKEN_TTL_SECS)\n        .ok_or_else(|| anyhow::anyhow!(\"deadline computation overflowed\"))?;\n    let sk = credential.private_key()?;\n    build_auth_token(\n        deadline,\n        credential.account_index(),\n        credential.api_key_index(),\n        &sk,\n        fresh_k(),\n    )\n    .map_err(|e| anyhow::anyhow!(\"failed to mint Lighter auth token: {e}\"))\n}\n\n/// Draws a fresh canonical [`Scalar`] from the thread-local CSPRNG suitable\n/// for the per-signature `k` nonce.\n///\n/// The Schnorr binding requires `k` to be drawn from a cryptographic RNG and\n/// used at most once per signature; see [`PrivateKey::sign`] for the full\n/// contract. The 40-byte draw is reduced modulo the curve order, so the\n/// returned scalar is always canonical.","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/signing/auth_token.rs#L109-L145","documentation":"build_auth_token_for computes the auth-token expiry deadline as 'current unix seconds + DEFAULT_AUTH_TOKEN_TTL_SECS' in i64. It uses checked_add so an i64 overflow anywhere in the sum aborts with this error instead of silently minting a token with a wrapped (far-past) deadline.","triggerScenarios":"The system clock is set to an absurdly far-future value (near i64::MAX seconds, year ~292 billion), so adding the TTL wraps; also reachable via any caller that mints tokens: apply_referral_attribution, is_maker_only_api_key, spawn_ws_consumer, generate_order_status_reports, paginate_fill_reports, build_auth_token_for_round_trips_against_credential.","commonSituations":"Misconfigured RTC/NTP on the host or container, mocked clocks in tests set to i64 extremes, emulators/VMs with bogus firmware time.","solutions":["Fix the host system clock (sync via NTP) so 'now' is a realistic unix timestamp","Verify any injected/mock clock source uses sane values","If TTL were configurable, clamp it so now + ttl stays well below i64::MAX"],"exampleFix":"// before: relies on wall clock\nlet now = SystemTime::now();\n// after: sanity-check before minting\nlet now = SystemTime::now().duration_since(UNIX_EPOCH)?;\nassert!(now.as_secs() < 4_102_444_800, \"system clock wildly in the future\");","handlingStrategy":"try-catch","validationCode":"let now = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();\nif now > 1 << 60 { return Err(anyhow!(\"system clock implausibly far in the future\")); }","typeGuard":"fn plausible_now(t: SystemTime) -> bool {\n    t.duration_since(UNIX_EPOCH).map(|d| d.as_secs() < 1 << 60).unwrap_or(false)\n}","tryCatchPattern":"match build_auth_token_for(&credential) {\n    Ok(tok) => tok,\n    Err(e) if e.to_string().contains(\"overflowed\") => {\n        fix_clock_and_retry();\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Enable NTP time sync on hosts running the adapter","Sanity-check wall clock at startup and refuse to trade on implausible times","Watch for this error in tests using mocked clocks with extreme values"],"tags":["rust","overflow","clock","auth"],"backgroundTag":"invalid-env-var-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}