Skip to content

Conversation

@rustopian
Copy link
Contributor

@rustopian rustopian commented Nov 24, 2025

[WIP]

This addresses Issue #235, fixing two issues with the original (reverted) PR:

  1. The contract of from_raw_parts_mut was being violated, in a way that miri considered safe, but which could have theoretically caused trouble in the future.
  2. The implementation assumed that the number of bytes returned by the runtime was exactly
    mem::size_of::<Self>(), which was not always true. Rent, for example, contains a u64, an f64 and a u8. In memory the compiler pads this struct to 24 bytes, but the runtime stores its contents as a 17‑byte bincode serialization. The get_sysvar call thus returns only 17 bytes. Passing a 24‑byte buffer results in an OFFSET_LENGTH_EXCEEDS_SYSVAR error and undefined behavior when uninitialized bytes are interpreted as f64.

In order to address this second issue, this PR provides 1‑byte‑aligned representations of the sysvars that match the on‑chain encoding. Then, we can zero-copy the bytes directly into those representations and convert them to the canonical structs without using bincode.

This is lightweight but bespoke deserialization to avoid requiring any given dependency.

@rustopian rustopian changed the title Use sol_get_sysvar instead of sol_get_<NAME>_sysvar (#257), with impl_sysvar_from_repr Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with impl_sysvar_from_repr Nov 24, 2025
@rustopian rustopian changed the title Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with impl_sysvar_from_repr [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with impl_sysvar_from_repr Nov 24, 2025
@rustopian rustopian changed the title [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with impl_sysvar_from_repr [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with WirePod trait Nov 24, 2025
@rustopian rustopian changed the title [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with WirePod trait [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with define_sysvar_wire Nov 24, 2025
@anza-xyz anza-xyz deleted a comment from github-actions bot Nov 25, 2025
@anza-xyz anza-xyz deleted a comment from github-actions bot Nov 25, 2025
@anza-xyz anza-xyz deleted a comment from github-actions bot Nov 25, 2025
@anza-xyz anza-xyz deleted a comment from github-actions bot Nov 25, 2025
@github-actions
Copy link
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@anza-xyz anza-xyz deleted a comment from github-actions bot Nov 25, 2025
@rustopian rustopian changed the title [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, with define_sysvar_wire [WIP] Use sol_get_sysvar instead of sol_get_<NAME>_sysvar, now with deserialization Nov 25, 2025
@github-actions
Copy link
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@github-actions
Copy link
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@rustopian
Copy link
Contributor Author

Replacing for sake of cleaner PR history

@rustopian rustopian closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant