{"record":{"id":"46935283d2970b51","repo":"nautechsystems/nautilus_trader","slug":"finalized-block-timestamp-overflows-nanoseconds","errorCode":null,"errorMessage":"Finalized block timestamp overflows nanoseconds","messagePattern":"Finalized block timestamp overflows nanoseconds","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":4812,"sourceCode":"            raw_amount_to_quantity(\n                base_amount.unsigned_abs(),\n                plan.pool.get_base_token().decimals,\n            )?\n        }\n    };\n\n    let block = &included.finality.inclusion_header;\n    anyhow::ensure!(\n        block.number == included.block_number\n            && block.hash == included.receipt.block_hash.to_string(),\n        \"Verified inclusion header {} does not match receipt hash {}\",\n        included.block_number,\n        included.receipt.block_hash\n    );\n    let timestamp_ns = block\n        .timestamp\n        .checked_mul(NANOSECONDS_IN_SECOND)\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized block timestamp overflows nanoseconds\"))?;\n    let mut swap = event.to_pool_swap(\n        plan.pool.chain.clone(),\n        plan.instrument_id,\n        plan.pool.pool_identifier,\n        UnixNanos::from(timestamp_ns),\n    );\n    swap.calculate_trade_info(&plan.pool.token0, &plan.pool.token1, None)?;\n    let trade = swap\n        .trade_info\n        .as_ref()\n        .ok_or_else(|| anyhow::anyhow!(\"Finalized Swap has no calculated trade information\"))?;\n    anyhow::ensure!(\n        trade.order_side == plan.order.order_side(),\n        \"Finalized Swap side {} does not match {} order\",\n        trade.order_side,\n        plan.order.order_side()\n    );\n    let gas_cost = included","sourceCodeStart":4794,"sourceCodeEnd":4830,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L4794-L4830","documentation":"The verified inclusion block's timestamp (seconds) is converted to nanoseconds for the swap event's ts_init. checked_mul fails when the seconds value overflows the nanosecond integer range, so the library refuses to construct the swap with a corrupt timestamp rather than emitting an event with an invalid time.","triggerScenarios":"Verifying a finalized swap whose inclusion_header.timestamp is anomalously large (ms/ns instead of seconds, sentinel u64 max, or corrupted header from a faulty provider), making timestamp * 1e9 exceed the integer bound.","commonSituations":"Provider returning millisecond timestamps; mocked headers with placeholder timestamps in tests; a hardfork or L2 sequencer quirk producing an out-of-range timestamp; mixing header sources with different timestamp units.","solutions":["Confirm the header source reports timestamp in seconds and convert ms/ns inputs before verification","Re-fetch the block header from a trusted endpoint; an overflow-level timestamp indicates corrupted upstream data","Sanitize/validate timestamp <= i64::MAX / 1_000_000_000 before invoking the verification API","Keep the header and receipt from the same provider so units and values are consistent"],"exampleFix":"// before\nlet timestamp_ns = block.timestamp.checked_mul(NANOSECONDS_IN_SECOND)?;\n// after\nlet secs = if block.timestamp > 253_402_300_800 { block.timestamp / 1000 } else { block.timestamp };\nlet timestamp_ns = secs.checked_mul(NANOSECONDS_IN_SECOND)?;","handlingStrategy":"validation","validationCode":"const MAX_TS_SECS: u64 = (i64::MAX as u64) / 1_000_000_000;\nif block.timestamp > MAX_TS_SECS { return Err(anyhow!(\"block timestamp {} out of range\", block.timestamp)); }","typeGuard":"fn ts_fits_nanos(ts: u64) -> bool { ts <= (i64::MAX as u64) / 1_000_000_000 }","tryCatchPattern":"let ts_ns = block.timestamp.checked_mul(NANOSECONDS_IN_SECOND)\n    .ok_or_else(|| { log::error!(\"timestamp overflow: {}\", block.timestamp); anyhow!(\"overflow\") })?;","preventionTips":["Validate header timestamps are in seconds at the provider boundary","Reject implausible timestamps (before genesis or far in the future) early","Use checked arithmetic for all timestamp scaling","Keep header and receipt sources consistent in units"],"tags":["overflow","timestamp","blockchain","integer-arithmetic"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}