Skip to main content
Fift is a stack-based programming language with TON-specific features that can work with cells. TVM assembly is another stack-based language designed for TON that also handles cells. What’s the difference between them?

Key differences

Fift executes at compile-time - when your compiler builds the smart contract code BoC after processing FunC code. Fift can appear in different forms:
  • TVM opcode definitions in Asm.fif:
  • wallet_v3_r2.fif:
The last code fragment resembles TVM assembly because most of it actually is TVM assembly. Here’s why: Imagine explaining programming concepts to a trainee. Your instructions become part of their program, processed twice - similar to how opcodes in capital letters (SETCP0, DUP, etc.) are processed by both Fift and TVM. Think of Fift as a teaching language where you can introduce high-level concepts to a learner. Just as a trainee programmer gradually absorbs and applies new concepts, Fift allows you to define custom commands and abstractions. The Asm.fif file demonstrates this perfectly - it’s essentially a collection of TVM opcode definitions. TVM assembly, in contrast, is like the trainee’s final working program. While it operates with fewer built-in features (it can’t perform cryptographic signing, for instance), it has direct access to the blockchain environment during contract execution. Where Fift works at compile-time to shape the contract’s code, TVM assembly runs that code on the actual blockchain.

Smart contract usage

(Fift) Including large BoCs in contracts

When using toncli, you can include large BoCs by:
  1. Editing project.yaml to include fift/blob.fif:
  1. Adding the BoC to fift/blob.boc
  2. Including this code in fift/blob.fif:
Now you can access the blob in your contract:

(TVM assembly) Converting integers to strings

Fift primitives can’t convert integers to strings at runtime because Fift operates at compile-time. For runtime conversion, use TVM assembly like this solution from TON Smart Challenge 3:

(TVM assembly) Efficient modulo multiplication

Compare these implementations:
The x{A988} opcode implements an optimized division operation with built-in multiplication (as specified in section 5.2 Division). This specialized instruction directly computes just the modulo remainder of the operation, skipping unnecessary computation steps. The s, suffix then handles the result storage - it takes the resulting slice from the stack’s top and efficiently writes it into the target builder. Together, this combination delivers substantial gas savings compared to conventional approaches.