The Blockchain Compression Project is designed to optimize blockchain data storage and management by incorporating a series of advanced techniques. The project focuses on reducing the storage overhead of full blockchain nodes, while maintaining data integrity, scalability, and security. It leverages block compression, state delta management, Merkle trees, and zero-knowledge proofs (ZK-SNARKs) to efficiently manage blockchain data without compromising the reliability of the system.
- Block Compression: Compresses blockchain block data using the LZMA algorithm to minimize storage requirements.
- State Delta Management: Efficiently stores only the changes (deltas) in blockchain states, instead of complete snapshots, reducing unnecessary data storage.
- Merkle Tree Construction: Provides cryptographic assurance for data integrity by hashing transactions into a Merkle tree structure, enabling efficient verification.
- Blockchain Pruning: Limits the number of stored blocks, removing old, unnecessary blocks, while retaining only the most recent blocks for operational efficiency.
- Zero-Knowledge Proofs (ZK-SNARKs): A conceptual framework for privacy-preserving data verification without revealing underlying data, enabling the blockchain to verify transactions without exposing sensitive information.
-
Python: Version 3.10 or higher (uv installs it for you if missing)
-
uv: the project is managed entirely with uv — install it with
curl -LsSf https://astral.sh/uv/install.sh | sh(on Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex") -
Required Libraries: The project itself relies only on Python's standard library. Development tools are declared in PEP 735
dependency-groups:Group Contents Purpose testpytest,pytest-covTest suite and coverage lintruffLinting and import sorting devtest+lintDefault local environment
-
Clone the repository:
git clone https://github.com/arec1b0/blockchain_compression_project.git
-
Navigate to the project directory:
cd blockchain_compression_project -
Create the virtual environment and install the project with its
devgroup (devis the default group, so no flag is needed):uv sync
To install only what a single task needs:
uv sync --only-group test # just pytest + pytest-cov uv sync --no-default-groups # runtime only, no dev tooling
-
To run the project using the command-line interface (CLI):
uv run blockchain-compress
-
To run the compression benchmark (compression ratio and throughput across datasets and LZMA presets):
uv run blockchain-compress-bench
Once installed, you can run the project to simulate blockchain compression and management. The following components are demonstrated in the system:
- Block Compression: Compresses and decompresses blockchain block data to reduce storage overhead.
- State Delta: Applies transactions and tracks state changes efficiently.
- Merkle Tree: Builds a Merkle tree from a list of transactions, allowing for efficient cryptographic verification of transaction data.
- Blockchain Pruning: Removes outdated blocks, retaining only the most recent ones.
- ZK-SNARKs: Demonstrates proof generation and verification using zero-knowledge proof concepts.
To run the system, execute the demo module (or the blockchain-compress console script):
uv run python -m blockchain_compression.mainAfter running the program, you should see outputs demonstrating various components:
=== Blockchain Data Compression and Management ===
--- Block Compression ---
Original block data: b'Sample blockchain block data' (28 bytes)
Compressed size: 84 bytes
Decompressed block data: b'Sample blockchain block data'
--- State Delta Storage ---
Transaction tx-001 already applied; ignoring replay.
Current state: {'Alice': 100, 'Bob': 50}
--- Merkle Tree Verification ---
Merkle Tree root hash: dc53b6c71a68a3277479b5a1ea820eb52bbae145ef8fb4e97a414b2b6c670f7f
Inclusion proof for 'tx3': [{'hash': '590b66ca...', 'position': 'right'}, {'hash': '60e1f5f6...', 'position': 'left'}]
Proof verifies: True
--- Blockchain Pruning ---
Pruned 1 old block(s); keeping the last 2.
Blocks after pruning: [{'block_number': 2, 'data': 'Block 2 data'}, {'block_number': 3, 'data': 'Block 3 data'}]
--- ZK-SNARK Proof Generation and Verification (mock) ---
Generated proof: {'proof': 'zk-snark-proof-placeholder', 'data_hash': 'd9e9b468...'}
Proof verification result: True
If you want to contribute to the project or run tests, follow the steps below.
We use pytest for testing. To run all tests, use the following command:
uv run pytestWith coverage:
uv run pytest --cov=srcLinting is handled by ruff (lint group):
uv run ruff check .The tests ensure that each module functions correctly, covering block compression, state delta application, Merkle tree integrity, blockchain pruning, and ZK-SNARK proof verification.
We welcome contributions to the project. Please follow these steps:
- Fork the repository.
- Create a new feature branch.
- Make changes and ensure all tests pass.
- Submit a pull request with a clear description of your changes.
For more detailed guidelines, see our CONTRIBUTING.md file.
This project is licensed under the MIT License - see the LICENSE file for details.
Special thanks to the open-source community and Python developers who provided tools, libraries, and insights to support the development of this project.