Skip to content

​In short

A cross-program call (CPI) is one program calling another inside the same transaction, the way your program would call the Token program to move tokens.
You’ve used this in: Trade settlement Step 2
A cross-program invocation (CPI) is one program calling an instruction on another while it runs. Any program can call any other program’s instructions.
Program A calls Program B within the same instruction, one level deeper in the call stack.Program A calls Program B within the same instruction, one level deeper in the call stack.
Program A calls Program B within the same instruction, one level deeper in the call stack.

​Key facts

  • Privilege extension: Account privileges (signer, writable) extend from caller to callee. A callee cannot escalate privileges beyond what the caller passed.
  • Shared compute budget: A callee’s CU consumption reduces the caller’s remaining budget.
  • Reentrancy: Direct self-recursion is allowed (A->A->A). Indirect reentrancy is not (A->B->A returns ReentrancyNotAllowed).
Security: Verify the program you invokeThe program you CPI into is an account the caller passes in. If your program invokes whatever account sits in the token_program position, an attacker can pass their own program. It receives every account and privilege you forward, can return success without doing the work, and can use your users’ signatures. Check the program ID before invoking:
Native Rust
In Anchor, Program<'info, Token> checks the ID for one program, and Interface<'info, TokenInterface> accepts either the Token Program or the Token Extensions Program. Instruction builders such as system_instruction::transfer hard-code the program ID, which is safe as long as you don’t overwrite it.
Security: Forward only the privileges the callee needsSigner and writable privileges pass from caller to callee for the duration of the CPI. Passing a user’s signer account into a program you don’t control gives that program the user’s signature for anything it does during the call, including CPIs of its own. Forward signer accounts only to programs you trust, and only the accounts that instruction needs.

​Limits

LimitValueSource
Max instruction stack depth5 (9 with SIMD-0268)MAX_INSTRUCTION_STACK_DEPTH, MAX_INSTRUCTION_STACK_DEPTH_SIMD_0268
CPI invocation cost946 CUs (1,000 before SIMD-0339)DEFAULT_INVOCATION_COST, INVOKE_UNITS_COST_SIMD_0339
Max PDA signers per CPI16MAX_SIGNERS
Max CPI instruction data10 KiB (10,240 bytes)MAX_INSTRUCTION_DATA_LEN
Max return data1,024 bytesMAX_RETURN_DATA
Max CPI account infos255 (128 before SIMD-0339)MAX_CPI_ACCOUNT_INFOS, MAX_CPI_ACCOUNT_INFOS_SIMD_0339
CPI serialization cost1 CU per 250 bytescpi_bytes_per_unit
Max account data realloc per CPI10,240 bytes (10 KiB)MAX_PERMITTED_DATA_INCREASE

​invoke vs invoke_signed

FunctionUse casePDA signing
invokeCPIs where all required signers have already signed the original transactionNo
invoke_signedCPIs where the calling program needs to sign on behalf of a PDA it ownsYes, via signer seeds
invoke is invoke_signed with an empty signer seeds array. Both use the same syscall (sol_invoke_signed_rust) and runtime path (cpi_common). When seeds are provided, the runtime derives the PDA addresses and adds them to the valid signers before checking privileges.