Skip to content

Design a zero-copy state deserialization routine for hot-path fractional balance lookups #477

Description

@Damola-Sodiq

Description

Refactor the contract to read fractional token balances directly from raw WASM byte slices, skipping expensive Rust struct allocations.

Architecture & Context

For high-frequency queries like balance checks, deserializing host environment data into full Rust structs consumes massive amounts of CPU instructions. Zero-copy deserialization allows the contract to extract exactly the needed bytes directly from memory, drastically lowering gas fees.

Technical Requirements

  • Intercept the raw byte payload from the Soroban host environment.
  • Implement pointer arithmetic and offset reading in Rust to extract the i128 balance.
  • Ensure all unsafe memory boundaries are heavily documented and proven safe.

Acceptance Criteria

  • Hot-path queries execute in a fraction of the original instruction count.
  • No heap memory allocations occur during a balance lookup.
  • Fuzz tests ensure out-of-bounds byte reads are impossible.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions