This Python script implements a permutation test to detect selfish mining behavior in blockchain networks. It analyzes sequences of consecutive mining by the most powerful miner to determine if they are statistically significant, which could indicate selfish mining practices.
- Data Loading: Reads mining data from numpy array files
- Monthly Analysis: Splits data into monthly segments for detailed analysis
- Statistical Testing: Implements permutation testing to detect unusual mining patterns
- Visualization: Plots computational power distribution over time
- P-value Analysis: Calculates statistical significance of mining sequences
-
Clone the Repository:
git clone https://github.com/IgorAugust0/tesi.git cd lab/selfish-mining
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Script:
python selfmin.py
or
python paste.txt
The script can be run directly with default parameters:
python selfmin.py
from selfmin import load_data, split_into_months, get_most_powerful_miner
# Load your data
data = load_data("your_data.npy")
# Split into months
monthly_data = split_into_months(data)
# Analyze specific month (e.g., November)
november = monthly_data[10] # 0-indexed
# Find most powerful miner
mp = get_most_powerful_miner(november)
-
Data Processing:
- Loads blockchain mining data from a numpy array
- Splits data into monthly segments
- Identifies the most powerful miner
-
Statistical Analysis:
- Generates random permutations of the mining sequence
- Counts consecutive mining sequences
- Calculates p-value through permutation testing
-
Result Interpretation:
- If p-value < 0.05: Likely selfish mining
- If p-value ≥ 0.05: No evidence of selfish mining
- Python 3.6+
- numpy
- matplotlib
- scipy
See requirements.txt
for specific versions.
The script provides both visual and textual output:
- Graph showing computational power distribution
- P-value calculation
- Conclusion about potential selfish mining behavior
This project is licensed under the MIT License. See the LICENSE file for details.