Skip to content

Commit 78161d4

Browse files
tcoratgerclaude
andauthored
refactor: replace abbreviated/vague locals with descriptive names (leanEthereum#837)
* refactor: replace abbreviated/vague locals with descriptive names Rename `acc` accumulators in the XMSS base-P decomposition helpers to names that say what they hold: `remaining_value` in field.py, `message_integer`/`encoded_tweak` in encoding.py, and `packed_lengths`/`packed_tweak` in poseidon.py. In `aborting_decode`, expand the banned `fe`/`a`/`d` to `field_element`/`element_value`/`quotient`. Also rename `description_count` to `descendant_count` in head_sync.py since it counts processed descendant blocks, not descriptions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: default pull requests to the upstream main repository Add a CLAUDE.md rule so PRs are opened against leanEthereum/leanSpec (base main) by default rather than the personal fork, unless the user explicitly requests otherwise. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 20e192f commit 78161d4

5 files changed

Lines changed: 23 additions & 20 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ subspecifications that the Lean Ethereum protocol relies on.
2020
- Keep specs simple, readable, and clear
2121
- Repository is `leanSpec` not `lean-spec`
2222
- **Always run linter checks before finishing**: Run `just check` at the end of any code changes to ensure all linting, formatting, type checking, and spell checking passes.
23+
- **Pull requests target the main repo by default**: Unless the user explicitly says otherwise, open pull requests against the upstream main repository (`leanEthereum/leanSpec`, the `upstream` remote, base `main`) — NOT against a personal fork. Push the branch to the fork and open a cross-fork PR with `gh pr create --repo leanEthereum/leanSpec --base main --head <fork-owner>:<branch>`.
2324
- **CRITICAL - NO BACKWARD COMPATIBILITY**: This is a STRICT requirement. NEVER add backward compatibility code under any circumstances. This means:
2425
- NO legacy constants (like `KEY_TYPE_ED25519 = KeyType.ED25519`)
2526
- NO wrapper functions that delegate to new classes

src/lean_spec/node/sync/head_sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,11 @@ async def _process_cached_descendants(
300300
self.block_cache.remove(child_root)
301301

302302
# Recursively process this child's descendants.
303-
description_count, store = await self._process_cached_descendants(
303+
descendant_count, store = await self._process_cached_descendants(
304304
parent_root=child_root,
305305
store=store,
306306
)
307-
processed_count += description_count
307+
processed_count += descendant_count
308308

309309
except Exception as exception:
310310
# Processing failed. Leave in cache for retry or discard.

src/lean_spec/spec/crypto/xmss/encoding.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ def encode_message(config: XmssConfig, message: Bytes32) -> list[Fp]:
6060
6161
The bytes are read little-endian as a single integer.
6262
"""
63-
acc = int.from_bytes(message, "little")
64-
return int_to_base_p(acc, config.MESSAGE_LENGTH_FIELD_ELEMENTS)
63+
message_integer = int.from_bytes(message, "little")
64+
return int_to_base_p(message_integer, config.MESSAGE_LENGTH_FIELD_ELEMENTS)
6565

6666

6767
def encode_epoch(config: XmssConfig, epoch: Uint64) -> list[Fp]:
@@ -72,8 +72,8 @@ def encode_epoch(config: XmssConfig, epoch: Uint64) -> list[Fp]:
7272
# Layout:
7373
#
7474
# (epoch << 8) | MESSAGE_PREFIX
75-
acc = (int(epoch) << 8) | TWEAK_PREFIX_MESSAGE
76-
return int_to_base_p(acc, config.TWEAK_LENGTH_FIELD_ELEMENTS)
75+
encoded_tweak = (int(epoch) << 8) | TWEAK_PREFIX_MESSAGE
76+
return int_to_base_p(encoded_tweak, config.TWEAK_LENGTH_FIELD_ELEMENTS)
7777

7878

7979
def aborting_decode(config: XmssConfig, field_elements: list[Fp]) -> list[int] | None:
@@ -90,18 +90,18 @@ def aborting_decode(config: XmssConfig, field_elements: list[Fp]) -> list[int] |
9090
threshold = config.Q * config.BASE**config.Z
9191

9292
digits: list[int] = []
93-
for fe in field_elements:
94-
a = int(fe)
93+
for field_element in field_elements:
94+
element_value = int(field_element)
9595

9696
# The only rejection case is A_i == P - 1.
97-
if a >= threshold:
97+
if element_value >= threshold:
9898
return None
9999

100100
# Quotient by Q strips the residue.
101101
# The remainder is uniform in [0, BASE^Z - 1].
102-
d = a // config.Q
102+
quotient = element_value // config.Q
103103
for _ in range(config.Z):
104-
d, digit = divmod(d, config.BASE)
104+
quotient, digit = divmod(quotient, config.BASE)
105105
digits.append(digit)
106106

107107
return digits[: config.DIMENSION]

src/lean_spec/spec/crypto/xmss/field.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
def int_to_base_p(value: int, num_limbs: int) -> list[Fp]:
1111
"""Decompose an integer into a fixed-size list of base-P field elements."""
12-
acc = value
12+
remaining_value = value
1313
limbs: list[Fp] = []
1414
for _ in range(num_limbs):
15-
limbs.append(Fp(value=acc))
16-
acc //= P
15+
limbs.append(Fp(value=remaining_value))
16+
remaining_value //= P
1717
return limbs
1818

1919

src/lean_spec/spec/crypto/xmss/poseidon.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ def safe_domain_separator(self, lengths: list[int], capacity_length: int) -> lis
8888
A capacity vector of length capacity_length.
8989
"""
9090
# Pack all lengths into a single unambiguous integer using 32-bit slots.
91-
acc = 0
91+
packed_lengths = 0
9292
for length in lengths:
93-
acc = (acc << 32) | length
93+
packed_lengths = (packed_lengths << 32) | length
9494

9595
# Compress the decomposed vector through the width-24 engine.
9696
# Width 24 is the only mode used for sponge domain separation.
97-
input_vec = int_to_base_p(acc, 24)
97+
input_vec = int_to_base_p(packed_lengths, 24)
9898
return self.compress(input_vec, 24, capacity_length)
9999

100100
def sponge(
@@ -182,10 +182,12 @@ def tweak_hash(
182182
# Every other field sits in its own bit range above the prefix.
183183
match tweak:
184184
case TreeTweak(level=level, index=index):
185-
acc = (level << 40) | (int(index) << 8) | TWEAK_PREFIX_TREE
185+
packed_tweak = (level << 40) | (int(index) << 8) | TWEAK_PREFIX_TREE
186186
case ChainTweak(epoch=epoch, chain_index=chain_index, step=step):
187-
acc = (int(epoch) << 24) | (chain_index << 16) | (step << 8) | TWEAK_PREFIX_CHAIN
188-
encoded_tweak = int_to_base_p(acc, config.TWEAK_LENGTH_FIELD_ELEMENTS)
187+
packed_tweak = (
188+
(int(epoch) << 24) | (chain_index << 16) | (step << 8) | TWEAK_PREFIX_CHAIN
189+
)
190+
encoded_tweak = int_to_base_p(packed_tweak, config.TWEAK_LENGTH_FIELD_ELEMENTS)
189191

190192
if len(message_parts) == 1:
191193
# Hash chain step: width-16 compression of (digest || parameter || tweak).

0 commit comments

Comments
 (0)