Skip to main content
A precompiled smart contract is a contract with a native C++ implementation in the validator node. When a validator processes a transaction for such a contract, it can execute this native implementation instead of TVM. This improves performance and reduces computation fees.

Config

The list of precompiled contracts is stored in the blockchain configuration:
precompiled_smc#b0 gas_usage:uint64 = PrecompiledSmc;
precompiled_contracts_config#c0 list:(HashmapE 256 PrecompiledSmc) = PrecompiledContractsConfig;
_ PrecompiledContractsConfig = ConfigParam 45;
The list:(HashmapE 256 PrecompiledSmc) represents a mapping of contract code hash to constant gas amount. A contract is considered precompiled if its code hash exists in this map.
View current values on mainnet at ConfigParam 45 on Tonviewer.

Accessing precompiled gas value

Contracts can check their precompiled gas value using the GETPRECOMPILEDGAS opcode:
  • Returns the configured gas_usage value if the contract code hash is in ConfigParam 45
  • Returns null if the contract code hash is not in ConfigParam 45
The value is also available in the c7 register environment tuple.

Execution modes

When a validator processes a transaction, the execution mode depends on whether the contract code hash is listed in ConfigParam 45.

1. Contract is not precompiled

The contract code hash is not in ConfigParam 45. TVM executes normally with standard gas accounting. GETPRECOMPILEDGAS returns null. Transaction result: gas_used reflects actual TVM consumption.

2. Contract is precompiled

The contract code hash exists in ConfigParam 45. The validator checks the contract balance against the configured gas_usage. If insufficient, the compute phase fails with cskip_no_gas. Otherwise, execution proceeds via one of two paths.

Contract has native C++ implementation

The native C++ implementation is available and enabled in the validator node. The validator executes the C++ code directly without invoking TVM. Transaction result:
  • gas_used set to the value from ConfigParam 45
  • vm_steps, vm_init_state_hash, vm_final_state_hash set to zero

Contract has no native C++ implementation

The native C++ implementation is disabled or unavailable in the validator node. TVM executes the contract code normally. GETPRECOMPILEDGAS returns the configured gas value during execution. After execution completes, the validator overrides the compute phase values. Transaction result:
  • gas_used set to the value from ConfigParam 45
  • vm_steps, vm_init_state_hash, vm_final_state_hash set to zero
The override ensures that both execution paths produce identical transaction results. This allows validators with and without native C++ implementations to coexist in the network and enables gradual adoption when adding new entries to ConfigParam 45.

Example: Stablecoin jetton wallet

The jetton wallet from the stablecoin-contract project is the first contract code hash added to ConfigParam 45 on mainnet. This jetton wallet is optimized as a precompiled contract to reduce computation fees for stablecoin transfers. The contract implements standard jetton wallet functionality with additional governance features. The precompiled gas logic is implemented in gas.fc.