Addressed Types
Problem
In addressed systems, data is identified by its hash. All addressing reduces to hashing — even physical locations can be geohashed. Producing the hash requires canonical serialization — the same data must always serialize to the same bytes. Rust has no built-in concept of canonical serialization or hash-derived identity.
Solution
The Addressed derive macro generates canonical serialization and a .particle() method.
Syntax
let link = Cyberlink ;
let id: Particle = link.particle; // Deterministic, canonical hash
// Two identical structs always produce the same Particle
let link2 = Cyberlink ;
assert_eq!;
Canonical Serialization Rules
The derived serializer follows strict rules:
- Fields are serialized in declaration order (not alphabetical, not random)
- Integers are serialized as little-endian fixed-width bytes
boolis serialized as a singleu8(0 = false, 1 = true)Option<T>is serialized as au8tag (0 = None, 1 = Some) followed byTdata if Some- Fixed-length arrays (
[T; N]) are serialized as N elements with no length prefix (length is known from the type) - Variable-length types (slices,
BoundedVec) are prefixed with a u32 length - No padding bytes between fields
- Enums serialized as discriminant (u32) + variant data
- Nested
Addressedtypes are serialized as their Particle (64 bytes), not expanded
Hash function: Hemera — a Poseidon2 sponge over the Goldilocks field (p = 2⁶⁴ − 2³² + 1), 64-byte output, producing a Particle. Parameters: state width 16 elements, rate 8, capacity 8, 8 full rounds, 64 partial rounds, S-box x⁷. Capacity 8 (256 bits) provides long-term collision resistance matching the permanence of particle addresses. See the Hemera spec for the full parameter rationale.
Compile-Time Checks
| Check | Error |
|---|---|
| Field type not serializable | error[RS301]: type MyOpaqueType does not implement CanonicalSerialize |
Contains f32/f64 |
error[RS302]: floating point types are not canonically serializable |
| Contains raw pointers | error[RS303]: pointers cannot be addressed |
Contains HashMap |
error[RS304]: HashMap has non-deterministic serialization; use BTreeMap |
Contains usize or isize |
error[RS305]: usize/isize width is platform-dependent; use u32 or u64 |
Enum has #[repr] wider than u32 |
error[RS306]: Addressed enum discriminant must fit in u32; #[repr(u64)] is not supported |
Serialization Order for Collections
BoundedMap<K, V, N> serializes entries in key-sorted order (ascending). This matches BTreeMap iteration order and guarantees canonical output regardless of insertion order.
Implementation
Implemented as a proc-macro (no compiler changes required). Works in both standard Rust and Rs editions. ~500 lines.
Error Reference
See errors/addressed.md for detailed descriptions of RS301–RS306.