Smart contract
The smart contract was first introduced in 1994 by cryptographer Nick Szabo, almost the same age as the Internet. A smart contract is a computer program that automatically enforces contract terms. Before the advent of Bitcoin, smart contracts could not be applied to reality because there was no safe and reliable execution environment. Due to its decentralized, open and transparent features, the blockchain is inherently capable of providing a credible execution environment for smart contracts. Therefore, the new blockchain framework will almost always have the function of a smart contract.
Bitcoin has a built-in stack-based script execution engine that runs a unique script code for simple validation of transactions, such as signature verification and multi-signature verification. This scripting language was deliberately designed to be non-turing, simple enough to handle the various needs of money transfers.
Ethereum is the first blockchain with Turing's complete smart contract as its main function. Users can create their own contracts on the Ethereum platform, and the contract content can contain any logic including currency transfer. The contract is written in a language called Solidity, a high-level language developed by the Ethereum team dedicated to writing smart contracts. The syntax is similar to JavaScript and is eventually compiled into bytecode and run on EVM (Ethereum Virtual Machine). Among them. EVM provides virtual hardware such as stack, memory, memory, and a dedicated set of instructions, all running in a sandbox. It provides the ability to call each other between contracts, and can even dynamically load code from other contracts at runtime to execute. This ability makes Ethereum's contract very flexible, but it may also make the contract's function uncertain.
Unlike Ethereum's own hands-on approach to developing languages and virtual machines, Fabric chose to use existing container technologies to support smart contract functionality. Fabric's smart contracts can theoretically be written in any language, which is quite friendly to developers, they will not need to learn new languages, and can reuse existing business code and rich development libraries, and use familiar development. tool. In contrast, there are a number of problems with Docker's smart contract architecture: first, it is difficult to control the execution flow of smart contracts, so that it cannot limit its functions. Second, it cannot accurately calculate the computing resources consumed by contract operations. In addition, running Docker is a relatively resource-intensive operation, which makes it difficult to run contracts on mobile devices; finally, hardware configurations for different nodes, development libraries for contract references, etc., may result in contracts. Behavior is highly uncertain.
Onchain DNA uses AVM (Antshares Virtual Machine) as the underlying support for its smart contract functionality. AVM is a micro-core, platform-independent smart contract execution environment that provides a set of instructions for stack operations, flow control, logic operations, arithmetic operations, cryptographic operations, string operations, and array operations. It only provides two calculation stacks. However, because it allows the implementer of the blockchain to create its own virtual hardware and open it to smart contracts in the form of interfaces, the contract can get platform-related data, persistent storage, and access to the Internet at runtime. Although this may also make the contract's behavior uncertain, blockchain implementers can eliminate this uncertainty by properly writing virtual hardware. However, since there is currently no compiler and development environment for AVM, it makes it difficult to develop smart contracts based on AVM. Developers have to use a similar assembly syntax for contract writing, which requires higher technology ability.
Corda's smart contract functionality, like its own, is based on the JVM (Java Virtual Machine). Therefore, you can use any JVM-compatible language for development, such as Java, Kotlin, and so on. However, it has made some modifications to the JVM to make the contract scripts running on it deterministic. The development process is roughly like this: use Java to create a class that implements the Contract interface, and provide a function called verify to validate the transaction. The function accepts the current transaction as a parameter, if the transaction If the verification fails, an exception is thrown. If there is no exception, the verification is passed. Corda uses JPA (Java Persistence Architecture) to provide persistence functionality, support for SQL statements and commonly used databases, but requires the installation of plugins, and because the data is only stored in the contract performer's nodes, global persistent storage is not possible.
Scalability
The data structure of the blockchain usually only can add records, but can not modify or delete records. It truly records the complete historical data, so that the newly added nodes have the ability to verify the complete transaction history of the whole network without trust. Other nodes. This feature brings decentralization convenience, but it also affects the scalability of the blockchain system, because the block will grow endlessly until it fills the entire hard disk. So it is necessary to provide a space recycling mechanism to cope with the growing data.
Bitcoin proposes to use the Merkle tree to store the transaction hash. When it is necessary to reclaim hard disk space, simply remove the old transaction from the Merkel tree. A block header with no transaction information is only 80 bytes in size. According to the bitcoin block generation rate of one every 10 minutes, the data generated every year is about 4.2MB, even if all the block headers are stored in the memory is not a problem.
Ethereum, Fabric and Onchain DNA use state snapshots to save disk space on the basis of bitcoin block compression. Specifically, in the structure of the block header, not only the root hash of all transactions of the current block but also the state root hash of the current block and all the past blocks are recorded. These states include all UTXO, account balance, contract storage, etc., so the node only needs to keep the latest block and complete status information.
Another important indicator of scalability is the throughput of the transaction. There are many factors that determine throughput, such as network structure, encryption algorithms, consensus mechanisms, etc., but the most important thing is whether transactions can be verified in parallel. If transactions can be verified in parallel, you can increase throughput by simply increasing the number of CPUs in the future.
Bitcoin based on UTXO system can easily verify the transaction in parallel. Because UTXO is not related, the state change of any UTXO can be independent and independent of order; while the balance-based account system is not so It's easy to implement parallelism, because multiple transactions can happen at the same time to perform asset operations on the same account, and some extra steps need to be taken. For example, suppose the balance in the account is 10 yuan, and there are two transactions for the account happening at the same time, the first transaction is +5 yuan in the account, and the second transaction is -11 yuan in the account. Then if the first transaction is executed first, both strokes will be successful, and the final balance will be 4 yuan. If the second transaction is executed first, it will fail due to insufficient balance. Only the first transaction will succeed, and the final balance will be 15 yuan.
And the decisive role in the parallel verification of transactions is the ability of smart contracts to have state persistence. If a set of contracts are stateless, they can be executed in any order without any side effects; instead, if the contract can affect a set of states, the results of the contract are executed in a different order. It will be different. For example, a contract that calculates interest on deposits has two sub-functions: deposit and interest settlement. Suppose there is 100 yuan in the account and the interest rate is 10%. Now there are two transactions at the same time. The content of the first transaction is deposited at 100 yuan, and the content of the second transaction is settlement interest. If the first transaction is executed first, then the balance of the final account is: 100+100) * 110% = 220 yuan; if the second transaction is executed first, the account balance will be: 100 * 110% + 100 = 210 yuan. It can be seen that smart contracts with state persistence capabilities are sequential and therefore difficult to verify concurrently, especially if the contracts can also be called from each other.
Currently, Fabric has not proposed any good solution to this problem; Corda does not have this problem, because its transaction itself will not broadcast to the entire network, so as long as the transaction participants and notaries can verify. Ethereum and Onchain DNA methods are partitions, which divide each contract into different logical areas. The contracts in each area are executed sequentially, and different areas are executed in parallel. Ethereum uses the first byte of the contract address as the partition basis, resulting in 256 partitions, each running in its own partition and can only call contracts with the same partition as itself. But this approach does not actually solve the problem effectively, because there are always some common underlying contracts that are widely used, and most caller contracts are grouped together in the same partition.
Onchain DNA divides contracts into functional code and application code. The functional contract is designed to provide reusable function functions, which are called by other contracts, and must be declared stateless, which eliminates most of the contract aggregation phenomenon; only the application contract can save its own state, so When executing an application contract, it adopts a dynamic partitioning scheme: before the contract is executed, its call tree is calculated first, and the contract with the intersection of the calling trees is executed in the same partition.
Unique characteristics
Ghost agreement
The Ghost Protocol is an improvement of the existing POW algorithm by Ethereum. The motivation is that the blockchain that is currently fast-recognized suffers from low security due to the high rate of blockage. Because the block needs to take some time to spread to the whole network, if miner A digs up a block and then miner B happens to dig another block before the block of A spreads to B, the block of miner B will be invalid. And did not contribute to network security. If A is a 30% computing power pool and B has 10% of the computing power, A will face 70% of the time is in the risk of creating a block and B is 90% of the time is invalid. Block. By including the waste block when calculating which chain is "longest", the ghost protocol solves the first problem of reducing network security; that is, not only the parent block of a block but earlier The ancestor block, the annihilated descendant block of the ancestor block (called the "uncle block" in the Ethereum terminology) is also added to calculate which block has the largest proof of workload. Ethereum pays 87.5% of the shards in the shards that contribute to the new block recognition as “unclear blocks”, and the inclusion of them in the calculated “scorpion block” will receive 12.5% of the reward. Calculations show that the five-layer ghost agreement with excitation achieves more than 95% efficiency even with a 15s out time, while a miner with 25% computational power gets less than 3% benefit from centralization.
National secret algorithm
The national secret algorithm is a series of commercial cryptographic algorithms developed by the China National Cryptography Authority, including the symmetric encryption algorithm SM1, the elliptic curve asymmetric encryption algorithm SM2, and the hash algorithm SM3. Usually the blockchain uses international standards such as AES, ECDSA, SHA2, etc. when using cryptographic algorithms. Domestic financial institutions usually consider the national secret algorithm when choosing a cryptography program. Onchain DNA provides an optional cryptography module that addresses different security and policy risks by selecting different cryptographic criteria for different scenarios.
Cross-chain interoperability
At present, blockchain technology is in an era of blooming and arguing, and various blockchains have emerged. Interoperability between blockchains has become a very important and urgent need. Enterprise users may need to move between different chains; ordinary users may need to exchange assets between different chains; the central bank's digital currency may need to be circulated across the blockchain. Onchain DNA provides a cross-chain interoperability protocol. Through this cross-chain protocol, users can perform asset trading, contract execution, etc. across different blockchains, and ensure transaction consistency across the blockchain. .
Chainless structure
As Corda claims in the white paper, it has no chain structure, and transactions are not broadcast to the entire network, but only between participants and notaries of the transaction. Therefore, the data can only be accessed by the “persons who need to access”, avoiding the problem of privacy leakage. Since there is no global chain structure, each node only stores transactions related to itself, without having to store all the transactions of the entire network, which greatly saves space.
Sum up
This paper compares and discusses the characteristics and functions of each blockchain framework from multiple dimensions, and expounds their advantages and disadvantages in various aspects, as well as the applicability and limitations in the application field.
Although bitcoin is a prototype of blockchain technology, it has a very important position. However, due to the limitations of its technical architecture, such as mining and non-turing, it is difficult to apply to complex business scenarios, but it is very suitable. Used for currency issuance.
Although Ethereum also uses mining, its ghost agreement has improved mining efficiency, and new consensus algorithms are under development. Ethereum has also developed a number of cryptographic-based privacy protection schemes, such as the ring signature hybrid scheme, which is ideal for creating Decentralized Autonomous Organizations.
The positioning of Fabric and Onchain DNA is an enterprise-level blockchain solution, which is suitable for customizing the alliance chain of various specific services, including application scenarios in the financial field. The difference is that Fabric is smart-oriented, while Onchain DNA is oriented toward digital assets; the former is more suitable for developing complex custom business processes, while the latter is more suitable for building financial business systems or equity registration flows with digital assets as the core. System, and has strong scalability.
Corda's positioning is a "distributed database" for interbank business, which abandons the block and chain structure to better separate the participants' business data; but introduces the notary role, network structure It is relatively fixed and not flexible and scalable, and does not differ much from the way the existing banking system operates.