区块链

Layers

img

OSI网络七层模型

图片

下图详细说明了各层作用

图片

实际应用过程中,五层协议结构里面是没有表示层和会话层的。应该说它们和应用层合并了。

数据层

区块链是通过区块(block)存储数据,每个数据节点之间都包含所有数据,即分布式账本。每个区块都包括了区块的大小、区块头、区块所包含的交易数量及部分或所有的近期新交易。

数据层主要是解决这些数据以什么样的形式组合在一起,形成一个有意义的区块。

区块链的数据结构中包括两种哈希指针,它们均是不可篡改特性的数据结构基础。

  1. 一个是形成“区块+链”(block+chain)的链状数据结构

  2. 另一个是哈希指针形成的梅克尔树(如下图所示)。

用处

链状数据结构使得对某一区块内的数据的修改很容易被发现; 梅克尔树的结构起类似作用,使得对其中的任何交易数据的修改很容易被发现。

img

网络层

img

区块链使用的是去中心化的网络架构,没有中心化服务器,依靠用户点对点交换信息,主要包括 P2P 组网机制、数据传播和验证机制。

P2P特性

正是由于节点的 P2P 特性,数据传输是分散在各个节点之间进行的,部分节点或网络遭到破坏对其他部分影响很小。

节点指的是区块链客户端软件(比如比特币客户端、以太坊客户端),一般分为全节点和轻节点,全节点包含了所有区块链的区块数据,轻节点仅包括与自己相关的数据。

共识层

共识层的功能是让高度分散的节点在 P2P 网络中,针对区块数据的有效性达成共识,决定了谁可以将新的区块添加到主链中(挖矿机制)。

工作量证明共识机制( PoW )

PoW

矿工需要将网络中未确认的交易按梅克尔树组装成候选区块,在候选区块的头部有一个 32位的随机数区域,矿工需要反复调整随机数并计算,目标是让整个区块的哈希值小于一个“目标值”,谁先完成这个目标谁就有权力将交易记录到区块链分布式账本中并获得一定的奖励。

挖矿的过程比拼的就是各个矿工节点的算力,可以变相认为谁的算力高谁的工作量就高,就有权力记账和获得奖励。

  • 比特币使用的是 PoW 机制;
  • 以太坊开始使用的是 PoW 机制,后来改成了 PoS 机制,原因是该机制交易速度更快、资源消耗更低。

这种挖矿计算是非对称的,挖矿可能需要经过许多次哈希计算,而要验证的确找到有效的随机数,只需要一次计算就可以,因此其他节点能够很快验证交易是否已经被记入账本。

激励层

激励层的功能主要是提供一些激励措施,鼓励节点参与记账,保证整个网络的安全运行。通过共识机制胜出取得记账权的节点能获得一定的奖励。

目前比特币的激励措施是新区块产生时系统会奖励矿工一定的比特币(系统产生的新比特币,也会记录在分布式账本,来源地址是 0,因此整个过程叫挖矿),奖励最初是 50 个比特币,每四年减半一次,分别为 25 个、12.5 个,以此类推。当比特币数量达到 2100 万枚的上限后(2140 年),激励就全靠交易的手续费了。以太坊交易是靠 gas 手续费来激励矿工。

合约层

合约层封装了各类脚本、算法和智能合约,使得区块链具有可编程能力。例如,比特币的脚本中就规定了比特币的交易方式和过程中的种种细节,不过这种脚本使用不够便捷且不是图灵完备的。

以太坊提出了智能合约的解决方案,提供了一种图灵完备的高级编程语言来编写智能合约,并使智能合约能够运行在分布式的以太坊虚拟机 EVM 上。

智能合约

智能合约就是存储在区块链上的一段代码,它们可以被区块链上的交易所触发,触发后,这段代码可以从区块链上读取数据或者向区块链上写入数据。

区块链系统(比特币、以太坊)可以认为是一个分布式状态机,通过交易触发合约(脚本、智能合约)运行来改变状态机的状态。

应用层

应用层封装了区块链的各种应用场景,具体应用可参见90+ #Ethereum Apps You Can Use Right Now

以下为一笔比特币转账交易的过程

img

