Very basic blockchain-free cryptocurrency PoC in Python
crackcoin
Crackcoin is a very basic blockchain-free cryptocurrency PoC in Python. It's a project for discovering cryptocurrencies.
Note that this is a PoC that runs only on local networks and does not provide proper security. The code should only be used to get familiar with the building blocks for a cryptocurrency. Also, crackcoin should not be confused with the (dead) currency CrackCoin (CRACK) from 2014.
This project was created as an exercise after reading "Mastering Bitcoin: unlocking digital cryptocurrencies".
Material covered
Transaction-based mining as a PoC for a blockchain-free cryptocurrency
Threading in Python
Working with sockets in Python (UDP)
ECC crypto / ECC public key compression/decompression
Base58 encoding like bitcoin
Having the whole thing work (wallet, crypto, validation, networking, mining, etc)
Blockchain-free cryptocurrencies
Most cryptocurrencies use a blockchain to validate transactions among other things. After years of running these networks it's beginning to look like blockchain-based currencies naturally evolve into a centralised network, because it's in the best interest of the participants to combine computing power to calculate solutions for blocks.
An interesting framework for a blockchain-free protocol is discussed in the paper "Blockchain-Free Cryptocurrencies: A Framework for Truly Decentralised Fast Transactions", which can be found here:
Do note that crackcoin doesn't implement nearly as complex a protocol as described in the paper. But the transaction-based mining method was used as an inspiration for implementing the 'core' for crackcoin.
Usage
Running it normally
First run python crackcoin.py
Then type h to see options and communicate with other crackcoin-nodes on the network
Generating and working with your own genesis transaction
Run python generateGenesis.py until a cool address pops up
Edit crackcoinBase.sql: replace the address for the transaction with transactionHash d34db33f in transactions_outputs with your generated address
Run crackcoin and wait until a confirmation is generated for d34db33f with a higher difficulty (>6) than the one in crackcoinBase.sql
Replace the confirmation for d34db33f
Share code on other nodes
Manually replace your wallet keys and address with the address and keys generated by generateGenesis.py. This will allow you to 'spend' the genesis cash.
Component basics
Wallets
A wallet consists of a public/private keypair and an address. The address is derived from the public key.
Transactions
A transaction contains inputs, outputs and a unique identifier (called 'hash').
An output has a unique identifier and is just an amount and a 'to'-address.
An input points to a previous output, and uses the coins from that output. It must contain a compressed public key and a signature. This way nodes can identify that the 'to'-address from the previous output, which can be generated with the public key, is owned by the spender.
The GUI
When you create a transaction, a confirmation is created and both the transaction and the confirmation are shared on the network (UDP broadcast).
When using the broadcast option b, your crackcoin node will broadcast a request packet on the network. Any crackcoin node receiving the request will send all transactions and confirmations to you. This is so new nodes can 'sync'.
Network server (UDP)
When the server receives a new transaction, it checks if the transaction is valid and adds it to the database ('ledger').
When a confirmation is received, the transaction's confirmation is updated if the received difficulty is higher than the existing difficulty.
Mining and confirmations
Confirmations are proof of work hashes for a transaction.
The mining component simply creates confirmations for some transaction.
Mining is done by hardening the transaction confirmation with the least difficulty.