[TEP-141] Enhancing TON with Remote Onchain Execution: A Draft Proposal for Inter-Contract Communication

Introduction

The TON Blockchain, known for its advanced features and scalability, is poised to adopt a revolutionary method for inter-contract communication. This technical document outlines a proposal, identified as TEP 141, aiming to introduce a mechanism for contracts to execute code or read data from other contracts asynchronously. This capability addresses the current limitations in contract interactions and paves the way for more integrated and efficient decentralized applications.

TEP 141 Overview

  • TEP Number: 141
  • Title: Remote Onchain Execution
  • Status: Draft
  • Type: Core
  • Authors: TEP Authors
  • Created Date: 20.01.2024

Summary

TEP 141 proposes a novel approach allowing smart contracts on the TON Blockchain to perform remote executions on other contracts. This process, which encompasses both code execution and data reading, introduces asynchronous inter-contract interactions without the prerequisite for both parties to implement specific interfaces for communication.

Motivation

The current architecture of the TON Blockchain supports inter-contract communication only when both contracts are designed with the necessary interfaces. Additionally, the separation between contract-to-contract and contract-to-user interactions complicates the development process. TEP 141 aims to simplify these interactions, making the development of decentralized applications more streamlined and flexible.

Specification

Introduction of New Internal Message Types

The proposal suggests extending the TON Blockchain’s messaging system to include new types of internal messages specifically designed for remote execution requests (RER) and their responses. This extension involves reallocating unused combinations of flags in the CommonMsgInfo structure to accommodate the new message types:

  • int_msg_info_remote_execution
  • int_msg_info_remote_execution_response

Remote Execution Request Process

When an RER message reaches its destination, it triggers an execution process with several key differences from standard internal message processing:

  1. Initialization: The TVM initializes with the code and data from the RER’s state init, while also loading the destination contract’s code and data onto the stack.
  2. Execution: The execution of the destination smart contract occurs with the modified stack, allowing the RER to perform the desired operation.
  3. Response Generation: Instead of producing regular output actions, the TVM generates a single int_msg_info_remote_execution_response message containing the results of the execution.

Drawbacks

While TEP 141 introduces significant advantages, it also presents potential challenges:

  1. Risk of Misuse: The ability to rely on volatile data may lead developers to unintentionally create contracts that behave unpredictably, potentially leading to financial losses.
  2. Increased Complexity: The introduction of new internal message types adds complexity to the transaction execution process on the TON Blockchain.

Rationale and Alternatives

The proposal restricts the ability to send messages from within an RER transaction to avoid complications in routing and guaranteeing logical timestamp (lt) order. This limitation ensures the integrity of the messaging system while facilitating the new functionality.

Conclusion

TEP 141 represents a significant step forward in the evolution of the TON Blockchain, offering a method for contracts to interact more freely and efficiently. By addressing current limitations in contract communication, this proposal opens the door to more sophisticated and integrated decentralized applications. As the TON community considers this draft, the potential for remote onchain execution heralds a new era of blockchain development.