/BlockChain

A Qt-based blockchain iOS App using asynchronous libevent & OpenSSL

Primary LanguageMakefile

BlockChain

This program is a Qt-based iOS App implementing blockchain fundamental features using libevent and OpenSSL.

  1. Decentralized distributed database.

  2. Network of nodes, real-time validation and incorruptible chain.

  3. Cross-platform framework with iOS/Android Apps and desktop application.

  4. Includes following features: "Publish Public Key", "Publish Address", "Sign Network Protocol", and "Validate New Block."

Overview

alt text

  1. Block name input: Input a new block name (space is NOT allowed)

  2. Block validation status

    "Validating...": The new block is under validating by other nodes

    "+1": The new block is already validated OK by 1 node

    "OK!" : The new block is already validated OK by N nodes (In this version, N = 2)

  3. Local address: Identity of this device

  4. Blockchain list: Show current blockchain list, from latest to oldest

  5. Debugging status: Show some network protocols and useful messages

Functionality

[Publish Public Key]

Once the program is launched, public/private key pairs will be generated by ECC (Elliptic-curve cryptography) secp521r1 algorithm.

Then, REMOTE_COMMAND_REPLY_PUBKEY and GET_PUBKEY will be broadcast by following format:

    REMOTE_COMMAND_REPLY_PUBKEY NodeAddress PublicKeyPlainFormat    
    GET_PUBKEY

When other nodes received neighbor's public key, this public key will be stored in a hash table with (key, value) = (NodeAddress, PublicKey).

When other nodes received "GET_PUBKEY", its public key will be sent back by:

    REMOTE_COMMAND_REPLY_PUBKEY NodeAddress PublicKeyPlainFormat

[Publish Address]

After public key is generated, address is then generated by RIPEMD160(SHA256(PublicKeyPlainFormat)).

The address will be used inside network protocol.

[Sign Network Protocol]

Here is network protocol:

    [BLOCKCHAIN_HEADER][ADDRESS][MessageLen][Message][Signature]
        BLOCKCHAIN_HEADER(strlen(BLOCKCHAIN_HEADER)): "__ThisIsBlockChainPacketByClarkYang__", to avoid conflicting to other network packets
        Address(40): Identify the user of this protocol
        MessageLen(4): (0000 ~ FFFF) Indicate message length
        Message(MessageLen): Transferred message
        Signature(-) : Message signature

On sender node, message signature will be generated by the private key before sending.

On receiver node, signature will be verified by the public key of sender (should already stored in hash table).

Only the verified message will be executed; otherwise it'll be dropped.

[Validate New Block]

Once user wants to new a block, following procedures would be executed:

1. ASK_VERIFY would be broadcast for this new block by following format:

   ASK_VERIFY NewBlockInfo

2. When other nodes received above command, this block will be validated along with their local blockchains.
   If validation pass, COMFIRM_VERIFY will be sent back:

   COMFIRM_VERIFY NewBlockHash

3. When adder got N validation (In this version, N = 2), the new block can be added to its local blockchain.
   Then, following message will be broadcast:
   
   NEW NewBlockInfo
    
4. When other nodes received above command, the new block can be added to their local blockchains.