Language understanding move from the different characteristics of Bitcoin, Ethernet Square, libra of

About Bitcoin, Ethernet Square, libra, we know that they are different blocks chain applications, so where is their fundamental difference in it.
In fact, just from the title of the white paper, you can see the difference about three items on the design goals.

  • Bitcoin goal - Programmable currency (Programmable Money), so that the white paper entitled "Bitcoin: A peer-to- peer electronic cash system".
  • Ether Square goal - programmable decentralized applications (Programmable dApps), on the basis of the currency, extended to more general areas. So the White Paper entitled: "Ethereum: a next generation smart contract and decentralized application platform", Yellow Book entitled: "Ethereum: A secure decentralized generalized transaction ledger".
  • Libra design goal just two intervening - programmable resources (Programmable Resources), or called programmable assets.

Then, "Programmable currency", "programmable application", "programmable resources," the three in the end what difference will it make?
Since they are "programmable XX" sentence, their main difference lies in two things:
what programming;
how to program.
What program?

What programming is the system described in the abstract or, in the end is what the real world.

Bitcoin for "currency" programming

Bitcoin system abstraction is the "currency", or is the concept of "books" of. Money can be used to describe a number, which is an account of a "balance." Users can "deal", the part of the money to others. When the Bitcoin network receives a transaction, each node checks the legality of the transaction, such as you spend is not their own money, there is not enough balance (Bitcoin allows no overdraft). When these checks are successful, the node will do a simple addition and subtraction: deduct the amount transferred in your account and add the same amount in each other's accounts. Therefore, Bitcoin only function is to billing, to ensure that the process of transfer of accounts with each other, the total amount of money does not somehow increase or decrease (without regard to mining reward and black holes, etc. address exceptions).

Ethernet Square on the "Apply" program

Square abstract Ethernet system is the "application", all-inclusive type of application, such as games, lending systems, electrical systems business, exchange, etc., these are the applications. In theory, any conventional computer program can be ported to Ethernet Square. Therefore, Ethernet Square is recorded in the internal data for various applications (ie, "state contract"), such as a stock system of electricity supplier, orders, billing information and so on. This information can not be described by a single number, the user must be allowed to define complex data structures, and allows the user codes (smart contract) to any required operations on these data. Of course, these applications also includes "Currency books." In fact, on an Ethernet Square it is the most widely used type of application (called "ERC20 smart contract"). Because Ethernet Square to such applications as a kind of platform that can support a variety of applications in comparison with other types of applications, and there is nothing special, so there is no more for such applications security only provides a similar interface specification ERC20 this. A new issue in the etheric Square "currency", which transfers the logical correctness sole responsibility of the developer.
Here Insert Picture Description
In the storage structure of the Ethernet Square, ERC20 tokens of different places in the books "secondary object", and ETH native balance stored tokens. For example as shown above, 0x0,0x1 and 0x2 square is three Ethernet address, wherein, 0x0 and 0x2 are common account address (External accounts), and the address 0x1 is a contract (Contract accounts). We can see that the balance of each account are stored in a ETH, this data is the top-level objects (First-Class Object). In the contract address 0x1, the contract also stores an intelligent code is MyCoin, it is a token ERC20 application. And MyCoin this entire books tokens are stored in 0x1 space, how to modify the code by 0x1 in the contract the final say.

Whether intentional or not, ERC20 tokens are very prone to security vulnerabilities. In other words, Square Ethernet system, native token and user ETH issued token does not enjoy the same level of security.

Libra on the "assets" program

So, you can not then go to extremes to try to abstract some of the more sophisticated than simple numeric types of assets, without the pursuit of all-encompassing "universal" mean? This is the starting point of Libra. Libra can be defined similar to a basket of currencies, financial derivatives geometric currency more complex asset types, and how to operate them, such assets are called "resources." Move by restricting the operation of resources to prevent improper modification to improve the safety of assets. No matter how logical resources, must meet two constraints:

  • Scarcity . That is the total amount of assets must be controlled, does not allow users to freely copy resources. In layman's terms, it is to allow banks to print money, but does not allow users to use the copier to "create" new money;
  • Access control . Simply means that operating resources must meet certain pre-defined rules. For example, Joe Smith can only spend their own money, while John Doe is not allowed to spend the money.
    Here Insert Picture Description
    Move on the map is the state of the world, with different Ethernet Square, which all assets are deemed to be "first-class citizens" (First-Class Resources), both native tokens Libra, or the user's own release of assets. Any one of the "currency" of the balance, are stored in the user address space corresponding in its operations are strictly limited. Such an object is called a resource (Resource), and can only be moved in the transaction, and only moved once, neither be copied, can not be perishable. Even to strictly assigned to a local variable in the code, but did not use it later is not allowed.

Storage of such assets is not unique Libra, has been used in some previous public chain, for example in public Vite chain, the balance of currency issued by the user is the top target. However Move can support more complex types of assets, and its extra protection, which is Libra's main contribution.

Editor Group: Vite is a project created by the author.

How to program?

We look at how the three projects to achieve extensive scalability through programming.

Bitcoin script

