Skip to content

feat: Serialization for Scalar types #130

@flyingrobots

Description

@flyingrobots

Problem / Motivation

Raw deserialization of floating-point values can bypass runtime invariants if not carefully guarded. For example, a serialized -0.0 or non-canonical NaN could
be loaded directly into memory, violating the strict determinism guarantees required for Echo's simulation loop. We must ensure that no path exists to
instantiate an F32Scalar without passing through the canonicalization logic.

Proposal / Scope

  1. Guard Deserialization: Verify that the serde::Deserialize implementation for F32Scalar strictly routes all inputs through F32Scalar::new() to apply canonicalization (mapping -0.0 to +0.0, sanitizing NaNs).
  2. Forbid Zerocopy: Explicitly ensure/document that F32Scalar does not implement zerocopy::FromBytes or similar traits that allow reinterpret casts from raw bytes.
  3. Verify Guard: Enable and pass test_policy_serialization_guard in crates/rmg-core/tests/determinism_policy_tests.rs to prove that deserializing a "bad" payload (e.g., -0.0) results in a clean +0.0 instance in memory.

Related Docs/Issues/PRs

Metadata

Metadata

Assignees

Labels

featureFeature umbrella (epic)mathMathematics

Projects

Status

Open

Relationships

None yet

Development

No branches or pull requests

Issue actions