RPC error InstructionError: Computational budget exceeded

Last updated:

At a glance

Error details
PropertyValue
Applies toSolana JSON-RPC
Display stringsComputational budget exceeded; exceeded CUs meter at BPF instruction
Default limit200,000 per non-builtin instruction, 3,000 per builtin
Maximum1,400,000 per transaction
Set withComputeBudget SetComputeUnitLimit
Fee chargedYes, if it failed on chain

Cause

Every transaction has a compute unit limit. Without an explicit instruction the default is 200,000 per non-builtin instruction and 3,000 per builtin, up to a maximum of 1,400,000. The VM reports the moment it runs out as exceeded CUs meter at BPF instruction, and the runtime reports the result as Computational budget exceeded. Both are the same event. A limit that was fine yesterday can fail today if the path through a program changes, for example a swap routed through more pools.

Solution

  1. Find the instruction in the logs: the last Program ... invoke before the failure names the program that ran out.
  2. Run a simulation and read unitsConsumed.
  3. Add a SetComputeUnitLimit instruction with that number plus a margin of about 10%.
  4. Do not set the limit far above what you use: your priority fee is the price multiplied by the limit you request, not by what you consume.

Example

{
  "err": {
    "InstructionError": [
      1,
      "ComputationalBudgetExceeded"
    ]
  },
  "logs": [
    "Program ... failed: exceeded CUs meter at BPF instruction"
  ]
}

FAQ

Why not always request 1,400,000 compute units?
Because the priority fee is computed from the limit you request. A generous limit makes the same price cost more, and large requests are harder for a leader to fit.
What margin should I add?
Around 10% above the simulated figure is a common choice. Use more if the path changes between simulation and landing, such as a swap against moving pools.