在比特币中,定义了一种 “比特币脚本”,用来描述花一笔钱的规则。比特币是基于 UTXO 模型的,只有满足了预先定义的脚本规则,才能花费一笔 UTXO。通过比特币脚本,可以实现 “多重签名” 之类的复杂逻辑。比特币脚本是一种非常简单的基于栈的字节码,不支持循环之类的复杂结构,也不是图灵完备的。虽然利用它可以在比特币网络上发行新的货币(Colored Coins),但它的描述能力非常有限,对开发者也不友好,无法应用到更复杂的场景中。

以太坊的 Solidity 语言

在以太坊中,定义了一种 Solidity 的编程语言,可以用来开发 “智能合约”。智能合约代码可以编译成一种基于栈的字节码 ——EVM Code,在以太坊虚拟机 EVM 中执行。Solidity 是一种高级语言,参考了 C++、Python 和 Javascript 的语法,是一种静态类型、图灵完备的语言,支持继承,允许用户自定义复杂的类型。Solidity 更像是一种通用的编程语言,理论上可以用来开发任何类型的程序,它没有针对货币或者资产类型的数据,在语法和语义上做任何限制和保护。比如用它来开发一个新的代币合约,代币的余额通常声明为 uint 类型,如果编码时对余额增减逻辑的处理不够小心,就会使余额变量发生溢出,造成超额铸币、随意增发、下溢增持等严重错误, 如: BEC 智能合约的漏洞。

Libra 的 Move 语言

再来看 Libra,它定义了一种新的编程语言 Move,这种语言主要面向资产类数据,基于 Libra 所设定的 “顶级资源” 结构,主要设计目标是灵活性、安全性和可验证性。目前,Move 高级语言的语法设计还没有完成,白皮书只给出了 Move 的中间语言(Move IR)和 Move 字节码定义。因此我们无法评估最终 Move 语言对开发者是否友好,但从 Move IR 的设计中,可以感受到它在安全性和可验证性方面的特点。

Move 语言的设计

下面我们来简单介绍一下 Move 的语法。Move 的基本封装单元是 “模块”(Module),模块有点类似于以太坊中的 “智能合约”,或者面向对象语言中的 “类”。模块中可以定义 “资源”(Resource)和 “过程”(Procedure),类似于类中的 “成员”(Member) 和 “方法”(Method)。

所有部署在 Libra 上的模块都是全局的,通过类似于 Java 中的包名 + 类名的方式来引用,例如 0x001.MyModule,0x001 是一个 Libra 地址,MyModule 是一个模块名。模块中的过程有 public 和 private 两种可见性,公有过程可以被其他模块调用,私有过程只能被同模块的过程调用。而模块中的资源都是私有的,只有通过公有过程才能被其他模块访问。而且,外部模块或者过程对本模块资源的修改受到严格的限制,唯一允许的操作就是 “移动”(Move),不能随意对资源赋值。例如,Move 中是不允许出现一个类似于 MyCoin.setBalance() 这样的接口,让其他用户有机会随意修改某个币种余额的。

除了受限的资源类型,Move 模块中也允许定义非受限的成员,被称为非受限类型(Unrestricted Type),包括原生类型(boolean、uint64、address、bytes)和非资源类的结构体(struct)。这些非受限类型就没有那么严格的访问限制,可以用来描述与资产无关的其他应用类数据。从这个角度来说,Move 语言理论上应该具有和 Solidity 同样的描述能力,但由于实际的去中心化应用中,总会涉及到资产类的数据,而任何引用了资源类型的结构体也都是受限的,能够真正脱离 Move 语言严格限制的机会并不多。所以在实际使用 Move 语言开发的时候,程序员一定会有一种戴着镣铐跳舞的感觉,代码出现编译时和运行时失败的可能也更大。

Popular to say, write code using Move will not make you feel "cool", which is security and verifiability price. Think about when you control allocate and free memory in C language themselves, although there is a kind of "I am God" feeling, but it also concerns the time buffer overflow, memory leaks and other potential risks; and the development of the Java language, though you do not and then do whatever they can to control memory, but do not worry about the safety of these memory problems. Freedom or security, often they do not have both.

Libra in a transaction (Transaction), a Move the code can be embedded section, the script is called transaction (Transaction Script). This code does not belong to any module, it is a one-time execution, can no longer be called by other code. The script may comprise a plurality of processes performed by the main entry procedure as in the process which can call other modules. This design is somewhat similar to Bitcoin, but completely different and Ethernet Square. Place in the ether, the transaction itself can not contain a piece of executable code, you can only deploy a new contract or a contract calling deployed. I do not like this design Libra, for any Move code must be released in order to go through a rigorous inspection bytecode verifier (Bytecode Verifier) ​​to the chain, the marginal cost of this one-time code that is much higher than reusable module, it will slow down the speed of the transaction is confirmed, reduce the throughput of the system. Transaction script is not necessary, most realistic scenarios can be covered by the module, and its presence has also increased the development and use of purse Libra difficulty, there is a chance I will propose to the Libra's development team canceled this design.

In this article first appeared in layman block chain technology blog, click the interpretation Libra Move: A programmable language resources look at the example code fragment in the White Paper, intuitive feelings Move languages, to learn more about move virtual machines.

In layman's language block chain technology blog, with your understanding move language , into the libra world.

Guess you like

Origin www.cnblogs.com/blockchainnote/p/11810633.html