← Runnable Projects

阅读中文版本

Python Merkle Root CLI

Python Merkle Root — a runnable python project with source, install and run commands, and expected output.

intermediatepythonunverified

Project

py-merkle-root-cli

Entry point: merkle.py

Install

python merkle.py a b c d

Run

python merkle.py a b c d

Test

pytest merkle_test.py

Expected output

Computes the Merkle root of a list of leaf strings by pairwise hashing.

Dependencies

  • python >=3.10

Verification evidence

Source reviewed against python standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Python Merkle Root CLI is a self-contained python command-line program. Computes the Merkle root of a list of leaf strings by pairwise hashing.

Install and run

python merkle.py a b c d
python merkle.py a b c d

Project structure

py-merkle-root-cli/
├── merkle.py
└── README snippet above

Key source

# merkle.py
import hashlib, sys
def h(x): return hashlib.sha256(x.encode()).hexdigest()
layer = [h(x) for x in sys.argv[1:]]
while len(layer) > 1:
    if len(layer) % 2: layer.append(layer[-1])
    layer = [h(layer[i] + layer[i+1]) for i in range(0, len(layer), 2)]
print(layer[0])

Testing

pytest merkle_test.py

Expected output

When run with the documented command, the program prints:

5891b5b522d5df8e9a...   (sha256 merkle root)

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.