Gram 백서

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 16쪽 중 14쪽

resented as a TL source le; cf. 2.2.5 ) or in serialized form, 34 can be publishedfor example, in a special eld in the smart-contract account description, stored in the blockchain, or separately, if this interface will be referred to many times. In the latter case a hash of the supported public interface may be incorporated into the smart-contract description instead of the interface description itself. An example of such a public interface is that of a DNS smart contract, which is supposed to implement at least one standard get method for looking up subdomains (cf. 4.3.6 ). A standard method for registering new subdo- mains can be also included in the standard public interface of DNS smart contracts. 4.3.15. User interface of a smart contract. The existence of a public interface for a smart contract has other benets, too. For example, a wallet client application may download such an interface while examining a smart contract on the request of a user, and display a list of public methods (i.e., of available actions) supported by the smart contract, perhaps with some human-readable comments if any are provided in the formal interface. After the user selects one of these methods, a form may be automatically generated according to the TL-scheme, where the user will be prompted for all elds required by the chosen method and for the desired amount of cryptocurrency (e.g., TON coins) to be attached to this request. Submitting this form will create a new blockchain transaction containing the message just composed, sent from the user's blockchain account. In this way, the user will be able to interact with arbitrary smart contracts 34 TL-schemes can be TL-serialized themselves; cf. https://core.telegram.org/ mtproto/TL-tl . 108 4.3. Accessing TON Ser vices from the wallet client application in a user-friendly way by lling and sub- mitting certain forms, provided these smart contracts have published their interfaces. 4.3.16. User interface of a ton-service. It turns out that ton-services (i.e., services residing in the TON Network and accepting queries through the ADNL and RLDP protocols of 3 ; cf. 4.1.5 ) may also prot from having public interfaces, described by TL-schemes (cf. 2.2.5 ). A client application, such as a light wallet or a ton-browser, might prompt the user to select one of the methods and to ll in a form with parameters dened by the interface, similarly to what has just been discussed in 4.3.15 . The only dierence is that the resulting TL-serialized message is not submitted as a transaction in the blockchain; instead, it is sent as an RPC query to the abstract address of the ton-service in question, and the response to this query is parsed and displayed according to the formal interface (i.e., a TL-scheme). 4.3.17. Locating user interfaces via TON DNS. The TON DNS record containing an abstract address of a ton-service or a smart-contract account identier might also contain an optional eld describing the public (user) interface of that entity, or several supported interfaces. Then the client application (be it a wallet, a ton-browser or a ton-proxy) will be able to download the interface and interact with the entity in question (be it a smart contract or a ton-service) in a uniform way. 4.3.18. Blurring the distinction between on-chain and o-chain ser- vices. In this way, the distinction between on-chain, o-chain and mixed services (cf. 4.1.2 ) is blurred for the end user: she simply enters the domain name of the desired service into the address line of her ton-browser or wallet, and the rest is handled seamlessly by the client application. 4.3.19. ton-sites as ton-services supporting an HTTP interface. A ton-site is simply a ton-service that supports an HTTP interface, perhaps along with some other interfaces. This support may be announced in the corresponding TON DNS record. 4.3.20. Hyperlinks. Notice that the HTML pages returned by ton-sites may contain ton-hyperlinks that is, references to other ton-sites, smart con- tracts and accounts by means of specially crafted URI schemes (cf. 4.3.21 ) containing either abstract network addresses, account identiers, or human- readable TON DNS domains. Then a ton-browser might follow such a 109 4.3. Accessing TON Ser vices hyperlink when the user selects it, detect the interface to be used, and dis- play a user interface form as outlined in 4.3.15 and 4.3.16 . 4.3.21. Hyperlink URLs may specify some parameters. The hyperlink URLs may contain not only a (TON) DNS domain or an abstract address of the service in question, but also the name of the method to be invoked and some or all of its parameters. A possible URI scheme for this might look as follows: ton:// <domain> / <method> ? <eld1> = <value1> & <eld2> = . . . When the user selects such a link in a ton-browser, either the action is per- formed immediately (especially if it is a get method of a smart contract, invoked anonymously), or a partially lled form is displayed, to be explic- itly conrmed and submitted by the user (this may be required for payment forms). 4.3.22. POST actions. A ton-site may embed into the HTML pages it returns some usual-looking POST forms, with POST actions referring ei- ther to ton-sites, ton-services or smart contracts by means of suitable (TON) URLs. In that case, once the user lls and submits that custom form, the corresponding action is taken, either immediately or after an explicit conr- mation. 4.3.23. TON WWW. All of the above will lead to the creation of a whole web of cross-referencing entities, residing in the TON Network, which would be accessible to the end user through a ton-browser, providing the user with a WWW-like browsing experience. For end users, this will nally make blockchain applications fundamentally similar to the web sites they are al- ready accustomed to. 4.3.24. Advantages of TON WWW. This TON WWW of on-chain and o-chain services has some advantages over its conventional counterpart. For example, payments are inherently integrated in the system. User identity can be always presented to the services (by means of automatically generated signatures on the transactions and RPC requests generated), or hidden at will. Services would not need to check and re-check user credentials; these credentials can be published in the blockchain once and for all. User network anonymity can be easily preserved by means of TON Proxy, and all services will be eectively unblockable. Micropayments are also possible and easy, because ton-browsers can be integrated with the TON Payments system. 110 5.1. Payment Channels 5 TON Payments The last component of the TON Project we will briey discuss in this text is TON Payments , the platform for (micro)payment channels and lightning network value transfers. It would enable instant payments, without the need to commit all transactions into the blockchain, pay the associated trans- action fees (e.g., for the gas consumed), and wait ve seconds until the block containing the transactions in question is conrmed. The overall overhead of such instant payments is so small that one can use them for micropayments. For example, a TON le-storing service might charge the user for every 128 KiB of downloaded data, or a paid TON Proxy might require some tiny micropayment for every 128 KiB of trac relayed. While TON Payments is likely to be released later than the core compo- nents of the TON Project, some considerations need to be made at the very beginning. For example, the TON Virtual Machine (TON VM; cf. 2.1.20 ), used to execute the code of TON Blockchain smart contracts, must support some special operations with Merkle proofs. If such support is not present in the original design, adding it at a later stage might become problematic (cf. 2.8.16 ). We will see, however, that the TON VM comes with natural support for smart payment channels (cf. 5.1.9 ) out of the box. 5.1 Payment Channels We start with a discussion of point-to-point payment channels, and how they can be implemented in the TON Blockchain. 5.1.1. The idea of a payment channel. Suppose two parties, A and B, know that they will need to make a lot of payments to each other in the future. Instead of committing each payment as a transaction in the blockchain, they create a shared money pool (or perhaps a small private bank with exactly two accounts), and contribute some funds to it: A contributes a coins, and B contributes b coins. This is achieved by creating a special smart contract in the blockchain, and sending the money to it. Before creating the money pool, the two sides agree to a certain protocol. They will keep track of the state of the poolthat is, of their balances in the shared pool. Originally, the state is (a,b ), meaning that a coins actually belong to A, and b coins belong to B. Then, if A wants to pay d coins to B, they can simply agree that the new state is (a′,b′) = (a−d,b +d). 111 5.1. Payment Channels Afterwards, if, say, B wants to pay d′ coins to A, the state will become (a′′,b′′) = (a′ +d′,b′−d′), and so on. All this updating of balances inside the pool is done completely o-chain. When the two parties decide to withdraw their due funds from the pool, they do so according to the nal state of the pool. This is achieved by sending a special message to the smart contract, containing the agreed-upon nal state (a∗,b∗) along with the signatures of both A and B. Then the smart contract sends a∗ coins to A, b∗ coins to B and self-destructs. This smart contract, along with the network protocol used by A and B to update the state of the pool, is a simple payment channel between A and B. According to the classication described in 4.1.2 , it is a mixed service: part of its state resides in the blockchain (the smart contract), but most of its state updates are performed o-chain (by the network protocol). If everything goes well, the two parties will be able to perform as many payments to each other as they want (with the only restriction being that the capacity of the channel is not overruni.e., their balances in the payment channel both remain non-negative), committing only two transactions into the blockchain: one to open (create) the payment channel (smart contract), and another to close (destroy) it. 5.1.2. Trustless payment channels. The previous example was somewhat unrealistic, because it assumes that both parties are willing to cooperate and will never cheat to gain some advantage. Imagine, for example, that A will choose not to sign the nal balance (a′,b′) with a′ <a . This would put B in a dicult situation. To protect against such scenarios, one usually tries to develop trustless payment channel protocols, which do not require the parties to trust each other, and make provisions for punishing any party who would attempt to cheat. This is usually achieved with the aid of signatures. The payment channel smart contract knows the public keys of A and B, and it can check their signatures if needed. The payment channel protocol requires the parties to sign the intermediate states and send the signatures to each other. Then, if one of the parties cheatsfor instance, pretends that some state of the payment channel never existedits misbehavior can be proved by showing its signature on that state. The payment channel smart contract acts as an on-chain arbiter, able to process complaints of the two parties about each other, and punish the guilty party by conscating all of its money and 112 5.1. Payment Channels awarding it to the other party. 5.1.3. Simple bidirectional synchronous trustless payment channel. Consider the following, more realistic example: Let the state of the payment channel be described by triple (δi,i,o i), where i is the sequence number of the state (it is originally zero, and then it is increased by one when a subsequent state appears), δi is the channel imbalance (meaning that A and B own a+δi and b−δi coins, respectively), and oi is the party allowed to generate the next state (either A or B). Each state must be signed both by A and B before any further progress can be made. Now, if A wants to transfer d coins to B inside the payment channel, and the current state is Si = (δi,i,o i) with oi =A, then it simply creates a new state Si+1 = (δi−d,i + 1,o i+1), signs it, and sends it to B along with its signature. Then B conrms it by signing and sending a copy of its signature to A. After that, both parties have a copy of the new state with both of their signatures, and a new transfer may occur. If A wants to transfer coins to B in a state Si with oi = B, then it rst asks B to commit a subsequent state Si+1 with the same imbalance δi+1 =δi, but with oi+1 =A. After that, A will be able to make its transfer. When the two parties agree to close the payment channel, they both put their special nal signatures on the state Sk they believe to be nal, and invoke the clean or two-sided nalization method of the payment channel smart contract by sending it the nal state along with both nal signatures. If the other party does not agree to provide its nal signature, or simply if it stops responding, it is possible to close the channel unilaterally. For this, the party wishing to do so will invoke the unilateral nalization method, sending to the smart contract its version of the nal state, its nal signature, and the most recent state having a signature of the other party. After that, the smart contract does not immediately act on the nal state received. Instead, it waits for a certain period of time (e.g., one day) for the other party to present its version of the nal state. When the other party submits its version and it turns out to be compatible with the already submitted version, the true nal state is computed by the smart contract and used to distribute the money accordingly. If the other party fails to present its version of the nal state to the smart contract, then the money is redistributed according to the only copy of the nal state presented. If one of the two parties cheatsfor example, by signing two dierent states as nal, or by signing two dierent next states Si+1 and S′i+1, or by 113 5.1. Payment Channels signing an invalid new state Si+1 (e.g., with imbalance δi+1 <−a or > b) then the other party may submit proof of this misbehavior to a third method of the smart contract. The guilty party is punished immediately by losing its share in the payment channel completely. This simple payment channel protocol is fair in the sense that any party can always get its due, with or without the cooperation of the other party, and is likely to lose all of its funds committed to the payment channel if it tries to cheat. 5.1.4. Synchronous payment channel as a simple virtual blockchain with two validators. The above example of a simple synchronous payment channel can be recast as follows. Imagine that the sequence of states S0, S1, . . . , Sn is actually the sequence of blocks of a very simple blockchain. Each block of this blockchain contains essentially only the current state of the blockchain, and maybe a reference to the previous block (i.e., its hash). Both parties A and B act as validators for this blockchain, so every block must collect both of their signatures. The state Si of the blockchain denes the designated producer oi for the next block, so there is no race between A and B for producing the next block. Producer A is allowed to create blocks that transfer funds from A to B (i.e., decrease the imbalance: δi+1≤δi), and B can only transfer funds from B to A (i.e., increase δ). If the two validators agree on the nal block (and the nal state) of the blockchain, it is nalized by collecting special nal signatures of the two parties, and submitting them along with the nal block to the channel smart contract for processing and re-distributing the money accordingly. If a validator signs an invalid block, or creates a fork, or signs two dierent nal blocks, it can be punished by presenting a proof of its misbehavior to the smart contract, which acts as an on-chain arbiter for the two validators; then the oending party will lose all its money kept in the payment channel, which is analogous to a validator losing its stake. 5.1.5. Asynchronous payment channel as a virtual blockchain with two workchains. The synchronous payment channel discussed in 5.1.3 has a certain disadvantage: one cannot begin the next transaction (money transfer inside the payment channel) before the previous one is conrmed by the other party. This can be xed by replacing the single virtual blockchain discussed in 5.1.4 by a system of two interacting virtual workchains (or rather shardchains). 114 5.1. Payment Channels The rst of these workchains contains only transactions by A, and its blocks can be generated only by A; its states are Si = (i,φ i,j,ψ j), where i is the block sequence number (i.e., the count of transactions, or money transfers, performed by A so far), φi is the total amount transferred from A to B so far, j is the sequence number of the most recent valid block in B's blockchain that A is aware of, and ψj is the amount of money transferred from B to A in its j transactions. A signature of B put onto its j-th block should also be a part of this state. Hashes of the previous block of this workchain and of the j-th block of the other workchain may be also included. Validity conditions for Si include φi≥ 0, φi≥ φi−1 if i > 0, ψj≥ 0, and −a≤ψj−φi≤b. Similarly, the second workchain contains only transactions by B, and its blocks are generated only by B; its states are Tj = (j,ψ j,i,φ i), with similar validity conditions. Now, if A wants to transfer some money to B, it simply creates a new block in its workchain, signs it, and sends to B, without waiting for conr- mation. The payment channel is nalized by A signing (its version of) the nal state of its blockchain (with its special nal signature), B signing the - nal state of its blockchain, and presenting these two nal states to the clean nalization method of the payment channel smart contract. Unilateral nal- ization is also possible, but in that case the smart contract will have to wait for the other party to present its version of the nal state, at least for some grace period. 5.1.6. Unidirectional payment channels. If only A needs to make pay- ments to B (e.g., B is a service provider, and A its client), then a unilateral payment channel can be created. Essentially, it is just the rst workchain described in 5.1.5 without the second one. Conversely, one can say that the asynchronous payment channel described in 5.1.5 consists of two unidi- rectional payment channels, or half-channels, managed by the same smart contract. 5.1.7. More sophisticated payment channels. Promises. We will see later in 5.2.4 that the lightning network (cf. 5.2 ), which enables instant money transfers through chains of several payment channels, requires higher degrees of sophistication from the payment channels involved. In particular, we want to be able to commit promises, or conditional money transfers: A agrees to send c coins to B, but B will get the money 115 5.1. Payment Channels only if a certain condition is fullled, for instance, if B can present some string u with Hash (u) =v for a known value of v. Otherwise, A can get the money back after a certain period of time. Such a promise could easily be implemented on-chain by a simple smart contract. However, we want promises and other kinds of conditional money transfers to be possible o-chain, in the payment channel, because they con- siderably simplify money transfers along a chain of payment channels existing in the lightning network (cf. 5.2.4 ). The payment channel as a simple blockchain picture outlined in 5.1.4 and 5.1.5 becomes convenient here. Now we consider a more complicated vir- tual blockchain, the state of which contains a set of such unfullled promises, and the amount o
프로젝트로 돌아가기