September 26, 2023

GRAM cryptocurrency on the Telegram Open Network (TON) blockchain

GRAM cryptocurrency on the Telegram Open Network (TON) blockchain

Sergey Prilutsky, a well-known blockchain expert, head of research at MixBytes and the SmartZ project during the Telegram Eventing shared detailed information about the project of Pavel Durov TON.

The data was obtained after studying classified information about the current state of TON development and will be of interest not only to specialists, but also to a wide range of potential investors.

Public Information

TON project funding wascollected during two rounds of closed ICO. Thanks to this, it was possible to raise $ 1.7 billion of investments, the minimum size of the stake was $ 20 million, about 100 investors took part in the ICO, among whom was Roman Abramovich.

GRAM cryptocurrency on the Telegram Open Network (TON) blockchain

The entire volume of the internal cryptocurrency of the project will be released immediately and will amount to 5 billion GRAM coins. After the launch of the project, ICO tokens from investors will be exchanged for coins in a ratio of 1 to 1.

Technical features of the TON blockchain

In the TON network, consensus is ensured by specialvalidator nodes that receive a commission for their services. Something similar is implemented in the Ripple protocol. The reliability of the transaction is confirmed by the BFT-algorithm (the task of the Byzantine generals).

GRAM cryptocurrency on the Telegram Open Network (TON) blockchain

Micropayments are not displayed immediately on the blockchain,only their hash is visible. To ensure the validity of microtransactions, each validator must have on the account some security deposit in GRAM coins, which is provided by the nominees.

The validator cannot make more transactions,than he is able to provide with collateral coins. In case of an erroneous payment, the validator and the nominator transfer coins to the accounts of other validators from this amount to cover their expenses for ensuring the transaction.

Each host is responsible for its partblockchain, which is divided into small pieces - shards (shardes). With a significant increase in the load on the network, part of the shards can be transferred to neighboring network nodes.

TON developers called this idea “Infinite Sharding”. The similar structure of the blockchain makes it possible not only to easily share shards, but also to automatically repair damaged areas.

TON Ecosystem Research Information

Sergei Prilutsky conducted a deepstudy of the TON project, during which interesting features of the new project surfaced. Below we propose to get acquainted with detailed information about the structure and features of the Telegram Open Network (TON) blockchain platform.

The idea of ​​Infinite Sharding

The main concept of the TON platform is the message. The user can send it from outside the blockchain to the address of any system account. Such a procedure causes the creation of a message to other network accounts. Moreover, the state of an individual account can be imagined in the form of its own blockchain (accountchain). It is essentially a repository of incoming and outgoing messages.

Many Shard accounts (shardes) mergein Shardchain, a blockchain that is served by a validator node. The internal composition of such a shard chain can change dynamically, depending on the load on a particular network node.

Many shardchains unite in a working chain(Workchain), another blockchain structure, due to the same prefix in its address. In turn, all the workchains form one masterchain, which is the general blockchain for the TON network. Let us dwell in more detail on these structures.


Masterchain is the main chain,which sets the rules for all lower-level blockchain chains. Its role is to monitor and manage the global state of the entire Telegram Open Network.

The peculiarity of the master chain is that it does not havebranching and merging of individual parts, i.e. in this it resembles a classic blockchain. Each block of the master chain contains hashes of the last shard blocks organized in a binary tree, and stores the status of system smart contracts, as well as their code. PoS control, data on validators, network participants - all this is stored in the master chain. However, accurate information on this subject could not be found, and the one that is is unreliable and not final.

Masterchain management is based on system smart contracts that contain such global parameters:

  • The total number and other characteristics of the coin GRAM.
  • List of validator nodes, parameters of their share, address of the contract by which a monthly selection of new validators takes place.
  • Parameters TVM (TON Virtual Machine), its version, minimum and maximum gas prices - similar to Ethereum.
  • Smart contracts of additional tokens and their status.

It is important that all changes to the global TON parameters are accepted by consensus of more than 2/3 of all validators according to the BFT algorithm.


Workchain is a conditional blockchain that combines the same type of chardchain. Its identifier is a prefix for the id number of shards, it is necessary for the exact routing of messages.

TON has plenty of room formany workchains (2 ^ 32 which corresponds to approximately 4.3 billion workchains), and in each of them you can organize your own message logic. For example, one workshop can serve Ethereum contracts, and the other can implement anonymous UTXO (unspent coins), as is done in ZCash.


Shardchayn is the main working unit inTON network. Shardchain is a separate chain of blocks that sends and receives messages from other shards, i.e. it is a blockchain serving its set of accounts.