Blockchains

  • Aleo. Leo is a rust flavoured zk language.
  • Aleph Zero. DAG, PoS, snark smart contracts (substrate based).
  • Anoma.network. PoS blockchain with privacy.
  • Bitcoin Cash. A library for creating and parsing Bitcoin Cash trasactions.
  • CITA. A high performance blockchain kernel for enterprise users.
  • CodeChain. Programmable multi-asset chain.
  • Concordium. Privacy centric (zk) PoS chain, yet with built in identities and rust smart contracts.
  • Conflux. The Rust implementation of Conflux protocol.
  • Darwinia. Relay chain of Darwinia Network, can connect to Polkadot as parachain in Polkadot Model.
  • Dusk.network. Privacy PoS using zk (plonk).
  • Enigma secures the decentralized web.
  • Elrond. Elrond (EGOLD( - scalable and usable blockchain, written is Rust and has smart contracts in Rust.
  • Exonum. An extensible open-source framework for creating private/permissioned blockchain applications.
  • Forest. An implementation of Filecoin written in Rust.
  • Fuel. Rust full node implementation of the Fuel v2 protocol.
  • Gear. Computational component of Polkadot network.
  • Grin. Minimal implementation of the MimbleWimble protocol.
  • Holochain. The core Holochain framework written in rust, a container, and hdk-rust library for writing Zomes.
  • Huobi Chain. The next generation high performance public chain for financial infrastructure.
  • Interledger. An easy-to-use, high-performance Interledger implementation written in Rust.
  • Internet of People. Decentralized software stack that provides the building blocks and tools to support a decentralized society.
  • Libra. Global currency and financial infrastructure that empowers billions of people.
  • Lighthouse. Fast and secure Ethereum 2.0 client.
  • NEAR. NEAR Protocol - scalable and usable blockchain.
  • Nervos CKB. Nervos CKB is a public permissionless blockchain, the common knowledge layer of Nervos network.
  • NYM. Selective privacy via a mixnet preventing metadata analysis.
  • Nomic. Nomic is a high-performance Bitcoin sidechain which is part of the Cosmos network.
  • Mina Protocol. A rust implementation of the mina succinct blockchain.
  • Mir Protocol. A succinct blockchain powered by zero-knowledge proofs. (plonk based)
  • OpenEthereum. The Ethereum Rust client
  • Parity Bitcoin. The Parity Bitcoin client.
  • Parity Ethereum. The fast, light, and robust EVM and WASM client.
  • Parity Zcash. Rust implementation of Zcash protocol.
  • Polkadot. Polkadot Node Implementation.
  • Polymesh. The Polymesh blockchain (built on Substrate) is an identity orientated chain for the issuance, lifecycle management and settlement of regulated securities.
  • QAN. Post-quantum blockchain.
  • Radix. Sharded smart contract DeFi platform.
  • Setheum. SETHEUM : “Secure Evergreen Truthful Heterogeneous Economically Unbiased Market” is an Ethical DeFi-friendly Blockchain (built on Substrate) working on achieving mass adoption, security, scalability, affordability, inclusivity and ethical DeFi Governance.
  • Shasper. Parity Shasper beacon chain implementation using the Substrate framework.
  • Solana. Blockchain Rebuilt for Scale.
  • Stacks 2.0. Proof of Transfer blockchain from Blockstack.
  • Tari. The Tari Digital Assets Protocol.
  • Tendermint. Tendermint is a high-performance blockchain consensus engine for Byzantine fault tolerant applications.
  • Witnet. Open source implementation of Witnet decentralized oracle network protocol in Rust.
  • xx-network. Post-quantum blockchain, mixnet privacy preventing metadata analysis. (Substrate rust+go)
  • Zebra. An ongoing Rust implementation of a Zcash node.
  • Zero-chain. A privacy-preserving blockchain on Substrate.

Blockchain Frameworks

  • Substrate. The platform for blockchain innovators.
  • slingshot. A new blockchain architecture under active development, with a strong focus on scalability, privacy and safety.
  • Tendermint ABCI. Tendermint ABCI server, written in the Rust programming language.
  • Orga. A high-performance state machine engine designed for Tendermint-based blockchain applications.

Cross-Chain

  • Comit is an open protocol facilitating trustless cross-blockchain applications.
  • IBC. Rust implementation of Cosmos’ Interblockchain Communication Protocol (IBC).

Virtual Machines

  • CKB-VM. RISC-V virtual machine.
  • CosmWasm. Multi-chain smart contract platform built for the Cosmos ecosystem.
  • EVM Parity. Parity implementation of EVM.
  • FuelVM FuelVM interpreter in Rust.
  • Lunatic. Erlang-inspired runtime for WebAssembly.
  • Polygon Miden. SNARK based VM.
  • SVM Spacemesh Virtual Machine.
  • Wasmi. WebAssembly interpreter.
  • Wasmer. A convenient Rust wrapper over WebAssembly backends.
  • Wasmtime. Standalone JIT-style runtime for WebAssembly, using Cranelift.
  • Zinc. Zinc zk smart contract language.

General-Purpose Consensus

  • Raft. Raft distributed consensus algorithm implemented in Rust.
  • Honey Badger. An implementation of the paper “Honey Badger of BFT Protocols” in Rust.
  • Narwhal. The consensus layer used by Sui.

P2P Network Libraries

  • chamomile. P2P library. Support build robust stable connection on p2p/distributed network.
  • crust. Reliable P2P network connections in Rust with NAT traversal. One of the most needed libraries for any server-less / decentralised projects.
  • rust-libp2p. The Rust Implementation of the libp2p networking stack.
  • Tentacle. A multiplexed p2p network framework that supports custom protocols
  • P2P NAT-Traversal. NAT Traversal techniques for p2p communication.
  • qp2p. Peer-to-peer communications library for Rust based on QUIC protocol.
  • sn_routing. Routing - specialised storage DHT.

Cryptography

Layer2

  • Arbitrum’s arb-os ArbOS is the “operating system” that runs an eth Layer 2 on an Arbitrum chain,
  • Noir language. Noir is a Domain Specific Language for SNARK proving systems. ( Aztec eth L2)
  • Penumbra. PoS network providing privacy to the Cosmos ecosystem.
  • Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage.
  • zkSync. Matter Labs’ scaling eth L2 engine secured by zero-knowledge proofs.

Dapps

  • Serum-dex. A decentralized exchange built on Solana.
  • SewUp. A library to help you build your Ethereum webassembly contract with Rust and just like develop in a common backend.

Other

  • abscissa. Micro-framework for CLI tools with strong focus on security.
  • tesseracts. A small block explorer for geth PoAs written in rust.
  • merk. High performance Merkle key/value store written in Rust, based on RocksDB.

参考资源

online-book

fragment

local