Skip to main content
Each instruction executed in TVM consumes gas. All instructions consume basic gas, which is calculated from the size of the instruction in the bitcode. Some instructions may consume extra gas, which is often not fixed but calculated based on the input data.

Basic gas usage (per bit of executed code)

Each instruction consumes a fixed amount of 10 gas and 1 gas for each bit of this instruction, not including variable-length operands and references. Examples:
InstructionTL-BGasNotes
NEWC#C8188-bit prefix without operands
STU#CB
cc:uint8
268-bit prefix, 8-bit operand
PUSHINT_LONG#82
l:(## 5)
xxx:(int (8 * l + 19))
238-bit prefix, 5-bit operand, length of xxx depends on l, so it is not included
STSLICE_CONST#CFC0_
x:(## 2)
y:(## 3)
c:(x * ^Cell)
sss:((8 * y + 2) * Bit)
249-bit prefix (CF is 8 bits, C0_ is C_, which is just bit 1), 2-bit and 3-bit operands, refs c and variable-length sss are not included

Cell operations

When any instruction internally finalizes a Builder to a Cell, it consumes 500 gas. When a Cell is loaded as a Slice, it consumes 100 gas for the first access in current smart contract invocation, and 25 gas for each subsequent load from cache. Cells are identified by representation hash, e.g., loading cell with the same hash for the second time will always cost 25 gas. This applies to all instructions that internally operate with cells (including dictionary operations). The only exceptions are:
  • BTOS converts a Builder to a Slice without consuming gas for cell operations.
  • HASHBU computes hash without consuming gas for converting Builder to a Cell

Exceptions

TVM consumes 50 gas when any exception is thrown, both explicitly by THROW-like instructions or implicitly during execution of other instructions. This happens before the jump to the exception handler c2.

Implicit jumps and returns

When the current continuation ends and there is a remaining reference, TVM jumps to it and consumes 10 gas. When there are no instructions to execute and references to jump to, implicit return to c0 occurs, which consumes 5 gas.

Nested continuations

Calling more than 8 extraordinary continuations in a chain consumes 1 gas for each subsequent continuation.

Tuple operations

TUPLE, TUPLEVAR, UNTUPLE, UNTUPLEVAR, UNPACKFIRST, UNPACKFIRSTVAR, EXPLODE, EXPLODEVAR consumes 1 gas for each entry been pushed or popped into a tuple. TPUSH, TPOP, SETINDEX, SETINDEXVAR, SETINDEXQ/SETINDEXVARQ consumes len(tuple) gas for the resulting tuple size after push/pop/set. Same applies to instructions operating with c7: SETGLOB/SETGLOBVAR, RANDU256/RAND, SETRAND, ADDRAND.

Stack operations

TVM consumes 1 gas for each stack element deeper than 32 elements inside the resulting new stack each time stack gets copied: when calling or jumping to a continuation with a non-empty argument number, an initial stack, or both, when extending a continuation stack using SETCONTARGS and similar instructions, when using RUNVM (both for initial and resulting stacks of the vm).

Extra currency

The first 5 executions of GETEXTRABALANCE consume at most 200 gas each. For example, if the gas cost was 1000, then 200 gas will be consumed, and the remaining 800 is free.

RUNVM

RUNVM and RUNVMX consume 40 extra gas before starting a VM.

Cryptography

CHKSIGNS/CHKSIGNU

CHKSIGNS and CHKSIGNU can be invoked 10 times without extra gas cost. Next checks will cost 4000 gas each.

HASHEXT

HASHEXT* instructions always consume 1 extra gas for each part of the input. Additionally, the following gas is consumed for each hashed byte:
AlgorithmGas consumed
SHA2561/33 per byte
SHA5121/16 per byte
BLAKE2B1/19 per byte
KECCAK2561/11 per byte
KECCAK5121/6 per byte
Only the integer part of the gas is consumed; for example, 0-32 bytes of SHA256 cost 0 gas, 33-64 bytes cost 1 gas, and so on.

RIST255

Instructions consume constant extra gas.

Other instructions

ECRECOVER consumes 1500 extra gas. SECP256K1_XONLY_PUBKEY_TWEAK_ADD consumes 1250 extra gas. P256_CHKSIGNU and P256_CHKSIGNS consume 3500 extra gas.

BLS

Signature verification and aggregation

InstructionGas consumedNotes
BLS_VERIFY61000
BLS_AGGREGATE-2650 + 4350 * nn is the number of signatures aggregated.
BLS_FASTAGGREGATEVERIFY58000 + 3000 * nn is the number of public keys verified against one message/signature pair.
BLS_AGGREGATEVERIFY38500 + 22500 * nn is the number of (public key, message) pairs checked against one signature.

G1 group helpers

InstructionGas consumed
BLS_G1_ADD / BLS_G1_SUB3900
BLS_G1_NEG750
BLS_G1_MUL5200
BLS_MAP_TO_G12350
BLS_G1_INGROUP2950
BLS_G1_MULTIEXP consumes 11375 + 630 * n + (8820 * n) / max(log₂ n, 4) extra gas, where n is the number of (point, scalar) pairs. Instructions BLS_G1_ZERO and BLS_G1_ISZERO do not charge additional gas.

G2 group helpers

InstructionGas consumed
BLS_G2_ADD / BLS_G2_SUB6100
BLS_G2_NEG1550
BLS_G2_MUL10550
BLS_MAP_TO_G27950
BLS_G2_INGROUP4250
BLS_G2_MULTIEXP consumes 30388 + 1280 * n + (22840 * n) / max(log₂ n, 4) gas, where n is the number of (point, scalar) pairs. Instructions BLS_G2_ZERO and BLS_G2_ISZERO do not charge additional gas.

Pairing and constants

InstructionGas consumedNotes
BLS_PAIRING20000 + 11800 * nn is the number of (G1, G2) pairs supplied for the pairing product check.
BLS_PUSHR do not charge additional gas.