- Subject - Introduction to Blockchains, Cryptocurrencies and Smart Contracts (CS 765)
- Semester - Autumn 2021
- Project
- Build a discrete-event Simulator for a P2P Cryptocurrency Network
- Simulating a selfish mining attack using the P2P Cryptocurrency Network developed in assignment 1
- Team Members
- 203050054 - Fenil Mehta
- 203059006 - Aditya Pradhan
- 20305R005 - Arnab Das
- Implementation/Solution
- Assignment 1
- Assigment 2
Node == Peer == Miner
all three mean the sametxn == transaction
Unit of time = seconds
for everythingmd5
hash function is used for speed - Can be updated to use any other hash functionGenesisBlock.prev_node_hash = -1
if
a block withblock_index < node.curr_block_index_max
is received, then it is not dropped because:- The received block can become ancestor of a block which forms a longer chain in future
- The block creator would not spend their time and computation power in creating and sending a block which does not create a longest chain
Transactions
created are always assumed to be authentic in this simulation- In the real world, they are signed by the transaction creators (i.e. money senders)
mining reward
is always the first transaction of any block, and sender is-1
onlySender == -1
means money is created from thin air- If mining reward transaction is placed at any position other than index 0, then it is invalid
- If id_sender for mining reward transaction is anything other than
-1
, then it is invalid
mining_reward_update_percent
is used as follows:new_reward = old_reward (1 + mining_reward_update_percent / 100)
- The above statement will be executed every
mining_reward_update_block_time
blocks- i.e. when
longest_chain.index % mining_reward_update_block_time == 0
- i.e. when
- The above statement will be executed every
- Empty blocks are valid
- Sometimes bitcoin and ethereum have empty blocks
- Any valid transaction created should enter the blockchain even if forks happen
- We find the common ansestor between the tails of the fork with the help of
block index
- We find the common ansestor between the tails of the fork with the help of
Simple Cache
is implemented to optimize block validation and creation- It is assumed that no one will create time pass transactions where sender and receiver are the same
- Clarifications specific to Assignment 2
- The attacker is a single node
- In case of more than one attacker nodes, they all will perform attack individually. They do NOT coordinate with each other and are unaware of the existence of other attackers
- Each attacker assumes that all other people are honest (this assumption is not used by the attacker in any part of the attacking logic)
- The attacker does not forward blocks generated/mined by other nodes
cd src1
python simulator.py --config config.json --debug
cd src2
python simulator.py --config config.json --debug
- Bitcoin and cryptocurrency mining explained
- Proof-of-Stake (vs proof-of-work)
- But how does bitcoin actually work?
- Graphviz Visualization
- Exponential Distribution
- Python specific features
- KiloByte (kB) vs. KibiByte (KiB)