Skip to main content

Module introspect

Module introspect 

Source
Expand description

Instruction introspection – stack height and sibling instruction access.

These syscalls are critical for security patterns that no framework wraps:

  • CPI guard: Detect if the current instruction is running inside a CPI call (stack height > 1). Prevents unauthorized composition – e.g., a governance instruction that must be top-level only.

  • Ed25519 signature verification: Check that a previous instruction in the same transaction was to the Ed25519 precompile with specific data. This is how on-chain programs verify off-chain signatures without heavy crypto libraries.

  • Secp256k1 recovery: Same pattern for Ethereum-compatible signatures.

No existing framework (pinocchio, Anchor, Steel, Quasar) wraps these syscalls with ergonomic APIs. Programs that need them write raw unsafe glue every time.

Structs§

ProcessedInstruction
Metadata about a previously processed sibling instruction.

Constants§

ED25519_PROGRAM_ID
Well-known precompile address for Ed25519 signature verification.
SECP256K1_PROGRAM_ID
Well-known precompile address for Secp256k1 signature recovery.

Functions§

get_processed_instruction
Retrieve a previously processed sibling instruction from the current transaction.
get_stack_height
Get the current instruction stack height.
is_cpi
Returns true if the current instruction is running inside a CPI.
is_top_level
Returns true if the current instruction is at the top level (not running inside a CPI).
require_cpi
Require that the current instruction IS inside a CPI.
require_ed25519_instruction
Check that a previous sibling instruction was to the Ed25519 precompile.
require_secp256k1_instruction
Check that a previous sibling instruction was to the Secp256k1 precompile.
require_top_level
Require that the current instruction is NOT a CPI call.