Skip to main content

hopper_native/
syscalls.rs

1//! Raw Solana syscall declarations.
2//!
3//! These are the extern "C" functions provided by the Solana BPF runtime.
4//! Only available when compiling for `target_os = "solana"`.
5
6#[cfg(target_os = "solana")]
7extern "C" {
8    /// Log a UTF-8 message.
9    pub fn sol_log_(message: *const u8, len: u64);
10
11    /// Log a 64-bit value.
12    pub fn sol_log_64_(arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u64);
13
14    /// Log the current compute unit consumption.
15    pub fn sol_log_compute_units_();
16
17    /// Log structured data segments (for events).
18    pub fn sol_log_data(data: *const u8, data_len: u64);
19
20    /// Invoke a cross-program instruction (C ABI).
21    pub fn sol_invoke_signed_c(
22        instruction_addr: *const u8,
23        account_infos_addr: *const u8,
24        account_infos_len: u64,
25        signers_seeds_addr: *const u8,
26        signers_seeds_len: u64,
27    ) -> u64;
28
29    /// Create a program-derived address.
30    pub fn sol_create_program_address(
31        seeds_addr: *const u8,
32        seeds_len: u64,
33        program_id_addr: *const u8,
34        address_addr: *mut u8,
35    ) -> u64;
36
37    /// Find a program-derived address with bump seed.
38    pub fn sol_try_find_program_address(
39        seeds_addr: *const u8,
40        seeds_len: u64,
41        program_id_addr: *const u8,
42        address_addr: *mut u8,
43        bump_seed_addr: *mut u8,
44    ) -> u64;
45
46    /// SHA-256 hash.
47    pub fn sol_sha256(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64;
48
49    /// Validate whether a point lies on the selected curve.
50    pub fn sol_curve_validate_point(
51        curve_id: u64,
52        point_addr: *const u8,
53        result_point_addr: *mut u8,
54    ) -> u64;
55
56    /// Keccak-256 hash.
57    pub fn sol_keccak256(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64;
58
59    /// Set return data for the current instruction.
60    pub fn sol_set_return_data(data: *const u8, length: u64);
61
62    /// Get return data from the previous CPI.
63    pub fn sol_get_return_data(data: *mut u8, length: u64, program_id: *mut u8) -> u64;
64
65    /// Get the current clock sysvar.
66    pub fn sol_get_clock_sysvar(addr: *mut u8) -> u64;
67
68    /// Get the current rent sysvar.
69    pub fn sol_get_rent_sysvar(addr: *mut u8) -> u64;
70
71    /// Get epoch schedule sysvar.
72    pub fn sol_get_epoch_schedule_sysvar(addr: *mut u8) -> u64;
73
74    /// Abort program execution.
75    pub fn sol_panic_(file: *const u8, len: u64, line: u64, column: u64) -> !;
76
77    // ── Memory operations (SVM-optimized) ─────────────────────────
78
79    /// Copy `n` bytes from `src` to `dst` (non-overlapping).
80    pub fn sol_memcpy_(dst: *mut u8, src: *const u8, n: u64);
81
82    /// Copy `n` bytes from `src` to `dst` (overlapping safe).
83    pub fn sol_memmove_(dst: *mut u8, src: *const u8, n: u64);
84
85    /// Compare `n` bytes. Sets `*result` to <0, 0, or >0.
86    pub fn sol_memcmp_(s1: *const u8, s2: *const u8, n: u64, result: *mut i32);
87
88    /// Fill `n` bytes with `c`.
89    pub fn sol_memset_(s: *mut u8, c: u8, n: u64);
90
91    // ── Instruction introspection ────────────────────────────────
92
93    /// Get the current instruction stack height.
94    pub fn sol_get_stack_height() -> u64;
95
96    /// Get a previously processed sibling instruction.
97    pub fn sol_get_processed_sibling_instruction(
98        index: u64,
99        meta: *mut u8,
100        program_id: *mut u8,
101        data: *mut u8,
102        accounts: *mut u8,
103    ) -> u64;
104
105    /// Get the last restart slot sysvar.
106    pub fn sol_get_last_restart_slot(addr: *mut u8) -> u64;
107}