Each validator contains a complete listtheir shards and only part of the blocks from neighboring ones. The validator produces new blocks in its shardchyn, sending and receiving messages from other shards. At this level, it is already possible to separate and merge chains of shard chain blocks. Schematically, it looks like a DAG (directed acyclic graph), where each block has several parents, which are the last blocks of the joined shardchains.

Shard blocks

Each shard block must contain a certain required data set, the so-called indivisible part. It includes:

  • The hash of the previous block and, possibly, the hashes of the parents in the event of a merger of shardchaynov.
  • Validator signatures for already accepted blocks.
  • The number of the last known master block chain.
  • Hashes of the initial and final state of the shard for this block.
  • An outgoing message queue in the form of a list of messages sent to other shards.


An account chain is an entry-level TON blockchain. Each account identifier is a 256-bit key + workchain identifier. For example, the address of a smart contract would look like this:

1: 81525a3672b55678d4139b993b542c5c9735ac41b653d963a42855c9834b6921a4.

And the user account address is like this:

Ef + BVndfdQ45nUdlsfsmv68KBHGSgBJsfsv58dG2SE4oPMgs4.

The account itself receives and receives messages (naturally these are not messages from Telegram). They can contain GRAM tokens, be smart contract calls, represent any other data, etc.

All messages are processed only whenthey are delivered to the correct shard. In this case, they can freely move through intermediate shards. Messages can also come from outside the TON blockchain, i.e. be "messages from nowhere."


Any account is a smart contract, possibly even with an empty code. Each account pays a fee for data storage, i.e. its balance decreases over time.

The account contains information about the balanceGRAM tokens, contract code or hash, time spent on the network, starting with the appearance of the root cell, statistics on the use of the data warehouse (for example, by the time the storage was last paid), a formal description of the interface.

Low level storage, cells

All data is stored in the TON blockchain instructures called cells. This is the basic unit for measuring the size of all network elements: messages, contract code, a wide variety of data.

Each cell contains 1023 bits of information and up to4 links to neighboring cells. There are 256 different types of cells, which differ in the way they are implemented and in the number of links to other cells. All of them are combined in a tree with the number of links for each element from 0 to 4. Cells are used for unified storage and deterministic operation in the blockchain storage.

Internal TON Algorithms

We have already met with the structure of the TON blockchain and its main elements. Now it’s the turn of the principles of their work and their fundamental concepts.

Logical time

As we learned earlier, the data structure in TONIt is a DAG, as, in principle, in 90% of other cryptocurrencies, including bitcoin. To fix the fact of delivery of a message or event in the blockchain, a monotonous counter is used during operations with them, and each such message contains its own time.

Due to the lack of central serverstime synchronization, the use of absolute time within the network can lead to various errors. That is why the message systems decided to stop at a logical time.


What is a message? This is absolutely any operation between shards. Any shard block must have an incoming message from an outgoing message from another existing and valid shard block. To confirm the truth of the message, only a few blocks from the sender’s chain are allowed to be stored; storage of its indivisible part is mandatory.

It is also forbidden to process an incoming message,until evidence of delivery of earlier outgoing messages from at least the next shard is received. This approach forces validators to prioritize sending messages first and then receiving them.

Instant Hypercube Routing

As it is now clear, each shard, in fact, is a queue of incoming and outgoing messages. To search for the desired account and the shortest path to it, an accelerated version of the "hypercube" algorithm is used.

This leads to the fact that if the destination is specifiedyour shard, the transaction is transferred to the desired account, and new messages generated by it are placed in the outgoing message queue. In the case when the addressee is someone else's shard, then, according to the deterministic routing rules, the message is transferred to the incoming messages of the next shard.

Enabling Message Queuing in Blocks is Newsolution in blockchain technology. Thanks to this approach, the status of the message can be immediately tracked on the blockchain. Globally, the entire array of sent messages between shards is a complex multidimensional directed acyclic graph (DAG). However, at the moment there is no final clarity about the operation of the message delivery guarantees to the addressee in such a DAG.

Smart contracts

In TON, creating a smart contract or account is the same thing. In the case of sending GRAM tokens to a non-existent address, it is created as an empty contract with a balance other than 0.

As mentioned earlier, any account, somethingstored on the blockchain, pays a commission for storage. Therefore, when creating a smart contract, you need to provide it with a balance in GRAM to pay for storage space, or even first ensure a balance, and then place the smart contract code.

GRAM cryptocurrency on the Telegram Open Network (TON) blockchain

