pub unsafe fn invoke_unchecked(
instruction: &InstructionView<'_, '_, '_, '_>,
accounts: &[CpiAccount<'_>],
) -> ProgramResultExpand description
Invoke a CPI without borrow validation (lowest CU cost).
This is Tier C of the CPI surface. The checked variant
(invoke) enforces the full contract below
before calling this function; prefer that unless you have measured
a reason to bypass the validation pass.
§Safety
The caller must uphold every one of the following invariants. A
violation of any of them is undefined behaviour, because the Solana
runtime’s sol_invoke_signed_c syscall assumes they already hold.
- No aliasing borrows. No
&or&mutreferences into any account data region referenced byaccountsmay be live for the duration of the call. The CPI can (and will) mutate those regions via the callee, and Rust’s aliasing rules do not permit the caller to hold outstanding references to memory that is about to change under it. - Account list consistency. Every
CpiAccountinaccountsmust correspond to a real account previously passed to the program’s entrypoint (same address, sameis_signer/is_writableflags the runtime already knows about). The runtime will not re-derive account permissions; invalid flags propagate into the callee. - Writability coverage. Every account that the
instructionmarks writable must haveis_writable = trueinaccounts, and every account the instruction marks as signer must haveis_signer = true. Mismatches are rejected by the runtime but the rejection path is not cheap and the caller is expected to get this right. - No shared mutable slices across CPIs. If the same account
appears more than once in
accounts(duplicate accounts), the caller is responsible for ensuring that any subsequent borrow of that account’s data respects the CPI’s writes. - Valid instruction encoding.
instruction.program_id,instruction.accounts, andinstruction.datamust all point to valid memory for the duration of the call. AnInstructionViewbuilt from a localInstructionAccountslice is fine; one built from a dropped stack slot is not.
The runtime does not enforce any of these from the caller side — it assumes a well-formed CPI. That is the cost of the Tier C path.