[go: up one dir, main page]

Skip to content

arcturus3/selfish-mining

Repository files navigation

Selfish Mining Attacks on Blockchains, Visualized

Mining Backend

This repo provides code for directly simulating a selfish mining attack on a real, simplified blockchain. Blocks are actually mined using their hashes, and mining order is determined by the relative hash power of each miner. This code supports an unlimited number of honest and adversarial miners (given that their fractional hash power sums to 1).

  • To run the mining backend, first install the python libraries in mining/requirements.txt.
  • Next, run python mining/server.py

Endpoints

GET /start (Start Mining with defaults)
POST /start (Start Mining with Custom Params)
Body (As JSON)
name type data type description
honest_power required list[int] List of honest mining powers
adversarial_power required list[int] List of adversarial mining powers
^^ Must sum to 1
difficulty optional str Difficulty, EX: 0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Example:
{"honest_power":[0.2,0.1], "adversarial_power":[0.7], "difficulty":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"}
Responses
http code content-type response
200 text/plain;charset=UTF-8 Started!
400 application/json Hash power does not sum to 1
GET /stop (Stop Mining) GET /restart (Restart Mining - Call /start afterwards) GET /blockchain (Get String representation of the Blockchain) GET /chain-quality (Get chain quality as a decimal) GET /longest-chain (Get block hashes of the longest chain)

Visualization

Setup

  1. Install packages with npm install
  2. Start the development server with npm run dev

Usage

  • Set the mining difficulty (higher leads to longer mining time)
  • Add some number of miners, set their hash powers as fractions which sum to 1, and choose which should be adversarial
  • Start mining, and stop mining to change simulation parameters again
  • The gray block is the genesis block
  • White blocks are blocks mined by honest nodes
  • Red blocks are published blocks mined by adversarial nodes
  • Yellow blocks are unpublished blocks mined by adversarial nodes
  • Block numbers are effectively the miner address, referring to the nth honest or adversarial miner

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published