There are also ready-made smart contract libraries in the master chain. Each contract has the following properties:

  • The contract may create a new contract.
  • You can place the hash from the smart contract code and only then demonstrate it.
  • The smart contract code can be changed, but this should be provided for in the code of the original smart contract.
  • You can not store the smart contract code in the blockchain, but then only incoming messages will be available to the account. Code and data will be stored outside the blockchain.
  • Code and state of the "dying" smart contract(whose balance is close to 0) is replaced by a hash of its code. Using a hash, a smart contract can still be restored subject to a balance replenishment, otherwise the hash will also be deleted after a few months.

In general, we can conclude that the behavior and properties of accounts in TON are similar at the same time to Bitcoin and Ethereum.

TVM (TON Virtual Machine)

TON Virtual Machine Introduces Newdevelopment in the field of smart contracts. It is deterministic and stackable. Therefore, it is easily scalable and does an excellent job of packing data into cells. On TVM it is convenient to keep track of GRAM expenses for the execution of smart contracts and it is very simple to restore smart contracts.

The constraint model in TVM is built on gas, and elliptical cryptography is implemented on the ed25519 protected curve.

Smart Contract Language

TON uses low-level and extremelydeterministic language Fift, the prototype of which was the language FORTH (which is probably why they chose the name Fift). It is a concatenated, stackable language for microcontrollers. Unfortunately, for writing smart contracts with determinism and maximum cost effectiveness, only two options were invented: EVM (Ethereum Virtual Machine) and WASM (WebAssembly).

Fift is strongly typed; there are a dozen and a half types in it, including complex ones (Tuple, List, Odject).

The whole idea of ​​this language is built around“Words” of operators: there are many different words for manipulating the stack, functions, logic blocks, variables - all this is subject to the central concept of a “word” operator.

For example, this is how the code for outputting two Fibonacci numbers of large 1000 looks like:

{1 0 rot {-rot over + swap rot 2dup> =} until drop}: fib-gtr

1000 fib-gtr


  • dop (xx x), duplicates the value of the top of the stack. If the stack is empty, it throws an exception error.
  • drop (x), deletes the value of the top of the stack.
  • swap (xyyx)swaps the two values ​​closest to the top of the stack.
  • rot (xyzyzx), rotates the three values ​​closest to the top of the stack.
  • -rot (xyzzxy), inverts the three values ​​closest to the top of the stack in the opposite direction. Equivalent to rot rot.
  • over (xyxyx), creates a copy of the second value on the stack and places it on top of the stack.
  • tuck (xyyxy), equivalent to swap over.
  • nip (xyy), removes the second value from the top of the stack. Equivalent to swap drop.
  • 2dup (xy-xyxy), equivalent to over over.

It should be noted that many developers are shocked by this syntax and before studying the documentation on Fift, it is recommended to study one on FORTH.

Why did the developers chooseas a language for smart contracts is Fift? Perhaps because in this form it is great for formal verification and more error-resistant, requiring application developers to fully understand the sequence of execution of any operations.

TON General Impressions

In general, building the TON ecosystem makes a good impression. Among the advantages should be noted:

  • A new, cost-effective implementation of data storage. This indicates a serious approach to the problem of blockchain size.
  • A primitive messaging system similar to that used in GO.
  • Processing a message chain, a memory pool on the blockchain, almost all transaction information is taken from the blockchain, and not from external sources.
  • Workchain for hard forks or radical changesin consensus, cryptography, virtual machine for smart contracts. This allows you to theoretically tie Bitcoin, Ethereum, or EOS blockchains to TON as a new working chain.

Managing TON with smart contracts is a well-established method. For example, in Ethereum, EOS, Polkadot, etc.

From the point of view of the developer, the TON node is a few blockchains: master chain, work chain, shard chain.

Smart contract interfaces are stored next to smart contracts, which is very convenient for dApp, as provides the simplest interaction with them.

All blockchain resources are honestly paid, up to and including data warehouse rental. There are no discounts for large GRAM holders or validators.

The only thing I would like to change is the availability of a more understandable mechanism for implementing formal proof of message delivery. Especially considering the variety of network topology options.


WhitePaper project gives the impression thatthe developers took the best working patterns from many modern projects, and for each of them did something different. There are parts that work like UTXO bitcoin (messages, accounts), there are like EVM (smart contracts, management), there are new individual developments (shards, routing), and there is an adaptation of old solutions to your project (language of smart contracts, cells storage).

In general, we can say that TON causesa huge number of developers and users are naturally interested. Unfortunately, so far, apart from TVM, examples of smart contract code and a test node, which with high probability are at least partially an emulation, there is nothing more. A full launch of TON can only wait impatiently.