TRON 백서

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

er Representatives. A total of 336,384,000 TRX will be awarded annually to the 27 SRs. Each time an SR finishes block production, rewards are sent to a sub-account in the super-ledger. SRs can check, but not directly make use of these TRX tokens. A withdrawal can be made by each SR once every 24 hours, transferring the rewards from the sub-account to the specified SR account. The three types of nodes on the TRON network are Witness Node, Full Node, and Solidity Node. Witness nodes are set up by SRs and are mainly responsible for block production and proposal creation/voting. Full nodes provide APIs and broadcast transactions and blocks. Solidity nodes sync blocks from other Full Nodes and also provide indexable APIs. 15 4. Account 4.1 Types The three types of accounts in the TRON network are regular accounts, token accounts, and contract accounts. 1. Regular accounts are used for standard transactions. 2. Token accounts are used for storing TRC-10 tokens. 3. Contract accounts are smart contract accounts created by regular accounts and can be triggered by regular accounts as well. 4.2 Creation There are three ways to create a TRON account: 1. Create a new account through API 2. Transfer TRX into a new account address 3. Transfer any TRC-10 token into a new account address An offline key-pair consisting of an address (public key) and a private key, and not recorded by the TRON network, can also be generated. The user address generation algorithm consists of generating a key-pair and then extracting the public key (64-byte byte array representing x, y coordinates). Hash the public key using the SHA3-256 function (the SHA3 protocol adopted is KECCAK-256) and extract the last 20 bytes of the result. Add 41 to the beginning of the byte array and ensure the initial address length is 21 bytes. Hash the address twice using SHA3-256 function and take the first 4 bytes as verification code. Add the verification code to the end of the initial address and obtain the address in base58check format through base58 encoding. An encoded Mainnet address begins with T and is 34 bytes in length. 4.3 Structure The three different account types are Normal, AssetIssue, and Contract. An Account contains 7 parameters: 1. account_name ​ : the name for this account – e.g. BillsAccount. 2. type ​ : what type of this account is – e.g. 0 (stands for type ‘Normal’). 3. balance ​ : balance of this account – e.g. 4213312. 16 4. vote ​ : received votes on this account – e.g. {(“0x1b7w…9xj3”,323), (“0x8djq…j12m”,88),…,(“0x82nd…mx6i”,10001)}. 5. asset ​ : other assets expected TRX in this account – e.g. {<“WishToken”, 66666>, <”Dogie”, 233>}. 6. latest_operation_time ​ : the latest operation time of this account. Protobuf data structure: message ​ ​ Account ​ { ​ message ​ ​ Vote ​ { ​ bytes ​ vote_address = ​ 1 ​ ; ​ int64 ​ vote_count = ​ 2 ​ ; } ​ bytes ​ accout_name = ​ 1 ​ ; AccountType type = ​ 2 ​ ; ​ bytes ​ address = ​ 3 ​ ; ​ int64 ​ balance = ​ 4 ​ ; ​ repeated ​ Vote votes = ​ 5 ​ ; map< ​ string ​ , ​ int64 ​ > asset = ​ 6 ​ ; ​ int64 ​ latest_operation_time = ​ 10 ​ ; } enum ​ ​ AccountType ​ { Normal = ​ 0 ​ ; AssetIssue = ​ 1 ​ ; Contract = ​ 2 ​ ; } 17 5. Block A block typically contains a block header and several transactions. Protobuf data structure: message ​ ​ Block ​ { BlockHeader block_header = ​ 1 ​ ; ​ repeated ​ Transaction transactions = ​ 2 ​ ; } 5.1 Block Header A block header contains ​ raw_data ​ , ​ witness_signature ​ , and ​ blockID ​ . Protobuf data structure: message ​ ​ BlockHeader ​ { ​ message ​ ​ raw ​ { ​ int64 ​ timestamp = ​ 1 ​ ; ​ bytes ​ txTrieRoot = ​ 2 ​ ; ​ bytes ​ parentHash = ​ 3 ​ ; ​ uint64 ​ number = ​ 4 ​ ; ​ uint64 ​ version = ​ 5 ​ ; ​ bytes ​ witness_address = ​ 6 ​ ; } ​ bytes ​ witness_signature = ​ 2 ​ ; ​ bytes ​ blockID = ​ 3 ​ ; } 5.1.1 Raw Data Raw data is denoted as ​ raw_data ​ in Protobuf. It contains the raw data of a message, containing 6 parameters: 1. timestamp ​ : timestamp of this message – e.g. 1543884429000. 2. txTrieRoot ​ : the Merkle Tree’s Root – e.g. 7dacsa…3ed. 3. parentHash ​ : the hash of the last block – e.g. 7dacsa…3ed. 4. number ​ : the block height – e.g. 4638708. 5. version ​ : reserved – e ​ .g. 5. 18 6. witness_address ​ : the address of the witness packed in this block – e.g. 41928c...4d21. 5.1.2 Witness Signature Witness signature is denoted as ​ witness_signature ​ in Protobuf, which is the signature for this block header from the witness node. 5.1.3 Block ID Block ID is denoted as ​ blockID ​ in Protobuf. It contains the atomic identification of a block. A Block ID contains 2 parameters: 1. hash ​ : the hash of block. 2. number ​ : the hash and height of the block. 5.2 Transaction 5.2.1 Signing TRON’s transaction signing process follows a standard ECDSA cryptographic algorithm, with a SECP256K1 selection curve. A private key is a random number, and the public key is a point on the elliptic curve. The public key generation process consists of first generating a random number as a private key, and then multiplying the base point of the elliptic curve by the private key to obtain the public key. When a transaction occurs, the transaction raw data is first converted into byte format. The raw data then undergoes SHA-256 hashing. The private key corresponding to the contract address then signs the result of the SHA256 hash. The signature result is then added to the transaction. 5.2.2 Bandwidth Model Ordinary transactions only consume bandwidth points, but smart contract operations consume both energy and bandwidth points. There are two types of bandwidth points available. Users can gain bandwidth points from freezing TRX, while 5000 free bandwidth points are also available daily. When a TRX transaction is broadcast, it is transmitted and stored in the form of a byte array over the network. Bandwidth Points consumed by one transaction = number of transaction bytes multiplied by bandwidth points rate. For example, if the byte array length of a transaction is 200, then the transaction consumes 200 bandwidth points. However, if a TRX or token transfer results in the target account being created, then only the bandwidth points consumed to create the account will be deducted, and additional bandwidth points will not be deducted. In an account creation scenario, the network will first consume the bandwidth points that the transaction initiator gained 19 from freezing TRX. If this amount is insufficient, then the network consumes the transaction initiator’s TRX. In standard TRX transfer scenarios from one TRX account to another, the network first consumes the bandwidth points gained by the transaction initiator for freezing TRX. If that is insufficient, it then consumes from the free 5000 daily bandwidth points. If that is still not enough, then the network consumes the TRX of the transaction initiator. The amount is calculated by the number of bytes in the transaction multiplied by 10 SUN. Thus, for most TRX holders who may not necessarily freeze their TRX to participate in SR voting, the first step is automatically skipped (since TRX balance frozen = 0) and the 5000 daily free bandwidth powers the transaction. For TRC-10 token transfers, the network first verifies whether the total free bandwidth points of the issued token asset are sufficient. If not, the bandwidth points obtained from freezing TRX are consumed. If there is still not enough bandwidth points, then it consumes the TRX of the transaction initiator. 5.2.3 Fee TRON network generally does not charge fees for most transactions, however, due to system restrictions and fairness, bandwidth usage and transactions do take in certain fees. Fee charges are broken down into the following categories: 1. Normal transactions cost bandwidth points. Users can use the free daily bandwidth points (5000) or freeze TRX to obtain more. When bandwidth points are not enough, TRX will be used directly from the sending account. The TRX needed is the number of bytes * 10 SUN. 2. Smart contracts cost energy (Section 6) but will also need bandwidth points for the transaction to be broadcasted and confirmed. The bandwidth cost is the same as above. 3. All query transactions are free. It doesn’t cost energy or bandwidth. TRON network also defines a set of fixed fees for the following transactions: 1. Creating a witness node: 9999 TRX 2. Issuing a TRC-10 token: 1024 TRX 3. Creating a new account: 0.1 TRX 4. Creating an exchange pair: 1024 TRX 5.2.4 Transaction as Proof of Stake (TaPoS) TRON uses TaPoS to ensure the transactions all confirm the main blockchain, while making it difficult to forge counterfeit chains. In TaPoS, the networks require each transaction include part of the hash of a recent block header. This requirement prevents transactions from being replayed on forks not including the referenced block, and also signals the network that a particular user and their 20 stake are on a specific fork. This consensus mechanism protects the network against Denial of Service, 51%, selfish mining, and double spend attacks. 5.2.5 Transaction Confirmation A transaction is included in a future block after being broadcast to the network. After 19 blocks are mined on TRON (including its own block), the transaction is confirmed. Each block is produced by one of the top 27 Super Representatives in a round robin fashion. Each block takes ~3 seconds to be mined on the blockchain. Time may slightly vary for each Super Representative due to network conditions and machine configurations. In general, a transaction is considered fully confirmed after ~1 minute. 5.2.6 Structure Transaction APIs consist of the following functions: message ​ ​ Transaction ​ { ​ message ​ ​ Contract ​ { ​ enum ​ ​ ContractType ​ { AccountCreateContract = ​ 0 ​ ; // Create account/wallet TransferContract = ​ 1 ​ ; // Transfer TRX TransferAssetContract = ​ 2 ​ ; // Transfer TRC10 token VoteWitnessContract = ​ 4 ​ ; // Vote for Super Representative (SR) WitnessCreateContract = ​ 5 ​ ; // Create a new SR account AssetIssueContract = ​ 6 ​ ; // Create a new TRC10 token WitnessUpdateContract = ​ 8 ​ ; // Update SR information ParticipateAssetIssueContract = ​ 9 ​ ; // Purchase TRC10 token AccountUpdateContract = ​ 10 ​ ; // Update account/wallet information FreezeBalanceContract = ​ 11 ​ ; // Freeze TRX for bandwidth or energy UnfreezeBalanceContract = ​ 12 ​ ; // Unfreeze TRX WithdrawBalanceContract = ​ 13 ​ ; // Withdraw SR rewards, once per day UnfreezeAssetContract = ​ 14 ​ ; // Unfreeze TRC10 token UpdateAssetContract = ​ 15 ​ ; // Update a TRC10 token’s information ProposalCreateContract = ​ 16 ​ ; // Create a new network proposal by any SR ProposalApproveContract = ​ 17 ​ ; // SR votes yes for a network proposal ProposalDeleteContract = ​ 18 ​ ; // Delete a network proposal by owner CreateSmartContract = ​ 30 ​ ; // Deploy a new smart contract TriggerSmartContract = ​ 31 ​ ; // Call a function on a smart contract GetContract = ​ 32 ​ ; // Get an existing smart contract UpdateSettingContract = ​ 33 ​ ; // Update a smart contract’s parameters ExchangeCreateContract = ​ 41 ​ ; // Create a token trading pair on DEX ExchangeInjectContract = ​ 42 ​ ; // Inject funding into a trading pair 21 ExchangeWithdrawContract = ​ 43 ​ ; // Withdraw funding from a trading pair ExchangeTransactionContract = ​ 44 ​ ; // Perform token trading UpdateEnergyLimitContract = ​ 45 ​ ; // Update origin_energy_limit on a smart contract } } } 22 6. TRON Virtual Machine (TVM) 6.1 Introduction TRON Virtual Machine (TVM) is a lightweight, Turing complete virtual machine developed for the TRON's ecosystem. Its goal is to provide a custom-built blockchain system that is efficient, convenient, stable, secure and scalable. TVM initially forked from EVM and can connect seamlessly with the existing solidity smart contract 11 development ecosystem. Based on that, TVM additionally supports DPoS consensus. TVM employs the concept of Energy. Different from the Gas mechanism on EVM, operations of transactions and smart contracts on TVM are free, with no TRX consumed. Technically, executable computation capacity on TVM is not restricted by total holding amount of tokens. 6.2 Workflow The compiler first translates the Solidity smart contract into bytecode readable and executable on the TVM. The TVM then processes data through opcode, which is equivalent to operating the logic of a stack-based finite state machine. Finally, the TVM accesses blockchain data and invokes External Data Interface through the Interoperation layer. 11 EVM: Ethereum Virtual Machine (https://github.com/ethereum/ethereumj) 23 Figure 3: TVM Workflow 24 6.3 Performance 6.3.1 Lightweight Architecture TVM adopts a lightweight architecture with the aim of reducing resource consumption to guarantee system performance. 6.3.2 Robust TRX transfers and smart contract execution cost bandwidth points only, instead of TRX, which exempts TRON from being attacked. Bandwidth consumption is predictable and static since each computational step cost is fixed. 6.3.3 High Compatibility TVM is compatible with EVM and will be compatible with more mainstream VMs in the future. Thereby, all smart contracts on EVM are executable on TVM. 6.3.4 Low Cost Due to TVM’s bandwidth setup, development costs are reduced and developers can focus on the logic development of their contract code. TVM also offers all-in-one interfaces for contract deployment, triggering and viewing to offer the convenience for developers. 25 7. Smart Contract 7.1 Introduction A smart contract is a protocol that digitally verifies contract negotiation. They define the rules and penalties related to an agreement and also automatically enforce those obligations. The smart contract code facilitates, verifies, and enforces the negotiation or performance of an agreement or transaction. From a tokenization perspective, smart contracts also facilitate automatic funds transfers between participating parties should certain criteria be met. TRON smart contracts are written in the Solidity language. Once written and tested, they can be compiled into bytecode, then deployed onto the TRON network for the TRON Virtual Machine. Once deployed, smart contracts can be queried via their contract addresses. The contract Application Binary Interface (ABI) shows the contract’s call functions and is used for interacting with the network. 7.2 Energy Model The maximum energy limit for deploying and triggering a smart contract is a function of several variables: ● Dynamic energy from freezing 1 TRX is 50,000,000,000 (Total Energy Limit) / (Total Energy Weight) ● Energy limit is the daily account energy limit from freezing TRX ● Remaining daily account energy from freezing TRX is calculated as Energy Limit - Energy Used ● Fee limit in TRX is set in smart contract deploy/trigger call ● Remaining usable TRX in the account ● Energy per TRX if purchased directly (10 SUN = 1 Energy) = 100,000, SRs can vote on adjustment There are two consumption scenarios to calculate for maximum energy limit for deployment and trigger. The logic can be expressed as follows: const ​ R = Dynamic Energy Limit const ​ F = Daily account energy ​ from ​ freezing TRX const ​ E = Remaining daily account energy ​ from ​ freezing TRX const ​ L = Fee limit ​ in ​ TRX set ​ in ​ deploy/trigger call const ​ T = Remaining usable TRX ​ in ​ account 26 const ​ C = Energy per TRX ​ if ​ purchased directly // Calculate M, defined as maximum energy limit for deployment/trigger of smart contract if ​ F > L*R let ​ M = min(E+T*C, L*R) else let ​ M = E+T*C 7.3 Deployment When a TRON solidity smart contract is compiled, the TRON Virtual Machine reads the compiled bytecode. The bytecode consists of a section for code deployment, contract code, and the Auxdata. The Auxdata is the source code’s cryptographic fingerprint, used for verification. The deployment bytecode runs the constructor function and sets up the initial storage variables. The deployment code also calculates the contract code and returns it to the TVM. The ABI is a JSON file that describes a TRON smart contract’s functions. This file defines the function names, their payability, the function return values, and their state mutability. 7.4 Trigger Function Once the TRON smart contracts are deployed, their functions can be triggered individually either via TronStudio or through API calls. State-changing functions require Energy while read-only functions execute without Energy. 7.5 TRON Solidity TRON Solidity is a fork from Ethereum’s Solidity language. TRON modifies the original project to support TRX and SUN units (1 TRX = 1,000,000 SUN). The rest of the language syntax is compatible with Solidity ^0.4.24. Thus the Tron Virtual Machine (TVM) is almost 100% compatible with EVM instructions. 27 8. Token 8.1 TRC-10 Token In the TRON network, each account can issue tokens at the expense of 1024 TRX. ​ To issue tokens, the issuer needs to specify a token name, the total capitalization, the exchange rate to TRX, circulation duration, description, website, maximum bandwidth consumption per account, total bandwidth consumption, and the amount of token frozen. Each token issuance can also configure each account’s maximum daily token transfer Bandwidth Points, the entire network’s maximum daily token transfer Bandwidth Points, total token supply, locking duration in days, and the total amount of tokens locked. 8.2 TRC-20 Token TRC-20 is a technical standard used for smart contracts implementing tokens supported by the TRON Virtual Machine. It is fully compatible with ERC-20. The interface is as follows: contract ​ TRC20Interface { ​ function ​ ​ totalSupply ​ () ​ public ​ ​ constant ​ ​ returns ​ (uint); ​ function ​ ​ balanceOf ​ (address tokenOwner) ​ public ​ ​ constant ​ ​ returns ​ (uint balance); ​ function ​ ​ allowance ​ (address tokenOwner, address spender) ​ public ​ ​ constant returns ​ (uint remaining); ​ function ​ ​ transfer ​ (address to, uint tokens) ​ public ​ ​ returns ​ (bool success); ​ function ​ ​ approve ​ (address spender, uint tokens) ​ public ​ ​ returns ​ (bool success); ​ function ​ ​ transferFrom ​ (address from, address to, uint tokens) ​ public returns ​ (bool success); ​ event ​ ​ Transfer ​ (address indexed from, address indexed to, uint tokens); ​ event ​ ​ Approval ​ (address indexed tokenOwner, address indexed spender, uint tokens); } From a developer’s perspective, there are several differences between TRC-10 and TRC-20. Some of the key differences are that TRC-10 tokens are accessible by APIs and smart contracts while TRC-20 tokens allow for interface customization but are only accessible within smart contracts. 28 From a cost perspective, TRC-10 tokens have transaction fees that are 1000 times lower than TRC-20, but carry bandwidth costs for API transfers and deposits. Transfers and deposits in smart contracts for TRC-10 tokens cost both bandwidth and energy. 8.3 Beyond Since TRON uses the same Solidity version as Ethereum, more token standards could be readily ported to TRON. 29 9. Governance 9.1 Super Representative 9.1.1 General Every account in the TRON network can apply and have the opportunity to become a Super Representative (denoted as SR). Everyone can vote for SR candidates. The top 27 candidates with the most votes will become SRs with the right and obligation to generate blocks. The votes are counted every 6 hours and the SRs will change accordingly. T
프로젝트로 돌아가기