[TEP-88] Enhancing TON Virtual Machine (TVM) with Advanced Features for Efficiency and Interoperability

Introduction

The TON Virtual Machine (TVM) serves as the execution environment for smart contracts on the TON blockchain, embodying the principle that “code is law.” However, the evolving demands of blockchain applications necessitate enhancements to TVM’s capabilities. This document proposes a series of updates aimed at improving the efficiency, functionality, and cross-chain compatibility of TVM. These updates include the addition of new op-codes related to data handling, cryptographic operations, and message sending, as well as enriching the c7 register with additional information about the smart contract’s context.

Motivation

The proposed updates to TVM are driven by the need to streamline common blockchain operations such as data hashing, signature verification, and on-chain data proof generation. The current limitations of TVM make these tasks cumbersome and resource-intensive, hindering the development of sophisticated smart contracts and their interaction with external blockchain systems. By introducing these enhancements, the proposal aims to reduce execution costs, improve cross-chain interoperability, and facilitate more complex contract logic.

Implementation Overview

The proposal introduces several key updates to TVM and its operation environment:

  • Expansion of the c7 register: To include the smart contract’s own code, transaction details, and information about masterchain blocks.
  • Addition of new op-codes: Focused on block data retrieval, various hashing algorithms, cryptographic signature verification, and enhanced message sending functionalities.
  • Fee calculation adjustments: To ensure fair charging for message forwarding, even in cases of failed message sending attempts.

Technical Specification

c7 Register Expansion

Index Description
10 Contains the cell with the executed smart contract’s code.
11 Stores the value of the incoming message, including TON amount and any extra currencies.
12 Indicates the fees collected during the storage phase.
13 Provides information about previous blocks, including details about the last masterchain blocks and the most recent key block.

New TVM Op-codes

Category Op-code Descriptions
c7 Primitives Includes MYCODE, INCOMINGVALUE, STORAGEFEES, PREVBLOCKSINFOTUPLE for accessing the expanded c7 register elements.
Block Primitives PREVMCBLOCKS and PREVKEYBLOCK for retrieving information about previous masterchain blocks and the last key block, respectively.
Hash Primitives Introduces HASHSTART_* for initiating different hashing algorithms, HASHEND* for finalizing the hash calculation, and HASHAPP* for appending data to the hash calculation.
Cryptography ECRECOVER for recovering public keys from signatures, compatible with Bitcoin/Ethereum.
Message Primitives SENDMSG for sending messages with an updated mode for fee calculation, enhancing message sending functionality with more accurate fee deductions.

Adjustments to Fee Calculation

The proposal recommends adjusting the fee calculation for message forwarding to include a charge for the computation involved in estimating the forwarding fee, even if the message ultimately fails to send. This adjustment aims to compensate for the resources expended during this process.

Comparative Analysis

Feature Current TVM Implementation Proposed Enhancements
Data Handling Efficiency Limited by the lack of specialized op-codes for hashing and data retrieval. Introduction of specialized op-codes for efficient data handling and hashing, reducing execution costs.
Cryptographic Functionality Basic, with limited support for modern cryptographic standards. Expanded cryptographic functionalities, including support for Bitcoin/Ethereum compatible signatures, facilitating cross-chain interoperability.
Cross-chain Data Proofs Challenging due to the lack of direct access to block information within smart contracts. Inclusion of block information within the c7 register, enabling smart contracts to generate and verify cross-chain data proofs more easily.
Message Sending Flexibility Constrained, with static fee calculation that may not reflect actual costs. Enhanced message sending with updated fee calculation modes, offering developers more control over the economics of message forwarding and ensuring fair compensation for network resources used.
Execution Context Awareness Limited insight into the execution context of smart contracts. Expanded c7 register provides smart contracts with direct access to their own code, incoming message details, and information about the blockchain state, enriching the execution context for more sophisticated contract logic.

Conclusion

The proposed updates to the TON Virtual Machine represent a significant

step forward in the blockchain’s ability to support advanced smart contracts and facilitate seamless cross-chain interactions. By enhancing TVM’s data handling, cryptographic capabilities, and execution context awareness, this proposal not only optimizes resource usage but also opens new avenues for blockchain application development on TON. As the blockchain ecosystem continues to evolve, these updates ensure that TON remains at the forefront of technological innovation and interoperability.

1 Like

It looks like this part has been implemented and is waiting to be activated.