Skip to content

refactor(crypto): use itertools.batched in merkleize pair-walk#966

Merged
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit/arch-26-batched-merkleize-pairwalk
Jun 12, 2026
Merged

refactor(crypto): use itertools.batched in merkleize pair-walk#966
tcoratger merged 1 commit into
leanEthereum:mainfrom
tcoratger:audit/arch-26-batched-merkleize-pairwalk

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Summary

The merkleize pair-walk in src/lean_spec/spec/crypto/merkleization.py stepped a manual index over each tree level to pull left and right siblings. This replaces that hand-rolled loop with itertools.batched(level, 2), the idiom already used across the xmss crypto modules (merkle.py, prf.py, poseidon.py).

An odd tail surfaces as a length-one tuple, exactly where the previous else branch fired. The missing right sibling is still filled with the all-zero subtree root, so the zero-padding behavior is unchanged.

Behavior

Behavior-preserving. No new tests; all 105 existing tests in tests/spec/crypto/test_merkleization.py pass.

Checks

just check passes (ruff, ruff format, ty, codespell, mdformat).

🤖 Generated with Claude Code

Replace the manual index-stepping pair iteration with itertools.batched,
the established idiom across the xmss crypto modules.

An odd tail surfaces as a length-one tuple, where the missing right
sibling is filled with the all-zero subtree root, preserving the exact
zero-padding behavior of the previous code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger tcoratger merged commit 6bed874 into leanEthereum:main Jun 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant