Skip to content

Gas Accounting

Back to Runtime Specification

The embedded runtime tracks gas consumption to approximate production Neo N3 behavior.

How Gas Works

Every opcode and syscall has an associated gas cost. The runtime deducts gas before executing each instruction. If gas reaches zero, execution halts with an out-of-gas error.

Opcode Gas Costs

Gas costs by opcode category:

CategoryTypical GasNotes
Constants (PUSH*)1-2PUSHDATA variants cost 2
Flow control (JMP*)2CALL variants cost 512
Stack operations2All stack manipulation
Slot operations2-3INITSLOT costs 3
Splice/buffer4All buffer operations
Bitwise/logic2-3
Numeric (basic)3ADD, SUB, comparisons
Numeric (complex)5-8MUL, DIV, POW, MODPOW
Collections4All compound operations
Type operations2ISNULL, ISTYPE, CONVERT
RET0Free

Syscall Gas Costs

Syscall CategoryGas CostNotes
Storage context (GetContext, AsReadOnly)1Cheap metadata operations
Storage read (Get, Find)100Per-operation
Storage write (Put)1,000Most expensive common operation
Storage delete (Delete)100
Iterator (Next, Value)1
Runtime metadata (Platform, GetTime, etc.)1
Runtime.CheckWitness200Signature verification
Runtime.GetRandom50
Runtime.Log / Notify1
Crypto.CheckSig / CheckMultisig1,000Cryptographic verification
Contract.Call10
Contract.Create*Account10

Current Accuracy

Gas accounting is an embedded-runtime approximation of production Neo N3 costs. Known gaps:

  • Dynamic costs for large integer operations are approximated
  • Some complex operations use fixed costs instead of size-dependent costs
  • Edge cases in exception handling gas effects need spec verification

TIP

For precise gas estimation, deploy to Neo-Express or TestNet and measure actual consumption. The embedded runtime is useful for development feedback but should not be used as the sole source of gas budgeting for mainnet.

MIT Licensed