BlockSim is an open source blockchain simulator, capturing network, consensus and incentives layers of blockchain systems. BlockSim aims to provide simulation constructs that are intuitive, hide unnecessary detail and can be easily manipulated to be applied to a large set of blockchains design and deployment questions (related to performance, reliability, security or other properties of interest). At the core of BlockSim is a Base Model, which contains a number of functional blocks (e.g., blocks, transactions and nodes) common across blockchains, that can be extended and configured as suited for the system and study of interest. BlockSim is implemented in Python.
Before you can use BlockSim simulator, you need to have Python version 3 or above installed in your machine as well as have the following packages installed:
- pandas
pip install pandas
- numpy
pip install numpy
- sklearn
pip install sklearn
- xlsxwriter
pip install xlsxwriter
Before you run the simulator, you can access the configuration file InputsConfig.py to choose the model of interest (Base Model 0, Bitcoin Model 1 and Ethereum Model 2) and to set up the related parameters. The parameters include the number of nodes (and their fraction of hash power), the block interval time, the block propagation delays, the block and transaction sizes, the block rewards, the tranaction fees etc. Each model has a slightly different (or additional) parameters to capture it.
To run the simulator, one needs to trigger the main class Main.py either from the command line
python Main.py
or using any Python editor such as Spyder.
This project focuses on applying game theory to blockchain technology. The goal is to analyze and optimize the behavior and interactions of various participants within the blockchain ecosystem. By modeling actions of miners, validators, and other stakeholders as strategic games, we incentivize honest behavior and deter malicious activities. This ensures consensus, security, and efficiency in blockchain operations, particularly in Proof of Stake and Proof of Work systems. The DRPoP-GT consensus algorithm is evaluated using performance metrics across various scenarios and experimental parameters.
The Main.py file handles the initial filtering of nodes based on stakes. Eligible nodes are selected as delegated nodes, which then participate in a two-stage game:
- First-Stage Game
- Second-Stage Game
The results of the first-stage game are utilized in the second-stage game. After completing the two-stage game, an eligible node is selected as the miner and receives rewards. A penalty is imposed at each stage if a node behaves maliciously. Detailed comments are provided in the Main.py file.
DRPoP-GT operates within the Ethereum Blockchain. The code for setting transactions, blocks, and nodes can be found in the Models/Ethereum folder. The model is specified as model 2 in the InputsConfig.py file.
Simulation results are printed in an Excel file at the end of the simulation. The Excel sheets, generated from the Statistics.py file, include:
- Blockchain ledger
- Number of blocks mined
- Number of stale (uncle) blocks
- Rewards gained by each miner
Results are stored in the results folder, which contains three subfolders:
- Nodes: Shows the number of nodes used in the simulation.
- Simulation: Shows the varying simulation times used in the simulation.
- Transactions: Shows the number of transactions completed in the simulation.
All results are tabulated in Excel sheets, varying parameters across nodes, transactions, and simulation time.
The drpopgt_images folder contains images of the results, including:
- Computational overhead
- Number of malicious nodes
- Payoff matrix for both stage games
This folder has three subfolders:
- Load (varies from 10000 to 50000)
- Nodes (varies from 1000 to 5000)
- Simulation (varies from 60 minutes to 300 minutes)
The REU.ipynb file provides calculations regarding transaction time, block creation time, computational overhead, number of malicious nodes, and fairness. Import the Excel sheets from the results folder and run all cells to get the final output. Graphs are plotted using Matplotlib to analyze the DRPoP-GT consensus algorithm compared to existing algorithms.
- Run
Main.pyto perform the simulation. - Check the
resultsfolder for Excel files containing the simulation data. - Use the
REU.ipynbnotebook for further analysis and visualization.