GithubHelp home page GithubHelp logo

divyanshusaxena / batcoin Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 94 KB

Custom cryptocurrency implementation using Python

License: MIT License

Python 100.00%
bitcoin cryptocurrency python multiprocessing bitcoin-mining

batcoin's Introduction

Batcoin

Custom cryptocurrency implementation using Python

Usage

Use the main.py file to spawn nodes, generate wallet key-pairs, share public keys, and initial transactions.

>>> python main.py <num-nodes> <block-size> <timeout-in-seconds> <num-miners> <num-dishonest-nodes>

Sample Usage:

>>> python main.py 4 4 10 2 1

Dishonest Nodes

The number of dishonest nodes can be set using Command Line Interface. The dishonest nodes, collude to agree upon the history mined by a single master. By default, node 0 is labelled as the Dishonest Master Node. Only one node among all miners can be set as dishonest, in the current implementation. There can be as many dishonest, non-miner nodes however.

Debugging

The project utilizes function print_level() for printing at three different logging levels: basic/info/debug.

Nodes

The nodes of the blockchain are simulated using the Python Multiprocessing module.

Network Messages

The Batcoin nodes communicate with each other using network messages which carry the necessary information. These communications work in a broadcast format currently, for the sake of simplicity. The format of these Network messages is as follows:

{
  "sender": "sender_node",
  "message": "TRANSACTION/BLOCK",
  "pl": "payload"
}

Transactions

The transactions for Batcoin are stored as JSON objects. Transactions also hold the cryptographic digests The format is as follows:

{
  "tx": {
    "type" : "INIT/TRANSFER/MINE",
    "amount" : "amount",
    "receiver" : "receiver_key",
    "sender" : "sender_id",
    "timestamp" : "timestamp"
  },
  "signature" : "signature of the remaining json object"
}

Confirmation of transactions

Any newly generated transaction is added to the unconfirmed pool of transactions at each of the nodes. Any subsequent transactions which might be invalid because of this transaction are then dropped. A transaction gets confirmed once it gets added to the blockchain, in the form of a block.

Validating transactions

Each transaction sends a certain amount from one wallet to another. Each node, independently keeps a list of wallets and their balances, and verifies the transaction based on that list.

Blocks

The blocks for Batcoin follow the following message format:

{
  "blk": {
    "prev_hash" : "prev_hash",
    "nonce" : "nonce",
    "merkle_root" : "merkle_root",
    "arity" : "arity",
    "transactions" : [
      // Transactions
    ],
  },
  "signature": "signature",
}

Initialization

At the initialization of the blockchain protocol, each node generates a genesis block. Since the contents of the genesis block are same, irrespective of the node, genesis blocks with the exact same hashes are generated in all of the nodes.

Further, each node gets to generate a transaction providing itself initial_amount of coins at the start for doing transactions.

Consensus

The blockchain maintains consensus based on a longest chain rule protocol. Whether a consensus has been reached or not, can be checked using the following command

>>> python find_forking.py <num-nodes>

Todo

  • Proof of work implementation for Nodes
  • Create and broadcast blocks over network
  • Validation of blocks
  • Implementation of UTXO transactions needed for validating transactions
  • Dishonest nodes
  • Smart Contracts
  • Experiments

batcoin's People

Contributors

divyanshusaxena avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

budthespud

batcoin's Issues

Authentication Public Key Decoding

The public keys are currently stored as strings for all nodes. However, while verification the RSA._RSAobj is needed.

Need to import the string as PEM encryption.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.