Intelligent contract

define

A smart contract is a set of digitally defined conventions, including agreements on which parties to the contract can enforce them. The basic idea behind smart contracts is that various contract terms can be embedded in the hardware and software we use, making it costly for an attacker to attack.

Features:

  • The if-then statement of a computer program
  • It is automatically implemented when the treaty is reached
  • Digital contracts
  • The computing system automatically executes the terms

Features:

  • Data transparency: The data on the blockchain is open and transparent to the participants, and the data processing is also open and transparent.
  • Imtamable: All data on the blockchain itself is imtamable, as is the smart contract code on the blockchain and the data output generated by the operation.
  • Permanent operation: There are often hundreds or even thousands of nodes supporting the blockchain network. The failure of some nodes does not cause the smart contract to stop, and its reliability is theoretically close to permanent operation.

Constitute a

  • Participant: A person or organization that participates in a digital asset transaction.
  • Asset: Something, either concrete or abstract, that has a certain value and is acquired as part of a transaction.
  • Transaction: The process in which participants query and transfer assets.
  • Ledger: a database that records the ownership of assets and the facts of their transactions.

The design process

  1. Multiple users participate in the development of smart contracts.
  2. Contracts spread through P2P networks and are deposited on blockchains.
  3. Smart contracts built by blockchains are executed automatically.

A programming language

Basic construction model

Operation mechanism

Application field

The problem challenges

Consensus mechanism

Introduction to the

The question of Byzantine generals

A story about fault tolerance in distributed systems.

Background:

At the time of battle, all the generals and adjutants in the Byzantine army had to reach a consensus on whether they had a chance to win before attacking the enemy’s camp. But there may be traitors and spies for the enemy within the army, influencing the decisions of the generals and disturbing the whole army. When consensus is reached, the results do not represent the majority. Now the Byzantine question arose as to how the remaining loyal generals could reach an agreement without being influenced by the traitors in the event of a known rebellion.

Solution:

Each node sends a message to all the other nodes

Each node determines the final policy based on all the messages it receives

disadvantages

Each node sends a large number of messages to the entire network.

concept

Due to the high network delay in point-to-point network, the transaction sequence observed by each node cannot be exactly the same. So a blockchain system needs to set up a mechanism to agree on the sequence of transactions that will take place in a similar amount of time. The algorithm that agrees on the sequence of transactions in a time window is called the consensus mechanism.

  • Consensus algorithm: A calculation algorithm in which nodes reach consensus according to consensus rules
  • Consensus rules: Each blockchain has carefully designed rule-based protocols that use consensus algorithms to ensure that consensus rules are implemented correctly.

role

Act as the law of life

An overview of

  • Proof of work PoW: Bitcoin BTC, Ethereum ETH, Ethereum Classic ETC
  • PoS: ADA, Peercoin
  • DPoS: EOS, Asch, Steem
  • Byzantine fault tolerance BFT: Practical Byzantine fault tolerance PBFT, derived BFT
  • RAFT algorithm: ETCD

PoW

Features:

The computational cost required to solve the computation-difficult problem is credited to the newly added block and rewarded.

Process:

Defect:

Because PoW lacks decentralization and consumes too many resources, there is another consensus mechanism, PoS

PoS

Features:

By using proof of equity instead of proof of work, the node with the highest interest can realize the addition of new blocks and obtain incentive benefits.

Process:

Before the competition for block bookkeeping begins, the node with interest puts its interest into the PoS mechanism, and at the same time, its identity becomes the verifier. The PoS mechanism selects a bookkeeper randomly for block bookkeeping according to the amount of bets made by the verifier.

Defect:

It is not completely random, but the larger the weight is, the more the probability is obtained, and the problem of the waste of resources and computing power has not been solved, and the problem of incomplete equivalence exists.

DPoS

Features:

First, the representatives are selected through PoS, and then the block generator is selected from the representatives and the revenue is obtained.

Process:

DPoS consensus system the basic train of thought is similar to “the board decision”, namely the system of each node can be holding shareholders’ rights, as a representative of the vote to grant a gets the most votes and willing to be on behalf of the top 101 nodes will enter the “board”, according to the established schedule to packaging trading and settlement in turn and signed a new block (i.e., production).

Defect:

BFT(Byzantine Fault Tolerant algorithm)

Features:

In THE DBFT algorithm, super nodes participate in the accounting, while ordinary nodes can see the consensus process and synchronize the accounting information, but do not participate in the accounting. A total of N super nodes are divided into a speaker and n-1 and lawmakers, and the speaker will be elected in turn. Every time an existing speaker initiates a blockchain proposal (the block content to be billed), once at least (2N +1) /3 billing nodes (Speaker + Member) agree to the proposal, then the proposal becomes the final published block and the block is irreversible.

Process:

PBFT process:

RAFT

Features:

It is a simple implementation of PAXOS algorithm. The core idea is that if the initial state of several databases is consistent, as long as the subsequent and retrograde operations are consistent, the subsequent data can be guaranteed to be consistent.

Process:

Evaluation standard

Comparison of consensus mechanisms

PoW PoS DPoS Raft PBFT
scenario The male chain Public chain, alliance chain Public chain, alliance chain League chain League chain
decentralized completely completely completely Half neutralization Half neutralization
The node of charge to an account Cut in Cut in Elect representatives Choosing a Leader Dynamic decision
The response time Ten minutes 1 minute 3 seconds Second level Second level
Storage efficiency All the books All the books All the books All the books Full ledger + partial ledger
throughput About 7 TPS About 15 TPS About 300TPS or higher Thousands or even tens of thousands About 10000TPS or higher
Fault tolerance 50% 50% 50% 50% 33%