Skip to main content

A high-fidelity blockchain discrete event simulator for research and education

Project description

BlockSimPy

PyPI version Python License

A discrete event simulator for blockchain networks supporting Proof-of-Work and Proof-of-Stake consensus mechanisms. Models mining competition, validator selection, block propagation, difficulty adjustment, and economic incentives. Includes attack simulations (selfish mining, 51% attacks, eclipse attacks) for security research and education. Enables controlled experimentation with blockchain protocols without operating live cryptocurrency nodes.

Supported chains: Bitcoin, Bitcoin Cash, Litecoin, Dogecoin, Ethereum 2.0

Features:

  • PoW consensus with exponential mining time distribution
  • PoS consensus with stake-weighted validator selection
  • Network propagation with configurable topology and peer connections
  • Difficulty adjustment algorithms and reward halving schedules
  • Attack simulations: selfish mining, 51% double-spend, eclipse attacks
  • Metrics export, checkpoint/resume, and reproducible simulations

Installation

pip install blocksimpy

Quick Start

Simulate Bitcoin for 100 blocks:

blocksimpy --chain btc --blocks 100

Simulate Ethereum 2.0 Proof-of-Stake:

blocksimpy --chain eth2 --blocks 100

Create custom blockchain with specific parameters:

blocksimpy --blocktime 30 --blocks 50 --miners 5

Short alias available:

bsim --chain btc --blocks 100

Attack Simulations

Selfish mining attack where adversary withholds blocks to gain unfair mining rewards:

blocksimpy --chain btc --blocks 100 --attack selfish --attacker-hashrate 0.3

51% double-spend attack where majority hashrate reverses confirmed transactions:

blocksimpy --chain btc --blocks 100 --attack double-spend --attacker-hashrate 0.51

Eclipse attack isolating victim nodes from the honest network:

blocksimpy --chain btc --blocks 100 --attack eclipse --victim-nodes 2

Testing

Run validation tests that verify simulator accuracy against known blockchain metrics:

python tests/test_validation.py

Documentation

Architecture

Configuration guide

License

Apache License 2.0 - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blocksimpy-1.4.0.tar.gz (46.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blocksimpy-1.4.0-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file blocksimpy-1.4.0.tar.gz.

File metadata

  • Download URL: blocksimpy-1.4.0.tar.gz
  • Upload date:
  • Size: 46.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for blocksimpy-1.4.0.tar.gz
Algorithm Hash digest
SHA256 cfa4354f8175b89bd2f2ca0a29a550f54d43d7dc1a9bec00f4e4eb98cc7c6cb6
MD5 1e871315f1a9b8aa5ddc6d08b190172b
BLAKE2b-256 92ba902ca11b6a296bbbcb1d9f88153298d2468e74c05af93f9f561d7d9c7fd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for blocksimpy-1.4.0.tar.gz:

Publisher: ci.yml on btursunbayev/blocksimpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blocksimpy-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: blocksimpy-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for blocksimpy-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f5d5f0e662f1c8ce2f56a1a7ede7fa37576a7be0414e2bc81e08b16fb611454
MD5 50e6112b7a0f897fcb9fe4aa774854d6
BLAKE2b-256 b5dc824c018ba36b7cd1e4dd655b2893d85307490b3df3785049313deef55920

See more details on using hashes here.

Provenance

The following attestation bundles were made for blocksimpy-1.4.0-py3-none-any.whl:

Publisher: ci.yml on btursunbayev/blocksimpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page