Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Einreichen
ToolsExploitsBlog
Einreichen

Hacking-, PenTest- und Cybersicherheits-Tools für Ihr Sicherheitsarsenal!

Kitploit ist ein Verzeichnis von Hacking-, Cybersicherheits- und Pentesting-Tools. Entdecken Sie die neuesten Projekt-Updates, um Schwachstellen zu finden, Systeme zu analysieren, Tests zu automatisieren und Ihre Sicherheit zu stärken.

FeedsKontaktDatenschutz© 2026 Kitploit

Tool-Verzeichnis

Kategorien

Alle Kategorien anzeigen
Loading categories
merkle-lab — 针对比特币 Merkle 根算法(含 CVE-2012-2459 变异检测机制)设计并实施自动化测试方案,覆盖功能正确性、边界场景与安全回归。 | Kitploit
Tools/GitHubGitHub/gj504b123/merkle-lab
静态分析漏洞分析密码学论文与研究学习与教育
GitHubgj504b123/merkle-lab

merkle-lab

针对比特币 Merkle 根算法(含 CVE-2012-2459 变异检测机制)设计并实施自动化测试方案,覆盖功能正确性、边界场景与安全回归。

Repository anzeigen
10. Nov. 2026Noch nicht geprüft
Teilen
Inhalt in der angeforderten Sprache nicht verfügbar. Englische Version wird angezeigt.

Automated Testing of the Merkle Root Algorithm

A Merkle root algorithm testing project based on Python + pytest, with tests designed around functional correctness, boundary scenarios, differential testing, real block test vectors, and security regression. After expanding parametrize, there are currently 72 pytest test items in total.

The project also includes an algorithm-level regression for the duplicate-transaction scenario related to CVE-2012-2459: it constructs inputs whose transaction lists differ but whose Merkle roots are identical, and verifies that the mutated detection flag behaves as expected.

1. Test Target

The code under test is located in merkle.py and mainly includes:

  • dsha256(data): applies SHA-256 twice in succession to the input bytes and returns a 32-byte result.
  • compute_merkle_root(tx_hashes): iteratively computes the Merkle root and detects adjacent duplicate hashes at paired positions.
    • Returns (root, mutated).
    • Empty input returns 32 zero bytes, mutated=False.
    • For an odd number of nodes, the last node is duplicated before pairing.
    • mutated detection occurs before odd-node padding.

The current implementation computes the result by copying the input list and generating a new hash list layer by layer, with an extra space complexity of O(n); it is not an in-place constant-space implementation.

2. Test Design

Test CategoryCountDesign MethodMain Coverage
Hand-crafted known answers3Known-answer testing, error guessingTwo leaves, three leaves with odd padding, adjacent duplicate leaves and mutated detection
Differential testing64Independent reference implementation, fixed-seed random dataTransaction sizes from 1 to 64, cross-checked group by group against a recursive reference implementation
Real block test vector1Real-data regressionTransaction list and Merkle root of Bitcoin block at height 170
Boundary testing2Boundary value analysisEmpty input, single-leaf input
CVE security regression2Control inputs, error guessingTwo constructions with 5/6 and 6/8 transactions, verifying identical roots and opposite mutated
Total72

The counts here are the number of test items after pytest parameterization expansion, not the number of test functions.

2.1 Differential Testing

test_merkle.py implements a recursive reference algorithm reference_root() that does not use mutated detection, serving as an independent reference:

  1. Use random.Random(2024 + n) to set a fixed random seed.
  2. For each n ∈ [1, 64], generate n random 32-byte transaction hashes.
  3. Call the iterative implementation under test and the recursive reference implementation respectively.
  4. Compare whether the two sets of Merkle roots are identical.

The fixed seed makes failing inputs reproducible, which helps with locating problems and adding regression cases.

2.2 Real Block Data and Offline Regression

fetch_block_data.py obtains real block data through the public Blockstream API:

  1. Obtain the block hash based on the block height.
  2. Obtain the list of transaction IDs in the block.
  3. Obtain the Merkle root from the block header.
  4. Save the above information as a local JSON test vector.

The currently saved data/block_170.json corresponds to the block at height 170 and contains 2 transaction IDs and the expected Merkle root. Daily pytest runs only read this local file and require no network access; only when re-collecting data is it necessary to connect to the network and install requests.

The tests also handle the difference between Bitcoin RPC display byte order and internal computation byte order: after reading the transaction IDs, they are reversed to internal byte order, and after computation the Merkle root is reversed back to display byte order for comparison.

2.3 CVE-2012-2459 Related Regression

