hopper_native/entrypoint.rs
1//! Program entrypoint ownership for Hopper Native.
2//!
3//! This file is the only raw program-entry boundary owner in Hopper Native.
4//! Loader input parsing lives in [`crate::raw_input`], while the public macros
5//! below own the raw `entrypoint(input: *mut u8)` boundary and delegate into
6//! Hopper callbacks.
7
8use core::mem::MaybeUninit;
9
10use crate::account_view::AccountView;
11use crate::address::Address;
12use crate::error::ProgramError;
13
14/// Convert a handler's `ProgramError` into the Solana runtime's u64 return code.
15///
16/// Outlined `#[cold] #[inline(never)]` so an entrypoint's success tail lowers to
17/// a bare `return SUCCESS` and the `ProgramError -> u64` mapping (the 25-arm
18/// `From<ProgramError> for u64` match) is never inlined into the hot frame,
19/// where it would add code size and stack traffic that every successful
20/// invocation pays for. This mirrors Pinocchio's cold error outline.
21///
22/// The conversion is exactly `Into::<u64>::into(e)`, byte-for-byte identical to
23/// the previous inline `error.into()`, so the runtime error codes are unchanged.
24#[cold]
25#[inline(never)]
26pub fn err_to_u64(e: ProgramError) -> u64 {
27 e.into()
28}
29
30/// Process the BPF entrypoint input.
31///
32/// This is the function called by the canonical Hopper Native entrypoint macro's
33/// generated entrypoint.
34///
35/// # Safety
36///
37/// `input` must be the raw pointer provided by the Solana runtime.
38#[inline(always)]
39pub unsafe fn process_entrypoint<const MAX: usize>(
40 input: *mut u8,
41 process_instruction: for<'info> fn(
42 &'info Address,
43 &'info [AccountView<'info>],
44 &'info [u8],
45 ) -> crate::ProgramResult,
46) -> u64 {
47 const UNINIT: MaybeUninit<AccountView<'static>> = MaybeUninit::uninit();
48 let mut accounts = [UNINIT; 254]; // MAX_TX_ACCOUNTS
49
50 let (program_id, count, instruction_data) =
51 // SAFETY: This block is part of Hopper's reviewed zero-copy/backend boundary; surrounding checks and caller contracts uphold the required raw-pointer, layout, and aliasing invariants.
52 unsafe { crate::raw_input::deserialize_accounts::<254>(input, &mut accounts) };
53
54 // Respect MAX: only pass up to MAX accounts to the callback.
55 let effective_count = count.min(MAX);
56 // SAFETY: This block is part of Hopper's reviewed zero-copy/backend boundary; surrounding checks and caller contracts uphold the required raw-pointer, layout, and aliasing invariants.
57 let account_slice = unsafe {
58 core::slice::from_raw_parts(accounts.as_ptr() as *const AccountView<'_>, effective_count)
59 };
60
61 match process_instruction(program_id, account_slice, instruction_data) {
62 Ok(()) => crate::SUCCESS,
63 Err(error) => err_to_u64(error),
64 }
65}
66
67/// Declare the canonical Hopper Native program entrypoint.
68///
69/// Generates the `extern "C" fn entrypoint` that the Solana runtime calls.
70/// `program_entrypoint!` remains available as a backward-compatible alias.
71///
72/// # Usage
73///
74/// ```ignore
75/// use hopper_native::hopper_program_entrypoint;
76///
77/// hopper_program_entrypoint!(process_instruction);
78///
79/// pub fn process_instruction(
80/// program_id: &Address,
81/// accounts: &[AccountView],
82/// instruction_data: &[u8],
83/// ) -> ProgramResult {
84/// Ok(())
85/// }
86/// ```
87#[macro_export]
88macro_rules! hopper_program_entrypoint {
89 ( $process_instruction:expr ) => {
90 $crate::hopper_program_entrypoint!($process_instruction, { $crate::MAX_TX_ACCOUNTS });
91 };
92 ( $process_instruction:expr, $maximum:expr ) => {
93 /// # Safety
94 ///
95 /// Called by the Solana runtime; `input` is a valid BPF input buffer.
96 #[no_mangle]
97 pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
98 const UNINIT: core::mem::MaybeUninit<$crate::AccountView<'static>> =
99 core::mem::MaybeUninit::<$crate::AccountView<'static>>::uninit();
100 let mut accounts = [UNINIT; $maximum];
101
102 // SAFETY: This block is part of Hopper's reviewed zero-copy/backend boundary; surrounding checks and caller contracts uphold the required raw-pointer, layout, and aliasing invariants.
103 let (program_id, count, instruction_data) = unsafe {
104 $crate::raw_input::deserialize_accounts::<$maximum>(input, &mut accounts)
105 };
106
107 match $process_instruction(
108 program_id,
109 // SAFETY: This block is part of Hopper's reviewed zero-copy/backend boundary; surrounding checks and caller contracts uphold the required raw-pointer, layout, and aliasing invariants.
110 unsafe {
111 core::slice::from_raw_parts(
112 accounts.as_ptr() as *const $crate::AccountView<'_>,
113 count,
114 )
115 },
116 instruction_data,
117 ) {
118 Ok(()) => $crate::SUCCESS,
119 Err(error) => $crate::entrypoint::err_to_u64(error),
120 }
121 }
122 };
123}
124
125/// Backward-compatible alias for `hopper_program_entrypoint!`.
126#[macro_export]
127macro_rules! program_entrypoint {
128 ( $process_instruction:expr ) => {
129 $crate::hopper_program_entrypoint!($process_instruction);
130 };
131 ( $process_instruction:expr, $maximum:expr ) => {
132 $crate::hopper_program_entrypoint!($process_instruction, $maximum);
133 };
134}
135
136/// Declare a fast two-argument Hopper Native program entrypoint.
137///
138/// Uses the SVM's second entrypoint register (`r2`), which carries a
139/// direct pointer to instruction data under [SIMD-0321], letting the
140/// entrypoint skip locating the instruction tail. Measured honestly
141/// (2026-07-21, post the 2026-07-07 fused single-pass walk): the fused
142/// scanning entrypoint already hops records by their `data_len` headers
143/// without touching account data, so on programs whose accounts fit the
144/// declared maximum the r2 path is CU-neutral (+/- 2 CU in controlled
145/// A/Bs) and costs ~368 bytes for carrying both paths. The historical
146/// "~30-40 CU" figure described the pre-fusion two-pass scanner. The r2
147/// path earns its keep as the base of the SIMD-0449 O(1) account-pointer
148/// table, and for instructions whose transaction carries many more
149/// accounts than the program materializes.
150///
151/// # Feature gating (`simd-0321`)
152///
153/// SIMD-0321 is **activated on all three public clusters** (feature gate
154/// `5xXZc66h4UdB6Yq7FzdBxBiRAFMMScMLwHxk2QZDaNZL`; mainnet-beta at slot
155/// 410,400,000, 2026-04-01). Current agave sets `r2` unconditionally, so
156/// builds may enable the feature for any cluster target; on a runtime
157/// that ever leaves `r2` zero, the null-check below still falls back to
158/// the scanning parse.
159///
160/// - **Default (feature off):** this macro expands to the standard
161/// scanning entrypoint ([`hopper_program_entrypoint!`]). Identical
162/// semantics, sound on every cluster today, and source-compatible:
163/// when the gate activates, rebuild with the feature to claim the
164/// CU savings.
165/// - **`simd-0321` enabled:** the macro expands to the two-argument
166/// entrypoint. As defense in depth it null-checks `r2` and falls
167/// back to the scanning parse when the register is zero (current
168/// SBPF VMs zero-initialize unused argument registers), so a binary
169/// built with the feature degrades to the slow path instead of
170/// reading garbage if it lands on a cluster without the activation.
171///
172/// `hopper doctor` / `hopper deploy` can check the feature-gate account
173/// on the target cluster before a `simd-0321` build ships.
174///
175/// [SIMD-0321]: https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0321-vm-r2-instruction-data-pointer.md
176///
177/// # Usage
178///
179/// ```ignore
180/// use hopper_native::hopper_fast_entrypoint;
181///
182/// hopper_fast_entrypoint!(process_instruction, 3);
183///
184/// pub fn process_instruction(
185/// program_id: &Address,
186/// accounts: &[AccountView],
187/// instruction_data: &[u8],
188/// ) -> ProgramResult {
189/// Ok(())
190/// }
191/// ```
192#[cfg(feature = "simd-0321")]
193#[macro_export]
194macro_rules! hopper_fast_entrypoint {
195 ( $process_instruction:expr ) => {
196 $crate::hopper_fast_entrypoint!($process_instruction, { $crate::MAX_TX_ACCOUNTS });
197 };
198 ( $process_instruction:expr, $maximum:expr ) => {
199 /// # Safety
200 ///
201 /// Called by the Solana runtime; `input` is a valid BPF input buffer.
202 /// When SIMD-0321 is active, `ix_data` points to the instruction data
203 /// with its u64 length stored at offset -8; when it is not active the
204 /// register is zero and the scanning fallback below is taken.
205 #[no_mangle]
206 pub unsafe extern "C" fn entrypoint(input: *mut u8, ix_data: *const u8) -> u64 {
207 const UNINIT: core::mem::MaybeUninit<$crate::AccountView<'static>> =
208 core::mem::MaybeUninit::<$crate::AccountView<'static>>::uninit();
209 let mut accounts = [UNINIT; $maximum];
210
211 let (program_id, count, instruction_data) = if ix_data.is_null() {
212 // SIMD-0321 not active on this cluster: r2 is zero. Fall back
213 // to the full scanning parse so the program stays correct.
214 // SAFETY: `input` is the loader-provided input buffer; the
215 // scanning parser owns all bounds/duplicate-marker checks.
216 unsafe { $crate::raw_input::deserialize_accounts::<$maximum>(input, &mut accounts) }
217 } else {
218 // Instruction data length is the u64 immediately before the
219 // data pointer (per SIMD-0321's serialization contract).
220 // SAFETY: SIMD-0321 ix_data points at instruction-data bytes
221 // with u64 length prefix at `ix_data - 8`.
222 let ix_len =
223 unsafe { core::ptr::read_unaligned(ix_data.sub(8) as *const u64) as usize };
224 let instruction_data: &'static [u8] =
225 unsafe { core::slice::from_raw_parts(ix_data, ix_len) };
226
227 // SAFETY: program id trails the instruction data per the
228 // loader serialization layout; `Address` is a transparent
229 // `[u8; 32]`, so a reference into the buffer is valid at any
230 // offset and lives as long as the invocation.
231 let program_id: &'static $crate::Address =
232 unsafe { &*(ix_data.add(ix_len) as *const $crate::Address) };
233
234 if $crate::raw_input::SIMD_0449_TABLE_ENABLED {
235 // SIMD-0449 build: consume the runtime's appended
236 // pre-deduplicated account-pointer table, O(1)
237 // resolution plus one pointer copy per account. The
238 // gate is a `const`, so the untaken branch folds
239 // away entirely.
240 // SAFETY: the `simd-0449` feature asserts the SIMD
241 // is active on the target cluster (table present);
242 // `instruction_data`/`program_id` were derived from
243 // the SIMD-0321 r2 register above.
244 unsafe {
245 $crate::raw_input::deserialize_accounts_0449_into::<$maximum>(
246 input,
247 &mut accounts,
248 instruction_data,
249 program_id,
250 )
251 }
252 } else {
253 // SAFETY: `input` is the loader input buffer; account-slot
254 // framing is validated by `deserialize_accounts_fast`.
255 unsafe {
256 $crate::raw_input::deserialize_accounts_fast::<$maximum>(
257 input,
258 &mut accounts,
259 instruction_data,
260 program_id,
261 )
262 }
263 }
264 };
265
266 match $process_instruction(
267 program_id,
268 // SAFETY: the first `count` slots were initialized by the
269 // parser above; `AccountView` is repr(C) over the slot data.
270 unsafe {
271 core::slice::from_raw_parts(
272 accounts.as_ptr() as *const $crate::AccountView<'_>,
273 count,
274 )
275 },
276 instruction_data,
277 ) {
278 Ok(()) => $crate::SUCCESS,
279 Err(error) => $crate::entrypoint::err_to_u64(error),
280 }
281 }
282 };
283}
284
285/// Without the `simd-0321` feature the "fast" entrypoint is an alias for
286/// the standard scanning entrypoint. The SIMD-0321 gate is live on every
287/// public cluster (mainnet-beta 2026-04-01); the r2 form is sound to build
288/// and stays opt-in only because it measured CU-neutral against the fused
289/// scanning walk for ~368 bytes of extra `.text`. The two-argument r2 form
290/// also null-checks the register and falls back to scanning, so it is safe
291/// even where the gate is somehow inactive.
292#[cfg(not(feature = "simd-0321"))]
293#[macro_export]
294macro_rules! hopper_fast_entrypoint {
295 ( $process_instruction:expr ) => {
296 $crate::hopper_program_entrypoint!($process_instruction);
297 };
298 ( $process_instruction:expr, $maximum:expr ) => {
299 $crate::hopper_program_entrypoint!($process_instruction, $maximum);
300 };
301}
302
303/// Backward-compatible alias for `hopper_fast_entrypoint!`.
304#[macro_export]
305macro_rules! fast_entrypoint {
306 ( $process_instruction:expr ) => {
307 $crate::hopper_fast_entrypoint!($process_instruction);
308 };
309 ( $process_instruction:expr, $maximum:expr ) => {
310 $crate::hopper_fast_entrypoint!($process_instruction, $maximum);
311 };
312}
313
314/// Declare the canonical lazy program entrypoint that defers account parsing.
315#[macro_export]
316macro_rules! hopper_lazy_entrypoint {
317 ( $process:expr ) => {
318 /// # Safety
319 ///
320 /// Called by the Solana runtime; `input` is a valid BPF input buffer.
321 #[no_mangle]
322 pub unsafe extern "C" fn entrypoint(input: *mut u8) -> u64 {
323 // SAFETY: This block is part of Hopper's reviewed zero-copy/backend boundary; surrounding checks and caller contracts uphold the required raw-pointer, layout, and aliasing invariants.
324 let mut ctx = unsafe { $crate::lazy::lazy_deserialize(input) };
325 match $process(&mut ctx) {
326 Ok(()) => $crate::SUCCESS,
327 Err(error) => $crate::entrypoint::err_to_u64(error),
328 }
329 }
330 };
331}
332
333/// Backward-compatible alias for `hopper_lazy_entrypoint!`.
334#[macro_export]
335macro_rules! lazy_entrypoint {
336 ( $process:expr ) => {
337 $crate::hopper_lazy_entrypoint!($process);
338 };
339}
340
341/// Set up a no-op global allocator that aborts on allocation.
342///
343/// Useful for `no_std` programs that must not allocate. Any attempt to
344/// allocate immediately aborts the invocation through the SVM's abort syscall.
345/// No experimental inline assembly is required. Returning null would also be
346/// valid for `GlobalAlloc`; this allocator deliberately fails immediately.
347#[macro_export]
348macro_rules! no_allocator {
349 () => {
350 #[cfg(target_os = "solana")]
351 mod __hopper_allocator {
352 struct NoAlloc;
353
354 unsafe impl core::alloc::GlobalAlloc for NoAlloc {
355 unsafe fn alloc(&self, _layout: core::alloc::Layout) -> *mut u8 {
356 // SAFETY: abort accepts no pointers and never returns.
357 unsafe { $crate::syscalls::abort() }
358 }
359 unsafe fn dealloc(&self, _ptr: *mut u8, _layout: core::alloc::Layout) {}
360 }
361
362 #[global_allocator]
363 static ALLOCATOR: NoAlloc = NoAlloc;
364 }
365 };
366}
367
368/// Canonical Solana heap region start address (`0x3_0000_0000`).
369pub const HEAP_START_ADDRESS: usize = 0x3_0000_0000;
370
371/// Default Solana heap region length (32 KiB).
372pub const HEAP_LENGTH: usize = 32 * 1024;
373
374/// Bytes of the heap's BOTTOM reserved as Hopper runtime scratch, starting
375/// right after the [`BumpAllocator`] cursor word: the byte range
376/// `[HEAP_START + 8, HEAP_START + 8 + HEAP_RUNTIME_RESERVED)`.
377///
378/// Why this exists: deployed SBF programs cannot carry writable sections,
379/// the loader rejects `.bss`/`.data` outright (`WritableSectionNotSupported`),
380/// so a `static mut` is not merely costly, it makes the program FAIL TO
381/// LOAD. The only writable, per-invocation, zero-initialized memory a
382/// program owns is this VM heap region. Hopper's instruction-scoped
383/// runtime state (today: the lamport gate in
384/// `hopper_runtime::write_policy`) therefore lives at the heap bottom,
385/// which works precisely because the VM zeroes the region on every
386/// invocation and every such structure is valid all-zero.
387///
388/// The [`BumpAllocator`] treats this range as out of bounds (its floor sits
389/// above it), so `alloc` can never hand it out. Programs that install a
390/// custom allocator over the heap must honor the same reservation if they
391/// link any hopper-runtime feature that uses it.
392pub const HEAP_RUNTIME_RESERVED: usize = 20 * 1024;
393
394/// A bump allocator over the SVM heap region.
395///
396/// This is the same single-pass, never-frees design the Solana SDK and
397/// Pinocchio use: the first word of the heap stores the current cursor,
398/// allocations bump it downward from the top of the region, and
399/// `dealloc` is a no-op. It is the right allocator for the cold paths of
400/// a program that wants `alloc` (e.g. a `Vec` while building a CPI) while
401/// keeping the hot path zero-allocation. For programs that must never
402/// allocate, prefer [`no_allocator!`] so any stray allocation traps.
403///
404/// Install it with `default_allocator!`.
405pub struct BumpAllocator {
406 /// Heap region start address.
407 pub start: usize,
408 /// Heap region length in bytes.
409 pub len: usize,
410}
411
412// SAFETY: Solana program execution is single-threaded, so the cursor word
413// at `start` is never accessed concurrently.
414unsafe impl core::alloc::GlobalAlloc for BumpAllocator {
415 #[inline]
416 unsafe fn alloc(&self, layout: core::alloc::Layout) -> *mut u8 {
417 // The cursor is stored in the first word of the heap region.
418 let pos_ptr = self.start as *mut usize;
419 // SAFETY: `pos_ptr` is the reserved cursor word; single-threaded.
420 let mut pos = unsafe { *pos_ptr };
421 if pos == 0 {
422 // First allocation: start at the top of the region.
423 pos = self.start + self.len;
424 }
425 pos = pos.saturating_sub(layout.size());
426 pos &= !(layout.align().wrapping_sub(1));
427 // Floor: the cursor word plus the Hopper runtime scratch region
428 // ([`HEAP_RUNTIME_RESERVED`], heap bottom). Bumping into either
429 // would corrupt the allocator state or the instruction-scoped
430 // runtime state (e.g. the lamport gate), so exhaust instead.
431 if pos < self.start + core::mem::size_of::<usize>() + HEAP_RUNTIME_RESERVED {
432 return core::ptr::null_mut();
433 }
434 // SAFETY: `pos_ptr` is the reserved cursor word; single-threaded.
435 unsafe { *pos_ptr = pos };
436 pos as *mut u8
437 }
438
439 #[inline]
440 unsafe fn dealloc(&self, _ptr: *mut u8, _layout: core::alloc::Layout) {
441 // Bump allocator: memory is reclaimed when the instruction ends.
442 }
443}
444
445/// Install the default bump allocator over the SVM heap region.
446///
447/// Opt-in counterpart to [`no_allocator!`]: use this when a program needs
448/// `alloc` (e.g. heap `Vec`/`String` on a cold path) while keeping the
449/// zero-copy hot path allocation-free. Never frees within an instruction;
450/// the whole heap is reclaimed when the instruction returns.
451#[macro_export]
452macro_rules! default_allocator {
453 () => {
454 #[cfg(target_os = "solana")]
455 #[global_allocator]
456 static ALLOCATOR: $crate::BumpAllocator = $crate::BumpAllocator {
457 start: $crate::HEAP_START_ADDRESS,
458 len: $crate::HEAP_LENGTH,
459 };
460 };
461}
462
463/// Default no_std panic handler that aborts immediately.
464///
465/// Uses the SVM abort syscall, without experimental inline assembly or a
466/// compute-consuming spin loop. The runtime rolls back the failed instruction.
467#[macro_export]
468macro_rules! nostd_panic_handler {
469 () => {
470 #[cfg(target_os = "solana")]
471 #[panic_handler]
472 fn panic(_info: &core::panic::PanicInfo) -> ! {
473 // SAFETY: abort accepts no pointers and never returns.
474 unsafe { $crate::syscalls::abort() }
475 }
476 };
477}
478
479#[cfg(test)]
480mod entrypoint_tail_tests {
481 extern crate std;
482
483 use std::vec;
484 use std::vec::Vec;
485
486 use super::*;
487
488 /// Serialize a zero-account loader frame: `u64` account count (0), then the
489 /// `u64` ix-data length prefix, the ix-data bytes, and the 32-byte program
490 /// id. Returns an 8-aligned `u64` backing (matching `MM_INPUT_START`).
491 fn build_zero_account_frame(ix_data: &[u8], program_id: [u8; 32]) -> Vec<u64> {
492 let mut buf: Vec<u8> = Vec::new();
493 buf.extend_from_slice(&0u64.to_le_bytes()); // account_count = 0
494 buf.extend_from_slice(&(ix_data.len() as u64).to_le_bytes());
495 buf.extend_from_slice(ix_data);
496 buf.extend_from_slice(&program_id);
497 let mut words = vec![0u64; buf.len().div_ceil(8)];
498 // SAFETY: `words` has at least `buf.len()` bytes of capacity and the
499 // regions do not overlap.
500 unsafe {
501 core::ptr::copy_nonoverlapping(buf.as_ptr(), words.as_mut_ptr() as *mut u8, buf.len());
502 }
503 words
504 }
505
506 fn ok_handler<'a>(
507 _: &'a Address,
508 _: &'a [AccountView<'a>],
509 _: &'a [u8],
510 ) -> crate::ProgramResult {
511 Ok(())
512 }
513
514 fn custom_err_handler<'a>(
515 _: &'a Address,
516 _: &'a [AccountView<'a>],
517 _: &'a [u8],
518 ) -> crate::ProgramResult {
519 Err(ProgramError::Custom(4242))
520 }
521
522 fn builtin_err_handler<'a>(
523 _: &'a Address,
524 _: &'a [AccountView<'a>],
525 _: &'a [u8],
526 ) -> crate::ProgramResult {
527 Err(ProgramError::MissingRequiredSignature)
528 }
529
530 #[test]
531 fn ok_returns_bare_success_zero() {
532 let mut frame = build_zero_account_frame(&[1, 2, 3], [7u8; 32]);
533 // SAFETY: `frame` is a well-formed, 8-aligned zero-account loader frame.
534 let code = unsafe { process_entrypoint::<4>(frame.as_mut_ptr() as *mut u8, ok_handler) };
535 assert_eq!(code, 0);
536 assert_eq!(code, crate::SUCCESS);
537 }
538
539 #[test]
540 fn custom_err_maps_through_cold_outline_unchanged() {
541 let mut frame = build_zero_account_frame(&[], [0u8; 32]);
542 // SAFETY: well-formed, 8-aligned zero-account loader frame.
543 let code =
544 unsafe { process_entrypoint::<4>(frame.as_mut_ptr() as *mut u8, custom_err_handler) };
545 // Cold outline must equal the direct `From<ProgramError> for u64` mapping.
546 assert_eq!(code, u64::from(ProgramError::Custom(4242)));
547 assert_eq!(code, err_to_u64(ProgramError::Custom(4242)));
548 assert_eq!(code, 4242);
549 }
550
551 #[test]
552 fn builtin_err_maps_through_cold_outline_unchanged() {
553 let mut frame = build_zero_account_frame(&[], [0u8; 32]);
554 // SAFETY: well-formed, 8-aligned zero-account loader frame.
555 let code =
556 unsafe { process_entrypoint::<4>(frame.as_mut_ptr() as *mut u8, builtin_err_handler) };
557 assert_eq!(code, u64::from(ProgramError::MissingRequiredSignature));
558 assert_eq!(code, err_to_u64(ProgramError::MissingRequiredSignature));
559 }
560
561 /// The cold outline is a byte-for-byte alias of `From<ProgramError> for u64`
562 /// across the full variant space (custom-zero, custom, and builtins).
563 #[test]
564 fn err_to_u64_matches_from_impl_for_all_variants() {
565 let cases = [
566 ProgramError::Custom(0),
567 ProgramError::Custom(1),
568 ProgramError::Custom(u32::MAX),
569 ProgramError::InvalidArgument,
570 ProgramError::MissingRequiredSignature,
571 ProgramError::AccountBorrowFailed,
572 ProgramError::ArithmeticOverflow,
573 ProgramError::IncorrectAuthority,
574 ];
575 for e in cases {
576 assert_eq!(err_to_u64(e.clone()), u64::from(e));
577 }
578 }
579}