Skip to main content

Module fast

Module fast 

Source
Expand description

Batched u32 header validation using a single-compare optimization.

The SVM RuntimeAccount header packs borrow_state, is_signer, is_writable, and executable into a 4-byte prefix. We read this as a single u32 and compare against precomputed constants, collapsing 3-4 branch instructions into ONE comparison.

This saves ~4-8 CU per account validation on the hot path.

§Wire Layout (RuntimeAccount header, little-endian u32)

byte 0 = borrow_state (0xFF for non-duplicate)
byte 1 = is_signer    (0 or 1)
byte 2 = is_writable  (0 or 1)
byte 3 = executable    (0 or 1)

§Safety Model

The read_account_header function relies on hopper-native’s AccountView being #[repr(C)] with its first field being a *mut u8 pointing to the start of the RuntimeAccount in the SVM input buffer. This is verified by hopper-native’s own compile-time assertions. If hopper-native changes its layout, the compile-time size assertion below will fail.

This optimization is gated to target_os = "solana" only. Off-chain code uses the safe fallback via AccountView::is_signer() etc.

Constants§

HEADER_AUTHORITY
Non-duplicate + writable + signer (same as SIGNER_WRITABLE, alias).
HEADER_EXECUTABLE
Non-duplicate + executable.
HEADER_NODUP
Non-duplicate, no flags.
HEADER_SIGNER
Non-duplicate + signer.
HEADER_SIGNER_WRITABLE
Non-duplicate + signer + writable.
HEADER_WRITABLE
Non-duplicate + writable.

Functions§

check_account_fast
Fast single-compare account validation.
check_authority_fast
Validate a signer + writable account (authority) with single u32 compare.
check_executable_fast
Validate an executable (program) account with single u32 compare.
check_signer_fast
Validate a signer account with single u32 compare.
check_writable_fast
Validate a writable account with single u32 compare.