The project includes two sets of algorithm-level control tests:

  • Honest input with 5 transactions, control input with 6 transactions.
  • Honest input with 6 transactions, control input with 8 transactions.

Both sets of tests verify:

  • The control input, by duplicating the last transaction, yields a Merkle root byte-for-byte identical to that of the honest input.
  • The honest input's mutated=False, and the constructed input's mutated=True.

Verification boundary: This project verifies the duplicate-transaction construction and the mutated detection logic in the Python implementation. It does not start bitcoind, nor does it verify that real nodes reject blocks or network consensus behavior; it should not be described as a complete reproduction of the consensus vulnerability in a real network.

3. Project Structure

merkle_lab/
├─ merkle.py             # 双 SHA-256、Merkle 根及 mutated 检测
├─ test_merkle.py        # pytest 测试与递归参考实现
├─ fetch_block_data.py   # 可选:重新采集真实区块数据
├─ data/
│  └─ block_170.json     # 本地真实区块测试向量
└─ README.md

4. Environment Setup

Python 3.9 or later is recommended (random data generation uses random.Random.randbytes).

Create and activate a virtual environment in the project root directory:

python -m venv .venv

Windows:

.venv\Scripts\activate
python -m pip install pytest

macOS / Linux:

source .venv/bin/activate
python -m pip install pytest

requests is only needed when re-collecting block data:

python -m pip install requests

5. Running the Tests

Please execute this in the project root directory to ensure the tests can read data/block_170.json:

python -m pytest -q

On Windows, you can also skip activating the virtual environment and run directly:

.venv\Scripts\python.exe -m pytest -q

If you only want to view the test collection results:

python -m pytest --collect-only -q

The actual number of passing tests and execution time are subject to the results of a complete run on your local machine; this project's documentation does not pre-fill unverified pass rates or execution times.

6. Optional: Re-collecting block data

After installing requests, run the following in the project root directory:

python fetch_block_data.py

This command accesses the Blockstream public API and overrides data/block_170.json. Running this script is not required for normal test execution.

7. Reproducibility Notes

  • The randomized differential tests use fixed seeds, so the same inputs can be generated repeatedly.
  • Real block data is saved as local JSON to prevent fluctuations in external services from affecting routine regression runs.
  • Each test category is located in test_merkle.py, so you can quickly locate the corresponding scenario by combining it with the test name.
  • The test scope focuses primarily on algorithms and input construction; it does not replace Bitcoin Core's full node, block validation, or network consensus testing.
Tool herunterladen

Ähnliche Tools

  • ghidra

    Ghidra ist ein Software-Reverse-Engineering (SRE)-Framework.

  • capa

    Regelbasiertes statisches und dynamisches Analyse-Tool, das Fähigkeiten in PE-, ELF-, .NET- und Shellcode-Dateien identifiziert und sie MITRE ATT&CK-Techniken zur Malware-Triage zuordnet.

  • yara-x

    Eine Neuimplementierung von YARA in Rust.

Beliebteste

Alle anzeigen →

Entdecken Sie die meistgenutzten Tools unserer Community.

  • 1

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    745
  • 2

    IMSIcatcher

    28zaaky/imsicatcher

    IMSI-Catcher-Plattform, die eine gefälschte GSM-Zelle bereitstellt, um SMS abzufangen, Nachrichten einzuschleusen und Mobilgeräte zu verfolgen

    732
  • 3

    Callisto

    jetp1ane/callisto

    Automatisiertes Binär-Schwachstellenanalyse-Tool, das ausführbare Dateien über Ghidra dekompiliert, Pseudo-C-Code mit Semgrep scannt und Ergebnisse mithilfe von GPT-3.5-Turbo validiert, um Fehlalarme zu reduzieren.

    610
  • 4

    opencti

    opencti-platform/opencti

    Offene Plattform für Cyber-Bedrohungsinformationen

    546
  • 5

    ARTEX

    baarai/artex

    LLM-basierte Multi-Agenten-Plattform für autonome Penetrationstests mit Planer-/Worker-Agenten, Asset- und Explorationsgraphen, MITM-Verkehrsaufzeichnung und Schwachstellen-Retesting.

    414
  • 6

    DFRoot

    a2333c/dfroot

    Android-Root-Tool für das Samsung Galaxy S25 Ultra (SM-S938B), das DirtyFrag CVE-2026-43284 und CVE-2026-43499 verkettet, um beim Booten automatisch über KernelSU Root zu erlangen.

    413

Alle Tools erkunden

Durchsuchen Sie unsere Tool-Sammlung

Alle Tools anzeigen →