LLeafVellin
Workflows

Coding workflows · Tagged Merkle root construction

03
Built around your work

A concrete starting point

Build a SHA-256 Merkle root from one to 64 byte leaves of at most 4096 bytes using distinct leaf and parent tags. Test an odd level by duplicating its last node and reject empty input without treating the root as proof of ownership.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Tagged Merkle root construction

A concrete starting point
import hashlib

def merkle_root(leaves):
    if type(leaves) is not list or not 1 <= len(leaves) <= 64 or any(type(x) is not bytes or len(x) > 4096 for x in leaves):
        raise ValueError("merkle.leaves")
    level = [hashlib.sha256(b"\x00"+x).digest() for x in leaves]
    while len(level) > 1:
        if len(level) % 2:
            level.append(level[-1])
        level = [hashlib.sha256(b"\x01"+level[i]+level[i+1]).digest() for i in range(0, len(level), 2)]
    return level[0].hex()

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