Skip to main content

hopper_native/
raw_account.rs

1//! Raw account header for the Solana loader input buffer.
2//!
3//! `RuntimeAccount` is the substrate-level truth Hopper Native uses when it
4//! reads the loader's account array. Duplicate-account tracking lives in
5//! [`crate::raw_input`]; this type models only the canonical backing account
6//! record that duplicates point at.
7
8use crate::address::Address;
9
10/// Raw C-layout struct matching the Solana BPF account input format.
11///
12/// Each non-duplicate account in the entrypoint input buffer begins with this
13/// header, immediately followed by `data_len` bytes of account data.
14///
15/// The first byte occupies the loader's duplicate marker slot. Hopper Native
16/// reuses that byte as `borrow_state`, which is valid because canonical
17/// accounts enter the program with the `0xFF` marker and Hopper uses the same
18/// value to mean `NOT_BORROWED`.
19#[repr(C)]
20#[cfg_attr(feature = "copy", derive(Copy))]
21#[derive(Clone, Default)]
22pub struct RuntimeAccount {
23    /// Borrow tracking state (repurposed from the loader duplicate marker).
24    ///
25    /// Duplicate-account relationships are tracked in `raw_input`; once a
26    /// canonical account is identified, this byte becomes Hopper's borrow
27    /// state for that canonical record.
28    pub borrow_state: u8,
29    /// 1 if transaction signer, 0 otherwise.
30    pub is_signer: u8,
31    /// 1 if writable, 0 otherwise.
32    pub is_writable: u8,
33    /// 1 if executable, 0 otherwise.
34    pub executable: u8,
35    /// Delta between original and current data length (realloc tracking).
36    pub resize_delta: i32,
37    /// Account public key (32 bytes).
38    pub address: Address,
39    /// Owning program (32 bytes).
40    pub owner: Address,
41    /// Lamport balance.
42    pub lamports: u64,
43    /// Length of account data following this struct.
44    pub data_len: u64,
45    // Account data bytes follow immediately in memory.
46}
47
48impl RuntimeAccount {
49    /// Size of the raw loader header before account data begins.
50    pub const SIZE: usize = core::mem::size_of::<Self>();
51}
52
53const _: () = assert!(core::mem::size_of::<RuntimeAccount>() == 88);