# Precompiled contracts (https://docs-fpm2731fy-ton-core-docs.vercel.app/llms/foundations/precompiled/content.md)



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 [#config]

The list of precompiled contracts is stored in the blockchain configuration:

```tlb
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.

<Callout>
  View current values on mainnet at [ConfigParam 45 on Tonviewer](https://tonviewer.com/config#45).
</Callout>

## Accessing precompiled gas value [#accessing-precompiled-gas-value]

Contracts can check their precompiled gas value using the [`GETPRECOMPILEDGAS`](/llms/tvm/instructions/content.md) 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`](/llms/tvm/registers/content.md) register environment tuple.

## Execution modes [#execution-modes]

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

<div className="fd-steps">
  <div className="fd-step">
    ### Contract is not precompiled [#1-contract-is-not-precompiled]

    The contract code hash is not in `ConfigParam 45`. TVM executes normally with standard gas accounting.

    [`GETPRECOMPILEDGAS`](#accessing-precompiled-gas-value) returns `null`. Transaction result: `gas_used` reflects actual TVM consumption.
  </div>

  <div className="fd-step">
    ### Contract is precompiled [#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 [#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](/llms/foundations/phases/content.md):

    * `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 [#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`](#accessing-precompiled-gas-value) 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

    <Callout type="note">
      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`.
    </Callout>
  </div>
</div>

## Example: Stablecoin jetton wallet [#example-stablecoin-jetton-wallet]

The jetton wallet from the [stablecoin-contract](https://github.com/ton-blockchain/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`](https://github.com/ton-blockchain/stablecoin-contract/blob/5e1d79f4009430f2f7f255c5093a59d9a1628d75/contracts/gas.fc).
