TCP/IP for Blockchain? Cosmos technical analysis

Introduction to Cosmos
From the perspective of the traditional Internet, it is precisely because of the relay of the IP protocol that the familiar HTTP, P2P, IEEE, WiFi and other protocols are connected to each other, so that we can log in to the web version of WeChat on the HTTP protocol and use P2P The protocol transfers files through the web version of WeChat and other application scenarios. The cross-chain technology represented by Cosmos and Polkadot is building the IP protocol in the blockchain field, so some people regard the cross-chain technology as the blockchain 3.0 era.

Cosmic principles

The four public chains on the leftmost and rightmost in the figure must create a new channel between each other if there is no Hub, but if there is a Hub, they only need to be connected to the Hub. Realize cross-chain transfer.
The Hub itself is also a public chain, developed using the Cosmos SDK, and has a tendermint structure; the public chain connected to the Hub and the proxy chain of the public chain are called "Zones", and all Zones need to implement the IBC communication standard.
Cosmos SDK Architecture

baseapp: defines a template for a basic ABCI application, communicating with Tendermint. Developers can also rewrite according to their own needs.
Applications: including gaia, basecoin, democoin. Among them, gaia is the main program of the hub, and basecoin and democoin are two sample applications provided.
plugins: the basic unit of cosmos-sdk, each plugin is a function extension of baseapp, including its own message and transaction processing logic.
Currently the SDK has integrated some important plugins:
staking: POS-related implementations, including: binding, unbinding, inflation, fees and other operations.
ibc: The implementation of the cross-chain protocol IBC, and also the main plug-in for Cosmos to support cross-chain.
governance : Governance-related implementations, such as proposals, voting, etc.
auth : defines a standard multi-asset account structure (BaseAccount), and developers can directly embed it into their own account system.
bank : Defines the transfer of assets.
Principle of PegZone
The blockchain developed based on Cosmos-sdk can easily satisfy real-time finality. However, the existing blockchains using POW consensus such as Bitcoin and Ethereum do not have this feature. They can only belong to probabilistic finality and cannot prevent blockchain rollback. For this type of chain, the team uses the PegZone solution to solve it.

From the figure above, we can see that PegZone can be divided into 5 parts:
Smart Contract: The role of asset custody, custody of tokens in Ethereum and tokens in Cosmos. It mainly provides four methods of lock, unlock, mint and burn.
Witness: It is an Ethereum full node, which listens to the events of the Ethereum contract, and waits for 100 blocks to be generated, then encapsulates WitnessTx and submits it to PegZone to prove the state change in Ethereum.
PegZone: PegZone is a Tendermint-based blockchain responsible for maintaining user account information, allowing asset transfers between users, and providing transaction queries.
Signer: Use secp256k1 to sign the transaction so that the signature can be efficiently verified by the smart contract, corresponding to the public key set of the verifier of the smart contract.
Relayer: The relayer is responsible for transaction forwarding. Forward the SignTx signed by all Signers to the smart contract.
Transfer process from Ethernet to Cosmos

The contract receives a lock transaction with an ERC20 token and a destination address on the Cosmos side. It locks the received funds in the consensus of the peg area, recording the event notifying the forwarder.
The repeater connects to the Ethereum full node through RPC and listens to the Lock event.
Once a node receives the smart contract's deposit, it waits 100 blocks (the final threshold) before generating and signing a SignWitnessMsg proof of an event that the cosmic peg block is listening to.
The peg region receives witness transactions until a supermajority of voting power witnesses the event. Each BeginBlock calls the peg area to check whether any incoming Ethereum transfers have reached more than a majority of confirmations.
Nodes then use internal transactions to update the state to reflect that someone wants to send tokens from Ethereum and generate an IBCWitness to convert the tokens to the specified target chain.
The contract operation process is as follows

Cosmos to Ethernet transmission process

The ABCI application receives IBCRelay's request to burn Ethereum tokens and processes it according to the IBC specification. The ABCI application generates a valid Ethereum transaction containing {address, token address, amount, cash} and writes it to its state.
Each signature application is monitoring the ABCI state for new transactions and detects new transactions.
Each signing application uses secp256k1 to sign transactions using keys known to Ethereum smart contracts.
Each signing application submits its relay back to the ABCI application as a SignRelayMsg for replication.
A relay process that periodically queries ABCI application transactions sees that transactions have reached the required relay threshold.
One of the relayers sends the transaction to the smart contract by calling the unlock function
The smart contract uses ecrecover to check that it is signed by the super-majority validator set corresponding to the transaction height (this may have been updated). The smart contract releases the token specified in the transaction, making it available to the destination address.
Standard Consensus Analysis
Cosmos currently has a series of full ecological environments such as Cosmos Hub module, cross-chain PegZone module, IBC module governance related modules, etc. From the perspective of vision, Cosmos hopes to build a blockchain Internet. Therefore, it is necessary to solve the problem of cross-chain. At present, it is unknown that there is no mature solution for cross-chain. This goal is still very ambitious, but it is difficult to achieve. There is no consensus layer in the analogy of the Internet network. As long as the transmission problem is solved, the basics can be completed. Communication, but the blockchain is different. Its characteristic is that it has a different consensus model. This is its vitality and the direction of its progress.


